Check more setsockopt return values when binding sockets. Found by coverity

This commit is contained in:
Nick Mathewson 2012-07-26 10:39:05 -04:00
parent a1a0e67531
commit a0912e3206
2 changed files with 14 additions and 5 deletions

9
http.c
View File

@ -3825,9 +3825,12 @@ bind_socket_ai(struct evutil_addrinfo *ai, int reuse)
if (evutil_make_socket_closeonexec(fd) < 0)
goto out;
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on));
if (reuse)
evutil_make_listen_socket_reuseable(fd);
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on))<0)
goto out;
if (reuse) {
if (evutil_make_listen_socket_reuseable(fd) < 0)
goto out;
}
if (ai != NULL) {
r = bind(fd, ai->ai_addr, (ev_socklen_t)ai->ai_addrlen);

View File

@ -226,9 +226,15 @@ evconnlistener_new_bind(struct event_base *base, evconnlistener_cb cb,
}
}
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&on, sizeof(on));
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&on, sizeof(on))<0) {
evutil_closesocket(fd);
return NULL;
}
if (flags & LEV_OPT_REUSEABLE) {
evutil_make_listen_socket_reuseable(fd);
if (evutil_make_listen_socket_reuseable(fd) < 0) {
evutil_closesocket(fd);
return NULL;
}
}
if (sa) {