fix segfault when passed blobmsg attr is NULL
[project/libubox.git] / blobmsg.c
index 1e93376a27b65cf816f94f87738b98e8bb497ef6..8019c45b83edff22263cd550497f67d4c0bc49ed 100644 (file)
--- a/blobmsg.c
+++ b/blobmsg.c
@@ -20,6 +20,7 @@ static const int blob_type[__BLOBMSG_TYPE_LAST] = {
        [BLOBMSG_TYPE_INT16] = BLOB_ATTR_INT16,
        [BLOBMSG_TYPE_INT32] = BLOB_ATTR_INT32,
        [BLOBMSG_TYPE_INT64] = BLOB_ATTR_INT64,
+       [BLOBMSG_TYPE_DOUBLE] = BLOB_ATTR_DOUBLE,
        [BLOBMSG_TYPE_STRING] = BLOB_ATTR_STRING,
        [BLOBMSG_TYPE_UNSPEC] = BLOB_ATTR_BINARY,
 };
@@ -134,6 +135,8 @@ int blobmsg_parse(const struct blobmsg_policy *policy, int policy_len,
        int i;
 
        memset(tb, 0, policy_len * sizeof(*tb));
+       if (!data || !len)
+               return -EINVAL;
        pslen = alloca(policy_len);
        for (i = 0; i < policy_len; i++) {
                if (!policy[i].name)