]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Fix return value for failure of base16_decode_update and base64_decode_update.
authorNiels Möller <nisse@lysator.liu.se>
Mon, 15 Dec 2025 19:40:36 +0000 (20:40 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Mon, 15 Dec 2025 19:40:36 +0000 (20:40 +0100)
ChangeLog
base16-decode.c
base64-decode.c

index 53b57c303af37dc153d7f190c918562417209b0a..b9b787dc72e85c26261235c1daaed01df6df31a8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2025-12-15  Niels Möller  <nisse@lysator.liu.se>
+
+       * 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  <nisse@lysator.liu.se>
 
        * testsuite/slh-dsa-test.c (read_hex_file): Simplify, using
index 549799294b90a2f212f129792c079a8ba849e430..d283cd77d38b8cec6e050ecde33a2a0de311df83 100644 (file)
@@ -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)
index 0949b35b1cbac35421128d520c713c4e40adaad6..cbd61083d85829aa2e1fa371cb1da2e92ff6e8a7 100644 (file)
@@ -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<<ctx->bits) - 1))
            /* We shouldn't have any leftover bits */
-           return -1;
+           return 0;
 
          ctx->padding++;
          ctx->bits -= 2;