diff mbox series

[uhttpd] ubus: use BLOBMSG_TYPE_UNSPEC for "params" JSON attribute

Message ID 20200725081850.32513-2-zajec5@gmail.com
State Accepted
Headers show
Series [uhttpd] ubus: use BLOBMSG_TYPE_UNSPEC for "params" JSON attribute | expand

Commit Message

Rafał Miłecki July 25, 2020, 8:18 a.m. UTC
From: Rafał Miłecki <rafal@milecki.pl>

According to the JSON-RPC 2.0 specification "params" value can be either
an Array or Object. This change makes parse_json_rpc() accept both.

Type validation should be handled by a function that actually reads
"params" depending on expected format. This doesn't change existing
behaviour but allows adding more methods (that expect Object) in the
future.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 ubus.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/ubus.c b/ubus.c
index 51c58b5..ddc2f05 100644
--- a/ubus.c
+++ b/ubus.c
@@ -48,7 +48,7 @@  enum {
 static const struct blobmsg_policy rpc_policy[__RPC_MAX] = {
 	[RPC_JSONRPC] = { .name = "jsonrpc", .type = BLOBMSG_TYPE_STRING },
 	[RPC_METHOD] = { .name = "method", .type = BLOBMSG_TYPE_STRING },
-	[RPC_PARAMS] = { .name = "params", .type = BLOBMSG_TYPE_ARRAY },
+	[RPC_PARAMS] = { .name = "params", .type = BLOBMSG_TYPE_UNSPEC },
 	[RPC_ID] = { .name = "id", .type = BLOBMSG_TYPE_UNSPEC },
 };
 
@@ -446,6 +446,9 @@  static void parse_call_params(struct rpc_data *d)
 	};
 	struct blob_attr *tb[4];
 
+	if (!d->params || blobmsg_type(d->params) != BLOBMSG_TYPE_ARRAY)
+		return;
+
 	blobmsg_parse_array(data_policy, ARRAY_SIZE(data_policy), tb,
 			    blobmsg_data(d->params), blobmsg_data_len(d->params));