libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit fbd7cef55e809f9fc75206d3b358a8cd077222c0
parent 61b407a25a6f9c3d761685b6ebad4065c2b4775e
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Thu, 25 May 2023 20:06:12 +0300

Added macro for base64 decoded size

Diffstat:
Msrc/microhttpd/basicauth.c | 2+-
Msrc/microhttpd/mhd_str.h | 10++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/microhttpd/basicauth.c b/src/microhttpd/basicauth.c @@ -60,7 +60,7 @@ MHD_basic_auth_get_username_password3 (struct MHD_Connection *connection) if ((NULL == params->token68.str) || (0 == params->token68.len)) return NULL; - decoded_max_len = (params->token68.len / 4) * 3; + decoded_max_len = MHD_base64_max_dec_size_ (params->token68.len); ret = (struct MHD_BasicAuthInfo *) malloc (sizeof(struct MHD_BasicAuthInfo) + decoded_max_len + 1); if (NULL != ret) diff --git a/src/microhttpd/mhd_str.h b/src/microhttpd/mhd_str.h @@ -740,6 +740,16 @@ MHD_str_quote (const char *unquoted, #ifdef BAUTH_SUPPORT /** + * Returns the maximum possible size of the Base64 decoded data. + * The real recoded size could be up to two bytes smaller. + * @param enc_size the size of encoded data, in characters + * @return the maximum possible size of the decoded data, in bytes, if + * @a enc_size is valid (properly padded), + * undefined value smaller then @a enc_size if @a enc_size is not valid + */ +#define MHD_base64_max_dec_size_(enc_size) (((enc_size) / 4) * 3) + +/** * Convert Base64 encoded string to binary data. * @param base64 the input string with Base64 encoded data, could be NOT zero * terminated