summaryrefslogtreecommitdiff
path: root/src/UriNormalize.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhsoting.net>2022-01-09 18:59:52 +0100
committerJörg Frings-Fürst <debian@jff-webhsoting.net>2022-01-09 18:59:52 +0100
commitf308d3149d855c4d6d0251cf6bce393dfa371329 (patch)
tree1c109543808e40e553cfea44f1329bd410f743ff /src/UriNormalize.c
parentd336d9867cfdbf1683653de369d67f5c7bea3f5e (diff)
parent592ab485a70ab4c8e4cefc37bbdfb76110f9205e (diff)
Update upstream source from tag 'upstream/0.9.6'
Update to upstream version '0.9.6' with Debian dir 046219032722c15fb3571e4dcdc4a0f0c418b137
Diffstat (limited to 'src/UriNormalize.c')
-rw-r--r--src/UriNormalize.c53
1 files changed, 30 insertions, 23 deletions
diff --git a/src/UriNormalize.c b/src/UriNormalize.c
index 04a8e5f..eb072b2 100644
--- a/src/UriNormalize.c
+++ b/src/UriNormalize.c
@@ -115,13 +115,17 @@ static void URI_FUNC(PreventLeakage)(URI_TYPE(Uri) * uri,
static URI_INLINE void URI_FUNC(PreventLeakage)(URI_TYPE(Uri) * uri,
unsigned int revertMask, UriMemoryManager * memory) {
if (revertMask & URI_NORMALIZE_SCHEME) {
+ /* NOTE: A scheme cannot be the empty string
+ * so no need to compare .first with .afterLast, here. */
memory->free(memory, (URI_CHAR *)uri->scheme.first);
uri->scheme.first = NULL;
uri->scheme.afterLast = NULL;
}
if (revertMask & URI_NORMALIZE_USER_INFO) {
- memory->free(memory, (URI_CHAR *)uri->userInfo.first);
+ if (uri->userInfo.first != uri->userInfo.afterLast) {
+ memory->free(memory, (URI_CHAR *)uri->userInfo.first);
+ }
uri->userInfo.first = NULL;
uri->userInfo.afterLast = NULL;
}
@@ -129,16 +133,18 @@ static URI_INLINE void URI_FUNC(PreventLeakage)(URI_TYPE(Uri) * uri,
if (revertMask & URI_NORMALIZE_HOST) {
if (uri->hostData.ipFuture.first != NULL) {
/* IPvFuture */
+ /* NOTE: An IPvFuture address cannot be the empty string
+ * so no need to compare .first with .afterLast, here. */
memory->free(memory, (URI_CHAR *)uri->hostData.ipFuture.first);
uri->hostData.ipFuture.first = NULL;
uri->hostData.ipFuture.afterLast = NULL;
uri->hostText.first = NULL;
uri->hostText.afterLast = NULL;
- } else if ((uri->hostText.first != NULL)
- && (uri->hostData.ip4 == NULL)
- && (uri->hostData.ip6 == NULL)) {
+ } else if (uri->hostText.first != NULL) {
/* Regname */
- memory->free(memory, (URI_CHAR *)uri->hostText.first);
+ if (uri->hostText.first != uri->hostText.afterLast) {
+ memory->free(memory, (URI_CHAR *)uri->hostText.first);
+ }
uri->hostText.first = NULL;
uri->hostText.afterLast = NULL;
}
@@ -161,13 +167,17 @@ static URI_INLINE void URI_FUNC(PreventLeakage)(URI_TYPE(Uri) * uri,
}
if (revertMask & URI_NORMALIZE_QUERY) {
- memory->free(memory, (URI_CHAR *)uri->query.first);
+ if (uri->query.first != uri->query.afterLast) {
+ memory->free(memory, (URI_CHAR *)uri->query.first);
+ }
uri->query.first = NULL;
uri->query.afterLast = NULL;
}
if (revertMask & URI_NORMALIZE_FRAGMENT) {
- memory->free(memory, (URI_CHAR *)uri->fragment.first);
+ if (uri->fragment.first != uri->fragment.afterLast) {
+ memory->free(memory, (URI_CHAR *)uri->fragment.first);
+ }
uri->fragment.first = NULL;
uri->fragment.afterLast = NULL;
}
@@ -407,22 +417,19 @@ static URI_INLINE UriBool URI_FUNC(MakeOwnerEngine)(URI_TYPE(Uri) * uri,
/* Host */
if ((*doneMask & URI_NORMALIZE_HOST) == 0) {
- if ((uri->hostData.ip4 == NULL)
- && (uri->hostData.ip6 == NULL)) {
- if (uri->hostData.ipFuture.first != NULL) {
- /* IPvFuture */
- if (!URI_FUNC(MakeRangeOwner)(doneMask, URI_NORMALIZE_HOST,
- &(uri->hostData.ipFuture), memory)) {
- return URI_FALSE; /* Raises malloc error */
- }
- uri->hostText.first = uri->hostData.ipFuture.first;
- uri->hostText.afterLast = uri->hostData.ipFuture.afterLast;
- } else if (uri->hostText.first != NULL) {
- /* Regname */
- if (!URI_FUNC(MakeRangeOwner)(doneMask, URI_NORMALIZE_HOST,
- &(uri->hostText), memory)) {
- return URI_FALSE; /* Raises malloc error */
- }
+ if (uri->hostData.ipFuture.first != NULL) {
+ /* IPvFuture */
+ if (!URI_FUNC(MakeRangeOwner)(doneMask, URI_NORMALIZE_HOST,
+ &(uri->hostData.ipFuture), memory)) {
+ return URI_FALSE; /* Raises malloc error */
+ }
+ uri->hostText.first = uri->hostData.ipFuture.first;
+ uri->hostText.afterLast = uri->hostData.ipFuture.afterLast;
+ } else if (uri->hostText.first != NULL) {
+ /* Regname */
+ if (!URI_FUNC(MakeRangeOwner)(doneMask, URI_NORMALIZE_HOST,
+ &(uri->hostText), memory)) {
+ return URI_FALSE; /* Raises malloc error */
}
}
}