net: Add check for failure of setsockopt()
authorDavid Gibson <david@gibson.dropbear.id.au>
Sun, 2 Apr 2017 15:15:53 +0000 (01:15 +1000)
committerDavid Gibson <david@gibson.dropbear.id.au>
Wed, 5 Apr 2017 05:56:33 +0000 (15:56 +1000)
make_listen_fd() didn't check for failure of setsockopt().  There's no
real reason not to, since we have an obvious way to report an error to the
caller.

Found with Coverity Scan.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
ccan/net/net.c

index e9199839936e85aebb93b0bcd486669b150d73da..11c6b670aa456809f528c0eb6d905d2cb3c0b5bb 100644 (file)
@@ -238,7 +238,9 @@ static int make_listen_fd(const struct addrinfo *addrinfo)
        if (fd < 0)
                return -1;
 
-       setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
+       if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0)
+               goto fail;
+
        if (bind(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) != 0)
                goto fail;