mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 07:56:59 +00:00
- GetUserNameW: Re-set an_len to the actual buffer size before second LookupAccountSidW call; set *lpSize correctly; fix leakage of hToken in failure cases.
- GetUserNameA: Don't include nul terminator when calculating NameW.Length. Remove redundant nul termination of NameA (RtlUnicodeStringToAnsiString already does it) svn path=/trunk/; revision=35147
This commit is contained in:
parent
a75b654567
commit
a804e14f3c
1 changed files with 8 additions and 12 deletions
|
@ -739,9 +739,8 @@ GetUserNameA( LPSTR lpszName, LPDWORD lpSize )
|
|||
lpSize);
|
||||
if(Ret)
|
||||
{
|
||||
NameW.Length = (*lpSize) * sizeof(WCHAR);
|
||||
NameW.Length = (*lpSize - 1) * sizeof(WCHAR);
|
||||
RtlUnicodeStringToAnsiString(&NameA, &NameW, FALSE);
|
||||
NameA.Buffer[NameA.Length] = '\0';
|
||||
|
||||
*lpSize = NameA.Length + 1;
|
||||
}
|
||||
|
@ -791,6 +790,7 @@ GetUserNameW ( LPWSTR lpszName, LPDWORD lpSize )
|
|||
if ( !tu_buf )
|
||||
{
|
||||
SetLastError ( ERROR_NOT_ENOUGH_MEMORY );
|
||||
CloseHandle ( hToken );
|
||||
return FALSE;
|
||||
}
|
||||
if ( !GetTokenInformation ( hToken, TokenUser, tu_buf, 36, &tu_len ) || tu_len > 36 )
|
||||
|
@ -800,6 +800,7 @@ GetUserNameW ( LPWSTR lpszName, LPDWORD lpSize )
|
|||
if ( !tu_buf )
|
||||
{
|
||||
SetLastError ( ERROR_NOT_ENOUGH_MEMORY );
|
||||
CloseHandle ( hToken );
|
||||
return FALSE;
|
||||
}
|
||||
if ( !GetTokenInformation ( hToken, TokenUser, tu_buf, tu_len, &tu_len ) )
|
||||
|
@ -811,6 +812,7 @@ GetUserNameW ( LPWSTR lpszName, LPDWORD lpSize )
|
|||
return FALSE;
|
||||
}
|
||||
}
|
||||
CloseHandle ( hToken );
|
||||
token_user = (TOKEN_USER*)tu_buf;
|
||||
|
||||
an_len = *lpSize;
|
||||
|
@ -836,27 +838,21 @@ GetUserNameW ( LPWSTR lpszName, LPDWORD lpSize )
|
|||
return FALSE;
|
||||
}
|
||||
}
|
||||
an_len = *lpSize;
|
||||
if ( !LookupAccountSidW ( NULL, token_user->User.Sid, lpszName, &an_len, domain_name, &dn_len, &snu ) )
|
||||
{
|
||||
/* don't call SetLastError(),
|
||||
as LookupAccountSid() ought to have set one */
|
||||
LocalFree ( domain_name );
|
||||
CloseHandle ( hToken );
|
||||
LocalFree ( tu_buf );
|
||||
*lpSize = an_len;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
LocalFree ( domain_name );
|
||||
LocalFree ( tu_buf );
|
||||
CloseHandle ( hToken );
|
||||
|
||||
if ( an_len > *lpSize )
|
||||
{
|
||||
*lpSize = an_len;
|
||||
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*lpSize = an_len + 1;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue