]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Interworking: Clearer ANQP element length validation
authorJouni Malinen <j@w1.fi>
Sun, 23 Nov 2014 15:13:47 +0000 (17:13 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 23 Nov 2014 15:41:13 +0000 (17:41 +0200)
The upper bound for the element length was already verified, but that
was not apparently noticed by a static analyzer (CID 68128).

Signed-off-by: Jouni Malinen <j@w1.fi>
wpa_supplicant/interworking.c

index 19b6e38da552dc327188ff8729cf73f94a519f20..a22c8634fd52ccb8cf746466bb9e52a46de59c9e 100644 (file)
@@ -2808,7 +2808,9 @@ void anqp_resp_cb(void *ctx, const u8 *dst, u8 dialog_token,
        end = pos + wpabuf_len(resp);
 
        while (pos < end) {
-               if (pos + 4 > end) {
+               unsigned int left = end - pos;
+
+               if (left < 4) {
                        wpa_printf(MSG_DEBUG, "ANQP: Invalid element");
                        break;
                }
@@ -2816,7 +2818,8 @@ void anqp_resp_cb(void *ctx, const u8 *dst, u8 dialog_token,
                pos += 2;
                slen = WPA_GET_LE16(pos);
                pos += 2;
-               if (pos + slen > end) {
+               left -= 4;
+               if (left < slen) {
                        wpa_printf(MSG_DEBUG, "ANQP: Invalid element length "
                                   "for Info ID %u", info_id);
                        break;