]> Savannah Git Hosting - gnulib.git/commitdiff
base32, base64: fix broken tests
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 29 Aug 2021 07:45:43 +0000 (00:45 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 29 Aug 2021 07:46:23 +0000 (00:46 -0700)
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2021-08/msg00170.html
* lib/base32.c, lib/base64.c: Do not include verify.h,
and omit all uses of ‘assume’.
* modules/base32, modules/base64 (Depends-on): Remove verify.
* tests/test-base32.c, tests/test-base64.c:
Don’t pass out-of-range values to allocator,
as converting them to idx_t relies on implementation-defined
behavior that could trap.

ChangeLog
lib/base32.c
lib/base64.c
modules/base32
modules/base64
tests/test-base32.c
tests/test-base64.c

index e46b36efb16a2a1dca1f1e8c1c5425dbf77b97b2..d9f291fcd7c132a6c97a8dc744ef5ace4777a462 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2021-08-29  Paul Eggert  <eggert@cs.ucla.edu>
 
+       base32, base64: fix broken tests
+       Problem reported by Bruno Haible in:
+       https://lists.gnu.org/r/bug-gnulib/2021-08/msg00170.html
+       * lib/base32.c, lib/base64.c: Do not include verify.h,
+       and omit all uses of ‘assume’.
+       * modules/base32, modules/base64 (Depends-on): Remove verify.
+       * tests/test-base32.c, tests/test-base64.c:
+       Don’t pass out-of-range values to allocator,
+       as converting them to idx_t relies on implementation-defined
+       behavior that could trap.
+
        ialloc: relicense
        * modules/ialloc (License): Change from LGPL to LGPLv2+.
 
index e8feaf1663e21b7ee53f407993ca8c7975145700..e3f2f9b4c1207c79eb2a0d5b6ff1d69c65f29de5 100644 (file)
@@ -46,7 +46,6 @@
 #include <ialloc.h>
 
 #include <intprops.h>
-#include <verify.h>
 
 /* Get UCHAR_MAX. */
 #include <limits.h>
@@ -143,7 +142,6 @@ idx_t
 base32_encode_alloc (const char *in, idx_t inlen, char **out)
 {
   /* Check for overflow in outlen computation.  */
-  assume (0 <= inlen);
   idx_t in_over_5 = inlen / 5 + (inlen % 5 != 0), outlen;
   if (! INT_MULTIPLY_OK (in_over_5, 8, &outlen))
     {
index 2a01ed34e9c0f590f8e232a7b0869cb42cbb145f..4611fe54858fe35e98cab0b16b6d8d0a193c438c 100644 (file)
@@ -48,7 +48,6 @@
 #include <ialloc.h>
 
 #include <intprops.h>
-#include <verify.h>
 
 /* Get UCHAR_MAX. */
 #include <limits.h>
@@ -148,7 +147,6 @@ idx_t
 base64_encode_alloc (const char *in, idx_t inlen, char **out)
 {
   /* Check for overflow in outlen computation.  */
-  assume (0 <= inlen);
   idx_t in_over_3 = inlen / 3 + (inlen % 3 != 0), outlen;
   if (! INT_MULTIPLY_OK (in_over_3, 4, &outlen))
     {
index 659081d7e3b9694638ef5130a6f7a93932c7c908..93c180b09d8fcb72aa67a7a9a89c2ffd21c485f5 100644 (file)
@@ -10,7 +10,6 @@ Depends-on:
 ialloc
 stdbool
 memchr
-verify
 
 configure.ac:
 gl_FUNC_BASE32
index 717c0697d12962181e0bd1515e0207915504d9dc..278e52fc8b8c8c17c0f3955e468d6fc43ab27c54 100644 (file)
@@ -10,7 +10,6 @@ Depends-on:
 ialloc
 stdbool
 memchr
-verify
 
 configure.ac:
 gl_FUNC_BASE64
index 24c46567deb2f5d07a3c4b481535b9214b58e05d..25df559fd74da1eba3e35350bd4b8c1cf0798c05 100644 (file)
@@ -150,7 +150,7 @@ main (void)
   ASSERT (strcmp (p, "MFRGGZDFMZTWQ2LKNNWG23TPOA======") == 0);
   free (p);
 
-  len = base32_encode_alloc (in, SIZE_MAX - 5, &p);
+  len = base32_encode_alloc (in, IDX_MAX - 5, &p);
   ASSERT (len == 0);
 
   /* Decode context function */
index bc75acd95f2518648d72db6eb33b23cf4faced99..a7f4e5370abd44ebcdd9588bc13856cd4bc1a29d 100644 (file)
@@ -127,7 +127,7 @@ main (void)
   ASSERT (strcmp (p, "YWJjZGVmZ2hpamtsbW5vcA==") == 0);
   free (p);
 
-  len = base64_encode_alloc (in, SIZE_MAX - 5, &p);
+  len = base64_encode_alloc (in, IDX_MAX - 5, &p);
   ASSERT (len == 0);
 
   /* Decode context function */