From cc27c8e68001aaa28599bf9e91025540d492efb8 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Mon, 13 Jun 2016 00:36:18 +0300 Subject: [PATCH] hostapd: Fix early init failure path eloop deinit calls could trigger segmentation fault if the early error path is hit before eloop_init() gets called. Signed-off-by: Jouni Malinen --- hostapd/main.c | 11 +++++++---- src/ap/hostapd.h | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hostapd/main.c b/hostapd/main.c index 5f3f83bf9..97fe23c02 100644 --- a/hostapd/main.c +++ b/hostapd/main.c @@ -339,6 +339,7 @@ static int hostapd_global_init(struct hapd_interfaces *interfaces, wpa_printf(MSG_ERROR, "Failed to initialize event loop"); return -1; } + interfaces->eloop_initialized = 1; random_init(entropy_file); @@ -366,7 +367,7 @@ static int hostapd_global_init(struct hapd_interfaces *interfaces, } -static void hostapd_global_deinit(const char *pid_file) +static void hostapd_global_deinit(const char *pid_file, int eloop_initialized) { int i; @@ -384,7 +385,8 @@ static void hostapd_global_deinit(const char *pid_file) random_deinit(); - eloop_destroy(); + if (eloop_initialized) + eloop_destroy(); #ifndef CONFIG_NATIVE_WINDOWS closelog(); @@ -816,8 +818,9 @@ int main(int argc, char *argv[]) } os_free(interfaces.iface); - eloop_cancel_timeout(hostapd_periodic, &interfaces, NULL); - hostapd_global_deinit(pid_file); + if (interfaces.eloop_initialized) + eloop_cancel_timeout(hostapd_periodic, &interfaces, NULL); + hostapd_global_deinit(pid_file, interfaces.eloop_initialized); os_free(pid_file); if (log_file) diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index 4dba8cb36..195679e53 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -53,6 +53,7 @@ struct hapd_interfaces { #ifndef CONFIG_NO_VLAN struct dynamic_iface *vlan_priv; #endif /* CONFIG_NO_VLAN */ + int eloop_initialized; }; enum hostapd_chan_status {