From 1bc6ba4482f55e349d4ade7fa7be602b2aad25ac Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Mon, 18 Aug 2025 16:06:32 +0300 Subject: [PATCH] Fix xmlNode clearing IB-8475 Signed-off-by: Raul Metsma --- .github/workflows/build.yml | 2 -- src/XMLDocument.h | 12 +++++++----- src/util/memory.h | 9 ++++++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 396d6d22c..73e82cf4a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -95,7 +95,6 @@ jobs: - name: Prepare vcpkg uses: lukka/run-vcpkg@v11 with: - vcpkgGitCommitId: 98e7cd3a7ba579efc543f8854af800d033031eae vcpkgJsonGlob: ./vcpkg.json runVcpkgInstall: true env: @@ -198,7 +197,6 @@ jobs: - name: Prepare vcpkg uses: lukka/run-vcpkg@v11 with: - vcpkgGitCommitId: 98e7cd3a7ba579efc543f8854af800d033031eae vcpkgJsonGlob: ./vcpkg.json runVcpkgInstall: true runVcpkgFormatString: "[`install`, `--recurse`, `--clean-after-build`, `--x-install-root`, `$[env.VCPKG_INSTALLED_DIR]`, `--triplet`, `$[env.VCPKG_DEFAULT_TRIPLET]`, `--x-feature`, `tests`]" diff --git a/src/XMLDocument.h b/src/XMLDocument.h index 33d4bf617..b518cccc6 100644 --- a/src/XMLDocument.h +++ b/src/XMLDocument.h @@ -233,7 +233,9 @@ struct XMLNode: public XMLElem { if(!d) return *this; - xmlNodeAddContentLen(d, pcxmlChar(text.data()), int(text.length())); + xmlNodeSetContentLen(d, nullptr, 0); + if(!text.empty()) + xmlNodeAddContentLen(d, pcxmlChar(text.data()), int(text.length())); return *this; } @@ -281,7 +283,7 @@ struct XMLNode: public XMLElem } }; -struct XMLDocument: public unique_free_t, public XMLNode +struct XMLDocument: public unique_free_d, public XMLNode { static constexpr std::string_view C14D_ID_1_0 {"http://www.w3.org/TR/2001/REC-xml-c14n-20010315"}; static constexpr std::string_view C14D_ID_1_0_COM {"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"}; @@ -293,7 +295,7 @@ struct XMLDocument: public unique_free_t, public XMLNode using XMLNode::operator bool; XMLDocument(element_type *ptr = {}, const XMLName &n = {}) noexcept - : unique_free_t(ptr, xmlFreeDoc) + : unique_free_d(ptr) , XMLNode{xmlDocGetRootElement(get())} { if(d && !n.name.empty() && n.name != name() && !n.ns.empty() && n.ns != ns()) @@ -438,8 +440,8 @@ struct XMLDocument: public unique_free_t, public XMLNode { for(xmlSecSize i = 0; i < xmlSecPtrListGetSize(&(ctx->signedInfoReferences)); ++i) { - auto *ref = xmlSecDSigReferenceCtxPtr(xmlSecPtrListGetItem(&(ctx->signedInfoReferences), i)); - if(ref->status != xmlSecDSigStatusSucceeded) + if(auto *ref = xmlSecDSigReferenceCtxPtr(xmlSecPtrListGetItem(&(ctx->signedInfoReferences), i)); + ref && ref->status != xmlSecDSigStatusSucceeded) { if(e) e->addCause(Exception(EXCEPTION_PARAMS("Failed to validate Reference '%s'", ref->uri))); diff --git a/src/util/memory.h b/src/util/memory.h index 82cc79d32..31d92c328 100644 --- a/src/util/memory.h +++ b/src/util/memory.h @@ -46,8 +46,12 @@ struct free_argument using type = T; }; +template +using free_argument_t = typename free_argument::type; template using unique_free_t = std::unique_ptr; +template +using unique_free_d = std::unique_ptr,free_deleter>; template [[nodiscard]] @@ -74,15 +78,14 @@ template [[nodiscard]] constexpr auto make_unique_ptr(nullptr_t) noexcept { - using T = typename free_argument::type; - return make_unique_ptr(nullptr); + return unique_free_d(nullptr); } template [[nodiscard]] constexpr auto make_unique_cast(void *p) noexcept { - using T = typename free_argument::type; + using T = free_argument_t; return make_unique_ptr(static_cast(p)); }