diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2023-05-25 20:06:12 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2023-06-01 13:27:49 +0300 |
commit | fbd7cef55e809f9fc75206d3b358a8cd077222c0 (patch) | |
tree | 8f45c04abdf46ce61e8cb310bd0c7257a7076dd7 | |
parent | 61b407a25a6f9c3d761685b6ebad4065c2b4775e (diff) |
Added macro for base64 decoded size
-rw-r--r-- | src/microhttpd/basicauth.c | 2 | ||||
-rw-r--r-- | src/microhttpd/mhd_str.h | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/microhttpd/basicauth.c b/src/microhttpd/basicauth.c index 07b124f1..78818a95 100644 --- 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 index e2964406..f7a4f79f 100644 --- 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 |