From a9ee3ef0cf20d8a7a807d46db4dfa48e072cca51 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Tue, 29 Oct 2013 17:28:33 +0100 Subject: [PATCH] libubus: pull the variable length data array out of struct ubus_msghdr to fix builds with clang Signed-off-by: Felix Fietkau --- libubus-io.c | 8 +++++--- libubus-obj.c | 2 +- libubus-req.c | 11 ++++++----- libubus.c | 4 ++-- libubus.h | 6 ++++++ ubusmsg.h | 1 - 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/libubus-io.c b/libubus-io.c index 78943bc..19e3c2f 100644 --- a/libubus-io.c +++ b/libubus-io.c @@ -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; diff --git a/libubus-obj.c b/libubus-obj.c index bdb2e03..212c13c 100644 --- a/libubus-obj.c +++ b/libubus-obj.c @@ -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; diff --git a/libubus-req.c b/libubus-req.c index 43a5c26..f89e7a7 100644 --- a/libubus-req.c +++ b/libubus-req.c @@ -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)) diff --git a/libubus.c b/libubus.c index 67363ad..c6e956a 100644 --- a/libubus.c +++ b/libubus.c @@ -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); } diff --git a/libubus.h b/libubus.h index 08f9c5b..f899ded 100644 --- a/libubus.h +++ b/libubus.h @@ -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); diff --git a/ubusmsg.h b/ubusmsg.h index 05d5c04..c9b92e7 100644 --- a/ubusmsg.h +++ b/ubusmsg.h @@ -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 { -- 2.11.0