From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matthew Daley Subject: [PATCH 2/2 v2] xenstore: check F_SETFL fcntl invocation in setnonblock Date: Tue, 3 Dec 2013 01:45:16 +1300 Message-ID: <1385988316-32707-1-git-send-email-mattd@bugfuzz.com> References: <21148.32357.871173.774555@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <21148.32357.871173.774555@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Andrew Cooper , Matthew Daley , Ian Jackson , Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org ...and check the newly-added result of setnonblock itself where used. Coverity-ID: 1055103 Signed-off-by: Matthew Daley --- v2: Use a constant value for the final setnonblock return, instead of a side-effecting expression tools/xenstore/xs.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c index 184886f..a636498 100644 --- a/tools/xenstore/xs.c +++ b/tools/xenstore/xs.c @@ -146,20 +146,20 @@ struct xs_handle { static int read_message(struct xs_handle *h, int nonblocking); -static void setnonblock(int fd, int nonblock) { - int esave = errno; +static bool setnonblock(int fd, int nonblock) { int flags = fcntl(fd, F_GETFL); if (flags == -1) - goto out; + return false; if (nonblock) flags |= O_NONBLOCK; else flags &= ~O_NONBLOCK; - fcntl(fd, F_SETFL, flags); -out: - errno = esave; + if (fcntl(fd, F_SETFL, flags) == -1) + return false; + + return true; } int xs_fileno(struct xs_handle *h) @@ -369,8 +369,8 @@ static bool read_all(int fd, void *data, unsigned int len, int nonblocking) if (!len) return true; - if (nonblocking) - setnonblock(fd, 1); + if (nonblocking && !setnonblock(fd, 1)) + return false; while (len) { int done; @@ -390,8 +390,9 @@ static bool read_all(int fd, void *data, unsigned int len, int nonblocking) len -= done; if (nonblocking) { - setnonblock(fd, 0); nonblocking = 0; + if (!setnonblock(fd, 0)) + goto out_false; } } -- 1.7.10.4