blob: introduce blob_parse_untrusted
[project/libubox.git] / blob.c
diff --git a/blob.c b/blob.c
index ee93894b9e6fd36503c870cf3795a0d18774afda..dc908d9ea7454b07cc01c2e1897b1717796f0b4c 100644 (file)
--- a/blob.c
+++ b/blob.c
@@ -252,6 +252,30 @@ blob_parse_attr(struct blob_attr *attr, struct blob_attr **data, const struct bl
        return found;
 }
 
+int
+blob_parse_untrusted(struct blob_attr *attr, size_t attr_len, struct blob_attr **data, const struct blob_attr_info *info, int max)
+{
+       struct blob_attr *pos;
+       size_t len = 0;
+       int found = 0;
+       size_t rem;
+
+       if (!attr || attr_len < sizeof(struct blob_attr))
+               return 0;
+
+       len = blob_raw_len(attr);
+       if (len != attr_len)
+               return 0;
+
+       memset(data, 0, sizeof(struct blob_attr *) * max);
+       blob_for_each_attr_len(pos, attr, len, rem) {
+               found += blob_parse_attr(pos, rem, data, info, max);
+       }
+
+       return found;
+}
+
+/* use only on trusted input, otherwise consider blob_parse_untrusted */
 int
 blob_parse(struct blob_attr *attr, struct blob_attr **data, const struct blob_attr_info *info, int max)
 {