]> Savannah Git Hosting - gnulib.git/commitdiff
base32, base64: treat negative sizes as overflows
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 29 Aug 2021 19:58:49 +0000 (12:58 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 29 Aug 2021 19:59:53 +0000 (12:59 -0700)
* lib/base64.c (base64_encode_alloc):
* lib/base32.c (base32_encode_alloc):
Treat negative sizes as overflows, for better compatibility
with previous API.

ChangeLog
lib/base32.c
lib/base64.c

index ce9a2b3664eb9dd68a88d12699adca84b2bda76b..ee933c9efaa6e2040fd513fe3393e5d4ca89e69a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2021-08-29  Paul Eggert  <eggert@cs.ucla.edu>
+
+       base32, base64: treat negative sizes as overflows
+       * lib/base64.c (base64_encode_alloc):
+       * lib/base32.c (base32_encode_alloc):
+       Treat negative sizes as overflows, for better compatibility
+       with previous API.
+
 2021-08-29  Bruno Haible  <bruno@clisp.org>
 
        explicit_bzero test: Fix test failure due to GCC optimizations.
index e3f2f9b4c1207c79eb2a0d5b6ff1d69c65f29de5..037747d80d0a3113af0dadcae4b6b2947fc7edfb 100644 (file)
@@ -141,9 +141,11 @@ base32_encode (const char *restrict in, idx_t inlen,
 idx_t
 base32_encode_alloc (const char *in, idx_t inlen, char **out)
 {
-  /* Check for overflow in outlen computation.  */
+  /* Check for overflow in outlen computation.
+     Treat negative INLEN as overflow, for better compatibility with
+     pre-2021-08-27 API, which used size_t.  */
   idx_t in_over_5 = inlen / 5 + (inlen % 5 != 0), outlen;
-  if (! INT_MULTIPLY_OK (in_over_5, 8, &outlen))
+  if (! INT_MULTIPLY_OK (in_over_5, 8, &outlen) || inlen < 0)
     {
       *out = NULL;
       return 0;
index 4611fe54858fe35e98cab0b16b6d8d0a193c438c..b204cb71171e5a65f161cc11abd42b44c3d78d3b 100644 (file)
@@ -146,9 +146,11 @@ base64_encode (const char *restrict in, idx_t inlen,
 idx_t
 base64_encode_alloc (const char *in, idx_t inlen, char **out)
 {
-  /* Check for overflow in outlen computation.  */
+  /* Check for overflow in outlen computation.
+     Treat negative INLEN as overflow, for better compatibility with
+     pre-2021-08-27 API, which used size_t.  */
   idx_t in_over_3 = inlen / 3 + (inlen % 3 != 0), outlen;
-  if (! INT_MULTIPLY_OK (in_over_3, 4, &outlen))
+  if (! INT_MULTIPLY_OK (in_over_3, 4, &outlen) || inlen < 0)
     {
       *out = NULL;
       return 0;