|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 2/2 v2] 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>
---
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
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |