From 987b046e41f407d17c622e580fc82a5e834b4329 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sat, 2 Oct 2021 02:15:05 +0200 Subject: [PATCH] UriNormalize.c: Fix .hostText copying in uriMakeOwnerEngine (#121) Commit is viewed best with "git show --ignore-all-space " --- ChangeLog | 4 ++++ src/UriNormalize.c | 29 +++++++++++++---------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8fceb664..22f1e4be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,10 @@ NOTE: uriparser is looking for help with a few things: XXXX-XX-XX -- X.X.X + * Fixed: Fix a bug affecting both uriNormalizeSyntax* and uriMakeOwner* + functions where the text range in .hostText would not be duped using + malloc but remain unchanged (and hence "not owned") for URIs with + an IPv4 or IPv6 address hostname (GitHub #121) * Fixed: CMake: Call "enable_language(CXX)" prior to tinkering with CMAKE_CXX_* variables (GitHub #110) Thanks to Alexander Richardson for the patch (originally at libexpat) diff --git a/src/UriNormalize.c b/src/UriNormalize.c index 04a8e5f4..b1f47b4f 100644 --- a/src/UriNormalize.c +++ b/src/UriNormalize.c @@ -407,22 +407,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 */ } } }