]> git.puffer.fish Git - matthieu/frr.git/commitdiff
2005-04-02 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
authorajs <ajs>
Sun, 3 Apr 2005 03:40:52 +0000 (03:40 +0000)
committerajs <ajs>
Sun, 3 Apr 2005 03:40:52 +0000 (03:40 +0000)
* if_ioctl.c: (interface_list_ioctl) Use if_get_by_name_len.
* if_proc.c: (ifaddr_proc_ipv6) Increase size of ifname buffer to
  avoid overflow.
* kernel_socket.c: (ifan_read) Use if_get_by_name_len.
* if.h: Fix comments to reflect that if_lookup_by_name and
  if_get_by_name now require the argument strings to be NUL-terminated.
* if.c: (if_lookup_by_name) Compare using strcmp.
  (if_get_by_name) Pass strlen(ifname) as 2nd arg to if_create.

lib/ChangeLog
lib/if.c
lib/if.h
zebra/ChangeLog
zebra/if_ioctl.c
zebra/if_proc.c
zebra/kernel_socket.c

index f55578e6d7e47b0f29d2bdad5a945b71e4070573..6701a90de63b568f80de7b1ba632cb4ebe6d4171 100644 (file)
@@ -1,3 +1,10 @@
+2005-04-02 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
+
+       * if.h: Fix comments to reflect that if_lookup_by_name and
+         if_get_by_name now require the argument strings to be NUL-terminated.
+       * if.c: (if_lookup_by_name) Compare using strcmp.
+         (if_get_by_name) Pass strlen(ifname) as 2nd arg to if_create.
+
 2005-04-02 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
 
        * if.c: (if_nametoindex) The man page is rather vague, but it seems
index a32cee0e5b30a9d9997c53f7db0b1c35ea65ad28..dbf4f20276426e6ebda9edf2e92215f9e4d338a6 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -219,9 +219,7 @@ if_lookup_by_name (const char *name)
   for (node = listhead (iflist); node; nextnode (node))
     {
       ifp = getdata (node);
-      /* Change this to strcmp once improper uses of this function
-         have been replaced with calls to if_lookup_by_name_len. */
-      if (strncmp (name, ifp->name, sizeof ifp->name) == 0)
+      if (strcmp(name, ifp->name) == 0)
        return ifp;
     }
   return NULL;
@@ -335,10 +333,8 @@ if_get_by_name (const char *name)
 {
   struct interface *ifp;
 
-  /* Replace 2nd arg to if_create with strlen(name) once improper uses of
-     this function have been replaced with calls to if_get_by_name_len. */
   return ((ifp = if_lookup_by_name(name)) != NULL) ? ifp :
-        if_create(name, INTERFACE_NAMSIZ);
+        if_create(name, strlen(name));
 }
 
 struct interface *
index 4cfc9e77b7ca7cf0aeed52f6fd3275aa88b8fa60..6946865cb9b170df4c7ec4a6ece0aa0df49553b5 100644 (file)
--- a/lib/if.h
+++ b/lib/if.h
@@ -217,20 +217,17 @@ struct interface *if_lookup_by_index (unsigned int);
 struct interface *if_lookup_exact_address (struct in_addr);
 struct interface *if_lookup_address (struct in_addr);
 
-/* Currently, the code assumes that the interface name arguments to these
-   functions have length <= INTERFACE_NAMSIZ, and they must be NUL-terminated
-   if they are shorter than INTERFACE_NAMSIZ.  After code cleanup, the
-   implementation will be changed to require the arguments to these functions
-   to terminate with a NUL character (no length limitation). */
-struct interface *if_lookup_by_name (const char *);
-struct interface *if_get_by_name (const char *);
-
-/* For these 2 functions, the 2nd argument should be the precise length
-   of the interface name (not counting a trailing NUL which may or may
-   not be present). */
-extern struct interface *if_lookup_by_name_len(const char *name,
+/* These 2 functions are to be used when the ifname argument is terminated
+   by a '\0' character: */
+struct interface *if_lookup_by_name (const char *ifname);
+struct interface *if_get_by_name (const char *ifname);
+
+/* For these 2 functions, the namelen argument should be the precise length
+   of the ifname string (not counting any optional trailing '\0' character).
+   In most cases, strnlen should be used to calculate the namelen value. */
+extern struct interface *if_lookup_by_name_len(const char *ifname,
                                               size_t namelen);
-extern struct interface *if_get_by_name_len(const char *name, size_t namelen);
+extern struct interface *if_get_by_name_len(const char *ifname, size_t namelen);
 
 
 /* Delete the interface, but do not free the structure, and leave it in the
index 924f0f0a6638f430abb9b9a5a156e8a5f0365bc8..1d0f1754893d8de69fb211e69d59a4fdcf29b973 100644 (file)
@@ -1,3 +1,10 @@
+2005-04-02 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
+
+       * if_ioctl.c: (interface_list_ioctl) Use if_get_by_name_len.
+       * if_proc.c: (ifaddr_proc_ipv6) Increase size of ifname buffer to
+         avoid overflow.
+       * kernel_socket.c: (ifan_read) Use if_get_by_name_len.
+
 2005-04-02 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
 
        * kernel_socket.c: (ifm_read) Use new if_lookup_by_name_len function
index 90f18e28e0f7a074daec5e0cc3494140a9110e94..0d7713db93ff1d1e59d30389bcc52e1ba4288903 100644 (file)
@@ -102,7 +102,9 @@ interface_list_ioctl ()
       int size;
 
       ifreq = (struct ifreq *)((caddr_t) ifconf.ifc_req + n);
-      ifp = if_get_by_name (ifreq->ifr_name);
+      ifp = if_get_by_name_len(ifreq->ifr_name,
+                              strnlen(ifreq->ifr_name,
+                                      sizeof(ifreq->ifr_name)));
       if_add_update (ifp);
       size = ifreq->ifr_addr.sa_len;
       if (size < sizeof (ifreq->ifr_addr))
@@ -113,7 +115,9 @@ interface_list_ioctl ()
 #else
   for (n = 0; n < ifconf.ifc_len; n += sizeof(struct ifreq))
     {
-      ifp = if_get_by_name (ifreq->ifr_name);
+      ifp = if_get_by_name_len(ifreq->ifr_name,
+                              strnlen(ifreq->ifr_name,
+                                      sizeof(ifreq->ifr_name)));
       if_add_update (ifp);
       ifreq++;
     }
index 504d2f3c05ab222d8a2ae8c0abb8c62798f24110..3257d03cfae0953be68fd318bd10d1921da034e1 100644 (file)
@@ -212,7 +212,7 @@ ifaddr_proc_ipv6 ()
   char buf[PROCBUFSIZ];
   int n;
   char addr[33];
-  char ifname[20];
+  char ifname[21];
   int ifindex, plen, scope, status;
   struct interface *ifp;
   struct prefix_ipv6 p;
index 121256302ce6763db208b27eadfbc3519b44dbd1..c1f785d46f86989f61fd92e426ce4f8dcc35e520 100644 (file)
@@ -201,7 +201,9 @@ ifan_read (struct if_announcemsghdr *ifan)
   if (ifp == NULL && ifan->ifan_what == IFAN_ARRIVAL)
     {
       /* Create Interface */
-      ifp = if_get_by_name (ifan->ifan_name);
+      ifp = if_get_by_name_len(ifan->ifan_name,
+                              strnlen(ifan->ifan_name,
+                                      sizeof(ifan->ifan_name)));
       ifp->ifindex = ifan->ifan_index;
 
       if_add_update (ifp);