diff options
author | Linus Nordberg <linus@nordu.net> | 2017-07-30 22:52:35 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2017-08-01 18:19:13 +0200 |
commit | b731b45fa8651fd3b386a96892d8e08856d5072a (patch) | |
tree | 953d3714ac187df46e14674cd40a4247cc6015b3 | |
parent | 91419d6d6622cb0b9ad09506273c091975ede9dd (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.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -160,7 +160,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; @@ -178,7 +185,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; } |