aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2024-12-10 13:55:54 +0100
committerCorinna Vinschen <corinna@vinschen.de>2024-12-10 16:50:11 +0100
commit815eba882e32ecadd6862c71c36fccdcb0842a76 (patch)
tree2822d4a6bf1afcd4e0b89141d3e86197289a2900
parent016ed8fba21e3fe880c95ecaf4df0df246c8d61c (diff)
downloadnewlib-815eba882e32ecadd6862c71c36fccdcb0842a76.zip
newlib-815eba882e32ecadd6862c71c36fccdcb0842a76.tar.gz
newlib-815eba882e32ecadd6862c71c36fccdcb0842a76.tar.bz2
Cygwin: path_conv: allow NULL handle in init_reopen_attr()
init_reopen_attr() doesn't guard against a NULL handle. However, there are scenarios calling functions deliberately with a NULL handle, for instance, av::setup() calling check_file_access() only if opening the file did NOT succeed. So check for a NULL handle in init_reopen_attr() and if so, use the name based approach filling the OBJECT_ATTRIBUTES struct, just as in the has_buggy_reopen() case. Fixes: 4c9d01fdad2a ("* mount.h (class fs_info): Add has_buggy_reopen flag and accessor methods.") Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
-rw-r--r--winsup/cygwin/local_includes/path.h2
-rw-r--r--winsup/cygwin/sec/base.cc7
2 files changed, 3 insertions, 6 deletions
diff --git a/winsup/cygwin/local_includes/path.h b/winsup/cygwin/local_includes/path.h
index 3dd21d9..2a05cf4 100644
--- a/winsup/cygwin/local_includes/path.h
+++ b/winsup/cygwin/local_includes/path.h
@@ -323,7 +323,7 @@ class path_conv
}
inline POBJECT_ATTRIBUTES init_reopen_attr (OBJECT_ATTRIBUTES &attr, HANDLE h)
{
- if (has_buggy_reopen ())
+ if (!h || has_buggy_reopen ())
InitializeObjectAttributes (&attr, get_nt_native_path (),
objcaseinsensitive (), NULL, NULL)
else
diff --git a/winsup/cygwin/sec/base.cc b/winsup/cygwin/sec/base.cc
index d5e39d2..ede314f 100644
--- a/winsup/cygwin/sec/base.cc
+++ b/winsup/cygwin/sec/base.cc
@@ -62,8 +62,7 @@ get_file_sd (HANDLE fh, path_conv &pc, security_descriptor &sd,
if (!fh || !NT_SUCCESS (status))
{
status = NtOpenFile (&fh, READ_CONTROL,
- fh ? pc.init_reopen_attr (attr, fh)
- : pc.get_object_attr (attr, sec_none_nih),
+ pc.init_reopen_attr (attr, fh),
&io, FILE_SHARE_VALID_FLAGS,
FILE_OPEN_NO_RECALL
| FILE_OPEN_FOR_BACKUP_INTENT
@@ -232,9 +231,7 @@ set_file_sd (HANDLE fh, path_conv &pc, security_descriptor &sd, bool is_chown)
OBJECT_ATTRIBUTES attr;
IO_STATUS_BLOCK io;
status = NtOpenFile (&fh, (is_chown ? WRITE_OWNER : 0) | WRITE_DAC,
- fh ? pc.init_reopen_attr (attr, fh)
- : pc.get_object_attr (attr, sec_none_nih),
- &io,
+ pc.init_reopen_attr (attr, fh), &io,
FILE_SHARE_VALID_FLAGS,
FILE_OPEN_NO_RECALL
| FILE_OPEN_FOR_BACKUP_INTENT