allowing NULL length in base64_decode

This commit is contained in:
Václav Šmejkal 2025-02-01 13:00:21 +01:00
parent 7bb6e38a99
commit 313c2930e9
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -72,8 +72,8 @@ char *base64_decode(char *encoded_message, size_t *length)
BIO *bio; BIO *bio;
BIO *b64; BIO *b64;
char *separator_ptr = strrchr(encoded_message, WHY2_CHAT_BASE64_LENGTH_DELIMITER); //GET THE DELIMITER POINTER char *separator_ptr = strrchr(encoded_message, WHY2_CHAT_BASE64_LENGTH_DELIMITER); //GET THE DELIMITER POINTER
*length = strtoull(separator_ptr + 1, NULL, 10); size_t length_local = strtoull(separator_ptr + 1, NULL, 10);
char* decoded_message = why2_malloc(*length + 1); char* decoded_message = why2_malloc(length_local + 1);
int decoded_length; int decoded_length;
//INIT BIOs //INIT BIOs
@ -83,7 +83,7 @@ char *base64_decode(char *encoded_message, size_t *length)
bio = BIO_push(b64, bio); bio = BIO_push(b64, bio);
//DECODE //DECODE
decoded_length = BIO_read(bio, decoded_message, *length); decoded_length = BIO_read(bio, decoded_message, length_local);
//NULL-TERM //NULL-TERM
decoded_message[decoded_length] = '\0'; decoded_message[decoded_length] = '\0';
@ -91,6 +91,9 @@ char *base64_decode(char *encoded_message, size_t *length)
//DEALLOCATION //DEALLOCATION
BIO_free_all(bio); BIO_free_all(bio);
//SET length
if (length != NULL) *length = length_local;
return decoded_message; return decoded_message;
} }