From 313c2930e9402843737e75b37c4e81d32fda9f06 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Sat, 1 Feb 2025 13:00:21 +0100 Subject: [PATCH] allowing NULL length in base64_decode --- src/chat/crypto.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/chat/crypto.c b/src/chat/crypto.c index 802cc68..b14871f 100644 --- a/src/chat/crypto.c +++ b/src/chat/crypto.c @@ -72,8 +72,8 @@ char *base64_decode(char *encoded_message, size_t *length) BIO *bio; BIO *b64; char *separator_ptr = strrchr(encoded_message, WHY2_CHAT_BASE64_LENGTH_DELIMITER); //GET THE DELIMITER POINTER - *length = strtoull(separator_ptr + 1, NULL, 10); - char* decoded_message = why2_malloc(*length + 1); + size_t length_local = strtoull(separator_ptr + 1, NULL, 10); + char* decoded_message = why2_malloc(length_local + 1); int decoded_length; //INIT BIOs @@ -83,7 +83,7 @@ char *base64_decode(char *encoded_message, size_t *length) bio = BIO_push(b64, bio); //DECODE - decoded_length = BIO_read(bio, decoded_message, *length); + decoded_length = BIO_read(bio, decoded_message, length_local); //NULL-TERM decoded_message[decoded_length] = '\0'; @@ -91,6 +91,9 @@ char *base64_decode(char *encoded_message, size_t *length) //DEALLOCATION BIO_free_all(bio); + //SET length + if (length != NULL) *length = length_local; + return decoded_message; }