Module: wine
Branch: master
Commit: c05973d077eed481d544e43cbfdac251831ca006
URL: https://gitlab.winehq.org/wine/wine/-/commit/c05973d077eed481d544e43cbfdac2…
Author: Zebediah Figura <zfigura(a)codeweavers.com>
Date: Sat Oct 14 21:14:20 2023 -0500
advapi32: Fix rewinding the last path segment in SetSecurityInfo().
In particular, handle the case where an object has no name.
In theory, this should not happen for regular files, but SetSecurityInfo() is
almost certainly not supposed to care about that [i.e. this code probably
belongs in the server, at the very least]. However, fixing that will require
much more work.
While we're at it, rewrite the code to be a little more idiomatic about its
intent.
---
dlls/advapi32/security.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/dlls/advapi32/security.c b/dlls/advapi32/security.c
index fd3f4b9fefc..d13fd65af78 100644
--- a/dlls/advapi32/security.c
+++ b/dlls/advapi32/security.c
@@ -2969,10 +2969,11 @@ DWORD WINAPI SetSecurityInfo(HANDLE handle, SE_OBJECT_TYPE ObjectType,
return RtlNtStatusToDosError(status);
}
- for (name_info->Name.Length-=2; name_info->Name.Length>0; name_info->Name.Length-=2)
- if (name_info->Name.Buffer[name_info->Name.Length/2-1]=='\\' ||
- name_info->Name.Buffer[name_info->Name.Length/2-1]=='/')
- break;
+ if (name_info->Name.Length && name_info->Name.Buffer[(name_info->Name.Length / 2) - 1] == '\\')
+ name_info->Name.Length -= 2;
+ while (name_info->Name.Length && name_info->Name.Buffer[(name_info->Name.Length / 2) - 1] != '\\')
+ name_info->Name.Length -= 2;
+
if (name_info->Name.Length)
{
OBJECT_ATTRIBUTES attr;