From 05eb30494760d1723d8fe18d902cdb9f8b9a5ab1 Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 14 Oct 2009 15:26:40 +0000 Subject: [PATCH] * ext/socket/init.c (rsock_init_sock): validate file descriptor. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25336 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ ext/socket/init.c | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/ChangeLog b/ChangeLog index fc56787c32..1e7382d71b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Thu Oct 15 00:26:07 2009 Tanaka Akira + + * ext/socket/init.c (rsock_init_sock): validate file descriptor. + Wed Oct 14 13:24:14 2009 Nobuyoshi Nakada * ruby.c (process_options): script name should not be shown in an 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;