WPS: 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:
parent
bf0ec17a51
commit
625745c297
1 changed files with 2 additions and 2 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue