summaryrefslogtreecommitdiffstats
path: root/text-utils/column.c
diff options
context:
space:
mode:
authorSami Kerola2011-05-01 19:24:47 +0200
committerSami Kerola2011-05-19 21:09:24 +0200
commit02b77f7b2b8d8d5337ef3d8b2cb232cae27c5cfc (patch)
treeea77d708e58152c69a1917dfce0af694baba0a92 /text-utils/column.c
parentcolumn.c: free memory before exit (diff)
downloadkernel-qcow2-util-linux-02b77f7b2b8d8d5337ef3d8b2cb232cae27c5cfc.tar.gz
kernel-qcow2-util-linux-02b77f7b2b8d8d5337ef3d8b2cb232cae27c5cfc.tar.xz
kernel-qcow2-util-linux-02b77f7b2b8d8d5337ef3d8b2cb232cae27c5cfc.zip
column.c: validate numeric user inputs
Use strtol_or_err from strutils.h to check numeric user input is sane. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'text-utils/column.c')
-rw-r--r--text-utils/column.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/text-utils/column.c b/text-utils/column.c
index 6b797d340..7604dc905 100644
--- a/text-utils/column.c
+++ b/text-utils/column.c
@@ -54,6 +54,7 @@
#include "widechar.h"
#include "c.h"
#include "xalloc.h"
+#include "strutils.h"
#ifdef HAVE_WIDECHAR
#define wcs_width(s) wcswidth(s,wcslen(s))
@@ -81,7 +82,7 @@ typedef struct _tbl {
int cols, *len;
} TBL;
-int termwidth = 80; /* default terminal width */
+long termwidth;
int entries; /* number of records */
int eval; /* exit value */
@@ -134,7 +135,8 @@ int main(int argc, char **argv)
if (ioctl(STDIN_FILENO, TIOCGWINSZ, &win) == -1 || !win.ws_col) {
if ((p = getenv("COLUMNS")) != NULL)
- termwidth = atoi(p);
+ termwidth = strtol_or_err(p,
+ _("terminal environment COLUMNS failed"));
} else
termwidth = win.ws_col;
@@ -149,7 +151,11 @@ int main(int argc, char **argv)
PACKAGE_STRING);
return(EXIT_SUCCESS);
case 'c':
- termwidth = atoi(optarg);
+ termwidth = strtol_or_err(optarg,
+ _("bad columns width value"));
+ if (termwidth < 1)
+ errx(EXIT_FAILURE,
+ _("-%c positive integer expected as an argument"), ch);
break;
case 's':
separator = mbs_to_wcs(optarg);