[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 02/06: digestauth: avoid malloc() repeat by using the ne
From: |
gnunet |
Subject: |
[libmicrohttpd] 02/06: digestauth: avoid malloc() repeat by using the new function |
Date: |
Mon, 19 Dec 2022 16:17:59 +0100 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit 784b802900cb51b885f20e68dddd0627d626d89c
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Wed Nov 16 12:31:55 2022 +0300
digestauth: avoid malloc() repeat by using the new function
---
src/microhttpd/digestauth.c | 29 ++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 926ac5f4..5505118c 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -3507,6 +3507,7 @@ queue_auth_required_response3_inner (struct
MHD_Connection *connection,
size_t buf_size;
char *buf;
size_t p; /* The position in the buffer */
+ char *hdr_name;
if (0 != (((unsigned int) malgo3) & MHD_DIGEST_AUTH_ALGO3_SESSION))
{
@@ -3836,24 +3837,34 @@ queue_auth_required_response3_inner (struct
MHD_Connection *connection,
buf[p++] = ' ';
}
mhd_assert (buf_size >= p);
- /* The build string ends with ", ". Replace comma with zero-termination. */
+ /* The built string ends with ", ". Replace comma with zero-termination. */
--p;
buf[--p] = 0;
- if (! MHD_add_response_entry_no_check_ (response, MHD_HEADER_KIND,
- MHD_HTTP_HEADER_WWW_AUTHENTICATE,
+ hdr_name = malloc (MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_WWW_AUTHENTICATE) +
1);
+ if (NULL != hdr_name)
+ {
+ memcpy (hdr_name, MHD_HTTP_HEADER_WWW_AUTHENTICATE,
+ MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_WWW_AUTHENTICATE) + 1);
+ if (MHD_add_response_entry_no_alloc_ (response, MHD_HEADER_KIND,
+ hdr_name,
MHD_STATICSTR_LEN_ ( \
MHD_HTTP_HEADER_WWW_AUTHENTICATE),
buf, p))
- {
+ {
+ *buf_ptr = NULL; /* The buffer will be free()ed when the response is
destroyed */
+ return MHD_queue_response (connection, MHD_HTTP_UNAUTHORIZED, response);
+ }
#ifdef HAVE_MESSAGES
- MHD_DLOG (connection->daemon,
- _ ("Failed to add Digest auth header.\n"));
+ else
+ {
+ MHD_DLOG (connection->daemon,
+ _ ("Failed to add Digest auth header.\n"));
+ }
#endif /* HAVE_MESSAGES */
- return MHD_NO;
+ free (hdr_name);
}
-
- return MHD_queue_response (connection, MHD_HTTP_UNAUTHORIZED, response);
+ return MHD_NO;
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd] branch master updated (3444792f -> 1e7ad301), gnunet, 2022/12/19
- [libmicrohttpd] 01/06: response.c: added new internal function to avoid repetitive malloc()s, gnunet, 2022/12/19
- [libmicrohttpd] 03/06: parse_http_version(): cosmetics, gnunet, 2022/12/19
- [libmicrohttpd] 05/06: test_parse_cookies: rewritten, gnunet, 2022/12/19
- [libmicrohttpd] 06/06: Refactored cookies parsing., gnunet, 2022/12/19
- [libmicrohttpd] 04/06: MHD_get_version_bin(): added new function, gnunet, 2022/12/19
- [libmicrohttpd] 02/06: digestauth: avoid malloc() repeat by using the new function,
gnunet <=