aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2023-05-25 20:06:12 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2023-06-01 13:27:49 +0300
commitfbd7cef55e809f9fc75206d3b358a8cd077222c0 (patch)
tree8f45c04abdf46ce61e8cb310bd0c7257a7076dd7
parent61b407a25a6f9c3d761685b6ebad4065c2b4775e (diff)
downloadlibmicrohttpd-fbd7cef55e809f9fc75206d3b358a8cd077222c0.tar.gz
libmicrohttpd-fbd7cef55e809f9fc75206d3b358a8cd077222c0.zip
Added macro for base64 decoded size
-rw-r--r--src/microhttpd/basicauth.c2
-rw-r--r--src/microhttpd/mhd_str.h10
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)
60 if ((NULL == params->token68.str) || (0 == params->token68.len)) 60 if ((NULL == params->token68.str) || (0 == params->token68.len))
61 return NULL; 61 return NULL;
62 62
63 decoded_max_len = (params->token68.len / 4) * 3; 63 decoded_max_len = MHD_base64_max_dec_size_ (params->token68.len);
64 ret = (struct MHD_BasicAuthInfo *) malloc (sizeof(struct MHD_BasicAuthInfo) 64 ret = (struct MHD_BasicAuthInfo *) malloc (sizeof(struct MHD_BasicAuthInfo)
65 + decoded_max_len + 1); 65 + decoded_max_len + 1);
66 if (NULL != ret) 66 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,
740#ifdef BAUTH_SUPPORT 740#ifdef BAUTH_SUPPORT
741 741
742/** 742/**
743 * Returns the maximum possible size of the Base64 decoded data.
744 * The real recoded size could be up to two bytes smaller.
745 * @param enc_size the size of encoded data, in characters
746 * @return the maximum possible size of the decoded data, in bytes, if
747 * @a enc_size is valid (properly padded),
748 * undefined value smaller then @a enc_size if @a enc_size is not valid
749 */
750#define MHD_base64_max_dec_size_(enc_size) (((enc_size) / 4) * 3)
751
752/**
743 * Convert Base64 encoded string to binary data. 753 * Convert Base64 encoded string to binary data.
744 * @param base64 the input string with Base64 encoded data, could be NOT zero 754 * @param base64 the input string with Base64 encoded data, could be NOT zero
745 * terminated 755 * terminated