Commit f391e9cf authored by Fabian Maurer's avatar Fabian Maurer Committed by Alexandre Julliard

kernel32: Prevent null pointer dereference in WritePrivateProfileStructW.

parent 65954db2
...@@ -2044,9 +2044,14 @@ BOOL WINAPI WritePrivateProfileStructW (LPCWSTR section, LPCWSTR key, ...@@ -2044,9 +2044,14 @@ BOOL WINAPI WritePrivateProfileStructW (LPCWSTR section, LPCWSTR key,
LPWSTR outstring, p; LPWSTR outstring, p;
DWORD sum = 0; 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 */ if (!section && !key && !buf) /* flush the cache */
return WritePrivateProfileStringW( NULL, NULL, NULL, filename ); return WritePrivateProfileStringW( NULL, NULL, NULL, filename );
if (!buf)
return WritePrivateProfileStringW(section, key, NULL, filename);
/* allocate string buffer for hex chars + checksum hex char + '\0' */ /* allocate string buffer for hex chars + checksum hex char + '\0' */
outstring = HeapAlloc( GetProcessHeap(), 0, (bufsize*2 + 2 + 1) * sizeof(WCHAR) ); outstring = HeapAlloc( GetProcessHeap(), 0, (bufsize*2 + 2 + 1) * sizeof(WCHAR) );
p = outstring; p = outstring;
......
...@@ -1109,6 +1109,7 @@ static void test_WritePrivateProfileString(void) ...@@ -1109,6 +1109,7 @@ static void test_WritePrivateProfileString(void)
static void test_profile_struct(void) static void test_profile_struct(void)
{ {
static const char expect_data[] = "[s]\r\nkey=616261637573006F\r\n"; static const char expect_data[] = "[s]\r\nkey=616261637573006F\r\n";
static const char expect_data_empty[] = "[s]\r\n";
char buffer[20]; char buffer[20];
BOOL ret; BOOL ret;
...@@ -1173,6 +1174,11 @@ static void test_profile_struct(void) ...@@ -1173,6 +1174,11 @@ static void test_profile_struct(void)
ok(!ret, "expected failure\n"); ok(!ret, "expected failure\n");
todo_wine ok(GetLastError() == ERROR_BAD_LENGTH, "got error %lu\n", GetLastError()); todo_wine ok(GetLastError() == ERROR_BAD_LENGTH, "got error %lu\n", GetLastError());
/* Test deleting struct */
ret = WritePrivateProfileStructA("s", "key", NULL, sizeof("abacus"), "./winetest.ini");
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"); ret = DeleteFileA("./winetest.ini");
ok(ret, "got error %lu\n", GetLastError()); ok(ret, "got error %lu\n", GetLastError());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment