diff mbox series

[uci] file: Fix uci -m import command

Message ID mailman.17073.1689267317.1880391.openwrt-devel@lists.openwrt.org
State Superseded
Delegated to: Hauke Mehrtens
Headers show
Series [uci] file: Fix uci -m import command | expand

Commit Message

Hauke Mehrtens July 13, 2023, 4:53 p.m. UTC
The sender domain has a DMARC Reject/Quarantine policy which disallows
sending mailing list messages using the original "From" header.

To mitigate this problem, the original message has been wrapped
automatically by the mailing list software.
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@maxlinear.com>
---
 file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

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;