From: Rafał Miłecki Date: Thu, 23 Jul 2020 05:38:07 +0000 (+0200) Subject: ubus: parse "call" method params only for relevant call X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=8d9e1fce9f89d07c41e8c4984c6583babfc9709f;p=project%2Fuhttpd.git ubus: parse "call" method params only for relevant call There is no point in parsing "call" specific params for other ("list") method calls. This is a minor cleanup that doesn't change uhttpd ubus behaviour. Signed-off-by: Rafał Miłecki Acked-by: Jo-Philipp Wich --- diff --git a/ubus.c b/ubus.c index 8578631..97cc1e2 100644 --- a/ubus.c +++ b/ubus.c @@ -409,14 +409,7 @@ static void uh_ubus_send_list(struct client *cl, json_object *obj, struct blob_a static bool parse_json_rpc(struct rpc_data *d, struct blob_attr *data) { - const struct blobmsg_policy data_policy[] = { - { .type = BLOBMSG_TYPE_STRING }, - { .type = BLOBMSG_TYPE_STRING }, - { .type = BLOBMSG_TYPE_STRING }, - { .type = BLOBMSG_TYPE_TABLE }, - }; struct blob_attr *tb[__RPC_MAX]; - struct blob_attr *tb2[4]; struct blob_attr *cur; blobmsg_parse(rpc_policy, __RPC_MAX, tb, blob_data(data), blob_len(data)); @@ -440,24 +433,35 @@ static bool parse_json_rpc(struct rpc_data *d, struct blob_attr *data) if (!d->params) return false; - blobmsg_parse_array(data_policy, ARRAY_SIZE(data_policy), tb2, + return true; +} + +static void parse_call_params(struct rpc_data *d) +{ + const struct blobmsg_policy data_policy[] = { + { .type = BLOBMSG_TYPE_STRING }, + { .type = BLOBMSG_TYPE_STRING }, + { .type = BLOBMSG_TYPE_STRING }, + { .type = BLOBMSG_TYPE_TABLE }, + }; + struct blob_attr *tb[4]; + + blobmsg_parse_array(data_policy, ARRAY_SIZE(data_policy), tb, blobmsg_data(d->params), blobmsg_data_len(d->params)); - if (tb2[0]) - d->sid = blobmsg_data(tb2[0]); + if (tb[0]) + d->sid = blobmsg_data(tb[0]); if (conf.ubus_noauth && (!d->sid || !*d->sid)) d->sid = UH_UBUS_DEFAULT_SID; - if (tb2[1]) - d->object = blobmsg_data(tb2[1]); - - if (tb2[2]) - d->function = blobmsg_data(tb2[2]); + if (tb[1]) + d->object = blobmsg_data(tb[1]); - d->data = tb2[3]; + if (tb[2]) + d->function = blobmsg_data(tb[2]); - return true; + d->data = tb[3]; } static void uh_ubus_init_batch(struct client *cl) @@ -528,6 +532,8 @@ static void uh_ubus_handle_request_object(struct client *cl, struct json_object goto error; if (!strcmp(data.method, "call")) { + parse_call_params(&data); + if (!data.sid || !data.object || !data.function || !data.data) goto error;