[PATCH 2/4] bootconfig: Fix xbc_node_compose_key_after() for value nodes

From: Masami Hiramatsu (Google)

Date: Sat Nov 21 2026 - 20:01:48 EST


From: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>

Fix two issues in xbc_node_compose_key_after() when @node is a value node:

1. Since array values are chained via the child pointer in
xbc_parse_array(), the 2nd and subsequent value nodes of an array have
the preceding value node as their parent rather than the owning key
node. Climbing only one parent (if (xbc_node_is_value(node))) caused
preceding array value strings to be included in the composed key
(e.g. "foo.bar.val1" instead of "foo.bar").

2. Checking `if (!node || node == root)` before climbing to the owning
key node allowed a value node belonging to the subtree @root key node
itself (e.g. `foo = "val"` with `@root = xbc_find_node("foo")`) to
pass the check, climb to @root, skip the key-collection loop
(depth == 0), and return 0 without writing anything (not even a NUL
terminator) to @buf.

Climb parent pointers in a loop while the node is a value node, and
perform the `if (!node || node == root)` check afterward.

Fixes: ca24306d83a1 ("bootconfig: Change array value to use child node")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
---
lib/bootconfig.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index 026d88a65c5c..280b7e73321b 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -421,12 +421,12 @@ int __init xbc_node_compose_key_after(struct xbc_node *root,
uint16_t keys[XBC_DEPTH_MAX];
int depth = 0, ret = 0, total = 0;

+ while (node && xbc_node_is_value(node))
+ node = xbc_node_get_parent(node);
+
if (!node || node == root)
return -EINVAL;

- if (xbc_node_is_value(node))
- node = xbc_node_get_parent(node);
-
while (node && node != root) {
if (depth == XBC_DEPTH_MAX)
return -ERANGE;