diff options
author | Jörg Frings-Fürst <debian@jff-webhsoting.net> | 2024-06-30 16:13:02 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhsoting.net> | 2024-06-30 16:13:02 +0200 |
commit | bc983f30186f3c204b1daea57b0057f93b74dde1 (patch) | |
tree | 357a9a66bd433007f792130ebbeb5c2df4f8c507 /src | |
parent | 89fb04a92f080a266c9b509cb522a4b8e8ad92de (diff) |
New upstream version 0.9.8+dfsgupstream/0.9.8+dfsgupstream
Diffstat (limited to 'src')
-rw-r--r-- | src/UriQuery.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/UriQuery.c b/src/UriQuery.c index b2734bc..bbc1548 100644 --- a/src/UriQuery.c +++ b/src/UriQuery.c @@ -70,6 +70,7 @@ #include <limits.h> +#include <stddef.h> /* size_t */ @@ -177,10 +178,13 @@ int URI_FUNC(ComposeQueryMallocExMm)(URI_CHAR ** dest, if (res != URI_SUCCESS) { return res; } + if (charsRequired == INT_MAX) { + return URI_ERROR_MALLOC; + } charsRequired++; /* Allocate space */ - queryString = memory->malloc(memory, charsRequired * sizeof(URI_CHAR)); + queryString = memory->calloc(memory, charsRequired, sizeof(URI_CHAR)); if (queryString == NULL) { return URI_ERROR_MALLOC; } @@ -218,16 +222,16 @@ int URI_FUNC(ComposeQueryEngine)(URI_CHAR * dest, const URI_CHAR * const key = queryList->key; const URI_CHAR * const value = queryList->value; const int worstCase = (normalizeBreaks == URI_TRUE ? 6 : 3); - const int keyLen = (key == NULL) ? 0 : (int)URI_STRLEN(key); + const size_t keyLen = (key == NULL) ? 0 : URI_STRLEN(key); int keyRequiredChars; - const int valueLen = (value == NULL) ? 0 : (int)URI_STRLEN(value); + const size_t valueLen = (value == NULL) ? 0 : URI_STRLEN(value); int valueRequiredChars; - if ((keyLen >= INT_MAX / worstCase) || (valueLen >= INT_MAX / worstCase)) { + if ((keyLen >= (size_t)INT_MAX / worstCase) || (valueLen >= (size_t)INT_MAX / worstCase)) { return URI_ERROR_OUTPUT_TOO_LARGE; } - keyRequiredChars = worstCase * keyLen; - valueRequiredChars = worstCase * valueLen; + keyRequiredChars = worstCase * (int)keyLen; + valueRequiredChars = worstCase * (int)valueLen; if (dest == NULL) { (*charsRequired) += ampersandLen + keyRequiredChars + ((value == NULL) |