diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c index 832e6faa9a..3c2665494e 100644 --- a/dlls/advapi32/security.c +++ b/dlls/advapi32/security.c @@ -3833,6 +3833,7 @@ static BOOL ParseStringAclToAcl(LPCWSTR StringAcl, LPDWORD lpdwFlags, return TRUE; lerr: + SetLastError(ERROR_INVALID_ACL); WARN("Invalid ACE string format\n"); return FALSE; } @@ -4025,6 +4026,11 @@ BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorW( SetLastError(ERROR_CALL_NOT_IMPLEMENTED); goto lend; } + else if (!StringSecurityDescriptor || !SecurityDescriptor) + { + SetLastError(ERROR_INVALID_PARAMETER); + goto lend; + } else if (StringSDRevision != SID_REVISION) { SetLastError(ERROR_UNKNOWN_REVISION); @@ -4476,7 +4482,6 @@ BOOL WINAPI ConvertStringSidToSidW(LPCWSTR StringSid, PSID* Sid) if (!bret) LocalFree(*Sid); } - TRACE("returning %s\n", bret ? "TRUE" : "FALSE"); return bret; } @@ -4502,7 +4507,6 @@ BOOL WINAPI ConvertStringSidToSidA(LPCSTR StringSid, PSID* Sid) bret = ConvertStringSidToSidW(wStringSid, Sid); HeapFree(GetProcessHeap(), 0, wStringSid); } - TRACE("returning %s\n", bret ? "TRUE" : "FALSE"); return bret; } diff --git a/dlls/advapi32/tests/security.c b/dlls/advapi32/tests/security.c index 45c8fd5fcc..f0d7adef54 100644 --- a/dlls/advapi32/tests/security.c +++ b/dlls/advapi32/tests/security.c @@ -81,6 +81,8 @@ typedef BOOL (WINAPI *fnConvertSidToStringSidA)( PSID pSid, LPSTR *str ); typedef BOOL (WINAPI *fnConvertStringSidToSidA)( LPCSTR str, PSID pSid ); static BOOL (WINAPI *pConvertStringSecurityDescriptorToSecurityDescriptorA)(LPCSTR, DWORD, PSECURITY_DESCRIPTOR*, PULONG ); +static BOOL (WINAPI *pConvertStringSecurityDescriptorToSecurityDescriptorW)(LPCWSTR, DWORD, + PSECURITY_DESCRIPTOR*, PULONG ); static BOOL (WINAPI *pConvertSecurityDescriptorToStringSecurityDescriptorA)(PSECURITY_DESCRIPTOR, DWORD, SECURITY_INFORMATION, LPSTR *, PULONG ); typedef BOOL (WINAPI *fnGetFileSecurityA)(LPCSTR, SECURITY_INFORMATION, @@ -144,6 +146,8 @@ static void init(void) pAddAuditAccessAceEx = (void *)GetProcAddress(hmod, "AddAuditAccessAceEx"); pConvertStringSecurityDescriptorToSecurityDescriptorA = (void *)GetProcAddress(hmod, "ConvertStringSecurityDescriptorToSecurityDescriptorA" ); + pConvertStringSecurityDescriptorToSecurityDescriptorW = + (void *)GetProcAddress(hmod, "ConvertStringSecurityDescriptorToSecurityDescriptorW" ); pConvertSecurityDescriptorToStringSecurityDescriptorA = (void *)GetProcAddress(hmod, "ConvertSecurityDescriptorToStringSecurityDescriptorA" ); pCreateWellKnownSid = (fnCreateWellKnownSid)GetProcAddress( hmod, "CreateWellKnownSid" ); @@ -2175,6 +2179,7 @@ static void test_ConvertStringSecurityDescriptor(void) { BOOL ret; PSECURITY_DESCRIPTOR pSD; + static const WCHAR Blank[] = { 0 }; if (!pConvertStringSecurityDescriptorToSecurityDescriptorA) { @@ -2255,11 +2260,51 @@ static void test_ConvertStringSecurityDescriptor(void) SetLastError(0xdeadbeef); ret = pConvertStringSecurityDescriptorToSecurityDescriptorA( "D:(A;;ROB;;;WD)", SDDL_REVISION_1, &pSD, NULL); - todo_wine ok(!ret && GetLastError() == ERROR_INVALID_ACL, "ConvertStringSecurityDescriptorToSecurityDescriptor should have failed with ERROR_INVALID_ACL instead of %d\n", GetLastError()); + /* test behaviour with NULL parameters */ + SetLastError(0xdeadbeef); + ret = pConvertStringSecurityDescriptorToSecurityDescriptorA( + NULL, 0xdeadbeef, &pSD, NULL); + todo_wine + ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, + "ConvertStringSecurityDescriptorToSecurityDescriptor should have failed with ERROR_INVALID_PARAMETER instead of %d\n", + GetLastError()); + + SetLastError(0xdeadbeef); + ret = pConvertStringSecurityDescriptorToSecurityDescriptorW( + NULL, 0xdeadbeef, &pSD, NULL); + ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, + "ConvertStringSecurityDescriptorToSecurityDescriptor should have failed with ERROR_INVALID_PARAMETER instead of %d\n", + GetLastError()); + + SetLastError(0xdeadbeef); + ret = pConvertStringSecurityDescriptorToSecurityDescriptorA( + "D:(A;;ROB;;;WD)", 0xdeadbeef, NULL, NULL); + ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, + "ConvertStringSecurityDescriptorToSecurityDescriptor should have failed with ERROR_INVALID_PARAMETER instead of %d\n", + GetLastError()); + + SetLastError(0xdeadbeef); + ret = pConvertStringSecurityDescriptorToSecurityDescriptorA( + "D:(A;;ROB;;;WD)", SDDL_REVISION_1, NULL, NULL); + ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, + "ConvertStringSecurityDescriptorToSecurityDescriptor should have failed with ERROR_INVALID_PARAMETER instead of %d\n", + GetLastError()); + + /* test behaviour with empty strings */ + SetLastError(0xdeadbeef); + ret = pConvertStringSecurityDescriptorToSecurityDescriptorA( + "", SDDL_REVISION_1, &pSD, NULL); + ok(ret, "ConvertStringSecurityDescriptorToSecurityDescriptor failed with error %d\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = pConvertStringSecurityDescriptorToSecurityDescriptorW( + Blank, SDDL_REVISION_1, &pSD, NULL); + ok(ret, "ConvertStringSecurityDescriptorToSecurityDescriptor failed with error %d\n", GetLastError()); + /* test ACE string SID */ SetLastError(0xdeadbeef); ret = pConvertStringSecurityDescriptorToSecurityDescriptorA(