summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2018-08-08 23:28:34 +0200
committerJo-Philipp Wich <jo@mein.io>2018-08-09 00:07:27 +0200
commit41333abee4c57e3de2bcfa08972954e2af20705a (patch)
tree82556898fc86a1de22db70295cdcb9daee9ffb58
parentf91751b767b4b354d29821c659a443b615f8e13d (diff)
downloadrpcd-41333abee4c57e3de2bcfa08972954e2af20705a.tar.gz
uci: tighten uci reorder operation error handling
- Return UBUS_STATUS_INVALID_ARGUMENT for invalid section names - Return UBUS_STATUS_NOT_FOUND if a section name could not be resolved
-rw-r--r--uci.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/uci.c b/uci.c
index e23c956..1587a19 100644
--- a/uci.c
+++ b/uci.c
@@ -1131,7 +1131,7 @@ rpc_uci_order(struct ubus_context *ctx, struct ubus_object *obj,
struct blob_attr *cur;
struct uci_package *p = NULL;
struct uci_ptr ptr = { 0 };
- int rem, i = 0;
+ int rem, i = 0, err = 0;
blobmsg_parse(rpc_uci_order_policy, __RPC_O_MAX, tb,
blob_data(msg), blob_len(msg));
@@ -1150,21 +1150,33 @@ rpc_uci_order(struct ubus_context *ctx, struct ubus_object *obj,
blobmsg_for_each_attr(cur, tb[RPC_O_SECTIONS], rem)
{
if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
+ {
+ if (!err)
+ err = UBUS_STATUS_INVALID_ARGUMENT;
+
continue;
+ }
ptr.s = NULL;
ptr.section = blobmsg_data(cur);
if (uci_lookup_ptr(cursor, &ptr, NULL, true) || !ptr.s)
+ {
+ if (!err)
+ err = UBUS_STATUS_NOT_FOUND;
+
continue;
+ }
uci_reorder_section(cursor, ptr.s, i++);
}
- uci_save(cursor, p);
+ if (!err)
+ uci_save(cursor, p);
+
uci_unload(cursor, p);
- return rpc_uci_status();
+ return err ? err : rpc_uci_status();
}
static void