summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2017-07-30 22:52:35 +0200
committerLinus Nordberg <linus@nordu.net>2017-08-01 18:25:36 +0200
commitd6f4fab82c4773ce0d5e7229d3d9309979acaac9 (patch)
treef400e913411e7b18e0dac6a209ad421fc5f342e0
parent011523ecf7f3fa53566c6f3066772d41c1ba84dc (diff)
Verify return code from fcntl calls.
Have connectnonblocking() warn and fail if setting O_NONBLOCK fails. Have it warn if restoring of flags fail. coverity: 1449515
-rw-r--r--util.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/util.c b/util.c
index 4cc7b8a..d9c3839 100644
--- a/util.c
+++ b/util.c
@@ -171,7 +171,14 @@ int connectnonblocking(int s, const struct sockaddr *addr, socklen_t addrlen, st
socklen_t len;
origflags = fcntl(s, F_GETFL, 0);
- fcntl(s, F_SETFL, origflags | O_NONBLOCK);
+ if (origflags == -1) {
+ debugerrno(errno, DBG_WARN, "Failed to get flags");
+ return -1;
+ }
+ if (fcntl(s, F_SETFL, origflags | O_NONBLOCK) == -1) {
+ debugerrno(errno, DBG_WARN, "Failed to set O_NONBLOCK");
+ return -1;
+ }
if (!connect(s, addr, addrlen)) {
r = 0;
goto exit;
@@ -189,7 +196,8 @@ int connectnonblocking(int s, const struct sockaddr *addr, socklen_t addrlen, st
r = 0;
exit:
- fcntl(s, F_SETFL, origflags);
+ if (fcntl(s, F_SETFL, origflags) == -1)
+ debugerrno(errno, DBG_WARN, "Failed to set original flags back");
return r;
}