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)".
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) {