Commit 0cffcb77 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

advapi32: Fix handling of zero account and domain size parameters in LookupAccountSid.

parent 02bdbbc4
......@@ -2069,6 +2069,11 @@ LookupAccountSidA(
} else
*domainSize = domainSizeW + 1;
}
else
{
*accountSize = accountSizeW + 1;
*domainSize = domainSizeW + 1;
}
HeapFree( GetProcessHeap(), 0, systemW );
HeapFree( GetProcessHeap(), 0, accountW );
......@@ -2225,8 +2230,11 @@ LookupAccountSidW(
if (domain)
lstrcpyW(domain, dm);
}
if (((*accountSize != 0) && (*accountSize < ac_len)) ||
((*domainSize != 0) && (*domainSize < dm_len))) {
if ((*accountSize && *accountSize < ac_len) ||
(!account && !*accountSize && ac_len) ||
(*domainSize && *domainSize < dm_len) ||
(!domain && !*domainSize && dm_len))
{
SetLastError(ERROR_INSUFFICIENT_BUFFER);
status = FALSE;
}
......@@ -2238,9 +2246,10 @@ LookupAccountSidW(
*accountSize = ac_len;
else
*accountSize = ac_len + 1;
*name_use = use;
HeapFree(GetProcessHeap(), 0, account_name);
HeapFree(GetProcessHeap(), 0, computer_name);
if (status) *name_use = use;
return status;
}
......
......@@ -1505,7 +1505,7 @@ static void test_LookupAccountSid(void)
PSID pUsersSid = NULL;
SID_NAME_USE use;
BOOL ret;
DWORD size,cbti = 0;
DWORD error, size, cbti = 0;
MAX_SID max_sid;
CHAR *str_sidA;
int i;
......@@ -1667,6 +1667,16 @@ static void test_LookupAccountSid(void)
"LookupAccountSidW() Expected dom_size = %u, got %u\n",
real_dom_sizeW + 1, dom_sizeW);
acc_sizeW = dom_sizeW = use = 0;
SetLastError(0xdeadbeef);
ret = LookupAccountSidW(NULL, pUsersSid, NULL, &acc_sizeW, NULL, &dom_sizeW, &use);
error = GetLastError();
ok(!ret, "LookupAccountSidW failed %u\n", GetLastError());
ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
ok(acc_sizeW, "expected non-zero account size\n");
ok(dom_sizeW, "expected non-zero domain size\n");
ok(!use, "expected zero use %u\n", use);
FreeSid(pUsersSid);
/* Test LookupAccountSid with Sid retrieved from token information.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment