jsoninfo: protect against a possible null-deref in ipc_print_neighbors
authorFerry Huberts <ferry.huberts@pelagic.nl>
Fri, 19 Feb 2016 12:32:43 +0000 (13:32 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Fri, 19 Feb 2016 17:00:10 +0000 (18:00 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/jsoninfo/src/olsrd_jsoninfo.c

index f854ffc..993ee2d 100644 (file)
@@ -165,7 +165,7 @@ void output_end(struct autobuf *abuf) {
 }
 
 static void ipc_print_neighbors_internal(struct autobuf *abuf, bool list_2hop) {
-  struct ipaddr_str buf1;
+  struct ipaddr_str buf1, buf2;
   struct neighbor_entry *neigh;
   struct neighbor_2_list_entry *list_2;
 
@@ -199,7 +199,7 @@ static void ipc_print_neighbors_internal(struct autobuf *abuf, bool list_2hop) {
           abuf_json_mark_object(true, true, abuf, "twoHopNeighbors");
           for (list_2 = neigh->neighbor_2_list.next; list_2 != &neigh->neighbor_2_list; list_2 = list_2->next) {
             abuf_json_mark_array_entry(true, abuf);
-            abuf_json_string(abuf, "ipAddress", olsr_ip_to_string(&buf1, &list_2->neighbor_2->neighbor_2_addr));
+            abuf_json_string(abuf, "ipAddress", list_2->neighbor_2 ? olsr_ip_to_string(&buf2, &list_2->neighbor_2->neighbor_2_addr) : "");
             abuf_json_mark_array_entry(false, abuf);
           }
           abuf_json_mark_object(false, true, abuf, false);