+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.
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;
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;