4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-22 00:38:06 +08:00

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>
This commit is contained in:
Corinna Vinschen 2024-12-10 13:55:54 +01:00
parent 016ed8fba2
commit 815eba882e
2 changed files with 3 additions and 6 deletions

View File

@ -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

View File

@ -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