diff options
| author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-05 09:14:12 +0000 |
|---|---|---|
| committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-05 09:14:12 +0000 |
| commit | 6350e4a368fc555bdadbdba77f28c8675da2e8f5 (patch) | |
| tree | 43e5f86618daf31b3639afaedf5d217f141708ce | |
| parent | 692f21b7fedaa45fb2c4386904fa0dfe0537903f (diff) | |
| download | ruby-6350e4a368fc555bdadbdba77f28c8675da2e8f5.tar.gz ruby-6350e4a368fc555bdadbdba77f28c8675da2e8f5.tar.xz ruby-6350e4a368fc555bdadbdba77f28c8675da2e8f5.zip | |
* win32/win32.c (rb_w32_read, rb_w32_write, rb_w32_isatty): check
whether fd is valid.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@20540 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 5 | ||||
| -rw-r--r-- | win32/win32.c | 12 |
2 files changed, 17 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Fri Dec 5 18:13:56 2008 NAKAMURA Usaku <usa@ruby-lang.org> + + * win32/win32.c (rb_w32_read, rb_w32_write, rb_w32_isatty): check + whether fd is valid. + Thu Dec 4 23:31:12 2008 NAKAMURA Usaku <usa@ruby-lang.org> * win32/win32.c (waitpid): fix bug of checking child slot. diff --git a/win32/win32.c b/win32/win32.c index 5829e86d6..eb062f5c0 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -4316,6 +4316,10 @@ rb_w32_read(int fd, void *buf, size_t size) if (is_socket(sock)) return rb_w32_recv(fd, buf, size, 0); + // validate fd by using _get_osfhandle() because we cannot access _nhandle + if (_get_osfhandle(fd) == -1) { + return -1; + } if (!(_osfile(fd) & FOPEN)) { errno = EBADF; return -1; @@ -4430,6 +4434,10 @@ rb_w32_write(int fd, const void *buf, size_t size) if (is_socket(sock)) return rb_w32_send(fd, buf, size, 0); + // validate fd by using _get_osfhandle() because we cannot access _nhandle + if (_get_osfhandle(fd) == -1) { + return -1; + } if (!(_osfile(fd) & FOPEN)) { errno = EBADF; return -1; @@ -4682,6 +4690,10 @@ rb_w32_unlink(const char *path) int rb_w32_isatty(int fd) { + // validate fd by using _get_osfhandle() because we cannot access _nhandle + if (_get_osfhandle(fd) == -1) { + return 0; + } if (!(_osfile(fd) & FOPEN)) { errno = EBADF; return 0; |
