]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
WPS: Avoid undefined behavior in pointer arithmetic
authorJouni Malinen <j@w1.fi>
Sat, 17 Oct 2015 22:42:03 +0000 (01:42 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 18 Oct 2015 08:37:47 +0000 (11:37 +0300)
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/wps/wps_attr_parse.c

index 11a967ba0ef182f2a7ddc882b160f7425f6d5d50..756d57e876c55186fc3c5097854f220c0f2046b8 100644 (file)
@@ -83,10 +83,10 @@ static int wps_parse_vendor_ext_wfa(struct wps_parse_attr *attr, const u8 *pos,
        const u8 *end = pos + len;
        u8 id, elen;
 
-       while (pos + 2 <= end) {
+       while (end - pos >= 2) {
                id = *pos++;
                elen = *pos++;
-               if (pos + elen > end)
+               if (elen > end - pos)
                        break;
                if (wps_set_vendor_ext_wfa_subelem(attr, id, elen, pos) < 0)
                        return -1;