]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
ldattach: check numeric user inputs with strtol_or_err
authorSami Kerola <kerolasa@iki.fi>
Tue, 1 Nov 2011 20:32:54 +0000 (21:32 +0100)
committerSami Kerola <kerolasa@iki.fi>
Wed, 2 Nov 2011 18:10:12 +0000 (19:10 +0100)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/Makefile.am
sys-utils/ldattach.c

index 48595dab5521eaec80d1898c8c2afe372ac3d595..2ef4c9804e28594815763e92886aec8ff3fb41da 100644 (file)
@@ -44,6 +44,7 @@ flock_SOURCES = flock.c $(top_srcdir)/lib/strutils.c
 prlimit_SOURCES = prlimit.c $(top_srcdir)/lib/strutils.c \
                        $(top_srcdir)/lib/mbsalign.c \
                        $(top_srcdir)/lib/tt.c
+ldattach_SOURCES = ldattach.c $(top_srcdir)/lib/strutils.c
 
 if BUILD_MOUNTPOINT
 bin_PROGRAMS += mountpoint
index b032a38503608ee7bafbe95db09077b5404c5c39..1cbf37396f116d8fe6158e377a357c4a3181fbb6 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "c.h"
 #include "nls.h"
+#include "strutils.h"
 
 #define dbg(format, arg...) \
        do { \
@@ -123,16 +124,13 @@ static void print_table(FILE * out, const struct ld_table *tab)
 static int parse_iflag(char *str, int *set_iflag, int *clr_iflag)
 {
        int iflag;
-       char *s, *end;
+       char *s;
 
        for (s = strtok(str, ","); s != NULL; s = strtok(NULL, ",")) {
                if (*s == '-')
                        s++;
-               if ((iflag = lookup_table(ld_iflags, s)) < 0) {
-                       iflag = strtol(s, &end, 0);
-                       if (*end || iflag < 0)
-                               errx(EXIT_FAILURE, _("invalid iflag: %s"), s);
-               }
+               if ((iflag = lookup_table(ld_iflags, s)) < 0)
+                       iflag = strtol_or_err(s, _("invalid iflag"));
                if (s > str && *(s - 1) == '-')
                        *clr_iflag |= iflag;
                else
@@ -206,7 +204,6 @@ int main(int argc, char **argv)
        int set_iflag = 0, clr_iflag = 0;
        int ldisc;
        int optc;
-       char *end;
        char *dev;
        static const struct option opttbl[] = {
                {"speed", required_argument, NULL, 's'},
@@ -254,10 +251,7 @@ int main(int argc, char **argv)
                        parity = optc;
                        break;
                case 's':
-                       speed = strtol(optarg, &end, 10);
-                       if (*end || speed <= 0)
-                               errx(EXIT_FAILURE, _("invalid speed: %s"),
-                                    optarg);
+                       speed = strtol_or_err(optarg, _("invalid speed"));
                        break;
                case 'i':
                        parse_iflag(optarg, &set_iflag, &clr_iflag);
@@ -278,13 +272,8 @@ int main(int argc, char **argv)
 
        /* parse line discipline specification */
        ldisc = lookup_table(ld_discs, argv[optind]);
-       if (ldisc < 0) {
-               ldisc = strtol(argv[optind], &end, 0);
-               if (*end || ldisc < 0)
-                       errx(EXIT_FAILURE,
-                            _("invalid line discipline: %s"),
-                            argv[optind]);
-       }
+       if (ldisc < 0)
+               ldisc = strtol_or_err(argv[optind], _("invalid line discipline"));
 
        /* open device */
        dev = argv[optind + 1];