A couple of related updates to base64 attached.

cheers,
Pádraig.
>From ffa477cfa10e4ef598792e9bde27a5e263761be9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Sun, 16 Aug 2015 21:45:47 -0700
Subject: [PATCH] base64: no longer support hex or oct --wrap params

* src/base64.c (main): Support decimal numbers with leading zeros,
by disabling the auto detection of octal and hex.  It's not
envisaged that base conversion is needed for --wrap parameters,
and in the edge case it is, $((0x0)) shell constructs can be used.
* tests/misc/base64.pl: Adjust accordingly.
* NEWS: Mention the change in behavior.
---
 NEWS                 | 5 +++++
 src/base64.c         | 2 +-
 tests/misc/base64.pl | 6 +++---
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index d247e9d..33414c4 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,11 @@ GNU coreutils NEWS                                    -*- outline -*-
   base32 is added to complement the existing base64 command,
   and encodes and decodes printable text as per RFC 4648.
 
+** Changes in behavior
+
+  base64 no longer supports hex or oct --wrap parameters,
+  thus better supporting decimals with leading zeros.
+
 
 * Noteworthy changes in release 8.24 (2015-07-03) [stable]
 
diff --git a/src/base64.c b/src/base64.c
index 7a79294..e4cf2aa 100644
--- a/src/base64.c
+++ b/src/base64.c
@@ -289,7 +289,7 @@ main (int argc, char **argv)
         break;
 
       case 'w':
-        wrap_column = xnumtoumax (optarg, 0, 0, UINTMAX_MAX, "",
+        wrap_column = xdectoumax (optarg, 0, UINTMAX_MAX, "",
                                   _("invalid wrap size"), 0);
         break;
 
diff --git a/tests/misc/base64.pl b/tests/misc/base64.pl
index 44c3d21..af39742 100755
--- a/tests/misc/base64.pl
+++ b/tests/misc/base64.pl
@@ -71,7 +71,7 @@ sub gen_tests($)
      ['inout4', {IN=>'a'x4}, {OUT=>&$enc(4)."\n"}],
      ['inout5', {IN=>'a'x5}, {OUT=>&$enc(5)."\n"}],
      ['wrap', '--wrap 0', {IN=>'a'}, {OUT=>&$enc(1)}],
-     ['wrap-hex', '--wrap 0x0', {IN=>'a'}, {OUT=>&$enc(1)}],
+     ['wrap-zero', '--wrap 08', {IN=>'a'}, {OUT=>&$enc(1)."\n"}],
      ['wrap5-39', '--wrap=5', {IN=>'a' x 39}, {OUT=>wrap &$enc(39),5}],
      ['wrap5-40', '--wrap=5', {IN=>'a' x 40}, {OUT=>wrap &$enc(40),5}],
      ['wrap5-41', '--wrap=5', {IN=>'a' x 41}, {OUT=>wrap &$enc(41),5}],
@@ -81,9 +81,9 @@ sub gen_tests($)
      ['wrap5-45', '--wrap=5', {IN=>'a' x 45}, {OUT=>wrap &$enc(45),5}],
      ['wrap5-46', '--wrap=5', {IN=>'a' x 46}, {OUT=>wrap &$enc(46),5}],
 
-     ['wrap-bad-1', '-w08', {IN=>''}, {OUT=>""},
+     ['wrap-bad-1', '-w0x0', {IN=>''}, {OUT=>""},
       {ERR_SUBST => 's/base..:/base..:/'},
-      {ERR => "base..: invalid wrap size: '08'\n"}, {EXIT => 1}],
+      {ERR => "base..: invalid wrap size: '0x0'\n"}, {EXIT => 1}],
      ['wrap-bad-2', '-w1k', {IN=>''}, {OUT=>""},
       {ERR_SUBST => 's/base..:/base..:/'},
       {ERR => "base..: invalid wrap size: '1k'\n"}, {EXIT => 1}],
-- 
2.4.1

>From 5ef435578e0558db8b21993f373f7f3468fe60f8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Sun, 16 Aug 2015 15:31:17 +0100
Subject: [PATCH] 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
(Auto base conversion is left enabled for backwards compat).
* tests/misc/base64.pl: Add tests for invalid wrap values.
---
 src/base64.c         |  7 +++----
 tests/misc/base64.pl | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/base64.c b/src/base64.c
index 8cc23e4..7a79294 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':
diff --git a/tests/misc/base64.pl b/tests/misc/base64.pl
index 872535a..44c3d21 100755
--- a/tests/misc/base64.pl
+++ b/tests/misc/base64.pl
@@ -71,6 +71,7 @@ sub gen_tests($)
      ['inout4', {IN=>'a'x4}, {OUT=>&$enc(4)."\n"}],
      ['inout5', {IN=>'a'x5}, {OUT=>&$enc(5)."\n"}],
      ['wrap', '--wrap 0', {IN=>'a'}, {OUT=>&$enc(1)}],
+     ['wrap-hex', '--wrap 0x0', {IN=>'a'}, {OUT=>&$enc(1)}],
      ['wrap5-39', '--wrap=5', {IN=>'a' x 39}, {OUT=>wrap &$enc(39),5}],
      ['wrap5-40', '--wrap=5', {IN=>'a' x 40}, {OUT=>wrap &$enc(40),5}],
      ['wrap5-41', '--wrap=5', {IN=>'a' x 41}, {OUT=>wrap &$enc(41),5}],
@@ -80,6 +81,19 @@ sub gen_tests($)
      ['wrap5-45', '--wrap=5', {IN=>'a' x 45}, {OUT=>wrap &$enc(45),5}],
      ['wrap5-46', '--wrap=5', {IN=>'a' x 46}, {OUT=>wrap &$enc(46),5}],
 
+     ['wrap-bad-1', '-w08', {IN=>''}, {OUT=>""},
+      {ERR_SUBST => 's/base..:/base..:/'},
+      {ERR => "base..: invalid wrap size: '08'\n"}, {EXIT => 1}],
+     ['wrap-bad-2', '-w1k', {IN=>''}, {OUT=>""},
+      {ERR_SUBST => 's/base..:/base..:/'},
+      {ERR => "base..: invalid wrap size: '1k'\n"}, {EXIT => 1}],
+     ['wrap-bad-3', '-w-1', {IN=>''}, {OUT=>""},
+      {ERR_SUBST => 's/base..:/base..:/'},
+      {ERR => "base..: invalid wrap size: '-1'\n"}, {EXIT => 1}],
+     ['wrap-bad-4', '-w-0', {IN=>''}, {OUT=>""},
+      {ERR_SUBST => 's/base..:/base..:/'},
+      {ERR => "base..: invalid wrap size: '-0'\n"}, {EXIT => 1}],
+
      ['buf-1',   '--decode', {IN=>&$enc(1)}, {OUT=>'a' x 1}],
      ['buf-2',   '--decode', {IN=>&$enc(2)}, {OUT=>'a' x 2}],
      ['buf-3',   '--decode', {IN=>&$enc(3)}, {OUT=>'a' x 3}],
-- 
2.4.1

Reply via email to