* dtable.cc (dtable::init_std_file_from_handle): Attempt stronger detection of

invalid handle.
(handle_to_fn): Detect pathological condition where NT resets the buffer
pointer to NULL on an invalid handle.
This commit is contained in:
Christopher Faylor
2002-05-29 05:15:43 +00:00
parent 654783b62f
commit cef6955910
2 changed files with 63 additions and 45 deletions

View File

@ -1,3 +1,10 @@
2002-05-29 Christopher Faylor <cgf@redhat.com>
* dtable.cc (dtable::init_std_file_from_handle): Attempt stronger
detection of invalid handle.
(handle_to_fn): Detect pathological condition where NT resets the
buffer pointer to NULL on an invalid handle.
2002-05-28 Christopher Faylor <cgf@redhat.com> 2002-05-28 Christopher Faylor <cgf@redhat.com>
* fhandler_disk_file.cc (fhandler_disk_file::fstat_helper): Properly * fhandler_disk_file.cc (fhandler_disk_file::fstat_helper): Properly

View File

@ -217,7 +217,7 @@ cygwin_attach_handle_to_fd (char *name, int fd, HANDLE handle, mode_t bin,
void void
dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess) dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess)
{ {
int bin; int bin = 0;
const char *name; const char *name;
CONSOLE_SCREEN_BUFFER_INFO buf; CONSOLE_SCREEN_BUFFER_INFO buf;
struct sockaddr sa; struct sockaddr sa;
@ -229,12 +229,12 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess)
if (!not_open (fd)) if (!not_open (fd))
return; return;
if (!handle || handle == INVALID_HANDLE_VALUE) SetLastError (0);
DWORD ft = GetFileType (handle);
if (ft == FILE_TYPE_UNKNOWN && GetLastError () == ERROR_INVALID_HANDLE)
name = NULL;
else
{ {
fds[fd] = NULL;
return;
}
if (__fmode) if (__fmode)
bin = __fmode; bin = __fmode;
else else
@ -258,7 +258,7 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess)
name = "/dev/conin"; name = "/dev/conin";
bin = 0; bin = 0;
} }
else if (GetFileType (handle) == FILE_TYPE_PIPE) else if (ft == FILE_TYPE_PIPE)
{ {
if (fd == 0) if (fd == 0)
name = "/dev/piper"; name = "/dev/piper";
@ -273,11 +273,17 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess)
name = "/dev/ttyS0"; // FIXME - determine correct device name = "/dev/ttyS0"; // FIXME - determine correct device
else else
name = handle_to_fn (handle, (char *) alloca (MAX_PATH + 100)); name = handle_to_fn (handle, (char *) alloca (MAX_PATH + 100));
}
if (!name)
fds[fd] = NULL;
else
{
path_conv pc; path_conv pc;
build_fhandler_from_name (fd, name, handle, pc)->init (handle, myaccess, bin); build_fhandler_from_name (fd, name, handle, pc)->init (handle, myaccess, bin);
set_std_handle (fd); set_std_handle (fd);
paranoid_printf ("fd %d, handle %p", fd, handle); paranoid_printf ("fd %d, handle %p", fd, handle);
}
} }
fhandler_base * fhandler_base *
@ -736,6 +742,11 @@ handle_to_fn (HANDLE h, char *posix_fn)
ntfn->Name.Buffer = (WCHAR *) ntfn + 1; ntfn->Name.Buffer = (WCHAR *) ntfn + 1;
DWORD res = NtQueryObject (h, ObjectNameInformation, ntfn, sizeof (fnbuf), NULL); DWORD res = NtQueryObject (h, ObjectNameInformation, ntfn, sizeof (fnbuf), NULL);
// NT seems to do this on an unopened file
if (!ntfn->Name.Buffer)
return NULL;
if (res) if (res)
{ {
strcpy (posix_fn, "some disk file"); strcpy (posix_fn, "some disk file");