]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
dhcpclient: Verify socket timeout was set
authorNikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
Tue, 9 Sep 2014 11:36:29 +0000 (14:36 +0300)
committerNikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
Tue, 9 Sep 2014 15:06:27 +0000 (18:06 +0300)
Verify the return code of setsockopt, as it may fail, in dhcpclient.c.

Coverity has reported the following error for this issue.

Error: CHECKED_RETURN (CWE-252):
freeradius-server-3.0.4rc2/src/modules/proto_dhcp/dhcpclient.c:424:
check_return: Calling function "setsockopt(sockfd, 1, 20, (char *)&tv,
16U)" without checking return value. This library function may fail and
return an error code.
freeradius-server-3.0.4rc2/src/modules/proto_dhcp/dhcpclient.c:424:
unchecked_value: No check of the return value of "setsockopt(sockfd, 1,
20, (char *)&tv, 16U)".

src/modules/proto_dhcp/dhcpclient.c

index bf42db9e29d26023b4f1a04a3786ce3a0c917b31..25820a7d34805aa403b7d02bd38ad9bd12cf30be 100644 (file)
@@ -434,7 +434,11 @@ int main(int argc, char **argv)
        struct timeval tv;
        tv.tv_sec = (time_t)timeout;
        tv.tv_usec = (uint64_t)(timeout * 1000000) - (tv.tv_sec * 1000000);
-       setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv,sizeof(struct timeval));
+       if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv,sizeof(struct timeval)) == -1) {
+               fprintf(stderr, "dhcpclient: failed setting socket timeout: %s\n",
+                       fr_syserror(errno));
+               exit(1);
+       }
        
        request->sockfd = sockfd;
        if (request->src_ipaddr.af == AF_UNSPEC) {