]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
col: check with strtol_or_err option argument
authorSami Kerola <kerolasa@iki.fi>
Mon, 23 May 2011 19:14:16 +0000 (21:14 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 8 Jun 2011 09:12:53 +0000 (11:12 +0200)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
text-utils/Makefile.am
text-utils/col.c

index 9ea7a9f3f838331dcad13190f2bef9f9186fda88..2c1dfa423bf2018c18232f113b185f80710d7934 100644 (file)
@@ -6,6 +6,8 @@ usrbin_exec_PROGRAMS = col colcrt colrm column hexdump rev tailf
 
 column_SOURCES = column.c $(top_srcdir)/lib/strutils.c
 
+col_SOURCES = col.c $(top_srcdir)/lib/strutils.c
+
 hexdump_SOURCES = hexdump.c conv.c display.c hexsyntax.c parse.c \
                  hexdump.h $(top_srcdir)/lib/strutils.c
 
index 0740687af58f042e8811d04b3826fa167d9c8b58..baec1945ad02f5fcc32b6700b9ce7a30dc0b6ea0 100644 (file)
@@ -55,6 +55,7 @@
 #include "nls.h"
 #include "xalloc.h"
 #include "widechar.h"
+#include "strutils.h"
 
 #define        BS      '\b'            /* backspace */
 #define        TAB     '\t'            /* tab */
@@ -155,6 +156,7 @@ int main(int argc, char **argv)
        int this_line;                  /* line l points to */
        int nflushd_lines;              /* number of lines that were flushed */
        int adjust, opt, warned;
+       unsigned long tmplong;
        int ret = EXIT_SUCCESS;
 
        static const struct option longopts[] = {
@@ -173,7 +175,7 @@ int main(int argc, char **argv)
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
 
-       max_bufd_lines = 128;
+       max_bufd_lines = 128 * 2;
        compress_spaces = 1;            /* compress spaces into tabs */
        pass_unknown_seqs = 0;          /* remove unknown escape sequences */
 
@@ -188,9 +190,15 @@ int main(int argc, char **argv)
                case 'h':               /* compress spaces into tabs */
                        compress_spaces = 1;
                        break;
-               case 'l':               /* buffered line count */
-                       if ((max_bufd_lines = atoi(optarg)) <= 0)
-                               errx(EXIT_FAILURE, _("bad -l argument %s."), optarg);
+               case 'l':
+                       /*
+                        * Buffered line count, which is a value in half
+                        * lines e.g. twice the amount specified.
+                        */
+                       tmplong = strtoul_or_err(optarg, _("bad -l argument")) * 2;
+                       if ((INT_MAX) < tmplong)
+                               errx(EXIT_FAILURE, _("argument %lu is too large"), tmplong);
+                       max_bufd_lines = (int) tmplong;
                        break;
                case 'p':
                        pass_unknown_seqs = 1;
@@ -211,9 +219,6 @@ int main(int argc, char **argv)
        if (optind != argc)
                usage(stderr);
 
-       /* this value is in half lines */
-       max_bufd_lines *= 2;
-
        adjust = cur_col = extra_lines = warned = 0;
        cur_line = max_line = nflushd_lines = this_line = 0;
        cur_set = last_set = CS_NORMAL;