advapi32: LookupAccountSid buffer size query fixes.
This commit is contained in:
parent
759e645794
commit
39b77ec560
|
@ -1827,8 +1827,8 @@ LookupAccountSidA(
|
||||||
LPWSTR systemW = NULL;
|
LPWSTR systemW = NULL;
|
||||||
LPWSTR accountW = NULL;
|
LPWSTR accountW = NULL;
|
||||||
LPWSTR domainW = NULL;
|
LPWSTR domainW = NULL;
|
||||||
DWORD accountSizeW = *accountSize * sizeof(WCHAR);
|
DWORD accountSizeW = *accountSize;
|
||||||
DWORD domainSizeW = *domainSize * sizeof(WCHAR);
|
DWORD domainSizeW = *domainSize;
|
||||||
|
|
||||||
TRACE("(%s,sid=%s,%p,%p(%lu),%p,%p(%lu),%p)\n",
|
TRACE("(%s,sid=%s,%p,%p(%lu),%p,%p(%lu),%p)\n",
|
||||||
debugstr_a(system),debugstr_sid(sid),
|
debugstr_a(system),debugstr_sid(sid),
|
||||||
|
@ -1838,22 +1838,30 @@ LookupAccountSidA(
|
||||||
|
|
||||||
if (system) {
|
if (system) {
|
||||||
len = MultiByteToWideChar( CP_ACP, 0, system, -1, NULL, 0 );
|
len = MultiByteToWideChar( CP_ACP, 0, system, -1, NULL, 0 );
|
||||||
systemW = HeapAlloc( GetProcessHeap(), 0, (len+1)*sizeof(WCHAR) );
|
systemW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
||||||
MultiByteToWideChar( CP_ACP, 0, system, -1, systemW, len );
|
MultiByteToWideChar( CP_ACP, 0, system, -1, systemW, len );
|
||||||
}
|
}
|
||||||
accountW = HeapAlloc( GetProcessHeap(), 0, accountSizeW );
|
if (account)
|
||||||
domainW = HeapAlloc( GetProcessHeap(), 0, domainSizeW );
|
accountW = HeapAlloc( GetProcessHeap(), 0, accountSizeW * sizeof(WCHAR) );
|
||||||
|
if (domain)
|
||||||
|
domainW = HeapAlloc( GetProcessHeap(), 0, domainSizeW * sizeof(WCHAR) );
|
||||||
|
|
||||||
r = LookupAccountSidW(systemW, sid, accountW, &accountSizeW, domainW, &domainSizeW, name_use );
|
r = LookupAccountSidW( systemW, sid, accountW, &accountSizeW, domainW, &domainSizeW, name_use );
|
||||||
|
|
||||||
if (r) {
|
if (r) {
|
||||||
len = WideCharToMultiByte( CP_ACP, 0, accountW, -1, NULL, 0, NULL, NULL );
|
if (accountW && *accountSize) {
|
||||||
WideCharToMultiByte( CP_ACP, 0, accountW, -1, account, len, NULL, NULL );
|
len = WideCharToMultiByte( CP_ACP, 0, accountW, -1, NULL, 0, NULL, NULL );
|
||||||
*accountSize = len;
|
WideCharToMultiByte( CP_ACP, 0, accountW, -1, account, len, NULL, NULL );
|
||||||
|
*accountSize = len;
|
||||||
|
} else
|
||||||
|
*accountSize = accountSizeW;
|
||||||
|
|
||||||
len = WideCharToMultiByte( CP_ACP, 0, domainW, -1, NULL, 0, NULL, NULL );
|
if (domainW && *domainSize) {
|
||||||
WideCharToMultiByte( CP_ACP, 0, domainW, -1, domain, len, NULL, NULL );
|
len = WideCharToMultiByte( CP_ACP, 0, domainW, -1, NULL, 0, NULL, NULL );
|
||||||
*domainSize = len;
|
WideCharToMultiByte( CP_ACP, 0, domainW, -1, domain, len, NULL, NULL );
|
||||||
|
*domainSize = len;
|
||||||
|
} else
|
||||||
|
*domainSize = domainSizeW;
|
||||||
}
|
}
|
||||||
|
|
||||||
HeapFree( GetProcessHeap(), 0, systemW );
|
HeapFree( GetProcessHeap(), 0, systemW );
|
||||||
|
@ -1988,17 +1996,25 @@ LookupAccountSidW(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dm) {
|
if (dm) {
|
||||||
*accountSize = strlenW(ac)+1;
|
BOOL status = TRUE;
|
||||||
if (account && (*accountSize > strlenW(ac)))
|
if (*accountSize > lstrlenW(ac)) {
|
||||||
strcpyW(account, ac);
|
if (account)
|
||||||
|
lstrcpyW(account, ac);
|
||||||
*domainSize = strlenW(dm)+1;
|
}
|
||||||
if (domain && (*domainSize > strlenW(dm)))
|
if (*domainSize > lstrlenW(dm)) {
|
||||||
strcpyW(domain,dm);
|
if (domain)
|
||||||
|
lstrcpyW(domain, dm);
|
||||||
|
}
|
||||||
|
if (((*accountSize != 0) && (*accountSize < strlenW(ac))) ||
|
||||||
|
((*domainSize != 0) && (*domainSize < strlenW(dm)))) {
|
||||||
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
status = FALSE;
|
||||||
|
}
|
||||||
|
*domainSize = strlenW(dm) + 1;
|
||||||
|
*accountSize = strlenW(ac) + 1;
|
||||||
*name_use = use;
|
*name_use = use;
|
||||||
HeapFree(GetProcessHeap(), 0, computer_name);
|
HeapFree(GetProcessHeap(), 0, computer_name);
|
||||||
return TRUE;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(), 0, computer_name);
|
HeapFree(GetProcessHeap(), 0, computer_name);
|
||||||
|
|
Loading…
Reference in New Issue