From 93280a4bdca1c6e6fa1946fbf9d8621c42bdd692 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 29 Aug 2021 00:45:43 -0700 Subject: [PATCH 2/2] base32, base64: fix broken tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 | 11 +++++++++++ lib/base32.c | 2 -- lib/base64.c | 2 -- modules/base32 | 1 - modules/base64 | 1 - tests/test-base32.c | 2 +- tests/test-base64.c | 2 +- 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index e46b36efb..d9f291fcd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2021-08-29 Paul Eggert + 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+. diff --git a/lib/base32.c b/lib/base32.c index e8feaf166..e3f2f9b4c 100644 --- a/lib/base32.c +++ b/lib/base32.c @@ -46,7 +46,6 @@ #include #include -#include /* Get UCHAR_MAX. */ #include @@ -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)) { diff --git a/lib/base64.c b/lib/base64.c index 2a01ed34e..4611fe548 100644 --- a/lib/base64.c +++ b/lib/base64.c @@ -48,7 +48,6 @@ #include #include -#include /* Get UCHAR_MAX. */ #include @@ -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)) { diff --git a/modules/base32 b/modules/base32 index 659081d7e..93c180b09 100644 --- a/modules/base32 +++ b/modules/base32 @@ -10,7 +10,6 @@ Depends-on: ialloc stdbool memchr -verify configure.ac: gl_FUNC_BASE32 diff --git a/modules/base64 b/modules/base64 index 717c0697d..278e52fc8 100644 --- a/modules/base64 +++ b/modules/base64 @@ -10,7 +10,6 @@ Depends-on: ialloc stdbool memchr -verify configure.ac: gl_FUNC_BASE64 diff --git a/tests/test-base32.c b/tests/test-base32.c index 24c46567d..25df559fd 100644 --- a/tests/test-base32.c +++ b/tests/test-base32.c @@ -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 */ diff --git a/tests/test-base64.c b/tests/test-base64.c index bc75acd95..a7f4e5370 100644 --- a/tests/test-base64.c +++ b/tests/test-base64.c @@ -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 */ -- 2.30.2