summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-03-08 10:36:05 +0100
committerJo-Philipp Wich <jo@mein.io>2021-03-08 19:18:58 +0100
commite8669a8902079b9485fbbf1fb8884b947de9bbfb (patch)
tree319b8b8c64085e41740a586a8bb1a46d4b755205 /lib
parenta6c69b18cbf19dc43092b0ae23758a83471357a8 (diff)
uci: fix potential invalid memory access in error()
Check the numerical error code index before attempting to look it up in the error string array. Also make error function available on the cursor instance as well. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'lib')
-rw-r--r--lib/uci.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/uci.c b/lib/uci.c
index e00f77e..be98214 100644
--- a/lib/uci.c
+++ b/lib/uci.c
@@ -49,7 +49,7 @@ uc_uci_error(uc_vm *vm, size_t nargs)
if (last_error == 0)
return NULL;
- if (errstr[last_error]) {
+ if (last_error >= 0 && last_error < ARRAY_SIZE(errstr)) {
errmsg = json_object_new_string(errstr[last_error]);
}
else {
@@ -993,6 +993,7 @@ static const uc_cfunction_list cursor_fns[] = {
{ "changes", uc_uci_changes },
{ "foreach", uc_uci_foreach },
{ "configs", uc_uci_configs },
+ { "error", uc_uci_error },
};
static const uc_cfunction_list global_fns[] = {