From 2cb0ef7402d2e6858282f488680cca523fd8ec17 Mon Sep 17 00:00:00 2001 From: khromenokroman Date: Wed, 7 Oct 2026 20:12:50 +0200 Subject: [PATCH 1/2] fix: make xp_ctx and xpath_tree layout independent of XPATH_CURRENT_OPTIMIZE xc_invariant in struct xp_ctx and xs_cached_result/xs_cached_initial in struct xpath_tree were only defined if XPATH_CURRENT_OPTIMIZE is set. That macro comes from clixon_custom.h via clixon_config.h, which is not included by clixon_xpath_ctx.c nor by external code using the installed headers via clixon.h. As a result ctx_dup() in clixon_xpath_ctx.c allocated xp_ctx without xc_invariant, while clixon_xpath_eval.c read and wrote that field past the end of the allocation. On 64-bit platforms this is hidden by struct padding, on 32-bit ARM it corrupts the heap and leads to random wrong XPath results, eg intermittent wrong NACM decisions. Define the fields unconditionally so that the struct layout is the same in all compilation units regardless of compile options. Fixes https://github.com/clicon/clixon/issues/698 --- lib/clixon/clixon_xpath.h | 4 ++-- lib/clixon/clixon_xpath_ctx.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/clixon/clixon_xpath.h b/lib/clixon/clixon_xpath.h index 3ccf4b9a4..53a655b6f 100644 --- a/lib/clixon/clixon_xpath.h +++ b/lib/clixon/clixon_xpath.h @@ -118,10 +118,10 @@ struct xpath_tree{ struct xpath_tree *xs_c0; /* child 0 */ struct xpath_tree *xs_c1; /* child 1 */ int xs_match; /* meta: match this node */ -#ifdef XPATH_CURRENT_OPTIMIZE + /* Unconditional (not only XPATH_CURRENT_OPTIMIZE): struct layout must not depend on + * compile options, see https://github.com/clicon/clixon/issues/698 */ void *xs_cached_result; /* xp_ctx *: cached evaluation result */ void *xs_cached_initial; /* cxobj *: xc_initial for which cache is valid */ -#endif }; typedef struct xpath_tree xpath_tree; diff --git a/lib/clixon/clixon_xpath_ctx.h b/lib/clixon/clixon_xpath_ctx.h index 4f4ba58fb..002734d9f 100644 --- a/lib/clixon/clixon_xpath_ctx.h +++ b/lib/clixon/clixon_xpath_ctx.h @@ -88,9 +88,9 @@ struct xp_ctx{ cxobj *xc_initial; /* RFC 7960 10.1.1 extension: for current() */ int xc_descendant; /* // */ /* NYI: a set of variable bindings, set of namespace declarations */ -#ifdef XPATH_CURRENT_OPTIMIZE + /* Unconditional (not only XPATH_CURRENT_OPTIMIZE): struct layout must not depend on + * compile options, see https://github.com/clicon/clixon/issues/698 */ int xc_invariant; /* result depends only on xc_initial (current()) */ -#endif }; typedef struct xp_ctx xp_ctx; From 8edd73105fc6acfe2b24161f60ed688cccb031fe Mon Sep 17 00:00:00 2001 From: khromenokroman Date: Wed, 7 Oct 2026 20:13:08 +0200 Subject: [PATCH 2/2] fix: include clixon_config.h in clixon_xpath_ctx.c All other xpath sources include clixon_config.h (and thereby clixon_custom.h) first. Without it compile-time options such as XPATH_CURRENT_OPTIMIZE were not visible in this file, see https://github.com/clicon/clixon/issues/698 --- lib/src/clixon_xpath_ctx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/src/clixon_xpath_ctx.c b/lib/src/clixon_xpath_ctx.c index f1022e67b..d8e7f256c 100644 --- a/lib/src/clixon_xpath_ctx.c +++ b/lib/src/clixon_xpath_ctx.c @@ -36,6 +36,10 @@ * Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10 * This file defines XPath contexts used in traversing the XPath parse tree. */ +#ifdef HAVE_CONFIG_H +#include "clixon_config.h" /* generated by config & autoconf */ +#endif + #include #include #include