Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f308616 authored by Johannes Berg's avatar Johannes Berg
Browse files

nl80211: use for_each_element() in validate_ie_attr()



This makes for much simpler code, simply walk through all
the elements and check that the last one found ends with
the end of the data. This works because if any element is
malformed the walk is aborted, we end up with a mismatch.

Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 49a68e0d
Loading
Loading
Loading
Loading
+8 −20
Original line number Diff line number Diff line
@@ -203,29 +203,17 @@ cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
static int validate_ie_attr(const struct nlattr *attr,
			    struct netlink_ext_ack *extack)
{
	const u8 *pos;
	int len;

	pos = nla_data(attr);
	len = nla_len(attr);

	while (len) {
		u8 elemlen;

		if (len < 2)
			goto error;
		len -= 2;
	const u8 *data = nla_data(attr);
	unsigned int len = nla_len(attr);
	struct element *elem;

		elemlen = pos[1];
		if (elemlen > len)
			goto error;

		len -= elemlen;
		pos += 2 + elemlen;
	for_each_element(elem, data, len) {
		/* nothing */
	}

	if (for_each_element_completed(elem, data, len))
		return 0;
error:

	NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements");
	return -EINVAL;
}