advapi32: add testcases for GetNamedSecurityInfo (try 2)

Austin English austinenglish at gmail.com
Fri Apr 17 04:08:06 CDT 2009


Changelog: Fixed Paul's concerns.

-- 
-Austin
-------------- next part --------------
diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c
index 65e68ff..1611bd8 100644
--- a/dlls/advapi32/security.c
+++ b/dlls/advapi32/security.c
@@ -5066,12 +5066,11 @@ DWORD WINAPI GetNamedSecurityInfoA(LPSTR pObjectName,
     TRACE("%s %d %d %p %p %p %p %p\n", pObjectName, ObjectType, SecurityInfo,
         ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor);
 
-    if( pObjectName )
-    {
-        len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
-        wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
-        MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
-    }
+    if (!pObjectName || !ppSecurityDescriptor) return ERROR_INVALID_PARAMETER;
+
+    len = MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, NULL, 0 );
+    wstr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR));
+    MultiByteToWideChar( CP_ACP, 0, pObjectName, -1, wstr, len );
 
     r = GetNamedSecurityInfoW( wstr, ObjectType, SecurityInfo, ppsidOwner,
                            ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor );
diff --git a/dlls/advapi32/tests/security.c b/dlls/advapi32/tests/security.c
index f775d10..b85dd18 100644
--- a/dlls/advapi32/tests/security.c
+++ b/dlls/advapi32/tests/security.c
@@ -2569,6 +2569,20 @@ static void test_GetNamedSecurityInfoA(void)
     }
     ok(!error, "GetNamedSecurityInfo failed with error %d\n", error);
 
+    /* Test with a NULL ObjectName */
+    SetLastError(0xdeadbeef);
+    error = pGetNamedSecurityInfoA(NULL, SE_FILE_OBJECT,
+        OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|DACL_SECURITY_INFORMATION,
+        NULL, NULL, NULL, NULL, &pSecDesc);
+    ok(error == ERROR_INVALID_PARAMETER, "GetNamedSecurityInfoA should've returned ERROR_INVALID PARAMETER, got %d\n", error);
+
+    /* Test with a NULL descriptor */
+    SetLastError(0xdeadbeef);
+    error = pGetNamedSecurityInfoA(windows_dir, SE_FILE_OBJECT,
+        OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|DACL_SECURITY_INFORMATION,
+        NULL, NULL, NULL, NULL, NULL);
+    ok(error == ERROR_INVALID_PARAMETER, "GetNamedSecurityInfoA should've returned ERROR_INVALID PARAMETER, got %d\n", error);
+
     ret = GetSecurityDescriptorControl(pSecDesc, &control, &revision);
     ok(ret, "GetSecurityDescriptorControl failed with error %d\n", GetLastError());
     ok((control & (SE_SELF_RELATIVE|SE_DACL_PRESENT)) == (SE_SELF_RELATIVE|SE_DACL_PRESENT) ||


More information about the wine-patches mailing list