diff options
author | Jörg Frings-Fürst <debian@jff-webhsoting.net> | 2024-07-12 08:33:43 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhsoting.net> | 2024-07-12 08:33:43 +0200 |
commit | d900a0ce85f9389882567e9698b4f785971f35a8 (patch) | |
tree | 866aa6eda9429d9e96cb770b7689d51d78f2b624 /src/UriQuery.c | |
parent | 9d31dcdfaf0dba9491580ba69eae7817a5b0d455 (diff) | |
parent | 9b93aee54f41e2700d2c10f46f26fec69673c7c9 (diff) |
Merge branch 'release/debian/0.9.8+dfsg-1'debian/0.9.8+dfsg-1
Diffstat (limited to 'src/UriQuery.c')
-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) |