Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49285 Signed-off-by: Fabian Maurer dark.shadow4@web.de
-- v3: kernel32: In WritePrivateProfileStructW prevent null pointer dereference
From: Fabian Maurer dark.shadow4@web.de
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49285 Signed-off-by: Fabian Maurer dark.shadow4@web.de --- dlls/kernel32/profile.c | 5 +++++ dlls/kernel32/tests/profile.c | 6 ++++++ 2 files changed, 11 insertions(+)
diff --git a/dlls/kernel32/profile.c b/dlls/kernel32/profile.c index e70874fa36f..bf1a9170896 100644 --- a/dlls/kernel32/profile.c +++ b/dlls/kernel32/profile.c @@ -2044,9 +2044,14 @@ BOOL WINAPI WritePrivateProfileStructW (LPCWSTR section, LPCWSTR key, LPWSTR outstring, p; DWORD sum = 0;
+ TRACE("(%s %s %p %u %s)\n", debugstr_w(section), debugstr_w(key), buf, bufsize, debugstr_w(filename)); + if (!section && !key && !buf) /* flush the cache */ return WritePrivateProfileStringW( NULL, NULL, NULL, filename );
+ if (!buf) + return WritePrivateProfileStringW(section, key, NULL, filename); + /* allocate string buffer for hex chars + checksum hex char + '\0' */ outstring = HeapAlloc( GetProcessHeap(), 0, (bufsize*2 + 2 + 1) * sizeof(WCHAR) ); p = outstring; diff --git a/dlls/kernel32/tests/profile.c b/dlls/kernel32/tests/profile.c index 71d945f81df..ae56b2d96cf 100644 --- a/dlls/kernel32/tests/profile.c +++ b/dlls/kernel32/tests/profile.c @@ -1109,6 +1109,7 @@ static void test_WritePrivateProfileString(void) static void test_profile_struct(void) { static const char expect_data[] = "[s]\r\nkey=616261637573006F\r\n"; + static const char expect_data_empty[] = "[s]\r\n"; char buffer[20]; BOOL ret;
@@ -1173,6 +1174,11 @@ static void test_profile_struct(void) ok(!ret, "expected failure\n"); todo_wine ok(GetLastError() == ERROR_BAD_LENGTH, "got error %lu\n", GetLastError());
+ /* Test deleting struct */ + ret = WritePrivateProfileStructA("s", "key", NULL, sizeof("abacus"), "./winetest.ini"); /* Must not crash */ + ok(ret, "got error %lu\n", GetLastError()); + ok(check_file_data("./winetest.ini", expect_data_empty), "file doesn't match\n"); + ret = DeleteFileA("./winetest.ini"); ok(ret, "got error %lu\n", GetLastError()); }