From eb314e8af2fa08f35e7787e2b6679df6138b3650 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 26 Apr 2019 16:17:59 +0300 Subject: [PATCH] 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 --- src/ap/hw_features.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ap/hw_features.c b/src/ap/hw_features.c index 9d3d990a2..8ac33bb39 100644 --- a/src/ap/hw_features.c +++ b/src/ap/hw_features.c @@ -936,11 +936,16 @@ int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq) int i, channel; struct hostapd_hw_modes *mode; - channel = hw_get_chan(hapd->iface->current_mode, freq); - if (channel) - return channel; + if (hapd->iface->current_mode) { + channel = hw_get_chan(hapd->iface->current_mode, freq); + if (channel) + return channel; + } + /* Check other available modes since the channel list for the current * mode did not include the specified frequency. */ + if (!hapd->iface->hw_features) + return 0; for (i = 0; i < hapd->iface->num_hw_features; i++) { mode = &hapd->iface->hw_features[i]; channel = hw_get_chan(mode, freq);