From c38b77d0c085734335f287bca319b73206c9dd7a Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Fri, 10 Aug 2018 11:42:31 -0500 Subject: [PATCH] network: Fix syncing the PSK on 1st connection The previous change did not consider the case of the PSK being written for the very first time. In this case storage_network_open would return NULL and an empty file would be written. Change this so that if storage_network_open fails, then the current network settings are written to disk and not a temporary. --- src/network.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/network.c b/src/network.c index 7a0895da..3b047238 100644 --- a/src/network.c +++ b/src/network.c @@ -434,15 +434,22 @@ void network_sync_psk(struct network *network) network->update_psk = false; - fs_settings = storage_network_open(SECURITY_PSK, network->info->ssid); hex = l_util_hexstring(network->psk, 32); l_settings_set_value(network->settings, "Security", "PreSharedKey", hex); - l_settings_set_value(fs_settings, "Security", "PreSharedKey", hex); - l_free(hex); - storage_network_sync(SECURITY_PSK, network->info->ssid, fs_settings); - l_settings_free(fs_settings); + fs_settings = storage_network_open(SECURITY_PSK, network->info->ssid); + if (fs_settings) { + l_settings_set_value(fs_settings, "Security", + "PreSharedKey", hex); + storage_network_sync(SECURITY_PSK, network->info->ssid, + fs_settings); + l_settings_free(fs_settings); + } else + storage_network_sync(SECURITY_PSK, network->info->ssid, + network->settings); + + l_free(hex); } int network_autoconnect(struct network *network, struct scan_bss *bss)