Package: bwm
Version: 1.1.0-8
Severity: normal
tags: patch

Try greating an interface with a name of over 11 characters -> funny
stuff on the screen. Here's a patch.

Matthew W. S. Bell
diff -ruN bwm-1.1.0/bwm.c bwm-1.1.0.new/bwm.c
--- bwm-1.1.0/bwm.c	2006-12-24 06:13:09.000000000 +0000
+++ bwm-1.1.0.new/bwm.c	2006-12-24 06:20:16.000000000 +0000
@@ -20,12 +20,14 @@
 #include <unistd.h>
 
 #include <sys/time.h>
+#include <net/if.h>
+#include <linux/stringify.h>
 
 #define MAX_INTERFACES 16
 
 struct interface_info
 {
-  char name[12];
+  char name[IF_NAMESIZE + 1];
 
   unsigned long tx_bytes_old;
   unsigned long rx_bytes_old;
@@ -99,7 +101,7 @@
       oldinum = inum;
     }
     printf("Bandwidth Monitor 1.1.0\n\n");
-    printf("       Iface        RX(KB/sec)   TX(KB/sec)   Total(KB/sec)\n\n");
+    printf("%" __stringify(IF_NAMESIZE) "s        RX(KB/sec)   TX(KB/sec)   Total(KB/sec)\n\n", "Interface");
 
     inum = -1;
 
@@ -126,7 +128,8 @@
       {
         buffer_pointer = buffer;
         buffer_pointer = strtok(buffer_pointer, " :");
-        strncpy(interface[inum].name, buffer_pointer, 11);
+	memset(interface[inum].name, 0, sizeof(interface[inum].name));
+        strncpy(interface[inum].name, buffer_pointer, IF_NAMESIZE);
 
         field_number = 0;
 
@@ -194,7 +197,7 @@
    
         if(!first_pass)
         {
-          printf("%12s     %8lu.%03u %8lu.%03u    %8lu.%03u\n", 
+          printf("%" __stringify(IF_NAMESIZE) "s     %8lu.%03u %8lu.%03u    %8lu.%03u\n", 
             interface[inum].name,
              interface[inum].rx_rate_whole, interface[inum].rx_rate_part, 
               interface[inum].tx_rate_whole, interface[inum].tx_rate_part, 
@@ -245,7 +248,8 @@
 
     if(!first_pass)
     {
-      printf("\n       Total     %8lu.%03u %8lu.%03u    %8lu.%03u\n\n",
+      printf("\n%" __stringify(IF_NAMESIZE) "s     %8lu.%03u %8lu.%03u    %8lu.%03u\n\n",
+       "Total",
        rx_bw_total_whole, rx_bw_total_part,
         tx_bw_total_whole, tx_bw_total_part,
          tot_bw_total_whole, tot_bw_total_part);

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to