diff options
author | Felix Fietkau <nbd@nbd.name> | 2018-07-25 10:37:30 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@nbd.name> | 2018-07-25 10:45:34 +0200 |
commit | 884be451622d21fe3a7b06cc5b9d245bc4fffbf2 (patch) | |
tree | ba4f657cc211f845e2c8a1ac539781cf53c8738c | |
parent | 5bae22eb5472c9c7cc30caa9a84004bba19940d3 (diff) | |
download | ubus-884be451622d21fe3a7b06cc5b9d245bc4fffbf2.tar.gz |
libubus: check for non-NULL data before running callbacks
UBUS_MSG_INVOKE and UBUS_MSG_DATA can be sent without UBUS_ATTR_DATA
present. Most ubus users assume that the msg argument passed can never
be NULL, so this change prevents a crash
Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r-- | libubus-obj.c | 7 | ||||
-rw-r--r-- | libubus-req.c | 3 |
2 files changed, 9 insertions, 1 deletions
diff --git a/libubus-obj.c b/libubus-obj.c index c1931b3..2580b24 100644 --- a/libubus-obj.c +++ b/libubus-obj.c @@ -74,7 +74,7 @@ ubus_process_invoke(struct ubus_context *ctx, struct ubus_msghdr *hdr, if (attrbuf[UBUS_ATTR_NO_REPLY]) no_reply = blob_get_int8(attrbuf[UBUS_ATTR_NO_REPLY]); - + req.peer = hdr->peer; req.seq = hdr->seq; req.object = obj->id; @@ -94,6 +94,11 @@ ubus_process_invoke(struct ubus_context *ctx, struct ubus_msghdr *hdr, goto send; found: + if (!attrbuf[UBUS_ATTR_DATA]) { + ret = UBUS_STATUS_INVALID_ARGUMENT; + goto send; + } + ret = obj->methods[method].handler(ctx, obj, &req, blob_data(attrbuf[UBUS_ATTR_METHOD]), attrbuf[UBUS_ATTR_DATA]); diff --git a/libubus-req.c b/libubus-req.c index 92f80fa..4eda383 100644 --- a/libubus-req.c +++ b/libubus-req.c @@ -32,6 +32,9 @@ static void req_data_cb(struct ubus_request *req, int type, struct blob_attr *da return; attr = ubus_parse_msg(data); + if (!attr[UBUS_ATTR_DATA]) + return; + req->data_cb(req, type, attr[UBUS_ATTR_DATA]); } |