From c643c392874a7e41dc447cd29afe14a2934e2289 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Mon, 2 Nov 2020 18:38:41 +0200 Subject: [PATCH] nl80211: Fix filtering of unsupported bands/modes The loop for removing unsupported bands was assuming there is always exactly one band/mode following the removed band. That was not at all correct, so fix this by dynamically determining how many (if any) bands need to be moved. Fixes: 106d67a93c2d ("nl80211: Filter out unsupported bands") Signed-off-by: Jouni Malinen --- src/drivers/driver_nl80211_capa.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/drivers/driver_nl80211_capa.c b/src/drivers/driver_nl80211_capa.c index 227f665c7..287b8aa30 100644 --- a/src/drivers/driver_nl80211_capa.c +++ b/src/drivers/driver_nl80211_capa.c @@ -1971,8 +1971,10 @@ wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes *modes, "nl80211: Remove unsupported mode"); os_free(modes[m].channels); os_free(modes[m].rates); - os_memmove(&modes[m], &modes[m + 1], - sizeof(struct hostapd_hw_modes)); + if (m + 1 < *num_modes) + os_memmove(&modes[m], &modes[m + 1], + sizeof(struct hostapd_hw_modes) * + (*num_modes - (m + 1))); (*num_modes)--; continue; }