]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Fix memory leak on hostapd eap_user_file parsing error paths
authorJouni Malinen <j@w1.fi>
Wed, 28 Dec 2016 10:12:14 +0000 (12:12 +0200)
committerJouni Malinen <j@w1.fi>
Wed, 28 Dec 2016 12:47:00 +0000 (14:47 +0200)
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>
hostapd/config_file.c
src/ap/ap_config.c
src/ap/ap_config.h

index ed1478c8e9bf869b78bc7a30550019a495c80f47..e1f9f640cf55d4f4d72355da01cff0d0674c4caf 100644 (file)
@@ -517,15 +517,10 @@ static int hostapd_config_read_eap_user(const char *fname,
        fclose(f);
 
        if (ret == 0) {
-               user = conf->eap_user;
-               while (user) {
-                       struct hostapd_eap_user *prev;
-
-                       prev = user;
-                       user = user->next;
-                       hostapd_config_free_eap_user(prev);
-               }
+               hostapd_config_free_eap_users(conf->eap_user);
                conf->eap_user = new_user;
+       } else {
+               hostapd_config_free_eap_users(new_user);
        }
 
        return ret;
index c532bf03daf8ca7936e48abda94572e101d87ee3..3f5e58bb8d133104dfef4aa823fff1640c3dcd32 100644 (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)
 {
        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)
 {
-       struct hostapd_eap_user *user, *prev_user;
-
        if (conf == NULL)
                return;
 
@@ -448,12 +458,7 @@ void hostapd_config_free_bss(struct hostapd_bss_config *conf)
        os_free(conf->ssid.vlan_tagged_interface);
 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
 
-       user = conf->eap_user;
-       while (user) {
-               prev_user = user;
-               user = user->next;
-               hostapd_config_free_eap_user(prev_user);
-       }
+       hostapd_config_free_eap_users(conf->eap_user);
        os_free(conf->eap_user_sqlite);
 
        os_free(conf->eap_req_id_text);
index 69801d35ea8678998b8965bf8638964b6c08b1e0..97ec0d4e4af21fa7ba8c070e00e59052e66d74ee 100644 (file)
@@ -732,6 +732,7 @@ int hostapd_mac_comp(const void *a, const void *b);
 struct hostapd_config * hostapd_config_defaults(void);
 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_users(struct hostapd_eap_user *user);
 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(struct hostapd_config *conf);