From 44fb25d66d42ef41dae6920428d17016f15121d1 Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Mon, 27 Jan 2020 19:33:01 -0600 Subject: [PATCH] advapi32-LsaLookupSids: Remove patches working around a Cygwin bug. See . There is no known current application that attempts this, and in fact simple testing shows that the assertion that "native has similar handling" is quite simply false. --- ...-a-hidden-LSA_TRUST_INFORMATION-in-L.patch | 47 ------------------- ...-a-hidden-LSA_TRUST_INFORMATION-in-L.patch | 39 --------------- patches/patchinstall.sh | 4 -- 3 files changed, 90 deletions(-) delete mode 100644 patches/advapi32-LsaLookupSids/0002-advapi32-Prepend-a-hidden-LSA_TRUST_INFORMATION-in-L.patch delete mode 100644 patches/advapi32-LsaLookupSids/0003-advapi32-Prepend-a-hidden-LSA_TRUST_INFORMATION-in-L.patch diff --git a/patches/advapi32-LsaLookupSids/0002-advapi32-Prepend-a-hidden-LSA_TRUST_INFORMATION-in-L.patch b/patches/advapi32-LsaLookupSids/0002-advapi32-Prepend-a-hidden-LSA_TRUST_INFORMATION-in-L.patch deleted file mode 100644 index d2221ef1..00000000 --- a/patches/advapi32-LsaLookupSids/0002-advapi32-Prepend-a-hidden-LSA_TRUST_INFORMATION-in-L.patch +++ /dev/null @@ -1,47 +0,0 @@ -From 246cb6b72666dcb77fb2f553d318d7dabbe8811d Mon Sep 17 00:00:00 2001 -From: Qian Hong -Date: Tue, 7 Apr 2015 13:18:47 +0800 -Subject: advapi32: Prepend a hidden LSA_TRUST_INFORMATION in LsaLookupSids to - avoid crash when Domains[-1] incorrectly accessed by application. (try 2) - ---- - dlls/advapi32/lsa.c | 10 +++++++--- - 1 file changed, 7 insertions(+), 3 deletions(-) - -diff --git a/dlls/advapi32/lsa.c b/dlls/advapi32/lsa.c -index 69c29c5..dfe25b3 100644 ---- a/dlls/advapi32/lsa.c -+++ b/dlls/advapi32/lsa.c -@@ -488,14 +488,17 @@ NTSTATUS WINAPI LsaLookupSids( - if (!(*Names = heap_alloc(name_fullsize))) return STATUS_NO_MEMORY; - /* maximum count of stored domain infos is Count, allocate it like that cause really needed - count could only be computed after sid data is retrieved */ -- domain_fullsize = sizeof(LSA_REFERENCED_DOMAIN_LIST) + sizeof(LSA_TRUST_INFORMATION)*Count; -+ domain_fullsize = sizeof(LSA_REFERENCED_DOMAIN_LIST) + sizeof(LSA_TRUST_INFORMATION) * (Count + 1); - if (!(*ReferencedDomains = heap_alloc(domain_fullsize))) - { - heap_free(*Names); - return STATUS_NO_MEMORY; - } - (*ReferencedDomains)->Entries = 0; -- (*ReferencedDomains)->Domains = (LSA_TRUST_INFORMATION*)((char*)*ReferencedDomains + sizeof(LSA_REFERENCED_DOMAIN_LIST)); -+ (*ReferencedDomains)->Domains = (LSA_TRUST_INFORMATION*)((char*)*ReferencedDomains + -+ sizeof(LSA_REFERENCED_DOMAIN_LIST) + sizeof(LSA_TRUST_INFORMATION)); -+ (*ReferencedDomains)->Domains[-1].Sid = NULL; -+ RtlInitUnicodeStringEx(&(*ReferencedDomains)->Domains[-1].Name, NULL); - - /* Get full names data length and full length needed to store domain name and SID */ - for (i = 0; i < Count; i++) -@@ -555,7 +558,8 @@ NTSTATUS WINAPI LsaLookupSids( - - *ReferencedDomains = heap_realloc(*ReferencedDomains, domain_fullsize); - /* fix pointer after reallocation */ -- (*ReferencedDomains)->Domains = (LSA_TRUST_INFORMATION*)((char*)*ReferencedDomains + sizeof(LSA_REFERENCED_DOMAIN_LIST)); -+ (*ReferencedDomains)->Domains = (LSA_TRUST_INFORMATION*)((char*)*ReferencedDomains + -+ sizeof(LSA_REFERENCED_DOMAIN_LIST) + sizeof(LSA_TRUST_INFORMATION)); - domain_data = (char*)(*ReferencedDomains)->Domains + sizeof(LSA_TRUST_INFORMATION)*Count; - - mapped = 0; --- -2.3.5 - diff --git a/patches/advapi32-LsaLookupSids/0003-advapi32-Prepend-a-hidden-LSA_TRUST_INFORMATION-in-L.patch b/patches/advapi32-LsaLookupSids/0003-advapi32-Prepend-a-hidden-LSA_TRUST_INFORMATION-in-L.patch deleted file mode 100644 index b89c63c2..00000000 --- a/patches/advapi32-LsaLookupSids/0003-advapi32-Prepend-a-hidden-LSA_TRUST_INFORMATION-in-L.patch +++ /dev/null @@ -1,39 +0,0 @@ -From ce254ac3659e0c040136341d035629f99ec6d1ea Mon Sep 17 00:00:00 2001 -From: Qian Hong -Date: Tue, 7 Apr 2015 13:19:06 +0800 -Subject: advapi32: Prepend a hidden LSA_TRUST_INFORMATION in LsaLookupNames2 - to avoid crash when Domains[-1] incorrectly accessed by application. (try 2) - ---- - dlls/advapi32/lsa.c | 10 +++++++--- - 1 file changed, 7 insertions(+), 3 deletions(-) - -diff --git a/dlls/advapi32/lsa.c b/dlls/advapi32/lsa.c -index dfe25b3..258b8ca 100644 ---- a/dlls/advapi32/lsa.c -+++ b/dlls/advapi32/lsa.c -@@ -404,14 +404,18 @@ NTSTATUS WINAPI LsaLookupNames2( LSA_HANDLE policy, ULONG flags, ULONG count, - sid = (SID *)(*sids + count); - - /* use maximum domain count */ -- if (!(*domains = heap_alloc(sizeof(LSA_REFERENCED_DOMAIN_LIST) + sizeof(LSA_TRUST_INFORMATION)*count + -- sid_size_total + domainname_size_total*sizeof(WCHAR)))) -+ if (!(*domains = heap_alloc(sizeof(LSA_REFERENCED_DOMAIN_LIST) + sizeof(LSA_TRUST_INFORMATION) * (count + 1) + -+ sid_size_total + domainname_size_total * sizeof(WCHAR)))) - { - heap_free(*sids); - return STATUS_NO_MEMORY; - } - (*domains)->Entries = 0; -- (*domains)->Domains = (LSA_TRUST_INFORMATION*)((char*)*domains + sizeof(LSA_REFERENCED_DOMAIN_LIST)); -+ (*domains)->Domains = (LSA_TRUST_INFORMATION*)((char*)*domains + -+ sizeof(LSA_REFERENCED_DOMAIN_LIST) + sizeof(LSA_TRUST_INFORMATION)); -+ (*domains)->Domains[-1].Sid = NULL; -+ RtlInitUnicodeStringEx(&(*domains)->Domains[-1].Name, NULL); -+ - domain_data = (char*)(*domains)->Domains + sizeof(LSA_TRUST_INFORMATION)*count; - - domain.Buffer = heap_alloc(domain_size_max*sizeof(WCHAR)); --- -2.3.5 - diff --git a/patches/patchinstall.sh b/patches/patchinstall.sh index 0a1169ab..8facf674 100755 --- a/patches/patchinstall.sh +++ b/patches/patchinstall.sh @@ -2225,13 +2225,9 @@ fi # | * dlls/advapi32/lsa.c, dlls/advapi32/security.c, dlls/advapi32/tests/security.c # | if test "$enable_advapi32_LsaLookupSids" -eq 1; then - patch_apply advapi32-LsaLookupSids/0002-advapi32-Prepend-a-hidden-LSA_TRUST_INFORMATION-in-L.patch - patch_apply advapi32-LsaLookupSids/0003-advapi32-Prepend-a-hidden-LSA_TRUST_INFORMATION-in-L.patch patch_apply advapi32-LsaLookupSids/0004-advapi32-Fallback-to-Sid-string-when-LookupAccountSi.patch patch_apply advapi32-LsaLookupSids/0007-advapi32-Fix-name-and-use-of-DOMAIN_GROUP_RID_USERS.patch ( - printf '%s\n' '+ { "Qian Hong", "advapi32: Prepend a hidden LSA_TRUST_INFORMATION in LsaLookupSids to avoid crash when Domains[-1] incorrectly accessed by application.", 2 },'; - printf '%s\n' '+ { "Qian Hong", "advapi32: Prepend a hidden LSA_TRUST_INFORMATION in LsaLookupNames2 to avoid crash when Domains[-1] incorrectly accessed by application.", 2 },'; printf '%s\n' '+ { "Qian Hong", "advapi32: Fallback to Sid string when LookupAccountSid fails.", 1 },'; printf '%s\n' '+ { "Qian Hong", "advapi32: Fix name and use of DOMAIN_GROUP_RID_USERS.", 1 },'; ) >> "$patchlist"