[libubox: blob.c] Weird comparison in blob_parse_attr!

Kevin Vigouroux ke.vigouroux at laposte.net
Mon Mar 24 10:41:29 PDT 2025


Hi!

#+BEGIN_SRC C
	len = blob_raw_len(attr);
	if (len > attr_len || len < sizeof(struct blob_attr))
		return 0;

	data_len = blob_len(attr);
	if (data_len > len)
		return 0;
#+END_SRC

I can't understand the meaning of ~data_len > len~!

#+BEGIN_SRC C
/*
 * blob_len: returns the length of the attribute's payload
 */
static inline size_t
blob_len(const struct blob_attr *attr)
{
	return (be32_to_cpu(attr->id_len) & BLOB_ATTR_LEN_MASK) - sizeof(struct blob_attr);
}

/*
 * blob_raw_len: returns the complete length of an attribute (including the header)
 */
static inline size_t
blob_raw_len(const struct blob_attr *attr)
{
	return blob_len(attr) + sizeof(struct blob_attr);
}

/*
 * blob_pad_len: returns the padded length of an attribute (including the header)
 */
static inline size_t
blob_pad_len(const struct blob_attr *attr)
{
	unsigned int len = blob_raw_len(attr);
	len = (len + BLOB_ATTR_ALIGN - 1) & ~(BLOB_ATTR_ALIGN - 1);
	return len;
}
#+END_SRC

By definition, ~blob_raw_len~ will be greater than ~blob_len~.

-- 
Best regards,
Kevin Vigouroux



More information about the openwrt-devel mailing list