Hi,

I'm running FreeBSD 8.1 and started using Bird 1.2.5 for the first time today, but it kept finding interfaces with garbled names, eg.

Jan 7 20:10:23 <daemon.debug> soek bird: WUG < interface bridge0^B^KM- \xf8L\xf8 goes up Jan 7 20:10:23 <daemon.debug> soek bird: WUG < primary address 172.18.87.128/28 on interface bridge0^B^KM- \xf8L\xf8 added

On closer inspection I think I've discovered a problem in sysdep/bsd/krt-sock.c in that it fails to use dl->sdl_nlen when extracting the interface name from dl->sdl_data. According to <net/if_dl.h> the interface name in sdl_data does not require null termination.

Possible patch attached.  Could someone review this please?


Thanks,
Aragon
--- sysdep/bsd/krt-sock.c.orig  2011-01-07 22:56:18.000000000 +0200
+++ sysdep/bsd/krt-sock.c       2011-01-07 23:06:19.000000000 +0200
@@ -418,7 +418,6 @@
   struct sockaddr_dl *dl = NULL;
   unsigned int i;
   struct iface *iface = NULL, f;
-  char *ifname = "(none)";
   int fl = ifm->ifm_flags;
 
   for(i = 1; i!=0; i <<= 1)
@@ -440,18 +439,18 @@
     return;
   }
 
-  if(dl) ifname = dl->sdl_data;
-
   iface = if_find_by_index(ifm->ifm_index);
 
   if(!iface)
   {
     /* New interface */
     if(!dl) return;    /* No interface name, ignoring */
-    DBG("New interface \"%s\" found", ifname);
     bzero(&f, sizeof(f));
     f.index = ifm->ifm_index;
-    strncpy(f.name, ifname, sizeof(f.name) -1);
+    strncpy(f.name, dl->sdl_data, sizeof(f.name) -1);
+    i = (dl->sdl_nlen >= sizeof(f.name) ? sizeof(f.name)-1 : dl->sdl_nlen);
+    f.name[i] = 0;
+    DBG("New interface \"%s\" found", f.name);
   }
   else
   {

Reply via email to