=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/last/last.c,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- src/usr.bin/last/last.c 2004/06/16 22:30:08 1.31 +++ src/usr.bin/last/last.c 2005/07/01 02:10:24 1.32 @@ -1,4 +1,4 @@ -/* $OpenBSD: last.c,v 1.31 2004/06/16 22:30:08 millert Exp $ */ +/* $OpenBSD: last.c,v 1.32 2005/07/01 02:10:24 millert Exp $ */ /* $NetBSD: last.c,v 1.6 1994/12/24 16:49:02 cgd Exp $ */ /* @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)last.c 8.2 (Berkeley) 4/2/94"; #endif -static char rcsid[] = "$OpenBSD: last.c,v 1.31 2004/06/16 22:30:08 millert Exp $"; +static char rcsid[] = "$OpenBSD: last.c,v 1.32 2005/07/01 02:10:24 millert Exp $"; #endif /* not lint */ #include @@ -111,11 +111,14 @@ { const char *errstr; char *p; - int ch; + int ch, lastch, newarg, prevoptind; maxrec = -1; snaptime = 0; - while ((ch = getopt(argc, argv, "0123456789cf:h:n:st:d:T")) != -1) + lastch = '\0'; + newarg = 1; + prevoptind = 1; + while ((ch = getopt(argc, argv, "0123456789cf:h:n:st:d:T")) != -1) { switch (ch) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': @@ -123,15 +126,11 @@ * kludge: last was originally designed to take * a number after a dash. */ - if (maxrec == -1) { - p = argv[optind - 1]; - if (p[0] == '-' && p[1] == ch && !p[2]) - maxrec = atol(++p); - else - maxrec = atol(argv[optind] + 1); - if (maxrec == 0) - exit(0); - } + if (newarg || !isdigit(lastch)) + maxrec = 0; + else if (maxrec > INT_MAX / 10) + usage(); + maxrec = (maxrec * 10) + (ch - '0'); break; case 'c': calculate++; @@ -163,10 +162,15 @@ case 'T': fulltime = 1; break; - case '?': default: usage(); } + lastch = ch; + newarg = optind != prevoptind; + prevoptind = optind; + } + if (maxrec == 0) + exit(0); if (argc) { setlinebuf(stdout);