Module: wine Branch: master Commit: 39b77ec560f2e2d8fd2c89d33e3ba384c7757a15 URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=39b77ec560f2e2d8fd2c89d3...
Author: Robert Reif reif@earthlink.net Date: Sat Aug 19 09:16:05 2006 -0400
advapi32: LookupAccountSid buffer size query fixes.
---
dlls/advapi32/security.c | 58 +++++++++++++++++++++++++++++----------------- 1 files changed, 37 insertions(+), 21 deletions(-)
diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c index 4c55f56..2ac1758 100644 --- a/dlls/advapi32/security.c +++ b/dlls/advapi32/security.c @@ -1827,8 +1827,8 @@ LookupAccountSidA( LPWSTR systemW = NULL; LPWSTR accountW = NULL; LPWSTR domainW = NULL; - DWORD accountSizeW = *accountSize * sizeof(WCHAR); - DWORD domainSizeW = *domainSize * sizeof(WCHAR); + DWORD accountSizeW = *accountSize; + DWORD domainSizeW = *domainSize;
TRACE("(%s,sid=%s,%p,%p(%lu),%p,%p(%lu),%p)\n", debugstr_a(system),debugstr_sid(sid), @@ -1838,22 +1838,30 @@ LookupAccountSidA(
if (system) { 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 ); } - accountW = HeapAlloc( GetProcessHeap(), 0, accountSizeW ); - domainW = HeapAlloc( GetProcessHeap(), 0, domainSizeW ); + if (account) + 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) { - len = WideCharToMultiByte( CP_ACP, 0, accountW, -1, NULL, 0, NULL, NULL ); - WideCharToMultiByte( CP_ACP, 0, accountW, -1, account, len, NULL, NULL ); - *accountSize = len; + if (accountW && *accountSize) { + len = WideCharToMultiByte( CP_ACP, 0, accountW, -1, NULL, 0, NULL, NULL ); + 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 ); - WideCharToMultiByte( CP_ACP, 0, domainW, -1, domain, len, NULL, NULL ); - *domainSize = len; + if (domainW && *domainSize) { + len = WideCharToMultiByte( CP_ACP, 0, domainW, -1, NULL, 0, NULL, NULL ); + WideCharToMultiByte( CP_ACP, 0, domainW, -1, domain, len, NULL, NULL ); + *domainSize = len; + } else + *domainSize = domainSizeW; }
HeapFree( GetProcessHeap(), 0, systemW ); @@ -1988,17 +1996,25 @@ LookupAccountSidW( }
if (dm) { - *accountSize = strlenW(ac)+1; - if (account && (*accountSize > strlenW(ac))) - strcpyW(account, ac); - - *domainSize = strlenW(dm)+1; - if (domain && (*domainSize > strlenW(dm))) - strcpyW(domain,dm); - + BOOL status = TRUE; + if (*accountSize > lstrlenW(ac)) { + if (account) + lstrcpyW(account, ac); + } + if (*domainSize > lstrlenW(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; HeapFree(GetProcessHeap(), 0, computer_name); - return TRUE; + return status; }
HeapFree(GetProcessHeap(), 0, computer_name);