diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h index f6280ebdfe5404c6e67bc008ce27f3fd1eaf1ab0..0ee11ee5d53a95c646b57ae722df0cfd63a7c024 100644 --- a/include/asterisk/utils.h +++ b/include/asterisk/utils.h @@ -267,7 +267,7 @@ int ast_base64decode(unsigned char *dst, const char *src, int max); * \brief Same as ast_base64decode, but does the math for you and returns * a decoded string * - * \note The returned string will need to be freed later + * \note The returned string will need to be freed later and IS NULL terminated * * \param src The source buffer * diff --git a/main/utils.c b/main/utils.c index 0b6c649342cc802841af018365fff4403f124531..827ee2e57aaec3fbb24285e92e7cb7f067007334 100644 --- a/main/utils.c +++ b/main/utils.c @@ -331,12 +331,13 @@ char *ast_base64decode_string(const char *src) } decoded_len = (encoded_len / 4 * 3) - padding; - decoded_string = ast_calloc(1, decoded_len); + decoded_string = ast_malloc(decoded_len + 1); if (!decoded_string) { return NULL; } ast_base64decode(decoded_string, src, decoded_len); + decoded_string[decoded_len] = '\0'; return (char *)decoded_string; }