nl80211: Avoid undefined behavior in pointer arithmetic
authorJouni Malinen <j@w1.fi>
Sun, 18 Oct 2015 16:08:09 +0000 (19:08 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 25 Oct 2015 13:35:00 +0000 (15:35 +0200)
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>
src/drivers/driver_nl80211_scan.c

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