James Hawkins : advapi32: Request the owner and group token size instead of hardcoding the value.
Alexandre Julliard
julliard at winehq.org
Fri Jan 2 08:25:43 CST 2009
Module: wine
Branch: master
Commit: 954820d027564d9a6fa34d7f258e0781f798520b
URL: http://source.winehq.org/git/wine.git/?a=commit;h=954820d027564d9a6fa34d7f258e0781f798520b
Author: James Hawkins <truiken at gmail.com>
Date: Thu Jan 1 23:20:54 2009 -0800
advapi32: Request the owner and group token size instead of hardcoding the value.
---
dlls/advapi32/tests/security.c | 26 ++++++++++++++++++++++----
1 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/dlls/advapi32/tests/security.c b/dlls/advapi32/tests/security.c
index d521e90..0eccbaa 100644
--- a/dlls/advapi32/tests/security.c
+++ b/dlls/advapi32/tests/security.c
@@ -1870,7 +1870,8 @@ static void test_granted_access(HANDLE handle, ACCESS_MASK access,
static void test_process_security(void)
{
BOOL res;
- char owner[32], group[32];
+ PTOKEN_OWNER owner;
+ PTOKEN_PRIMARY_GROUP group;
PSID AdminSid = NULL, UsersSid = NULL;
PACL Acl = NULL;
SECURITY_DESCRIPTOR *SecurityDescriptor = NULL;
@@ -1879,7 +1880,7 @@ static void test_process_security(void)
STARTUPINFOA startup;
SECURITY_ATTRIBUTES psa;
HANDLE token, event;
- DWORD tmp;
+ DWORD size;
Acl = HeapAlloc(GetProcessHeap(), 0, 256);
res = InitializeAcl(Acl, 256, ACL_REVISION);
@@ -1900,16 +1901,31 @@ static void test_process_security(void)
return;
}
- res = GetTokenInformation( token, TokenOwner, owner, sizeof(owner), &tmp );
+ res = GetTokenInformation( token, TokenOwner, NULL, 0, &size );
+ ok(!res, "Expected failure, got %d\n", res);
+ ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
+ "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
+
+ owner = HeapAlloc(GetProcessHeap(), 0, size);
+ res = GetTokenInformation( token, TokenOwner, owner, size, &size );
ok(res, "GetTokenInformation failed with error %d\n", GetLastError());
AdminSid = ((TOKEN_OWNER*)owner)->Owner;
- res = GetTokenInformation( token, TokenPrimaryGroup, group, sizeof(group), &tmp );
+
+ res = GetTokenInformation( token, TokenPrimaryGroup, NULL, 0, &size );
+ ok(!res, "Expected failure, got %d\n", res);
+ ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
+ "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
+
+ group = HeapAlloc(GetProcessHeap(), 0, size);
+ res = GetTokenInformation( token, TokenPrimaryGroup, group, size, &size );
ok(res, "GetTokenInformation failed with error %d\n", GetLastError());
UsersSid = ((TOKEN_PRIMARY_GROUP*)group)->PrimaryGroup;
CloseHandle( token );
if (!res)
{
+ HeapFree(GetProcessHeap(), 0, group);
+ HeapFree(GetProcessHeap(), 0, owner);
HeapFree(GetProcessHeap(), 0, Acl);
return;
}
@@ -1969,6 +1985,8 @@ static void test_process_security(void)
CloseHandle( info.hProcess );
CloseHandle( info.hThread );
CloseHandle( event );
+ HeapFree(GetProcessHeap(), 0, group);
+ HeapFree(GetProcessHeap(), 0, owner);
HeapFree(GetProcessHeap(), 0, Acl);
HeapFree(GetProcessHeap(), 0, SecurityDescriptor);
}
More information about the wine-cvs
mailing list