]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: validate numeric option arguments
authorSami Kerola <kerolasa@iki.fi>
Mon, 25 Jul 2011 22:04:34 +0000 (00:04 +0200)
committerSami Kerola <kerolasa@iki.fi>
Tue, 26 Jul 2011 16:15:14 +0000 (18:15 +0200)
Instead atoi() use strtoul_or_err().

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
hwclock/Makefile.am
hwclock/clock.h
hwclock/hwclock.c

index 2dd70b301aa2329976f43e26ec1415478f76cdde..c7d95f29b5cd8fa8c2ddd9bfa6d4e6ec11f5cef5 100644 (file)
@@ -4,7 +4,7 @@ dist_man_MANS = hwclock.8
 
 sbin_PROGRAMS = hwclock
 
-hwclock_SOURCES = hwclock.c cmos.c kd.c clock.h
+hwclock_SOURCES = hwclock.c cmos.c kd.c clock.h $(top_srcdir)/lib/strutils.c
 hwclock_LDADD =
 
 if LINUX
index 363541bbdd34edb2fb2ec595d83ea207dbfcfb3f..175a6d1ae8452bd724ba91f803a0de1fda32554e 100644 (file)
@@ -26,7 +26,7 @@ typedef int bool;
 /* hwclock.c */
 extern char *progname;
 extern int debug;
-extern int epoch_option;
+extern unsigned long epoch_option;
 extern double time_diff(struct timeval subtrahend, struct timeval subtractor);
 /* cmos.c */
 extern void set_cmos_epoch(int ARCconsole, int SRM);
index 2c35e857aad664f04ebe709aba19fd86097d571d..b8623d21ef4d1e61e29c74cafb08040d92880c90 100644 (file)
@@ -74,6 +74,7 @@
 #include "clock.h"
 #include "nls.h"
 #include "pathnames.h"
+#include "strutils.h"
 
 #ifdef HAVE_LIBAUDIT
 #include <libaudit.h>
@@ -143,7 +144,7 @@ bool debug;
 bool badyear;
 
 /* User-specified epoch, used when rtc fails to return epoch. */
-int epoch_option = -1;
+unsigned long epoch_option = -1;
 
 /*
  * Almost all Award BIOS's made between 04/26/94 and 05/31/95 have a nasty
@@ -1307,7 +1308,7 @@ manipulate_clock(const bool show, const bool adjust, const bool noadjfile,
 static void
 manipulate_epoch(const bool getepoch __attribute__ ((__unused__)),
                 const bool setepoch __attribute__ ((__unused__)),
-                const int epoch_opt __attribute__ ((__unused__)),
+                const unsigned long epoch_opt __attribute__ ((__unused__)),
                 const bool testing __attribute__ ((__unused__)))
 {
        warnx(_("The kernel keeps an epoch value for the Hardware Clock "
@@ -1319,7 +1320,7 @@ manipulate_epoch(const bool getepoch __attribute__ ((__unused__)),
 static void
 manipulate_epoch(const bool getepoch,
                 const bool setepoch,
-                const int epoch_opt,
+                const unsigned long epoch_opt,
                 const bool testing)
 {
        if (getepoch) {
@@ -1600,7 +1601,8 @@ int main(int argc, char **argv)
                        date_opt = optarg;      /* --date */
                        break;
                case OPT_EPOCH:
-                       epoch_option = atoi(optarg);    /* --epoch */
+                       epoch_option =          /* --epoch */
+                           strtoul_or_err(optarg, _("failed to parse epoch"));
                        break;
                case OPT_ADJFILE:
                        adj_file_name = optarg; /* --adjfile */