nl80211: Avoid undefined behavior in pointer arithmetic

Reorder terms in a way that no invalid pointers are generated with
pos+len operations. end-pos is always defined (with a valid pos pointer)
while pos+len could end up pointing beyond the end pointer which would
be undefined behavior.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2015-10-18 19:08:09 +03:00
parent 78c8ee488f
commit 336869f05a

View file

@ -448,8 +448,8 @@ const u8 * nl80211_get_ie(const u8 *ies, size_t ies_len, u8 ie)
pos = ies; pos = ies;
end = ies + ies_len; end = ies + ies_len;
while (pos + 1 < end) { while (end - pos > 1) {
if (pos + 2 + pos[1] > end) if (2 + pos[1] > end - pos)
break; break;
if (pos[0] == ie) if (pos[0] == ie)
return pos; return pos;