From: Nikolai Kondrashov Date: Tue, 9 Sep 2014 11:36:29 +0000 (+0300) Subject: dhcpclient: Verify socket timeout was set X-Git-Tag: release_3_0_5~584^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9984ca85c77282928f424127c240a4764e3dcd4f;p=thirdparty%2Ffreeradius-server.git dhcpclient: Verify socket timeout was set 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)". --- diff --git a/src/modules/proto_dhcp/dhcpclient.c b/src/modules/proto_dhcp/dhcpclient.c index bf42db9e29d..25820a7d348 100644 --- a/src/modules/proto_dhcp/dhcpclient.c +++ b/src/modules/proto_dhcp/dhcpclient.c @@ -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) {