summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/socket/init.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/ext/socket/init.c b/ext/socket/init.c
index ed85e0b503..85cc3de4f9 100644
--- a/ext/socket/init.c
+++ b/ext/socket/init.c
@@ -43,6 +43,12 @@ VALUE
rsock_init_sock(VALUE sock, int fd)
{
rb_io_t *fp;
+ struct stat sbuf;
+
+ if (fstat(fd, &sbuf) < 0)
+ rb_sys_fail(0);
+ if (!S_ISSOCK(sbuf.st_mode))
+ rb_raise(rb_eArgError, "not a socket file descriptor");
MakeOpenFile(sock, fp);
fp->fd = fd;