[PATCH 6/7] column.c: validate numeric user inputs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use strtol_or_err from strutils.h to check numeric user input is
sane.

Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 text-utils/Makefile.am |    2 ++
 text-utils/column.c    |   12 +++++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/text-utils/Makefile.am b/text-utils/Makefile.am
index 513f1c3..cc4b8b6 100644
--- a/text-utils/Makefile.am
+++ b/text-utils/Makefile.am
@@ -4,6 +4,8 @@ EXTRA_DIST = README.clear README.col
 
 usrbin_exec_PROGRAMS = col colcrt colrm column hexdump rev line tailf
 
+column_SOURCES = column.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
 
diff --git a/text-utils/column.c b/text-utils/column.c
index 99053fd..05ab689 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);
-- 
1.7.5

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux