slabtop: use strutils.c to validate user input

This commit fixes also peculiar behavior of

$ slabtop -d 0

which did not make sense. The fix is to disallow anything else but
positive integers, which includes zero as is is not positive (or
negative) number.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2011-12-18 15:12:06 +01:00
parent 032f2ed674
commit 741de935ef
2 changed files with 5 additions and 7 deletions

View File

@ -58,6 +58,7 @@ dist_man_MANS += \
slabtop.1 \ slabtop.1 \
top.1 \ top.1 \
watch.1 watch.1
slabtop_SOURCES = slabtop.c $(top_srcdir)/lib/strutils.c
slabtop_LDADD = @NCURSES_LIBS@ slabtop_LDADD = @NCURSES_LIBS@
top_LDADD = @NCURSES_LIBS@ top_LDADD = @NCURSES_LIBS@
watch_LDADD = @WATCH_NCURSES_LIBS@ watch_LDADD = @WATCH_NCURSES_LIBS@

View File

@ -28,6 +28,7 @@
#include "c.h" #include "c.h"
#include "nls.h" #include "nls.h"
#include "strutils.h"
#include "proc/slab.h" #include "proc/slab.h"
#include "proc/version.h" #include "proc/version.h"
@ -297,14 +298,10 @@ int main(int argc, char *argv[])
char *end; char *end;
case 'd': case 'd':
errno = 0; errno = 0;
delay = strtol(optarg, &end, 10); delay = strtol_or_err(optarg, _("illegal delay"));
if (errno || optarg == end || (end && *end)) if (delay < 1)
errx(EXIT_FAILURE, _("illegal delay `%s'"),
optarg);
if (delay < 0)
errx(EXIT_FAILURE, errx(EXIT_FAILURE,
_("delay can not have a " _("delay must be positive integer"));
"negative value"));
break; break;
case 's': case 's':
sort_func = (int (*)(const struct slab_info*, sort_func = (int (*)(const struct slab_info*,