CI: add CodeQL workflow tests
[project/libubox.git] / blobmsg.c
index 7da41838029984bd94b367ceb320b016aaa9fd9c..d87d60728fcdd89c6df32a2c818b1a2325c7ce81 100644 (file)
--- a/blobmsg.c
+++ b/blobmsg.c
@@ -195,9 +195,17 @@ int blobmsg_parse(const struct blobmsg_policy *policy, int policy_len,
                                continue;
 
                        if (policy[i].type != BLOBMSG_TYPE_UNSPEC &&
+                           policy[i].type != BLOBMSG_CAST_INT64 &&
                            blob_id(attr) != policy[i].type)
                                continue;
 
+                       if (policy[i].type == BLOBMSG_CAST_INT64 &&
+                           (blob_id(attr) != BLOBMSG_TYPE_INT64 &&
+                            blob_id(attr) != BLOBMSG_TYPE_INT32 &&
+                            blob_id(attr) != BLOBMSG_TYPE_INT16 &&
+                            blob_id(attr) != BLOBMSG_TYPE_INT8))
+                               continue;
+
                        if (blobmsg_namelen(hdr) != pslen[i])
                                continue;
 
@@ -288,7 +296,7 @@ int blobmsg_vprintf(struct blob_buf *buf, const char *name, const char *format,
        if (len < 0)
                return -1;
 
-       sbuf = blobmsg_alloc_string_buffer(buf, name, len + 1);
+       sbuf = blobmsg_alloc_string_buffer(buf, name, len);
        if (!sbuf)
                return -1;
 
@@ -320,6 +328,7 @@ blobmsg_alloc_string_buffer(struct blob_buf *buf, const char *name, unsigned int
        struct blob_attr *attr;
        void *data_dest;
 
+       maxlen++;
        attr = blobmsg_new(buf, BLOBMSG_TYPE_STRING, name, maxlen, &data_dest);
        if (!attr)
                return NULL;
@@ -335,7 +344,7 @@ blobmsg_realloc_string_buffer(struct blob_buf *buf, unsigned int maxlen)
 {
        struct blob_attr *attr = blob_next(buf->head);
        int offset = attr_to_offset(buf, blob_next(buf->head)) + blob_pad_len(attr) - BLOB_COOKIE;
-       int required = maxlen - (buf->buflen - offset);
+       int required = maxlen + 1 - (buf->buflen - offset);
 
        if (required <= 0)
                goto out;