Skip to content

Commit

Permalink
Pull in the over-allocation fix for the USER_INFO_0 structure also.
Browse files Browse the repository at this point in the history
Existing logic allocates it, then calls NetUserGetInfo which returns a
newly allocated structure containing the requested information.
So we've had 2x allocations.  We then only return one.


Signed-off-by: Bevan Weiss <[email protected]>
  • Loading branch information
bevanweiss committed Jul 13, 2024
1 parent c78704a commit 1076df1
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/ext/Util/ca/scauser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ HRESULT ScaUserExecute(
LPWSTR pwzBaseScriptKey = NULL;
DWORD cScriptKey = 0;

USER_INFO_0 *pUserInfo = NULL;
LPUSER_INFO_0 pUserInfo = NULL;
LPWSTR pwzScriptKey = NULL;
LPWSTR pwzActionData = NULL;
LPWSTR pwzRollbackData = NULL;
Expand Down Expand Up @@ -520,14 +520,10 @@ HRESULT ScaUserExecute(
// Check to see if the user already exists since we have to be very careful when adding
// and removing users. Note: MSDN says that it is safe to call these APIs from any
// user, so we should be safe calling it during immediate mode.
er = ::NetApiBufferAllocate(sizeof(USER_INFO_0), reinterpret_cast<LPVOID*>(&pUserInfo));
hr = HRESULT_FROM_WIN32(er);
ExitOnFailure(hr, "Failed to allocate memory to check existence of user: %ls", psu->wzName);

LPWSTR wzDomain = NULL;
GetDomainServerName(psu->wzDomain, &wzDomain);

er = ::NetUserGetInfo(wzDomain, psu->wzName, 0, reinterpret_cast<LPBYTE*>(pUserInfo));
er = ::NetUserGetInfo(wzDomain, psu->wzName, 0, reinterpret_cast<LPBYTE*>(&pUserInfo));
if (NERR_Success == er)
{
ueUserExists = USER_EXISTS_YES;
Expand Down

0 comments on commit 1076df1

Please sign in to comment.