Hey,

Currently jot(1) allows reps to be negative and also allows reps to
overflow (in some cases) without being caught.

$ uname -ms
OpenBSD i386
$ jot -n -- -1
$ jot -n 2147483648
$ jot 4294967297
1
$

In the negative case, nothing is printed (except for a newline if -n is
not given).  FreeBSD's jot behaves like this, while NetBSD's jot gives
an error.  The man page says that "reps is expected to be an unsigned
integer" and negative reps have no defined (or obvious) meaning, so I
think an error is appropriate in this case.

I have a patch below to use strtonum instead of sscanf when converting
reps (like the way a precision value is converted and checked).  Since
reps is a long, bound it by 0 and LONG_MAX.

Cheers,
Kris Katterjohn

Index: jot.c
===================================================================
RCS file: /cvs/src/usr.bin/jot/jot.c,v
retrieving revision 1.46
diff -u -p -r1.46 jot.c
--- jot.c       24 Jun 2018 18:39:57 -0000      1.46
+++ jot.c       31 Jul 2018 21:31:31 -0000
@@ -153,8 +153,10 @@ main(int argc, char *argv[])
                }
        case 1:
                if (!is_default(argv[0])) {
-                       if (!sscanf(argv[0], "%ld", &reps))
-                               errx(1, "Bad reps value:  %s", argv[0]);
+                       reps = strtonum(argv[0], 0, LONG_MAX, &errstr);
+                       if (errstr != NULL)
+                               errx(1, "Bad reps value, %s:  %s", errstr,
+                                       argv[0]);
                        mask |= REPS;
                        if (reps == 0)
                                infinity = true;

Reply via email to