]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
last: check expected numeric user input is number
authorSami Kerola <kerolasa@iki.fi>
Sat, 17 Aug 2013 18:15:13 +0000 (19:15 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 23 Aug 2013 08:58:55 +0000 (10:58 +0200)
This commit also changes the line count to use unsigned integers, as
negative numbers in this context does not make sense.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
login-utils/Makemodule.am
login-utils/last.c

index e4361ede2746d3ef77e0d4a057b6680968ffdba5..8d65cc58358b9adc41536262c1f1987b88c0e601 100644 (file)
@@ -4,7 +4,7 @@ usrbin_exec_PROGRAMS += last
 dist_man_MANS += \
        login-utils/last.1 \
        login-utils/lastb.1
-last_SOURCES = login-utils/last.c
+last_SOURCES = login-utils/last.c lib/strutils.c
 
 install-exec-hook-last:
        cd $(DESTDIR)$(usrsbin_execdir) && ln -sf last lastb
index f08632bbf010449e17046790b858f4b0a47349e6..f188092c8e083969ef4980893617e0b0186fe51f 100644 (file)
@@ -46,6 +46,7 @@
 #include "xalloc.h"
 #include "closestream.h"
 #include "carefulputc.h"
+#include "strutils.h"
 
 #ifndef SHUTDOWN_TIME
 # define SHUTDOWN_TIME 254
@@ -72,8 +73,8 @@ struct utmplist *utmplist = NULL;
 #define R_TIMECHANGE   7 /* NEW_TIME or OLD_TIME */
 
 /* Global variables */
-static int maxrecs = 0;                /* Maximum number of records to list. */
-static int recsdone = 0;       /* Number of records listed */
+static unsigned int maxrecs = 0; /* Maximum number of records to list. */
+static unsigned int recsdone = 0; /* Number of records listed */
 static int showhost = 1;       /* Show hostname too? */
 static int altlist = 0;                /* Show hostname at the end. */
 static int usedns = 0;         /* Use DNS to lookup the hostname. */
@@ -540,7 +541,7 @@ int main(int argc, char **argv)
                        extended = 1;
                        break;
                case 'n':
-                       maxrecs = atoi(optarg);
+                       maxrecs = strtos32_or_err(optarg, _("failed to parse number"));
                        break;
                case 'f':
                        altufile = xstrdup(optarg);