From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 08/16] last: check expected numeric user input is number
Date: Sat, 17 Aug 2013 19:15:13 +0100 [thread overview]
Message-ID: <1376763321-22782-9-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1376763321-22782-1-git-send-email-kerolasa@iki.fi>
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 | 2 +-
login-utils/last.c | 7 ++++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/login-utils/Makemodule.am b/login-utils/Makemodule.am
index e4361ed..8d65cc5 100644
--- a/login-utils/Makemodule.am
+++ b/login-utils/Makemodule.am
@@ -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
diff --git a/login-utils/last.c b/login-utils/last.c
index f08632b..f188092 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);
--
1.8.3.4
next prev parent reply other threads:[~2013-08-17 18:16 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-17 18:15 [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Sami Kerola
2013-08-17 18:15 ` [PATCH 01/16] build-sys: remove unnecessary environment variable Sami Kerola
2013-08-17 18:15 ` [PATCH 02/16] docs: update TODO Sami Kerola
2013-08-17 18:15 ` [PATCH 03/16] build-sys: complete elvtune removal Sami Kerola
2013-08-17 18:15 ` [PATCH 04/16] docs: be clear which last(1) is deprecated Sami Kerola
2013-08-17 18:15 ` [PATCH 05/16] docs: add long options to last.1 manual page Sami Kerola
2013-08-17 18:15 ` [PATCH 06/16] include: carefulput: print determined char when unprintable char is found Sami Kerola
2013-08-17 18:15 ` [PATCH 07/16] last: use carefulput() for printable character output Sami Kerola
2013-08-17 18:15 ` Sami Kerola [this message]
2013-08-17 18:15 ` [PATCH 09/16] last: make switch cases complete, and inform if impossible occurs Sami Kerola
2013-08-17 18:15 ` [PATCH 10/16] last: prefer enum rather than #definition list Sami Kerola
2013-08-17 18:15 ` [PATCH 11/16] last: remove broken code Sami Kerola
2013-08-17 18:15 ` [PATCH 12/16] last: use as narrow variable scoping as possible Sami Kerola
2013-08-17 18:15 ` [PATCH 13/16] last: use ISO 8601 time format for --fulltimes Sami Kerola
2013-08-17 18:15 ` [PATCH 14/16] last: global variables are initialize automatically to zero Sami Kerola
2013-08-17 18:15 ` [PATCH 15/16] last: allow --file to be defined multiple times Sami Kerola
2013-08-17 18:15 ` [PATCH 16/16] last: add --present option Sami Kerola
2013-08-23 10:07 ` [PATCH 00/16] pull: additions recent to last(1) work, plus few small changes Karel Zak
2013-08-23 10:42 ` Sami Kerola
2013-08-23 11:04 ` Karel Zak
2013-08-23 11:08 ` Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1376763321-22782-9-git-send-email-kerolasa@iki.fi \
--to=kerolasa@iki.fi \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox