summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 80c9f748ba..872fcd013c 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;
@@ -4434,6 +4438,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;
@@ -4686,6 +4694,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;