From a8cc9ce3f290a83dfb656dabfab2a98e765a68a0 Mon Sep 17 00:00:00 2001 From: Pádraig Brady Date: Sun, 16 Aug 2015 15:31:17 +0100 Subject: base64: use stricter validation on wrap column * src/base64.c (main): Use the higher level xnumtoumax() rather than xstrtoumax(), which is simpler and improves validation of input. Also pass the _empty_ rather than NULL string as the suffixes parameter so that invalid trailing characters are not allowed. For example -w08 is now flagged as an error, rather than being interpreted as 0. A subsequent commit will further improve verification of numbers with leading zeros by dropping backwards compatibility wrt auto parsing oct and hex numbers. * tests/misc/base64.pl: Add tests for invalid wrap values. --- src/base64.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/base64.c b/src/base64.c index 679044e40..15888fa83 100644 --- a/src/base64.c +++ b/src/base64.c @@ -29,7 +29,7 @@ #include "fadvise.h" #include "xstrtol.h" #include "quote.h" -#include "quotearg.h" +#include "xdectoint.h" #include "xfreopen.h" #define AUTHORS proper_name ("Simon Josefsson") @@ -289,9 +289,8 @@ main (int argc, char **argv) break; case 'w': - if (xstrtoumax (optarg, NULL, 0, &wrap_column, NULL) != LONGINT_OK) - error (EXIT_FAILURE, 0, _("invalid wrap size: %s"), - quotearg (optarg)); + wrap_column = xnumtoumax (optarg, 0, 0, UINTMAX_MAX, "", + _("invalid wrap size"), 0); break; case 'i': -- cgit v1.2.3-70-g09d2