[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen master] xenstore: check F_SETFL fcntl invocation in setnonblock



commit 7e52bfb60520816a218c1505498298926421cd09
Author:     Matthew Daley <mattd@xxxxxxxxxxx>
AuthorDate: Tue Dec 3 01:45:16 2013 +1300
Commit:     Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
CommitDate: Fri Dec 13 16:55:12 2013 +0000

    xenstore: check F_SETFL fcntl invocation in setnonblock
    
    ...and check the newly-added result of setnonblock itself where used.
    
    Coverity-ID: 1055103
    Signed-off-by: Matthew Daley <mattd@xxxxxxxxxxx>
    Reviewed-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/xenstore/xs.c |   19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
index 261b841..f1f1b9d 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;
                }
        }
 
--
generated by git-patchbot for /home/xen/git/xen.git#master

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.