[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 01/03: postprocessor: minor code improvement
From: |
gnunet |
Subject: |
[libmicrohttpd] 01/03: postprocessor: minor code improvement |
Date: |
Wed, 15 Sep 2021 20:18:44 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit ddcc20a0bad70fd87ed60625460b6efd6a7e84e6
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Wed Sep 15 19:54:46 2021 +0300
postprocessor: minor code improvement
---
src/microhttpd/postprocessor.c | 47 +++++++++++++++++++++++-------------------
1 file changed, 26 insertions(+), 21 deletions(-)
diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c
index 2720e916..9b87554a 100644
--- a/src/microhttpd/postprocessor.c
+++ b/src/microhttpd/postprocessor.c
@@ -646,25 +646,27 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
break;
case PP_Callback:
mhd_assert ((NULL != end_key) || (NULL == start_key));
- if ( (pp->buffer_pos + (end_key - start_key) >=
- pp->buffer_size) ||
- (pp->buffer_pos + (end_key - start_key) <
- pp->buffer_pos) )
+ if (1)
{
- /* key too long, cannot parse! */
- pp->state = PP_Error;
- continue;
- }
- /* compute key, if we have not already */
- if (NULL != start_key)
- {
- memcpy (&kbuf[pp->buffer_pos],
- start_key,
- end_key - start_key);
- pp->buffer_pos += end_key - start_key;
- start_key = NULL;
- end_key = NULL;
- pp->must_unescape_key = true;
+ const size_t key_len = end_key - start_key;
+ if (0 != key_len)
+ {
+ if ( (pp->buffer_pos + key_len >= pp->buffer_size) ||
+ (pp->buffer_pos + key_len < pp->buffer_pos) )
+ {
+ /* key too long, cannot parse! */
+ pp->state = PP_Error;
+ continue;
+ }
+ /* compute key, if we have not already */
+ memcpy (&kbuf[pp->buffer_pos],
+ start_key,
+ key_len);
+ pp->buffer_pos += key_len;
+ start_key = NULL;
+ end_key = NULL;
+ pp->must_unescape_key = true;
+ }
}
if (pp->must_unescape_key)
{
@@ -706,18 +708,21 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
/* save remaining data for next iteration */
if (NULL != start_key)
{
+ size_t key_len;
mhd_assert ((PP_Init == pp->state) || (NULL != end_key));
if (NULL == end_key)
end_key = &post_data[poff];
- if (pp->buffer_pos + (end_key - start_key) >= pp->buffer_size)
+ key_len = end_key - start_key;
+ mhd_assert (0 != key_len); /* it must be always non-zero here */
+ if (pp->buffer_pos + key_len >= pp->buffer_size)
{
pp->state = PP_Error;
return MHD_NO;
}
memcpy (&kbuf[pp->buffer_pos],
start_key,
- end_key - start_key);
- pp->buffer_pos += end_key - start_key;
+ key_len);
+ pp->buffer_pos += key_len;
pp->must_unescape_key = true;
start_key = NULL;
end_key = NULL;
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.