upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/main/config.c
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-18 19:55:33 +0530
committerYour Name <you@example.com>2026-05-18 19:55:33 +0530
commit65b4c9dc8626757f5f7cda279881b059e926916c (patch)
tree7f41d7faf5cd3bd86344eda056fc56269b646225 /main/config.c
parent78d0c3795e9a90a9f99178e38346a53d9b2ebe57 (diff)
fix: divide-by-zero crash when no WiFi networks configured
- Guard tollgate_config_get_next_wifi against network_count=0 - Add fallback parsing for wifi_ssid/wifi_password flat fields - Add heap info to API server failure log for debugging - All 75 unit tests passing
Diffstat (limited to 'main/config.c')
-rw-r--r--main/config.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/main/config.c b/main/config.c
index 45eb8ff..54642a2 100644
--- a/main/config.c
+++ b/main/config.c
@@ -126,6 +126,16 @@ esp_err_t tollgate_config_init(void)
126 } 126 }
127 } 127 }
128 128
129 if (g_config.network_count == 0) {
130 cJSON *ssid = cJSON_GetObjectItem(root, "wifi_ssid");
131 cJSON *pass = cJSON_GetObjectItem(root, "wifi_password");
132 if (ssid && cJSON_IsString(ssid) && pass && cJSON_IsString(pass)) {
133 strncpy(g_config.networks[0].ssid, ssid->valuestring, sizeof(g_config.networks[0].ssid) - 1);
134 strncpy(g_config.networks[0].password, pass->valuestring, sizeof(g_config.networks[0].password) - 1);
135 g_config.network_count = 1;
136 }
137 }
138
129 cJSON *ap_pass = cJSON_GetObjectItem(root, "ap_password"); 139 cJSON *ap_pass = cJSON_GetObjectItem(root, "ap_password");
130 if (ap_pass) strncpy(g_config.ap_password, ap_pass->valuestring, sizeof(g_config.ap_password) - 1); 140 if (ap_pass) strncpy(g_config.ap_password, ap_pass->valuestring, sizeof(g_config.ap_password) - 1);
131 141
@@ -315,6 +325,7 @@ esp_err_t tollgate_config_get_wifi(wifi_config_t *wifi_config)
315 325
316esp_err_t tollgate_config_get_next_wifi(wifi_config_t *wifi_config) 326esp_err_t tollgate_config_get_next_wifi(wifi_config_t *wifi_config)
317{ 327{
328 if (g_config.network_count == 0) return ESP_ERR_NOT_FOUND;
318 g_config.current_network = (g_config.current_network + 1) % g_config.network_count; 329 g_config.current_network = (g_config.current_network + 1) % g_config.network_count;
319 return tollgate_config_get_wifi(wifi_config); 330 return tollgate_config_get_wifi(wifi_config);
320} 331}