common: Use for_each_element_id() in mb_ies_info_by_ies()

The change is bigger because here we need to catch the error
condition if the last element doesn't fit.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Johannes Berg 2019-02-08 17:57:51 +01:00 committed by Jouni Malinen
parent 9008048f0f
commit b644797429

View file

@ -1322,27 +1322,27 @@ const char * fc2str(u16 fc)
int mb_ies_info_by_ies(struct mb_ies_info *info, const u8 *ies_buf, int mb_ies_info_by_ies(struct mb_ies_info *info, const u8 *ies_buf,
size_t ies_len) size_t ies_len)
{ {
const struct element *elem;
os_memset(info, 0, sizeof(*info)); os_memset(info, 0, sizeof(*info));
while (ies_buf && ies_len >= 2 && if (!ies_buf)
info->nof_ies < MAX_NOF_MB_IES_SUPPORTED) { return 0;
size_t len = 2 + ies_buf[1];
if (len > ies_len) { for_each_element_id(elem, WLAN_EID_MULTI_BAND, ies_buf, ies_len) {
wpa_hexdump(MSG_DEBUG, "Truncated IEs", if (info->nof_ies >= MAX_NOF_MB_IES_SUPPORTED)
ies_buf, ies_len); return 0;
return -1;
}
if (ies_buf[0] == WLAN_EID_MULTI_BAND) { wpa_printf(MSG_DEBUG, "MB IE of %u bytes found",
wpa_printf(MSG_DEBUG, "MB IE of %zu bytes found", len); elem->datalen + 2);
info->ies[info->nof_ies].ie = ies_buf + 2; info->ies[info->nof_ies].ie = elem->data;
info->ies[info->nof_ies].ie_len = ies_buf[1]; info->ies[info->nof_ies].ie_len = elem->datalen;
info->nof_ies++; info->nof_ies++;
} }
ies_len -= len; if (!for_each_element_completed(elem, ies_buf, ies_len)) {
ies_buf += len; wpa_hexdump(MSG_DEBUG, "Truncated IEs", ies_buf, ies_len);
return -1;
} }
return 0; return 0;