]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: if_lookup_by_name should be more robust to null argument
authorPaul Jakma <paul@quagga.net>
Thu, 6 Aug 2009 11:08:50 +0000 (12:08 +0100)
committerPaul Jakma <paul@quagga.net>
Fri, 28 Aug 2009 13:51:18 +0000 (14:51 +0100)
* if.c: (if_lookup_by_name) shouldn't crash just cause we got a NULL name

lib/if.c

index ecf9ff904dbe2f47d61f3bf54488bdc50c4af732..e31071164cbceba91e635348dea12b7488763422 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -205,7 +205,8 @@ ifname2ifindex (const char *name)
 {
   struct interface *ifp;
 
-  return ((ifp = if_lookup_by_name(name)) != NULL) ? ifp->ifindex : 0;
+  return ((ifp = if_lookup_by_name(name)) != NULL) ? ifp->ifindex
+                                                   : IFINDEX_INTERNAL;
 }
 
 /* Interface existance check by interface name. */
@@ -214,12 +215,13 @@ if_lookup_by_name (const char *name)
 {
   struct listnode *node;
   struct interface *ifp;
-
-  for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
-    {
-      if (strcmp(name, ifp->name) == 0)
-       return ifp;
-    }
+  
+  if (name)
+    for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
+      {
+        if (strcmp(name, ifp->name) == 0)
+          return ifp;
+      }
   return NULL;
 }