session: Fix crash when the UCI option 'password' or 'username' is missing
[project/rpcd.git] / uci.c
diff --git a/uci.c b/uci.c
index 0de6f3e23f8d3ba2fbfa1a653a9129ce26fb7dd0..3cd2b829efd055e3096da1499fbf2e70f5f1850b 100644 (file)
--- a/uci.c
+++ b/uci.c
@@ -734,6 +734,7 @@ rpc_uci_add(struct ubus_context *ctx, struct ubus_object *obj,
        {
                blobmsg_for_each_attr(cur, tb[RPC_A_VALUES], rem)
                {
+                       ptr.flags = 0;
                        ptr.o = NULL;
                        ptr.option = blobmsg_name(cur);
 
@@ -830,8 +831,10 @@ rpc_uci_merge_set(struct blob_attr *opt, struct uci_ptr *ptr)
 
        if (blobmsg_type(opt) == BLOBMSG_TYPE_ARRAY)
        {
-               if (ptr->o)
+               if (ptr->o) {
                        uci_delete(cursor, ptr);
+                       ptr->flags = 0;
+               }
 
                rv = UBUS_STATUS_INVALID_ARGUMENT;
 
@@ -849,6 +852,7 @@ rpc_uci_merge_set(struct blob_attr *opt, struct uci_ptr *ptr)
        else if (ptr->o && ptr->o->type == UCI_TYPE_LIST)
        {
                uci_delete(cursor, ptr);
+               ptr->flags = 0;
 
                if (!rpc_uci_format_blob(opt, &ptr->value))
                        return UBUS_STATUS_INVALID_ARGUMENT;
@@ -980,6 +984,7 @@ rpc_uci_merge_delete(struct blob_attr *opt, struct uci_ptr *ptr)
                                continue;
 
                        uci_delete(cursor, ptr);
+                       ptr->flags = 0;
                        rv = 0;
                }
 
@@ -1286,6 +1291,8 @@ rpc_uci_changes(struct ubus_context *ctx, struct ubus_object *obj,
                uci_unload(cursor, p);
        }
 
+       free(configs);
+
        blobmsg_close_table(&buf, c);
 
        ubus_send_reply(ctx, req, buf.head);
@@ -1390,6 +1397,8 @@ rpc_uci_configs(struct ubus_context *ctx, struct ubus_object *obj,
        for (i = 0; configs[i]; i++)
                blobmsg_add_string(&buf, NULL, configs[i]);
 
+       free(configs);
+
        blobmsg_close_array(&buf, c);
 
        ubus_send_reply(ctx, req, buf.head);
@@ -1769,7 +1778,7 @@ int rpc_uci_api_init(struct ubus_context *ctx)
        };
 
        static struct ubus_object_type uci_type =
-               UBUS_OBJECT_TYPE("luci-rpc-uci", uci_methods);
+               UBUS_OBJECT_TYPE("rpcd-plugin-uci", uci_methods);
 
        static struct ubus_object obj = {
                .name = "uci",