Skip to content

Commit

Permalink
bgpd: fix res validity in rpki_create_socket
Browse files Browse the repository at this point in the history
Fix coverity scanner issue 1575912 where res pointer is supposed to
valid in:

> socket = vrf_socket(res->ai_family, ...)

but is checked for validity a few lines later.

Note that vrf_getaddrinfo returns an error code if getaddrinfo() fails
to allocate res and in this case, rpki_create_socket() returns.

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 39c8c97 commit b28fd4e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions bgpd/bgp_rpki.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "memory.h"
#include "frrevent.h"
#include "filter.h"
#include "lib_errors.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_table.h"
#include "bgp_advertise.h"
Expand Down Expand Up @@ -1332,8 +1333,11 @@ static int rpki_create_socket(void *_cache)
frr_with_privs (&bgpd_privs) {
ret = vrf_getaddrinfo(host, port, &hints, &res, vrf->vrf_id);
}
if (ret != 0)
if (ret != 0) {
flog_err_sys(EC_LIB_SOCKET, "getaddrinfo: %s",
gai_strerror(ret));
return -1;
}

frr_with_privs (&bgpd_privs) {
socket = vrf_socket(res->ai_family, res->ai_socktype,
Expand All @@ -1354,15 +1358,13 @@ static int rpki_create_socket(void *_cache)
setsockopt(socket, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));

if (connect(socket, res->ai_addr, res->ai_addrlen) == -1) {
if (res)
freeaddrinfo(res);
freeaddrinfo(res);
close(socket);
pthread_setcancelstate(cancel_state, NULL);
return -1;
}

if (res)
freeaddrinfo(res);
freeaddrinfo(res);
pthread_setcancelstate(cancel_state, NULL);

setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &prev_rcv_tmout,
Expand Down

0 comments on commit b28fd4e

Please sign in to comment.