]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Fix segmentation fault for NULL confname in SAVE_CONFIG
authorZhaoyang Liu <zhaoyang@codeaurora.org>
Thu, 5 Mar 2020 03:25:00 +0000 (11:25 +0800)
committerJouni Malinen <j@w1.fi>
Fri, 6 Mar 2020 09:21:58 +0000 (11:21 +0200)
When wpa_supplicant interface is added without a configuration file, the
SAVE_CONFIG command causes a segmentation fault due to referencing a
NULL pointer if the update_config parameter is first explicitly enabled.

Fix the issue by checking the confname for NULL before saving
configuration.

Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
wpa_supplicant/config_file.c

index 4c37b61a0787b51fbf7d6cee33c2a2979df03eed..b8e56f5b2807f81c3033060240c1f51c48368c06 100644 (file)
@@ -1612,9 +1612,16 @@ int wpa_config_write(const char *name, struct wpa_config *config)
 #endif /* CONFIG_NO_CONFIG_BLOBS */
        int ret = 0;
        const char *orig_name = name;
-       int tmp_len = os_strlen(name) + 5; /* allow space for .tmp suffix */
-       char *tmp_name = os_malloc(tmp_len);
+       int tmp_len;
+       char *tmp_name;
 
+       if (!name) {
+               wpa_printf(MSG_ERROR, "No configuration file for writing");
+               return -1;
+       }
+
+       tmp_len = os_strlen(name) + 5; /* allow space for .tmp suffix */
+       tmp_name = os_malloc(tmp_len);
        if (tmp_name) {
                os_snprintf(tmp_name, tmp_len, "%s.tmp", name);
                name = tmp_name;