[tor-commits] [tor/master] nodelist: Fix possible NULL deref

dgoulet at torproject.org dgoulet at torproject.org
Thu Jul 16 18:17:52 UTC 2020


commit aa9561164a94c7ad8d61d3fdc153fac15d98143a
Author: David Goulet <dgoulet at torproject.org>
Date:   Thu Jul 16 13:18:53 2020 -0400

    nodelist: Fix possible NULL deref
    
    Found by coverity with CID 1465290. Fix unreleased code.
    
    Fixes #40049
    
    Signed-off-by: David Goulet <dgoulet at torproject.org>
---
 src/feature/nodelist/nodelist.c | 6 ++++++
 1 file changed, 6 insertions(+)

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);
 }
 





More information about the tor-commits mailing list