txtinfo: avoid a potential null deref in routes
authorFerry Huberts <ferry.huberts@pelagic.nl>
Sat, 20 Feb 2016 10:58:31 +0000 (11:58 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Sun, 21 Feb 2016 12:23:40 +0000 (13:23 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/txtinfo/src/olsrd_txtinfo.c

index dd7c426..84e075e 100644 (file)
@@ -235,13 +235,15 @@ void ipc_print_routes(struct autobuf *abuf) {
     struct ipaddr_str nexthopAddr;
     struct lqtextbuffer costbuffer;
 
-    abuf_appendf(abuf, "%s/%d\t%s\t%d\t%s\t%s\t\n",
-      olsr_ip_to_string(&dstAddr, &rt->rt_dst.prefix),
-      rt->rt_dst.prefix_len,
-      olsr_ip_to_string(&nexthopAddr, &rt->rt_best->rtp_nexthop.gateway),
-      rt->rt_best->rtp_metric.hops,
-      get_linkcost_text(rt->rt_best->rtp_metric.cost, true, &costbuffer),
-      if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
+    if (rt->rt_best) {
+      abuf_appendf(abuf, "%s/%d\t%s\t%d\t%s\t%s\t\n",
+        olsr_ip_to_string(&dstAddr, &rt->rt_dst.prefix),
+        rt->rt_dst.prefix_len,
+        olsr_ip_to_string(&nexthopAddr, &rt->rt_best->rtp_nexthop.gateway),
+        rt->rt_best->rtp_metric.hops,
+        get_linkcost_text(rt->rt_best->rtp_metric.cost, true, &costbuffer),
+        if_ifwithindex_name(rt->rt_best->rtp_nexthop.iif_index));
+    }
   } OLSR_FOR_ALL_RT_ENTRIES_END(rt);
   abuf_puts(abuf, "\n");
 }