From f57d5da27792f79e9e42c9b0ca8626455a5dc94d Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 14 Oct 2009 15:26:40 +0000 Subject: * ext/socket/init.c (rsock_init_sock): validate file descriptor. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/socket/init.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ext/socket') diff --git a/ext/socket/init.c b/ext/socket/init.c index ed85e0b50..85cc3de4f 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; -- cgit