summaryrefslogtreecommitdiffstats
path: root/text-utils/col.c
diff options
context:
space:
mode:
authorSami Kerola2011-05-23 21:14:16 +0200
committerKarel Zak2011-06-08 11:12:53 +0200
commitb07e72d9ec0e1578564887525cff3a62d9551492 (patch)
treee16c2011ea342116df8f7babe1c6a558bb0cddb3 /text-utils/col.c
parentlib: [linux_version.c] accommodate two-component linux version (e.g. 3.0) (diff)
downloadkernel-qcow2-util-linux-b07e72d9ec0e1578564887525cff3a62d9551492.tar.gz
kernel-qcow2-util-linux-b07e72d9ec0e1578564887525cff3a62d9551492.tar.xz
kernel-qcow2-util-linux-b07e72d9ec0e1578564887525cff3a62d9551492.zip
col: check with strtol_or_err option argument
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'text-utils/col.c')
-rw-r--r--text-utils/col.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/text-utils/col.c b/text-utils/col.c
index 0740687af..baec1945a 100644
--- a/text-utils/col.c
+++ b/text-utils/col.c
@@ -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;