Verify that channel info is available in hostapd_hw_get_channel()

Unexpected CHAN_SWITCH command could get this function using a NULL
pointer if the channel switch was requested while the interface was
already disabled.

Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
This commit is contained in:
Jouni Malinen 2019-04-26 16:17:59 +03:00 committed by Jouni Malinen
parent b9058266f0
commit eb314e8af2

View file

@ -936,11 +936,16 @@ int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq)
int i, channel; int i, channel;
struct hostapd_hw_modes *mode; struct hostapd_hw_modes *mode;
channel = hw_get_chan(hapd->iface->current_mode, freq); if (hapd->iface->current_mode) {
if (channel) channel = hw_get_chan(hapd->iface->current_mode, freq);
return channel; if (channel)
return channel;
}
/* Check other available modes since the channel list for the current /* Check other available modes since the channel list for the current
* mode did not include the specified frequency. */ * mode did not include the specified frequency. */
if (!hapd->iface->hw_features)
return 0;
for (i = 0; i < hapd->iface->num_hw_features; i++) { for (i = 0; i < hapd->iface->num_hw_features; i++) {
mode = &hapd->iface->hw_features[i]; mode = &hapd->iface->hw_features[i];
channel = hw_get_chan(mode, freq); channel = hw_get_chan(mode, freq);