From c166dbdad665e720068ab5b10cd74b5b09e76c45 Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Sun, 9 Feb 2014 21:03:17 +0100 Subject: [PATCH] Add additional error checking in IO on fcntl calls --- vm/builtin/io.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/vm/builtin/io.cpp b/vm/builtin/io.cpp index 7b9cc96728..5ebc9ae85b 100644 --- a/vm/builtin/io.cpp +++ b/vm/builtin/io.cpp @@ -122,7 +122,10 @@ namespace rubinius { void IO::new_open_fd(STATE, native_int new_fd) { if(new_fd > 2) { - fcntl(new_fd, F_SETFD, fcntl(new_fd, F_GETFD) | FD_CLOEXEC); + int flags = fcntl(new_fd, F_GETFD); + if(flags == -1) Exception::errno_error(state, "fcntl(2) failed"); + flags = fcntl(new_fd, F_SETFD, fcntl(new_fd, F_GETFD) | FD_CLOEXEC); + if(flags == -1) Exception::errno_error(state, "fcntl(2) failed"); } update_max_fd(state, new_fd); } @@ -1356,14 +1359,15 @@ namespace rubinius { void IO::set_nonblock(STATE) { #ifdef F_GETFL int flags = fcntl(descriptor_->to_native(), F_GETFL); - if(flags == -1) return; + if(flags == -1) Exception::errno_error(state, "fcntl(2) failed"); #else int flags = 0; #endif if((flags & O_NONBLOCK) == 0) { flags |= O_NONBLOCK; - fcntl(descriptor_->to_native(), F_SETFL, flags); + flags = fcntl(descriptor_->to_native(), F_SETFL, flags); + if(flags == -1) Exception::errno_error(state, "fcntl(2) failed"); } }