]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
WPS: Check NDEF record length fields separately
authorJouni Malinen <j@w1.fi>
Sun, 20 Nov 2022 10:08:47 +0000 (12:08 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 20 Nov 2022 13:15:58 +0000 (15:15 +0200)
Try to make the bounds checking easier for static analyzers by checking
each length field separately in addition to checking them all in the end
against the total buffer length.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/wps/ndef.c

index bb3c055486c027ca994054440aa13c4a8df63f53..63f0d527d5874e3e5636d7c4d7108d4dba158b10 100644 (file)
@@ -63,12 +63,18 @@ static int ndef_parse_record(const u8 *data, u32 size,
        } else
                record->id_length = 0;
 
+       if (record->type_length > data + size - pos)
+               return -1;
        record->type = record->type_length == 0 ? NULL : pos;
        pos += record->type_length;
 
+       if (record->id_length > data + size - pos)
+               return -1;
        record->id = record->id_length == 0 ? NULL : pos;
        pos += record->id_length;
 
+       if (record->payload_length > (size_t) (data + size - pos))
+               return -1;
        record->payload = record->payload_length == 0 ? NULL : pos;
        pos += record->payload_length;