]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/commitdiff
Fix array out of bounds problem
authorStephen Hemminger <stephen.hemminger@vyatta.com>
Mon, 30 Jun 2008 17:37:28 +0000 (10:37 -0700)
committerStephen Hemminger <stephen.hemminger@vyatta.com>
Mon, 30 Jun 2008 17:37:28 +0000 (10:37 -0700)
The current kernel generates 71 possible header fields, but
MAX_FIELDS in lnstat is only 64. This leads to referencing outside
of the array. To fix, increase size of array and chop off parsing
at MAX_FIELDS - 1.

misc/lnstat.c

index b56598ab89ba22c18cc1789f69c908c2285a914c..b04e6cebfdf7b0733c14bafa9db6aabf62fa21cb 100644 (file)
@@ -17,7 +17,7 @@
  */
 
 /* Maximum number of fields that can be displayed */
-#define MAX_FIELDS             64
+#define MAX_FIELDS             128
 
 /* Maximum number of header lines */
 #define HDR_LINES              10
@@ -121,9 +121,12 @@ static int map_field_params(struct lnstat_file *lnstat_files,
                                if (!fps->params[j].print.width)
                                        fps->params[j].print.width =
                                                        FIELD_WIDTH_DEFAULT;
-                               j++;
+                               
+                               if (++j >= MAX_FIELDS - 1)
+                                       goto full;
                        }
                }
+       full:
                fps->num = j;
                return 1;
        }