From 4d1bd74a2ad316a485124c44c241124b4760dc69 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niels=20M=C3=B6ller?= Date: Mon, 15 Dec 2025 20:40:36 +0100 Subject: [PATCH] Fix return value for failure of base16_decode_update and base64_decode_update. --- ChangeLog | 8 ++++++++ base16-decode.c | 4 ++-- base64-decode.c | 8 ++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 53b57c30..b9b787dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2025-12-15 Niels Möller + + * base16-decode.c (base16_decode_update): Fix returned value on + failure, should be 0. Previous change accidentally returned -1 + instead. + * base64-decode.c (base64_decode_update): Analogous fix. This + regression was reported by Robert Augusteijn. + 2025-11-05 Niels Möller * testsuite/slh-dsa-test.c (read_hex_file): Simplify, using diff --git a/base16-decode.c b/base16-decode.c index 54979929..d283cd77 100644 --- a/base16-decode.c +++ b/base16-decode.c @@ -87,13 +87,13 @@ base16_decode_update(struct base16_decode_ctx *ctx, { unsigned char usrc = src[i]; if (usrc >= 0x80) - return -1; + return 0; int digit = hex_decode_table[usrc]; if (digit == HEX_SPACE) continue; if (digit < 0 || done >= *dst_length) - return -1; + return 0; assert(digit < 0x10); if (ctx->bits) diff --git a/base64-decode.c b/base64-decode.c index 0949b35b..cbd61083 100644 --- a/base64-decode.c +++ b/base64-decode.c @@ -99,7 +99,7 @@ base64_decode_update(struct base64_decode_ctx *ctx, assert(data >= 0 && data < 0x40); if (ctx->padding || (done >= *dst_length)) - return -1; + return 0; ctx->word = ctx->word << 6 | data; ctx->bits += 6; @@ -111,17 +111,17 @@ base64_decode_update(struct base64_decode_ctx *ctx, } break; case TABLE_INVALID: - return -1; + return 0; case TABLE_SPACE: continue; case TABLE_END: /* There can be at most two padding characters. */ if (!ctx->bits || ctx->padding > 2) - return -1; + return 0; if (ctx->word & ( (1<bits) - 1)) /* We shouldn't have any leftover bits */ - return -1; + return 0; ctx->padding++; ctx->bits -= 2; -- 2.47.3