All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Daley <mattd@bugfuzz.com>
To: xen-devel@lists.xen.org
Cc: Matthew Daley <mattd@bugfuzz.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	Ian Campbell <ian.campbell@citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH 2/2] xenstore: check F_SETFL fcntl invocation in setnonblock
Date: Sat, 30 Nov 2013 13:20:05 +1300	[thread overview]
Message-ID: <1385770805-1929-3-git-send-email-mattd@bugfuzz.com> (raw)
In-Reply-To: <1385770805-1929-1-git-send-email-mattd@bugfuzz.com>

...and check the newly-added result of setnonblock itself where used.

Coverity-ID: 1055103
Signed-off-by: Matthew Daley <mattd@bugfuzz.com>
---
 tools/xenstore/xs.c |   16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
index 184886f..abac788 100644
--- a/tools/xenstore/xs.c
+++ b/tools/xenstore/xs.c
@@ -146,20 +146,17 @@ 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;
+	return fcntl(fd, F_SETFL, flags) != -1;
 }
 
 int xs_fileno(struct xs_handle *h)
@@ -369,8 +366,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 +387,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))
+				return false;
 		}
 	}
 
-- 
1.7.10.4

  parent reply	other threads:[~2013-11-30  0:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-30  0:20 Minor Coverity xenstore fixes Matthew Daley
2013-11-30  0:20 ` [PATCH 1/2] xenstore: sanity check incoming message body lengths Matthew Daley
2013-12-01 11:44   ` Andrew Cooper
2013-12-02 11:33   ` Ian Jackson
2013-12-02 11:53     ` Matthew Daley
2013-12-19 15:42       ` [PATCH 1/2] xenstore: sanity check incoming message body lengths [and 2 more messages] Ian Jackson
2013-12-19 15:51         ` Ian Campbell
2013-12-19 17:17           ` Ian Jackson
2013-11-30  0:20 ` Matthew Daley [this message]
2013-11-30  0:30   ` [PATCH 2/2 v2] xenstore: check F_SETFL fcntl invocation in setnonblock Matthew Daley
2013-12-01 11:48     ` Andrew Cooper
2013-12-02 11:36     ` Ian Jackson
2013-12-02 11:41       ` Ian Campbell
2013-12-02 12:34         ` Ian Jackson
2013-12-02 12:45           ` Matthew Daley
2013-12-13  5:55             ` Matthew Daley
2013-12-13 16:56               ` Ian Jackson
2013-11-30  1:33 ` Minor Coverity xenstore fixes Matthew Daley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1385770805-1929-3-git-send-email-mattd@bugfuzz.com \
    --to=mattd@bugfuzz.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.