Commit f56fe2c1 authored by Rob Shearman's avatar Rob Shearman Committed by Alexandre Julliard

advapi32: Fix ComputeStringSidSize to work with SIDs with one sub authority.

Use GetSidLengthRequired instead of computing the length in a way that won't always be correct.
parent 3f2d93b5
...@@ -3743,9 +3743,7 @@ BOOL WINAPI EnumDependentServicesW( ...@@ -3743,9 +3743,7 @@ BOOL WINAPI EnumDependentServicesW(
*/ */
static DWORD ComputeStringSidSize(LPCWSTR StringSid) static DWORD ComputeStringSidSize(LPCWSTR StringSid)
{ {
DWORD size = sizeof(SID); if (StringSid[0] == 'S' && StringSid[1] == '-') /* S-R-I(-S)+ */
if (StringSid[0] == 'S' && StringSid[1] == '-') /* S-R-I-S-S */
{ {
int ctok = 0; int ctok = 0;
while (*StringSid) while (*StringSid)
...@@ -3755,8 +3753,8 @@ static DWORD ComputeStringSidSize(LPCWSTR StringSid) ...@@ -3755,8 +3753,8 @@ static DWORD ComputeStringSidSize(LPCWSTR StringSid)
StringSid++; StringSid++;
} }
if (ctok > 3) if (ctok >= 3)
size += (ctok - 3) * sizeof(DWORD); return GetSidLengthRequired(ctok - 2);
} }
else /* String constant format - Only available in winxp and above */ else /* String constant format - Only available in winxp and above */
{ {
...@@ -3764,10 +3762,10 @@ static DWORD ComputeStringSidSize(LPCWSTR StringSid) ...@@ -3764,10 +3762,10 @@ static DWORD ComputeStringSidSize(LPCWSTR StringSid)
for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++) for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++)
if (!strncmpW(WellKnownSids[i].wstr, StringSid, 2)) if (!strncmpW(WellKnownSids[i].wstr, StringSid, 2))
size += (WellKnownSids[i].Sid.SubAuthorityCount - 1) * sizeof(DWORD); return GetSidLengthRequired(WellKnownSids[i].Sid.SubAuthorityCount);
} }
return size; return GetSidLengthRequired(0);
} }
/****************************************************************************** /******************************************************************************
...@@ -3796,7 +3794,7 @@ static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes) ...@@ -3796,7 +3794,7 @@ static BOOL ParseStringSidToSid(LPCWSTR StringSid, PSID pSid, LPDWORD cBytes)
if (StringSid[0] == 'S' && StringSid[1] == '-') /* S-R-I-S-S */ if (StringSid[0] == 'S' && StringSid[1] == '-') /* S-R-I-S-S */
{ {
DWORD i = 0, identAuth; DWORD i = 0, identAuth;
DWORD csubauth = ((*cBytes - sizeof(SID)) / sizeof(DWORD)) + 1; DWORD csubauth = ((*cBytes - GetSidLengthRequired(0)) / sizeof(DWORD));
StringSid += 2; /* Advance to Revision */ StringSid += 2; /* Advance to Revision */
pisid->Revision = atoiW(StringSid); pisid->Revision = atoiW(StringSid);
......
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