Package: apt-file
Severity: wishlist
Tags: patch

Please include improved error checks in argument parsing code.  Patch
is attached which will error on arguments such as "-n 10FOOBAR".

Also fixed is a spelling error and a grammar error.

This patch would probably conflict with:
apt-spy.inline-initializations, but I've included the necessary
renaming of the variable BESTNUMBER here.

Justin
diff -ur apt-spy-3.1/main.c apt-spy-3.1.jp6/main.c
--- apt-spy-3.1/main.c  2005-07-08 20:48:09.000000000 -0400
+++ apt-spy-3.1.jp6/main.c      2005-07-09 14:28:52.000000000 -0400
@@ -71,6 +71,7 @@
        /* Parse options... */
        while((c = getopt(argc, argv, "a:c:d:e:f:i:m:o:p:s:t:u:w:n:vh")) != -1)
                switch(c) {
+               char *end;
                /* Area to benchmark */
                case 'a':
                        area = optarg;
@@ -85,7 +86,13 @@
                        break;
                /* Number of servers to benchmark */
                case 'e':
-                       test_number = atoi(optarg);
+                       test_number = strtol(optarg, &end, 10);
+                       if (!*optarg || end!=optarg+strlen(optarg)) {
+                               fprintf(stderr, "Error parsing number"
+                                               " of servers to be"
+                                               " benchmarked\n");
+                               exit(1);
+                       }
                        break;
                /* File, relative to Debian base, to grab from server. */
                case 'f':
@@ -111,9 +118,15 @@
                case 's':
                        country_list = optarg;
                        break;
-               /* Time to bencmark each server for. */
+               /* Time for which to benchmark each server. */
                case 't':
-                       timeout = atoi(optarg);
+                       timeout = strtol(optarg, &end, 10);
+                       if (!*optarg || end!=optarg+strlen(optarg)) {
+                               fprintf(stderr, "Error parsing server"
+                                               " benchmark time"
+                                               " interval\n");
+                               exit(1);
+                       }
                        break;
                /* The URL we should update ourselves from */                   
                
                case 'u':
@@ -126,7 +139,13 @@
                        break;
                /* Number of servers to write in "top" server list */
                case 'n':
-                       BESTNUMBER = atoi(optarg);
+                       bestnumber = strtol(optarg, &end, 10);
+                       if (!*optarg || end!=optarg+strlen(optarg)) {
+                               fprintf(stderr, "Error parsing number"
+                                               " of best servers to"
+                                               " write\n");
+                               exit(1);
+                       }
                        break;
                case 'v':
                        version();

Reply via email to