[PATCH] kernel32: GetPrivateProfileSectionNamesA handle 0 arguments (Coverity)

Marcus Meissner marcus at jet.franken.de
Fri Jan 30 14:50:17 CST 2009


Hi,

CID 519, this changes the behaviour to be more consistent with the W
version. Actually just the boundary case buf==NULL size != 0 was missing,
but this is a simpler fix.

Testcase actually also crashes with buf=NULL and size!=0 in windows, but
capture it here.

Ciao, Marcus
---
 dlls/kernel32/profile.c       |    2 ++
 dlls/kernel32/tests/profile.c |    6 ++++++
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/dlls/kernel32/profile.c b/dlls/kernel32/profile.c
index 0a36801..3c5ef1c 100644
--- a/dlls/kernel32/profile.c
+++ b/dlls/kernel32/profile.c
@@ -1654,6 +1654,8 @@ DWORD WINAPI GetPrivateProfileSectionNamesA( LPSTR buffer, DWORD size,
     LPWSTR bufferW;
     INT retW, ret = 0;
 
+    if (!buffer || !size)
+        return 0;
     bufferW = buffer ? HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR)) : NULL;
     if (filename) RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
     else filenameW.Buffer = NULL;
diff --git a/dlls/kernel32/tests/profile.c b/dlls/kernel32/tests/profile.c
index 5292c33..2880060 100644
--- a/dlls/kernel32/tests/profile.c
+++ b/dlls/kernel32/tests/profile.c
@@ -214,6 +214,12 @@ static void test_profile_sections_names(void)
     WriteFile( h, content, sizeof(content), &count, NULL);
     CloseHandle( h);
 
+    /* Check some borderline cases. Not crashing on win2k, xp and wine */
+    ret = GetPrivateProfileSectionNamesA( NULL, 0, testfile3 );
+    ok (ret == 0, "GetPrivateProfileSectionNamesA(NULL,0) returned %d instead of 0\n", ret);
+    ret = GetPrivateProfileSectionNamesA( buf, 0, testfile3 );
+    ok (ret == 0, "GetPrivateProfileSectionNamesA(buf,0) returned %d instead of 0\n", ret);
+
     /* Test with sufficiently large buffer */
     memset(buf, 0xc, sizeof(buf));
     ret = GetPrivateProfileSectionNamesA( buf, 29, testfile3 );
-- 
1.5.6



More information about the wine-patches mailing list