Don't crash on NULL data in RegSetValueEx

Mike Hearn mh at codeweavers.com
Tue Jul 20 09:25:57 CDT 2004


I tested this on Win98. The platform SDK installer does this.

Mike Hearn <mh at codeweavers.com>
Don't crash on NULL data in RegSetValueEx

Index: dlls/advapi32/registry.c
===================================================================
RCS file: /home/wine/wine/dlls/advapi32/registry.c,v
retrieving revision 1.63
diff -u -p -r1.63 registry.c
--- dlls/advapi32/registry.c    13 Jul 2004 23:33:14 -0000      1.63
+++ dlls/advapi32/registry.c    20 Jul 2004 13:23:57 -0000
@@ -987,6 +987,8 @@ DWORD WINAPI RegSetValueExA( HKEY hkey,
     WCHAR *dataW = NULL;
     NTSTATUS status;
  
+    if (!data) return ERROR_INVALID_PARAMETER;
+
     if (!is_version_nt())  /* win95 */
     {
         if (type == REG_SZ) count = strlen(data) + 1;
@@ -1043,7 +1045,7 @@ DWORD WINAPI RegSetValueW( HKEY hkey, LP
  
     TRACE("(%p,%s,%ld,%s,%ld)\n", hkey, debugstr_w(name), type, debugstr_w(data), count );
  
-    if (type != REG_SZ) return ERROR_INVALID_PARAMETER;
+    if ((type != REG_SZ) || !data) return ERROR_INVALID_PARAMETER;
  
     if (name && name[0])  /* need to create the subkey */
     {
cvs server: Diffing dlls/advapi32/tests
Index: dlls/advapi32/tests/registry.c
===================================================================
RCS file: /home/wine/wine/dlls/advapi32/tests/registry.c,v
retrieving revision 1.7
diff -u -p -r1.7 registry.c
--- dlls/advapi32/tests/registry.c      26 Jan 2004 20:23:35 -0000      1.7
+++ dlls/advapi32/tests/registry.c      20 Jul 2004 13:23:57 -0000
@@ -67,6 +67,9 @@ static void test_enum_value(void)
     static const WCHAR testW[] = {'T','e','s','t',0};
     static const WCHAR xxxW[] = {'x','x','x','x','x','x','x','x',0};
  
+    res = RegSetValueExA( hkey_main, "Test", 0, REG_SZ, NULL, 0 );
+    ok( res == ERROR_INVALID_PARAMETER, "RegSetValueExA returned %d\n", res );
+
     res = RegSetValueExA( hkey_main, "Test", 0, REG_SZ, (BYTE *)"foobar", 7 );
     ok( res == 0, "RegSetValueExA failed error %ld\n", res );
  





More information about the wine-patches mailing list