mirror of
https://github.com/Telecominfraproject/wlan-ap.git
synced 2025-11-01 02:48:18 +00:00
ucode: backport uci.foreach fix
Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
58
feeds/ucentral/ucode/patches/0009-uci_foreach.patch
Normal file
58
feeds/ucentral/ucode/patches/0009-uci_foreach.patch
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
From d2cc00310dba05de233ff18d3c830c8638f9bfdf Mon Sep 17 00:00:00 2001
|
||||||
|
From: Jo-Philipp Wich <jo@mein.io>
|
||||||
|
Date: Wed, 23 Nov 2022 12:48:07 +0100
|
||||||
|
Subject: [PATCH] uci: auto-load package in `ctx.foreach()` and
|
||||||
|
`ctx.get_first()`
|
||||||
|
|
||||||
|
Functions that use `uci_lookup_ptr()` internally, such as `ctx.get()`,
|
||||||
|
`ctx.set()` or `ctx.delete()`, implicitly load the given configuration
|
||||||
|
name while the higher level functions `ctx.foreach()` or `ctx.get_first()`
|
||||||
|
do not.
|
||||||
|
|
||||||
|
This behaviour violates the principle of least surprise and might lead to
|
||||||
|
non-deterministic program behavior as the outcome of these functions
|
||||||
|
depends on prior uci operations performed on the cursor.
|
||||||
|
|
||||||
|
Fix this issue by invoking `uci_load()` internally in case the given
|
||||||
|
uci package name cannot be found in the cursor's package cache.
|
||||||
|
|
||||||
|
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
||||||
|
---
|
||||||
|
lib/uci.c | 10 ++++------
|
||||||
|
1 file changed, 4 insertions(+), 6 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/lib/uci.c b/lib/uci.c
|
||||||
|
index 50cc050e..b88dabd1 100644
|
||||||
|
--- a/lib/uci.c
|
||||||
|
+++ b/lib/uci.c
|
||||||
|
@@ -346,8 +346,8 @@ uc_uci_get_first(uc_vm_t *vm, size_t nargs)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
- if (!p)
|
||||||
|
- err_return(UCI_ERR_NOTFOUND);
|
||||||
|
+ if (!p && uci_load(*c, ucv_string_get(conf), &p))
|
||||||
|
+ err_return((*c)->err);
|
||||||
|
|
||||||
|
uci_foreach_element(&p->sections, e) {
|
||||||
|
sc = uci_to_section(e);
|
||||||
|
@@ -917,8 +917,8 @@ uc_uci_foreach(uc_vm_t *vm, size_t nargs)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
- if (!p)
|
||||||
|
- err_return(UCI_ERR_NOTFOUND);
|
||||||
|
+ if (!p && uci_load(*c, ucv_string_get(conf), &p))
|
||||||
|
+ err_return((*c)->err);
|
||||||
|
|
||||||
|
uci_foreach_element_safe(&p->sections, tmp, e) {
|
||||||
|
sc = uci_to_section(e);
|
||||||
|
@@ -946,8 +946,6 @@ uc_uci_foreach(uc_vm_t *vm, size_t nargs)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
- /* XXX: rethrow */
|
||||||
|
-
|
||||||
|
return ucv_boolean_new(ret);
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user