From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH 2/2 v2] xenstore: check F_SETFL fcntl invocation in setnonblock Date: Sun, 1 Dec 2013 11:48:04 +0000 Message-ID: <529B21F4.4000705@citrix.com> References: <1385770805-1929-3-git-send-email-mattd@bugfuzz.com> <1385771454-14153-1-git-send-email-mattd@bugfuzz.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1385771454-14153-1-git-send-email-mattd@bugfuzz.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: Matthew Daley , xen-devel@lists.xen.org Cc: Ian Jackson , Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org On 30/11/2013 00:30, Matthew Daley wrote: > ...and check the newly-added result of setnonblock itself where used. > > Coverity-ID: 1055103 > Signed-off-by: Matthew Daley Reviewed-by: Andrew Cooper > --- > v2: return false -> goto out_false > > 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..504d524 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)) > + goto out_false; > } > } >