Source: mswatch Version: 1.2.0-2.1 Severity: important Tags: patch User: debian-...@lists.debian.org Usertags: fcntl-fd-cloexec
Hi! This package contains code that tries to set the FD_CLOEXEC flag for a file descriptor, but it does using F_SETFL instead of F_SETFD. Using that value on F_SETFL is just wrong, and might make the call fail on some systems, as it's requesting to set an undetermined flag. For example on GNU/* FD_CLOEXEC has value 1, which matches with O_WRONLY. This will cause the code to at least leak file descriptors, and at worst to terminate execution. Attached a patch fixing this. Thanks, Guillem
From e87cb8bfe4d34780902608e386c7f8a57bd134cd Mon Sep 17 00:00:00 2001 From: Guillem Jover <guil...@hadrons.org> Date: Tue, 18 Dec 2012 17:14:57 +0100 Subject: [PATCH] mswatch: Set FD_CLOEXEC correctly using F_SETFD not F_SETFL Using that value on F_SETFL is just wrong, and might make the call fail on some systems, as it's requesting to set an undetermined flag. For example on GNU/* FD_CLOEXEC has value 1, which matches with O_WRONLY. This might cause the code to at least leak file descriptors, and at worst to terminate execution. --- src/mswatch/mailstore_watcher.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mswatch/mailstore_watcher.cc b/src/mswatch/mailstore_watcher.cc index ef51a61..d148954 100644 --- a/src/mswatch/mailstore_watcher.cc +++ b/src/mswatch/mailstore_watcher.cc @@ -135,9 +135,11 @@ bool mailstore_watcher::start() die_if(1, "Expected start message '\n' from %s watcher, received '%c'\n", name, c); } - r = fcntl(from_fd, F_SETFL, O_NONBLOCK | FD_CLOEXEC); - die_if(r < 0, "fcntl(NONBLOCK | FD_CLOEXEC)"); - r = fcntl(to_fd, F_SETFL, FD_CLOEXEC); + r = fcntl(from_fd, F_SETFL, O_NONBLOCK); + die_if(r < 0, "fcntl(NONBLOCK)"); + r = fcntl(from_fd, F_SETFD, FD_CLOEXEC); + die_if(r < 0, "fcntl(FD_CLOEXEC)"); + r = fcntl(to_fd, F_SETFD, FD_CLOEXEC); die_if(r < 0, "fcntl(FD_CLOEXEC)"); return true; -- 1.8.1.rc0