Skip to content

Commit 9f30861

Browse files
committed
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: Johannes Berg <[email protected]>
1 parent 49a68e0 commit 9f30861

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

net/wireless/nl80211.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -203,29 +203,17 @@ cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
203203
static int validate_ie_attr(const struct nlattr *attr,
204204
struct netlink_ext_ack *extack)
205205
{
206-
const u8 *pos;
207-
int len;
206+
const u8 *data = nla_data(attr);
207+
unsigned int len = nla_len(attr);
208+
struct element *elem;
208209

209-
pos = nla_data(attr);
210-
len = nla_len(attr);
211-
212-
while (len) {
213-
u8 elemlen;
214-
215-
if (len < 2)
216-
goto error;
217-
len -= 2;
218-
219-
elemlen = pos[1];
220-
if (elemlen > len)
221-
goto error;
222-
223-
len -= elemlen;
224-
pos += 2 + elemlen;
210+
for_each_element(elem, data, len) {
211+
/* nothing */
225212
}
226213

227-
return 0;
228-
error:
214+
if (for_each_element_completed(elem, data, len))
215+
return 0;
216+
229217
NL_SET_ERR_MSG_ATTR(extack, attr, "malformed information elements");
230218
return -EINVAL;
231219
}

0 commit comments

Comments
 (0)