libubus: pull the variable length data array out of struct ubus_msghdr to fix builds with clang
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
This commit is contained in:
parent
6ae17d0298
commit
a9ee3ef0cf
6 changed files with 20 additions and 12 deletions
|
@ -152,13 +152,15 @@ static int recv_retry(int fd, struct iovec *iov, bool wait)
|
|||
|
||||
static bool ubus_validate_hdr(struct ubus_msghdr *hdr)
|
||||
{
|
||||
struct blob_attr *data = ubus_msghdr_data(hdr);
|
||||
|
||||
if (hdr->version != 0)
|
||||
return false;
|
||||
|
||||
if (blob_raw_len(hdr->data) < sizeof(*hdr->data))
|
||||
if (blob_raw_len(data) < sizeof(*data))
|
||||
return false;
|
||||
|
||||
if (blob_pad_len(hdr->data) > UBUS_MAX_MSGLEN)
|
||||
if (blob_pad_len(data) > UBUS_MAX_MSGLEN)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
@ -179,7 +181,7 @@ static bool get_next_msg(struct ubus_context *ctx)
|
|||
return false;
|
||||
}
|
||||
|
||||
iov.iov_len = blob_len(ctx->msgbuf.hdr.data);
|
||||
iov.iov_len = blob_len(ubus_msghdr_data(&ctx->msgbuf.hdr));
|
||||
if (iov.iov_len > 0 && !recv_retry(ctx->sock.fd, &iov, true))
|
||||
return false;
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr
|
|||
struct ubus_object *obj;
|
||||
uint32_t objid;
|
||||
|
||||
attrbuf = ubus_parse_msg(hdr->data);
|
||||
attrbuf = ubus_parse_msg(ubus_msghdr_data(hdr));
|
||||
if (!attrbuf[UBUS_ATTR_OBJID])
|
||||
return;
|
||||
|
||||
|
|
|
@ -297,7 +297,7 @@ int ubus_notify(struct ubus_context *ctx, struct ubus_object *obj,
|
|||
|
||||
static bool ubus_get_status(struct ubus_msghdr *hdr, int *ret)
|
||||
{
|
||||
struct blob_attr **attrbuf = ubus_parse_msg(hdr->data);
|
||||
struct blob_attr **attrbuf = ubus_parse_msg(ubus_msghdr_data(hdr));
|
||||
|
||||
if (!attrbuf[UBUS_ATTR_STATUS])
|
||||
return false;
|
||||
|
@ -321,12 +321,13 @@ ubus_process_req_status(struct ubus_request *req, struct ubus_msghdr *hdr)
|
|||
static void
|
||||
ubus_process_req_data(struct ubus_request *req, struct ubus_msghdr *hdr)
|
||||
{
|
||||
struct blob_attr *msg_data = ubus_msghdr_data(hdr);
|
||||
struct ubus_pending_data *data;
|
||||
int len;
|
||||
|
||||
if (!req->blocked) {
|
||||
req->blocked = true;
|
||||
req_data_cb(req, hdr->type, hdr->data);
|
||||
req_data_cb(req, hdr->type, msg_data);
|
||||
__ubus_process_req_data(req);
|
||||
req->blocked = false;
|
||||
|
||||
|
@ -336,13 +337,13 @@ ubus_process_req_data(struct ubus_request *req, struct ubus_msghdr *hdr)
|
|||
return;
|
||||
}
|
||||
|
||||
len = blob_raw_len(hdr->data);
|
||||
len = blob_raw_len(msg_data);
|
||||
data = calloc(1, sizeof(*data) + len);
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
data->type = hdr->type;
|
||||
memcpy(data->data, hdr->data, len);
|
||||
memcpy(data->data, msg_data, len);
|
||||
list_add(&data->list, &req->pending);
|
||||
}
|
||||
|
||||
|
@ -403,7 +404,7 @@ static void ubus_process_notify_status(struct ubus_request *req, int id, struct
|
|||
|
||||
if (!id) {
|
||||
/* first id: ubusd's status message with a list of ids */
|
||||
tb = ubus_parse_msg(hdr->data);
|
||||
tb = ubus_parse_msg(ubus_msghdr_data(hdr));
|
||||
if (tb[UBUS_ATTR_SUBSCRIBERS]) {
|
||||
blob_for_each_attr(cur, tb[UBUS_ATTR_SUBSCRIBERS], rem) {
|
||||
if (!blob_check_type(blob_data(cur), blob_len(cur), BLOB_ATTR_INT32))
|
||||
|
|
|
@ -75,11 +75,11 @@ ubus_queue_msg(struct ubus_context *ctx, struct ubus_msghdr *hdr)
|
|||
{
|
||||
struct ubus_pending_msg *pending;
|
||||
|
||||
pending = calloc(1, sizeof(*pending) + blob_raw_len(hdr->data));
|
||||
pending = calloc(1, sizeof(*pending) + blob_raw_len(ubus_msghdr_data(hdr)));
|
||||
if (!pending)
|
||||
return;
|
||||
|
||||
memcpy(&pending->hdr, hdr, sizeof(*hdr) + blob_raw_len(hdr->data));
|
||||
memcpy(&pending->hdr, hdr, sizeof(*hdr) + blob_raw_len(ubus_msghdr_data(hdr)));
|
||||
list_add(&pending->list, &ctx->pending);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,12 @@ struct ubus_event_handler;
|
|||
struct ubus_subscriber;
|
||||
struct ubus_notify_request;
|
||||
|
||||
static inline struct blob_attr *
|
||||
ubus_msghdr_data(struct ubus_msghdr *hdr)
|
||||
{
|
||||
return (struct blob_attr *) (hdr + 1);
|
||||
}
|
||||
|
||||
typedef void (*ubus_lookup_handler_t)(struct ubus_context *ctx,
|
||||
struct ubus_object_data *obj,
|
||||
void *priv);
|
||||
|
|
|
@ -29,7 +29,6 @@ struct ubus_msghdr {
|
|||
uint8_t type;
|
||||
uint16_t seq;
|
||||
uint32_t peer;
|
||||
struct blob_attr data[];
|
||||
} __packetdata;
|
||||
|
||||
enum ubus_msg_type {
|
||||
|
|
Loading…
Add table
Reference in a new issue