From: Michael Tremer Date: Sat, 21 Jun 2025 13:02:44 +0000 (+0000) Subject: base64: No longer require the input length X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6cf0a1af180edc57903dcab143c8998b909dce87;p=pakfire.git base64: No longer require the input length Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/base64.c b/src/pakfire/base64.c index c0af7b96..49180b1b 100644 --- a/src/pakfire/base64.c +++ b/src/pakfire/base64.c @@ -67,7 +67,7 @@ ERROR: return r; } -int pakfire_b64decode(unsigned char** output, size_t* length, const char* input, ssize_t l) { +int pakfire_b64decode(unsigned char** output, size_t* length, const char* input) { unsigned char* buffer = NULL; size_t block; int r; @@ -76,9 +76,8 @@ int pakfire_b64decode(unsigned char** output, size_t* length, const char* input, if (!input || !output || !length) return -EINVAL; - // Determine the length of the input if none given - if (l < 0) - l = strlen(input); + // Determine the length of the input + size_t l = strlen(input); // Remove any trailing whitespace while (l >= 1 && isspace(input[l - 1])) diff --git a/src/pakfire/base64.h b/src/pakfire/base64.h index 21fe7c24..a310c9ca 100644 --- a/src/pakfire/base64.h +++ b/src/pakfire/base64.h @@ -26,7 +26,7 @@ int pakfire_b64encode(char** output, const unsigned char* input, const size_t length); -int pakfire_b64decode(unsigned char** output, size_t* length, const char* input, ssize_t l); +int pakfire_b64decode(unsigned char** output, size_t* length, const char* input); int pakfire_b64normalize(char** output, const char* input, ssize_t length); diff --git a/src/pakfire/jwt.c b/src/pakfire/jwt.c index 20fa9fb6..4474104e 100644 --- a/src/pakfire/jwt.c +++ b/src/pakfire/jwt.c @@ -79,7 +79,7 @@ static int pakfire_jwt_decode_payload(char** payload, size_t* length, const char goto ERROR; // Decode the payload - r = pakfire_b64decode((unsigned char**)payload, length, normalized, -1); + r = pakfire_b64decode((unsigned char**)payload, length, normalized); ERROR: if (normalized) diff --git a/src/pakfire/key.c b/src/pakfire/key.c index eaee5145..db945dec 100644 --- a/src/pakfire/key.c +++ b/src/pakfire/key.c @@ -430,7 +430,7 @@ int pakfire_key_import(struct pakfire_key** key, // The second line should hold the key case 2: // Decode the key - r = pakfire_b64decode(&buffer, &buffer_length, line, -1); + r = pakfire_b64decode(&buffer, &buffer_length, line); if (r < 0) { ERROR(ctx, "Could not decode the key: %s\n", strerror(-r)); goto ERROR; @@ -912,7 +912,7 @@ static int pakfire_key_read_signature(struct pakfire_key* key, continue; // Decode the signature - r = pakfire_b64decode(&buffer, &buffer_length, line, -1); + r = pakfire_b64decode(&buffer, &buffer_length, line); if (r < 0) { ERROR(key->ctx, "Could not decode the signature: %s\n", strerror(-r)); goto ERROR; diff --git a/tests/libpakfire/util.c b/tests/libpakfire/util.c index 4053f164..ff710304 100644 --- a/tests/libpakfire/util.c +++ b/tests/libpakfire/util.c @@ -67,7 +67,7 @@ static int test_base64(const struct test* t) { printf("%s\n", base64); // Decode the data - ASSERT_SUCCESS(pakfire_b64decode(&output, &length, base64, -1)); + ASSERT_SUCCESS(pakfire_b64decode(&output, &length, base64)); // Print the decoded data printf("%.*s\n", (int)length, (char*)output);