[0.4.7][ADVAPI32] Fix crash when running advapi32:security with DPH CORE-14719
authorJoachim Henze <Joachim.Henze@reactos.org>
Fri, 4 Mar 2022 09:59:16 +0000 (10:59 +0100)
committerJoachim Henze <Joachim.Henze@reactos.org>
Fri, 4 Mar 2022 09:59:16 +0000 (10:59 +0100)
Import the following Wine commits:
79636bebbfa Michael Müller: advapi32: Set last error to ERROR_SUCCESS in GetSidIdentifierAuthority.
1d03ba76116 Hans Leidekker: advapi32: Fix parsing empty DACL/SACL security descriptor strings.
5bc2e83c7ab Hans Leidekker: advapi32: Fix size returned from ConvertStringSecurityDescriptorToSecurityDescriptor on 64-bit.

It crashed randomly only without DPH, but was crashing reliably with system-wide-DPH.

The bug in advapi32.dll was unhidden by the upgraded test in 0.4.9-dev-555-g 3c1b7834e15b652076c21d2d4ed8232d522b971a
but the bug did also affect older versions of advapi32.dll. Was just not triggered then.
So that rev is not really "guilty". And that is also the reason why I do port it back further than
releases/0.4.9, because *when using the upgraded test* I could make it crash also on
0.4.8-release-113-g5daae85 and 0.4.7-release-128-ga203b7a with system-wide-DPH-enabled.
And the fix is effective in solving the issue also there.

The fix was picked from
0.4.10-dev-219-g 95c3e17a80a6645c51d3316953e42b21e098c574
---------------
and since I do touch this module anyway, I decided to pick also the small improvements from
0.4.8-dev-272-g 7ed4c1dd03a9d82f47708538daf829e8f68f9a82 which had no JIRA-ticket.

dll/win32/advapi32/misc/dllmain.c
dll/win32/advapi32/misc/unicode.c
dll/win32/advapi32/sec/trustee.c
dll/win32/advapi32/wine/security.c

index 7959cc2..e914bc8 100644 (file)
@@ -9,7 +9,6 @@
  */
 
 #include <advapi32.h>
-WINE_DEFAULT_DEBUG_CHANNEL(advapi);
 
 extern BOOL RegInitialize(VOID);
 extern BOOL RegCleanup(VOID);
index b4e2ddb..d9cebc5 100644 (file)
@@ -10,8 +10,6 @@
 
 #include <advapi32.h>
 
-WINE_DEFAULT_DEBUG_CHANNEL(advapi);
-
 /**************************************************************************
  *  IsTextUnicode (ADVAPI32.@)
  *
index a889cc9..196cbd9 100644 (file)
@@ -6,8 +6,6 @@
  */
 
 #include <advapi32.h>
-WINE_DEFAULT_DEBUG_CHANNEL(advapi);
-
 
 /******************************************************************************
  * BuildImpersonateTrusteeA [ADVAPI32.@]
index 9b85eee..54dd595 100644 (file)
@@ -120,7 +120,9 @@ static const WELLKNOWNRID WellKnownRids[] = {
     { {'R','S'}, WinAccountRasAndIasServersSid, DOMAIN_ALIAS_RID_RAS_SERVERS },
 };
 
+#ifndef __REACTOS__
 static const SID sidWorld = { SID_REVISION, 1, { SECURITY_WORLD_SID_AUTHORITY} , { SECURITY_WORLD_RID } };
+#endif
 
 static const WCHAR SDDL_NO_READ_UP[]       = {'N','R',0};
 static const WCHAR SDDL_NO_WRITE_UP[]      = {'N','W',0};
@@ -131,13 +133,17 @@ static const WCHAR SDDL_NO_EXECUTE_UP[]    = {'N','X',0};
  */
 static const WCHAR SDDL_ACCESS_ALLOWED[]        = {'A',0};
 static const WCHAR SDDL_ACCESS_DENIED[]         = {'D',0};
+#ifndef __REACTOS__
 static const WCHAR SDDL_OBJECT_ACCESS_ALLOWED[] = {'O','A',0};
 static const WCHAR SDDL_OBJECT_ACCESS_DENIED[]  = {'O','D',0};
+#endif
 static const WCHAR SDDL_AUDIT[]                 = {'A','U',0};
 static const WCHAR SDDL_ALARM[]                 = {'A','L',0};
 static const WCHAR SDDL_MANDATORY_LABEL[]       = {'M','L',0};
+#ifndef __REACTOS__
 static const WCHAR SDDL_OBJECT_AUDIT[]          = {'O','U',0};
 static const WCHAR SDDL_OBJECT_ALARM[]          = {'O','L',0};
+#endif
 
 /*
  * SDDL ADS Rights
@@ -753,6 +759,7 @@ PSID_IDENTIFIER_AUTHORITY
 WINAPI
 GetSidIdentifierAuthority(PSID pSid)
 {
+    SetLastError(ERROR_SUCCESS);
     return RtlIdentifierAuthoritySid(pSid);
 }
 
@@ -2221,7 +2228,7 @@ static DWORD ParseAclStringFlags(LPCWSTR* StringAcl)
     DWORD flags = 0;
     LPCWSTR szAcl = *StringAcl;
 
-    while (*szAcl != '(')
+    while (*szAcl && *szAcl != '(')
     {
         if (*szAcl == 'P')
         {
@@ -2532,7 +2539,7 @@ static BOOL ParseStringAclToAcl(LPCWSTR StringAcl, LPDWORD lpdwFlags,
         pAcl->AclRevision = ACL_REVISION;
         pAcl->Sbz1 = 0;
         pAcl->AclSize = length;
-        pAcl->AceCount = acecount++;
+        pAcl->AceCount = acecount;
         pAcl->Sbz2 = 0;
     }
     return TRUE;
@@ -2543,7 +2550,6 @@ lerr:
     return FALSE;
 }
 
-
 /******************************************************************************
  * ParseStringSecurityDescriptorToSecurityDescriptor
  */
@@ -2559,7 +2565,7 @@ static BOOL ParseStringSecurityDescriptorToSecurityDescriptor(
     LPBYTE lpNext = NULL;
     DWORD len;
 
-    *cBytes = sizeof(SECURITY_DESCRIPTOR);
+    *cBytes = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
 
     tok = heap_alloc( (lstrlenW(StringSecurityDescriptor) + 1) * sizeof(WCHAR));