jsoninfo: protect abuf_json_ip_address against a NULL IP address
authorFerry Huberts <ferry.huberts@pelagic.nl>
Fri, 19 Feb 2016 12:25:23 +0000 (13:25 +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_helpers.c

index 23d3b1e..6d35a5d 100644 (file)
@@ -153,9 +153,17 @@ void abuf_json_float(struct autobuf *abuf, const char* key, double value) {
   entrynumber[currentjsondepth]++;
 }
 
+static const char * empty = "";
+
 void abuf_json_ip_address(struct autobuf *abuf, const char* key, union olsr_ip_addr *ip) {
   struct ipaddr_str ipStr;
-  const char * value = olsr_ip_to_string(&ipStr, ip);
+  const char * value;
+
+  if (!ip) {
+    value = empty;
+  } else {
+    value = olsr_ip_to_string(&ipStr, ip);
+  }
 
   abuf_json_insert_comma(abuf);
   abuf_json_new_indent(abuf);