diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2007-08-21 15:37:10 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2007-08-21 15:37:10 +0000 |
commit | 2e9fe498f27316f6b91ecf4540ca3c2c64f959c5 (patch) | |
tree | 153ce64ca295fa2e2b6b74e09735f7f86d0a99d5 | |
parent | f5f0ae3e262d87de3097b79291cb349e65dc234d (diff) | |
download | newlib-2e9fe498f27316f6b91ecf4540ca3c2c64f959c5.zip newlib-2e9fe498f27316f6b91ecf4540ca3c2c64f959c5.tar.gz newlib-2e9fe498f27316f6b91ecf4540ca3c2c64f959c5.tar.bz2 |
* fhandler_disk_file.cc (fhandler_base::fstat_helper): Rewrite checking
for executable file magic using a thread safe method and re-enable this
code.
-rw-r--r-- | winsup/cygwin/ChangeLog | 6 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_disk_file.cc | 40 |
2 files changed, 23 insertions, 23 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index f1caebe..0db674f 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,11 @@ 2007-08-21 Corinna Vinschen <corinna@vinschen.de> + * fhandler_disk_file.cc (fhandler_base::fstat_helper): Rewrite checking + for executable file magic using a thread safe method and re-enable this + code. + +2007-08-21 Corinna Vinschen <corinna@vinschen.de> + * syscalls.cc (unlink_nt): Drop one local FILE_BASIC_INFORMATION struct. 2007-08-21 Corinna Vinschen <corinna@vinschen.de> diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 164e9a0..c7c5d9f 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -570,37 +570,31 @@ fhandler_base::fstat_helper (struct __stat64 *buf, else { buf->st_mode |= S_IFREG; -#if 0 - /* FIXME: Is this code really necessary? There are already - two places in path_conv which look for executability. - Also, by using the fhandler's io HANDLE, a stat call might - change the file position for a short period of time in - a not thread-safe way. */ if (pc.exec_state () == dont_know_if_executable) { - DWORD cur, done; - LONG curhigh = 0; - char magic[3]; - - /* First retrieve current position, set to beginning - of file if not already there. */ - cur = SetFilePointer (get_handle (), 0, &curhigh, FILE_CURRENT); - if ((cur != INVALID_SET_FILE_POINTER || GetLastError () == NO_ERROR) - && ((!cur && !curhigh) || SetFilePointer (get_handle (), 0, NULL, FILE_BEGIN) - != INVALID_SET_FILE_POINTER)) - { - /* FIXME should we use /etc/magic ? */ - magic[0] = magic[1] = magic[2] = '\0'; - if (ReadFile (get_handle (), magic, 3, &done, NULL) - && has_exec_chars (magic, done)) + UNICODE_STRING same; + OBJECT_ATTRIBUTES attr; + HANDLE h; + IO_STATUS_BLOCK io; + + RtlInitUnicodeString (&same, L""); + InitializeObjectAttributes (&attr, &same, 0, get_handle (), NULL); + if (NT_SUCCESS (NtOpenFile (&h, FILE_READ_DATA, &attr, &io, + FILE_SHARE_VALID_FLAGS, 0))) + { + LARGE_INTEGER off = { QuadPart:0LL }; + char magic[3]; + + if (NT_SUCCESS (NtReadFile (h, NULL, NULL, NULL, &io, magic, + 3, &off, NULL)) + && has_exec_chars (magic, io.Information)) { pc.set_exec (); buf->st_mode |= STD_XBITS; } - SetFilePointer (get_handle (), cur, &curhigh, FILE_BEGIN); + NtClose (h); } } -#endif } if (pc.exec_state () == is_executable) buf->st_mode |= STD_XBITS; |