From db1ff3b932fba5679de5580ffb26fb1949456456 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 27 Aug 2014 09:39:44 +0000 Subject: [PATCH] * ntea.cc (read_ea): Change left-over return to __leave. Fix condition to close handle. Call NtClose rather than CloseHandle. (write_ea): Fix condition to close handle. Call NtClose rather than CloseHandle. * security.cc (get_file_sd): Call pc.init_reopen_attr if a valid incoming handle was given, pc.get_object_attr otherwise. (set_file_sd): Ditto. --- winsup/cygwin/ChangeLog | 10 ++++++++++ winsup/cygwin/ntea.cc | 10 +++++----- winsup/cygwin/security.cc | 21 +++++++++++---------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index e6b835a10..2df627c09 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,13 @@ +2014-08-27 Corinna Vinschen + + * ntea.cc (read_ea): Change left-over return to __leave. Fix + condition to close handle. Call NtClose rather than CloseHandle. + (write_ea): Fix condition to close handle. Call NtClose rather than + CloseHandle. + * security.cc (get_file_sd): Call pc.init_reopen_attr if a valid + incoming handle was given, pc.get_object_attr otherwise. + (set_file_sd): Ditto. + 2014-08-26 Corinna Vinschen * path.h (path_conv::init_reopen_attr): Change from void to returning diff --git a/winsup/cygwin/ntea.cc b/winsup/cygwin/ntea.cc index b5851c410..9e18fa77d 100644 --- a/winsup/cygwin/ntea.cc +++ b/winsup/cygwin/ntea.cc @@ -101,7 +101,7 @@ read_ea (HANDLE hdl, path_conv &pc, const char *name, char *value, size_t size) if ((nlen = strlen (name)) >= MAX_EA_NAME_LEN) { set_errno (EINVAL); - return -1; + __leave; } glen = sizeof (FILE_GET_EA_INFORMATION) + nlen; gea = (PFILE_GET_EA_INFORMATION) alloca (glen); @@ -225,8 +225,8 @@ read_ea (HANDLE hdl, path_conv &pc, const char *name, char *value, size_t size) } __except (EFAULT) {} __endtry - if (!hdl) - CloseHandle (h); + if (!hdl && h) + NtClose (h); debug_printf ("%d = read_ea(%S, %s, %p, %lu)", ret, attr.ObjectName, name, value, size); return ret; @@ -360,8 +360,8 @@ write_ea (HANDLE hdl, path_conv &pc, const char *name, const char *value, } __except (EFAULT) {} __endtry - if (!hdl) - CloseHandle (h); + if (!hdl && h) + NtClose (h); debug_printf ("%d = write_ea(%S, %s, %p, %lu, %d)", ret, attr.ObjectName, name, value, size, flags); return ret; diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc index 8cee7e58b..becc3fef6 100644 --- a/winsup/cygwin/security.cc +++ b/winsup/cygwin/security.cc @@ -39,7 +39,7 @@ LONG get_file_sd (HANDLE fh, path_conv &pc, security_descriptor &sd, bool justcreated) { - NTSTATUS status; + NTSTATUS status = STATUS_SUCCESS; OBJECT_ATTRIBUTES attr; IO_STATUS_BLOCK io; ULONG len = SD_MAXIMUM_SIZE, rlen; @@ -56,20 +56,19 @@ get_file_sd (HANDLE fh, path_conv &pc, security_descriptor &sd, status = NtQuerySecurityObject (fh, ALL_SECURITY_INFORMATION, sd, len, &rlen); if (!NT_SUCCESS (status)) - { - debug_printf ("NtQuerySecurityObject (%S), status %y", - pc.get_nt_native_path (), status); - fh = NULL; - } + debug_printf ("NtQuerySecurityObject (%S), status %y", + pc.get_nt_native_path (), status); } /* If the handle was NULL, or fetching with the original handle didn't work, try to reopen the file with READ_CONTROL and fetch the security descriptor using that handle. */ - if (!fh) + if (!fh || !NT_SUCCESS (status)) { status = NtOpenFile (&fh, READ_CONTROL, - pc.init_reopen_attr (attr, fh), &io, - FILE_SHARE_VALID_FLAGS, FILE_OPEN_FOR_BACKUP_INTENT); + fh ? pc.init_reopen_attr (attr, fh) + : pc.get_object_attr (attr, sec_none_nih), + &io, FILE_SHARE_VALID_FLAGS, + FILE_OPEN_FOR_BACKUP_INTENT); if (!NT_SUCCESS (status)) { sd.free (); @@ -216,7 +215,9 @@ 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, - pc.init_reopen_attr (attr, fh), &io, + fh ? pc.init_reopen_attr (attr, fh) + : pc.get_object_attr (attr, sec_none_nih), + &io, FILE_SHARE_VALID_FLAGS, FILE_OPEN_FOR_BACKUP_INTENT); if (!NT_SUCCESS (status))