summaryrefslogtreecommitdiffstats
path: root/login-utils/last.c
diff options
context:
space:
mode:
authorSami Kerola2013-08-17 20:15:13 +0200
committerKarel Zak2013-08-23 10:58:55 +0200
commit1bd68aab3b3495f62b9eb596524e7fab73e7135d (patch)
tree367cd289b2c71e5fe567d2d1e72abffbef4f228f /login-utils/last.c
parentlast: use carefulput() for printable character output (diff)
downloadkernel-qcow2-util-linux-1bd68aab3b3495f62b9eb596524e7fab73e7135d.tar.gz
kernel-qcow2-util-linux-1bd68aab3b3495f62b9eb596524e7fab73e7135d.tar.xz
kernel-qcow2-util-linux-1bd68aab3b3495f62b9eb596524e7fab73e7135d.zip
last: check expected numeric user input is number
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>
Diffstat (limited to 'login-utils/last.c')
-rw-r--r--login-utils/last.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/login-utils/last.c b/login-utils/last.c
index f08632bbf..f188092c8 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -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);