]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospfd: Fix crash with usage of incorrect command
authorDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 9 Sep 2016 16:41:35 +0000 (12:41 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 9 Sep 2016 18:53:24 +0000 (14:53 -0400)
Entering 'show ip ospf interface json' causes ospf
to crash.

Entering 'show ip ospf interface <intf> json' causes
ospf to crash if intf has no neighbors on the otherside

Modify the code to not crash in these cases.

Ticket: CM-12776
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Reviewed-by: Daniel Walton <dwalton@cumulusnetworks.com>
ospfd/ospf_vty.c

index 264249b4c0f571c337b39fdbce40f0fc35f41c6b..1b26c678667dd6dca3683b2418cb86b79a15c704 100644 (file)
@@ -3871,7 +3871,13 @@ show_ip_ospf_interface_sub (struct vty *vty, struct ospf *ospf, struct interface
             {
               struct timeval result;
               unsigned long time_store = 0;
-              result = tv_sub (oi->t_hello->u.sands, recent_relative_time());
+             if (oi->t_hello)
+               result = tv_sub (oi->t_hello->u.sands, recent_relative_time());
+             else
+               {
+                 result.tv_sec = 0;
+                 result.tv_usec = 0;
+               }
               time_store = (1000 * result.tv_sec) + (result.tv_usec / 1000);
               json_object_int_add(json_interface_sub, "timerHelloInMsecs", time_store);
             }
@@ -3933,20 +3939,29 @@ show_ip_ospf_interface_common (struct vty *vty, struct ospf *ospf, int argc,
           if (ospf_oi_count(ifp))
             {
               show_ip_ospf_interface_sub (vty, ospf, ifp, json_interface_sub, use_json);
+             if (use_json)
+               json_object_object_add (json, ifp->name, json_interface_sub);
             }
         }
     }
   else if (argv[iface_argv] && strcmp(argv[iface_argv], "json") == 0)
     {
+      if (!use_json)
+       {
+         json = json_object_new_object();
+         json_interface_sub = json_object_new_object ();
+         use_json = 1;
+       }
       /* Show All Interfaces. */
       for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
         {
           if (ospf_oi_count(ifp))
             {
               show_ip_ospf_interface_sub (vty, ospf, ifp, json_interface_sub, use_json);
-              json_object_object_add(json, ifp->name, json_interface_sub);
-            }
-        }
+             if (use_json)
+               json_object_object_add(json, ifp->name, json_interface_sub);
+           }
+       }
     }
   else
     {