diff mbox series

libubus ubus_invoke() with an extended struct blob_attr *msg as input

Message ID 87edbgrtrc.fsf@miraculix.mork.no
State New
Headers show
Series libubus ubus_invoke() with an extended struct blob_attr *msg as input | expand

Commit Message

Bjørn Mork April 8, 2024, 11:14 a.m. UTC
Not too sure about any of this, so I just wanted to ask if this would
make sense:

bjorn@miraculix:/usr/local/src/git/ubus$ git diff

The reason is that I spent some time scratching my head trying to figure
out why the blob I passed to ubus_invoke() had no effect at all. It
turned out to be because I passed a msg parameter with a blobmsg header
(and name).

I know it sounds like a strange thing to do. But the input was passed to
my program as an element of a larger json struct.  So I simply ran
blobmsg_add_json_from_string() and blobmsg_parse() on that, extracting
the attribute with the input for my ubus call. Which means that the
attribute ended up with a blobmsg_hdr.

I can fix the problem now that I know of it, although it doesn't seem
like there's any helpers doing just that? But I think it would be nice
if this just worked either way.  And I believe the above diff will do

AFAICS, it changes nothing unless the BLOB_ATTR_EXTENDED flag is set.

diff mbox series


diff --git a/libubus-req.c b/libubus-req.c
index ae9d1925ecdf..cf85303e6aed 100644
--- a/libubus-req.c
+++ b/libubus-req.c
@@ -197,7 +197,7 @@  void ubus_complete_deferred_request(struct ubus_context *ctx, struct ubus_reques
 static void ubus_put_data(struct blob_buf *buf, struct blob_attr *msg)
        if (msg)
-               blob_put(buf, UBUS_ATTR_DATA, blob_data(msg), blob_len(msg));
+               blob_put(buf, UBUS_ATTR_DATA, blobmsg_data(msg), blobmsg_len(msg));
                blob_put(buf, UBUS_ATTR_DATA, NULL, 0);