* blob_len: returns the length of the attribute's payload
*/
static inline unsigned int
-blob_len(struct blob_attr *attr)
+blob_len(const struct blob_attr *attr)
{
return (be32_to_cpu(attr->id_len) & BLOB_ATTR_LEN_MASK) - sizeof(struct blob_attr);
}
#include "blobmsg.h"
+bool blobmsg_check_attr(const struct blob_attr *attr, bool name)
+{
+ const struct blobmsg_hdr *hdr;
+
+ if (blob_len(attr) < sizeof(struct blobmsg_hdr))
+ return false;
+
+ hdr = (void *) attr->data;
+ if (!hdr->namelen && name)
+ return false;
+
+ if (hdr->namelen > blob_len(attr))
+ return false;
+
+ if (hdr->name[hdr->namelen] != 0)
+ return false;
+
+ return true;
+}
+
int blobmsg_parse(const struct blobmsg_policy *policy, int policy_len,
struct blob_attr **tb, void *data, int len)
{
if (hdr->namelen != pslen[i])
continue;
- if (!hdr->namelen)
- return -1;
-
- if (sizeof(*attr) + blobmsg_hdrlen(hdr->namelen) > blob_pad_len(attr))
- return -1;
-
- if (hdr->name[hdr->namelen] != 0)
+ if (!blobmsg_check_attr(attr, true))
return -1;
if (tb[i])
return blob_len(attr) - (end - start);
}
+bool blobmsg_check_attr(const struct blob_attr *attr, bool name);
int blobmsg_parse(const struct blobmsg_policy *policy, int policy_len,
struct blob_attr **tb, void *data, int len);