[PATCH v2 1/1] kernel32: In WritePrivateProfileStructW prevent null pointer dereference

Zebediah Figura zfigura at codeweavers.com
Mon May 16 12:37:15 CDT 2022


On 5/16/22 12:31, Fabian Maurer wrote:
> From: Fabian Maurer <dark.shadow4 at web.de>
> 
> Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=49285
> Signed-off-by: Fabian Maurer <dark.shadow4 at web.de>
> ---
>   dlls/kernel32/profile.c       | 5 +++++
>   dlls/kernel32/tests/profile.c | 4 ++++
>   2 files changed, 9 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..dc5beb89823 100644
> --- a/dlls/kernel32/tests/profile.c
> +++ b/dlls/kernel32/tests/profile.c
> @@ -1173,6 +1173,10 @@ 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());

Can you please test that this actually does delete the field?



More information about the wine-devel mailing list