Hi,

change atoi(3) -> strtonum(3) in lpr(1) and lprm(1).
lprm(1) avoids negative numbers to be the first argument by using getopt(3),
but supported values like 2.2.

--F.


Index: lpr/lpr.c
===================================================================
RCS file: /cvs/src/usr.sbin/lpr/lpr/lpr.c,v
retrieving revision 1.48
diff -u -p -r1.48 lpr.c
--- lpr/lpr.c   9 Feb 2015 23:00:14 -0000       1.48
+++ lpr/lpr.c   25 Sep 2015 12:08:57 -0000
@@ -112,6 +112,7 @@ main(int argc, char **argv)
        char buf[PATH_MAX];
        int i, f, ch;
        struct stat stb;
+       const char *errstr;
 
        /*
         * Simulate setuid daemon w/ PRIV_END called.
@@ -145,11 +146,11 @@ main(int argc, char **argv)
                switch (ch) {
 
                case '#':               /* n copies */
-                       if (isdigit((unsigned char)*optarg)) {
-                               i = atoi(optarg);
-                               if (i > 0)
-                                       ncopies = i;
-                       }
+                       i = strtonum(optarg, 0, INT_MAX, &errstr);
+                       if (errstr)
+                               errx(1, "invalid quantity number");
+                       if (i > 0)
+                               ncopies = i;
                        break;
 
                case '4':               /* troff fonts */
@@ -203,7 +204,9 @@ main(int argc, char **argv)
 
                case 'i':               /* indent output */
                        iflag++;
-                       indent = atoi(optarg);
+                       indent = strtonum(optarg, 0, INT_MAX, &errstr);
+                       if (errstr)
+                               errx(1, "invalid number");
                        if (indent < 0)
                                indent = 8;
                        break;
Index: lprm/lprm.c
===================================================================
RCS file: /cvs/src/usr.sbin/lpr/lprm/lprm.c,v
retrieving revision 1.21
diff -u -p -r1.21 lprm.c
--- lprm/lprm.c 16 Jan 2015 06:40:18 -0000      1.21
+++ lprm/lprm.c 25 Sep 2015 12:08:57 -0000
@@ -77,8 +77,9 @@ main(int argc, char **argv)
 {
        struct passwd *pw;
        char *cp;
+       const char *errstr;
        long l;
-       int ch;
+       int ch, i;
 
        /*
         * Simulate setuid daemon w/ PRIV_END called.
@@ -135,7 +136,10 @@ main(int argc, char **argv)
                if (isdigit((unsigned char)*argv[0])) {
                        if (requests >= MAXREQUESTS)
                                fatal("Too many requests");
-                       requ[requests++] = atoi(argv[0]);
+                       i = strtonum(argv[0], 0, INT_MAX, &errstr);
+                       if (errstr)
+                               fatal("invalid job number");
+                       requ[requests++] = i;
                } else {
                        if (users >= MAXUSERS)
                                fatal("Too many users");

Reply via email to