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

Alexandre Julliard julliard at wine.codeweavers.com
Thu Jul 19 07:59:41 CDT 2007


Module: wine
Branch: master
Commit: f56fe2c1bc9627ea4f47c2000ea7526b1b503f3c
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f56fe2c1bc9627ea4f47c2000ea7526b1b503f3c

Author: Rob Shearman <rob at codeweavers.com>
Date:   Wed Jul 18 18:06:36 2007 +0100

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.

---

 dlls/advapi32/security.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c
index b46a6f7..0f067de 100644
--- a/dlls/advapi32/security.c
+++ b/dlls/advapi32/security.c
@@ -3743,9 +3743,7 @@ BOOL WINAPI EnumDependentServicesW(
  */
 static DWORD ComputeStringSidSize(LPCWSTR StringSid)
 {
-    DWORD size = sizeof(SID);
-
-    if (StringSid[0] == 'S' && StringSid[1] == '-') /* S-R-I-S-S */
+    if (StringSid[0] == 'S' && StringSid[1] == '-') /* S-R-I(-S)+ */
     {
         int ctok = 0;
         while (*StringSid)
@@ -3755,8 +3753,8 @@ static DWORD ComputeStringSidSize(LPCWSTR StringSid)
             StringSid++;
         }
 
-        if (ctok > 3)
-            size += (ctok - 3) * sizeof(DWORD);
+        if (ctok >= 3)
+            return GetSidLengthRequired(ctok - 2);
     }
     else /* String constant format  - Only available in winxp and above */
     {
@@ -3764,10 +3762,10 @@ static DWORD ComputeStringSidSize(LPCWSTR StringSid)
 
         for (i = 0; i < sizeof(WellKnownSids)/sizeof(WellKnownSids[0]); i++)
             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)
     if (StringSid[0] == 'S' && StringSid[1] == '-') /* S-R-I-S-S */
     {
         DWORD i = 0, identAuth;
-        DWORD csubauth = ((*cBytes - sizeof(SID)) / sizeof(DWORD)) + 1;
+        DWORD csubauth = ((*cBytes - GetSidLengthRequired(0)) / sizeof(DWORD));
 
         StringSid += 2; /* Advance to Revision */
         pisid->Revision = atoiW(StringSid);




More information about the wine-cvs mailing list