Skip to content

Commit

Permalink
bgpd: check sockopt returns in rpki_create_socket
Browse files Browse the repository at this point in the history
Check (g|s)etsockopt returns in rpki_create_socket(). Coverity scanner
issues 1575916 and 1575924.

Fixes: a951752 ("bgpd: create cache server socket in vrf")
Signed-off-by: Louis Scalbert <[email protected]>
  • Loading branch information
louis-6wind committed Jan 23, 2024
1 parent a1d4769 commit efdb5f1
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions bgpd/bgp_rpki.c
Original file line number Diff line number Diff line change
Expand Up @@ -1353,11 +1353,27 @@ static int rpki_create_socket(void *_cache)
timeout.tv_usec = 0;

optlen = sizeof(prev_rcv_tmout);
getsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &prev_rcv_tmout, &optlen);
getsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &prev_snd_tmout, &optlen);

setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));
ret = getsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &prev_rcv_tmout,
&optlen);
if (ret < 0)
zlog_warn("%s: failed to getsockopt SO_RCVTIMEO for socket %d",
__func__, socket);
ret = getsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &prev_snd_tmout,
&optlen);
if (ret < 0)
zlog_warn("%s: failed to getsockopt SO_SNDTIMEO for socket %d",
__func__, socket);
ret = setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &timeout,
sizeof(timeout));
if (ret < 0)
zlog_warn("%s: failed to setsockopt SO_RCVTIMEO for socket %d",
__func__, socket);

ret = setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &timeout,
sizeof(timeout));
if (ret < 0)
zlog_warn("%s: failed to setsockopt SO_SNDTIMEO for socket %d",
__func__, socket);

if (connect(socket, res->ai_addr, res->ai_addrlen) == -1) {
freeaddrinfo(res);
Expand All @@ -1369,10 +1385,17 @@ static int rpki_create_socket(void *_cache)
freeaddrinfo(res);
pthread_setcancelstate(cancel_state, NULL);

setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &prev_rcv_tmout,
sizeof(prev_rcv_tmout));
setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &prev_snd_tmout,
sizeof(prev_snd_tmout));
ret = setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &prev_rcv_tmout,
sizeof(prev_rcv_tmout));
if (ret < 0)
zlog_warn("%s: failed to setsockopt SO_RCVTIMEO for socket %d",
__func__, socket);

ret = setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &prev_snd_tmout,
sizeof(prev_snd_tmout));
if (ret < 0)
zlog_warn("%s: failed to setsockopt SO_SNDTIMEO for socket %d",
__func__, socket);

return socket;
}
Expand Down

0 comments on commit efdb5f1

Please sign in to comment.