diff options
author | Louis Scalbert <louis.scalbert@6wind.com> | 2024-01-23 09:51:15 +0100 |
---|---|---|
committer | Louis Scalbert <louis.scalbert@6wind.com> | 2024-01-23 13:13:13 +0100 |
commit | efdb5f144cf9c288a172498e5fa79531efcdd767 (patch) | |
tree | 90121f197ffb4f8b7e7aac33e034ff4b26ec5e06 /bgpd | |
parent | bgpd: fix memory leak in rpki_create_socket (diff) | |
download | frr-efdb5f144cf9c288a172498e5fa79531efcdd767.tar.xz frr-efdb5f144cf9c288a172498e5fa79531efcdd767.zip |
bgpd: check sockopt returns in rpki_create_socket
Check (g|s)etsockopt returns in rpki_create_socket(). Coverity scanner
issues 1575916 and 1575924.
Fixes: a951752d4a ("bgpd: create cache server socket in vrf")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
Diffstat (limited to 'bgpd')
-rw-r--r-- | bgpd/bgp_rpki.c | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c index 65f4f1e08..9604578d9 100644 --- a/bgpd/bgp_rpki.c +++ b/bgpd/bgp_rpki.c @@ -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); @@ -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; } |