Fix memory leak on hostapd eap_user_file parsing error paths

Need to free all the pending completed EAP users if a parsing error
prevents the file from being used.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2016-12-28 12:12:14 +02:00
parent 44785ff27b
commit 78022c8366
3 changed files with 17 additions and 16 deletions

View file

@ -517,15 +517,10 @@ static int hostapd_config_read_eap_user(const char *fname,
fclose(f); fclose(f);
if (ret == 0) { if (ret == 0) {
user = conf->eap_user; hostapd_config_free_eap_users(conf->eap_user);
while (user) {
struct hostapd_eap_user *prev;
prev = user;
user = user->next;
hostapd_config_free_eap_user(prev);
}
conf->eap_user = new_user; conf->eap_user = new_user;
} else {
hostapd_config_free_eap_users(new_user);
} }
return ret; return ret;

View file

@ -382,6 +382,18 @@ void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
} }
void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
{
struct hostapd_eap_user *prev_user;
while (user) {
prev_user = user;
user = user->next;
hostapd_config_free_eap_user(prev_user);
}
}
static void hostapd_config_free_wep(struct hostapd_wep_keys *keys) static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
{ {
int i; int i;
@ -434,8 +446,6 @@ static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
void hostapd_config_free_bss(struct hostapd_bss_config *conf) void hostapd_config_free_bss(struct hostapd_bss_config *conf)
{ {
struct hostapd_eap_user *user, *prev_user;
if (conf == NULL) if (conf == NULL)
return; return;
@ -448,12 +458,7 @@ void hostapd_config_free_bss(struct hostapd_bss_config *conf)
os_free(conf->ssid.vlan_tagged_interface); os_free(conf->ssid.vlan_tagged_interface);
#endif /* CONFIG_FULL_DYNAMIC_VLAN */ #endif /* CONFIG_FULL_DYNAMIC_VLAN */
user = conf->eap_user; hostapd_config_free_eap_users(conf->eap_user);
while (user) {
prev_user = user;
user = user->next;
hostapd_config_free_eap_user(prev_user);
}
os_free(conf->eap_user_sqlite); os_free(conf->eap_user_sqlite);
os_free(conf->eap_req_id_text); os_free(conf->eap_req_id_text);

View file

@ -732,6 +732,7 @@ int hostapd_mac_comp(const void *a, const void *b);
struct hostapd_config * hostapd_config_defaults(void); struct hostapd_config * hostapd_config_defaults(void);
void hostapd_config_defaults_bss(struct hostapd_bss_config *bss); void hostapd_config_defaults_bss(struct hostapd_bss_config *bss);
void hostapd_config_free_eap_user(struct hostapd_eap_user *user); void hostapd_config_free_eap_user(struct hostapd_eap_user *user);
void hostapd_config_free_eap_users(struct hostapd_eap_user *user);
void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **p); void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **p);
void hostapd_config_free_bss(struct hostapd_bss_config *conf); void hostapd_config_free_bss(struct hostapd_bss_config *conf);
void hostapd_config_free(struct hostapd_config *conf); void hostapd_config_free(struct hostapd_config *conf);