diff options
author | Jo-Philipp Wich <jo@mein.io> | 2018-08-08 23:55:07 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2018-08-09 00:07:26 +0200 |
commit | 948bb5187523ee596f2de64bd6b94ec9a7f27546 (patch) | |
tree | 7d796f39eab92bd78d84f45113fd373bba4fc924 | |
parent | 51980c687b92d2ce78a77ad2a3ca8e4959bd937f (diff) | |
download | rpcd-948bb5187523ee596f2de64bd6b94ec9a7f27546.tar.gz |
uci: tighten uci add operation error handling
- Return UBUS_STATUS_INVALID_ARGUMENT for invalid section or option names
- Return UBUS_STATUS_NOT_FOUND if a section name could not be resolved
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | uci.c | 49 |
1 files changed, 40 insertions, 9 deletions
@@ -687,7 +687,7 @@ rpc_uci_add(struct ubus_context *ctx, struct ubus_object *obj, struct uci_package *p = NULL; struct uci_section *s; struct uci_ptr ptr = { 0 }; - int rem, rem2; + int rem, rem2, err = 0; blobmsg_parse(rpc_uci_add_policy, __RPC_A_MAX, tb, blob_data(msg), blob_len(msg)); @@ -738,37 +738,68 @@ rpc_uci_add(struct ubus_context *ctx, struct ubus_object *obj, ptr.option = blobmsg_name(cur); if (!rpc_uci_verify_name(ptr.option)) + { + if (!err) + err = UBUS_STATUS_INVALID_ARGUMENT; + continue; + } if (rpc_uci_lookup(&ptr) || !ptr.s) + { + if (!err) + err = UBUS_STATUS_NOT_FOUND; + continue; + } switch (blobmsg_type(cur)) { case BLOBMSG_TYPE_ARRAY: blobmsg_for_each_attr(elem, cur, rem2) - if (rpc_uci_format_blob(elem, &ptr.value)) - uci_add_list(cursor, &ptr); + { + if (!rpc_uci_format_blob(elem, &ptr.value)) + { + if (!err) + err = UBUS_STATUS_INVALID_ARGUMENT; + + continue; + } + + uci_add_list(cursor, &ptr); + } + break; default: - if (rpc_uci_format_blob(cur, &ptr.value)) + if (!rpc_uci_format_blob(cur, &ptr.value)) + { + if (!err) + err = UBUS_STATUS_INVALID_ARGUMENT; + } + else + { uci_set(cursor, &ptr); + } + break; } } } - uci_save(cursor, p); + if (!err) + { + uci_save(cursor, p); - blob_buf_init(&buf, 0); - blobmsg_add_string(&buf, "section", ptr.section); - ubus_send_reply(ctx, req, buf.head); + blob_buf_init(&buf, 0); + blobmsg_add_string(&buf, "section", ptr.section); + ubus_send_reply(ctx, req, buf.head); + } out: uci_unload(cursor, p); - return rpc_uci_status(); + return err ? err : rpc_uci_status(); } /* |