aboutsummaryrefslogtreecommitdiff
path: root/src/feature/nodelist
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2020-07-16 13:18:53 -0400
committerDavid Goulet <dgoulet@torproject.org>2020-07-16 13:23:03 -0400
commitaa9561164a94c7ad8d61d3fdc153fac15d98143a (patch)
treecfc27625b33778ef73a4f19febe77d8541765274 /src/feature/nodelist
parent4b24b3628926e864220d59b9d1b8c0dd45a1d52b (diff)
downloadtor-aa9561164a94c7ad8d61d3fdc153fac15d98143a.tar.gz
tor-aa9561164a94c7ad8d61d3fdc153fac15d98143a.zip
nodelist: Fix possible NULL deref
Found by coverity with CID 1465290. Fix unreleased code. Fixes #40049 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/feature/nodelist')
-rw-r--r--src/feature/nodelist/nodelist.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/feature/nodelist/nodelist.c b/src/feature/nodelist/nodelist.c
index c2e2f53038..c30684d2d8 100644
--- a/src/feature/nodelist/nodelist.c
+++ b/src/feature/nodelist/nodelist.c
@@ -1988,6 +1988,12 @@ node_set_country(node_t *node)
else if (node->ri)
ipv4_addr = &node->ri->ipv4_addr;
+ /* IPv4 is mandatory for a relay so this should not happen unless we are
+ * attempting to set the country code on a node without a descriptor. */
+ if (BUG(!ipv4_addr)) {
+ node->country = -1;
+ return;
+ }
node->country = geoip_get_country_by_addr(ipv4_addr);
}