Skip to content

Commit ef9e361

Browse files
committed
Fix xmlNode clearing
IB-8475 Signed-off-by: Raul Metsma <[email protected]>
1 parent d499a3b commit ef9e361

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/XMLDocument.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ struct XMLNode: public XMLElem<xmlNode>
233233
{
234234
if(!d)
235235
return *this;
236-
xmlNodeAddContentLen(d, pcxmlChar(text.data()), int(text.length()));
236+
xmlNodeSetContentLen(d, nullptr, 0);
237+
if(!text.empty())
238+
xmlNodeAddContentLen(d, pcxmlChar(text.data()), int(text.length()));
237239
return *this;
238240
}
239241

@@ -281,7 +283,7 @@ struct XMLNode: public XMLElem<xmlNode>
281283
}
282284
};
283285

284-
struct XMLDocument: public unique_free_t<xmlDoc>, public XMLNode
286+
struct XMLDocument: public unique_free_d<xmlFreeDoc>, public XMLNode
285287
{
286288
static constexpr std::string_view C14D_ID_1_0 {"http://www.w3.org/TR/2001/REC-xml-c14n-20010315"};
287289
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<xmlDoc>, public XMLNode
293295
using XMLNode::operator bool;
294296

295297
XMLDocument(element_type *ptr = {}, const XMLName &n = {}) noexcept
296-
: unique_free_t<xmlDoc>(ptr, xmlFreeDoc)
298+
: unique_free_d<xmlFreeDoc>(ptr)
297299
, XMLNode{xmlDocGetRootElement(get())}
298300
{
299301
if(d && !n.name.empty() && n.name != name() && !n.ns.empty() && n.ns != ns())
@@ -438,8 +440,8 @@ struct XMLDocument: public unique_free_t<xmlDoc>, public XMLNode
438440
{
439441
for(xmlSecSize i = 0; i < xmlSecPtrListGetSize(&(ctx->signedInfoReferences)); ++i)
440442
{
441-
auto *ref = xmlSecDSigReferenceCtxPtr(xmlSecPtrListGetItem(&(ctx->signedInfoReferences), i));
442-
if(ref->status != xmlSecDSigStatusSucceeded)
443+
if(auto *ref = xmlSecDSigReferenceCtxPtr(xmlSecPtrListGetItem(&(ctx->signedInfoReferences), i));
444+
ref && ref->status != xmlSecDSigStatusSucceeded)
443445
{
444446
if(e)
445447
e->addCause(Exception(EXCEPTION_PARAMS("Failed to validate Reference '%s'", ref->uri)));

src/util/memory.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ struct free_argument<R (&)(T *)>
4646
using type = T;
4747
};
4848

49+
template <auto D>
50+
using free_argument_t = typename free_argument<decltype(D)>::type;
4951
template <class T>
5052
using unique_free_t = std::unique_ptr<T, void(*)(T*)>;
53+
template <auto D>
54+
using unique_free_d = std::unique_ptr<free_argument_t<D>,free_deleter<D>>;
5155

5256
template<class T, class U>
5357
[[nodiscard]]
@@ -74,15 +78,14 @@ template<auto D>
7478
[[nodiscard]]
7579
constexpr auto make_unique_ptr(nullptr_t) noexcept
7680
{
77-
using T = typename free_argument<decltype(D)>::type;
78-
return make_unique_ptr<D, T>(nullptr);
81+
return unique_free_d<D>(nullptr);
7982
}
8083

8184
template<auto D>
8285
[[nodiscard]]
8386
constexpr auto make_unique_cast(void *p) noexcept
8487
{
85-
using T = typename free_argument<decltype(D)>::type;
88+
using T = free_argument_t<D>;
8689
return make_unique_ptr<D>(static_cast<T*>(p));
8790
}
8891

0 commit comments

Comments
 (0)