[PATCH] kernel32: GetPrivateProfileSectionNamesA error checking (Coverity)

Marcus Meissner marcus at jet.franken.de
Wed Jan 6 06:26:51 CST 2010


Hi,

buffer and size need to be either 0 at the same time or not,
otherwise this breaks up. Windows is inconsistent (either crashes
or returns invalids), so we can just add checking.

I added some more checks for OOM and failing A->U conversion.
(Also missing in other functions, not sure of how far we want to
push it)

Ciao, Marcus
---
 dlls/kernel32/profile.c |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/dlls/kernel32/profile.c b/dlls/kernel32/profile.c
index 26c6736..43a7fd8 100644
--- a/dlls/kernel32/profile.c
+++ b/dlls/kernel32/profile.c
@@ -1585,13 +1585,25 @@ DWORD WINAPI GetPrivateProfileSectionNamesA( LPSTR buffer, DWORD size,
 					     LPCSTR filename)
 {
     UNICODE_STRING filenameW;
-    LPWSTR bufferW;
+    LPWSTR bufferW = NULL;
     INT retW, ret = 0;
 
-    bufferW = buffer ? HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR)) : NULL;
-    if (filename) RtlCreateUnicodeStringFromAsciiz(&filenameW, filename);
-    else filenameW.Buffer = NULL;
-
+    if (size && !buffer) {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return 0;
+    }
+    if (buffer) {
+        bufferW = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
+        if (!bufferW) {
+            SetLastError(ERROR_OUTOFMEMORY);
+            return 0;
+        }
+    }
+    filenameW.Buffer = NULL;
+    if (!RtlCreateUnicodeStringFromAsciiz(&filenameW, filename)) {
+        SetLastError(ERROR_OUTOFMEMORY);
+        return 0;
+    }
     retW = GetPrivateProfileSectionNamesW(bufferW, size, filenameW.Buffer);
     if (retW && size)
     {
-- 
1.5.6



More information about the wine-patches mailing list