diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-03-08 10:36:05 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-03-08 19:18:58 +0100 |
commit | e8669a8902079b9485fbbf1fb8884b947de9bbfb (patch) | |
tree | 319b8b8c64085e41740a586a8bb1a46d4b755205 /lib/uci.c | |
parent | a6c69b18cbf19dc43092b0ae23758a83471357a8 (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/uci.c')
-rw-r--r-- | lib/uci.c | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -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[] = { |