[PATCH uci] file: Fix uci -m import command

Hauke Mehrtens hmehrtens at maxlinear.com
Thu Jul 13 09:53:22 PDT 2023


Without this change we see the following error:
  # uci -m import optic < /etc/optic-db/default
  uci: Parse error (option/list command found before the first section) at line 4, byte 1

ptr.last is still a null pointer in case the uci_lookup_list() call
found a matching section and set ptr.s to it. The code expects that
uci_set() updates the ptr.last pointer, but this is not done any more.
If case uci_lookup_list() did not found a section ptr->s is a null
pointer and then uci_set() will allocate a new section.

Fixes: ae61e1cad4a1 ("uci: optimize update section in uci_set")
Fixes: 7e01d66d7bec ("uci: optimize update option in uci_set")
Signed-off-by: Hauke Mehrtens <hmehrtens at maxlinear.com>
---
 file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/file.c b/file.c
index 93abfae..b01480c 100644
--- a/file.c
+++ b/file.c
@@ -449,6 +449,7 @@ static void uci_parse_config(struct uci_context *ctx)
 		e = uci_lookup_list(&pctx->package->sections, name);
 		if (e) {
 			ptr.s = uci_to_section(e);
+			ptr.last = &ptr.s->e;
 
 			if ((ctx->flags & UCI_FLAG_STRICT) && strcmp(ptr.s->type, type))
 				uci_parse_error(ctx, "section of different type overwrites prior section with same name");
@@ -490,8 +491,10 @@ static void uci_parse_option(struct uci_context *ctx, bool list)
 
 	uci_fill_ptr(ctx, &ptr, &pctx->section->e);
 	e = uci_lookup_list(&pctx->section->options, name);
-	if (e)
+	if (e) {
 		ptr.o = uci_to_option(e);
+		ptr.last = &ptr.o->e;
+	}
 	ptr.option = name;
 	ptr.value = value;
 
-- 
2.17.1




More information about the openwrt-devel mailing list