upleb.uk

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

summaryrefslogtreecommitdiff
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
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
-rw-r--r--main/config.c11
-rw-r--r--main/tollgate_api.c4
-rw-r--r--main/tollgate_main.c1
-rwxr-xr-xtests/unit/test_cvm_serverbin0 -> 45728 bytes
-rwxr-xr-xtests/unit/test_geohashbin20776 -> 20784 bytes
-rwxr-xr-xtests/unit/test_identitybin297880 -> 297888 bytes
-rwxr-xr-xtests/unit/test_lightning_payoutbin20552 -> 20560 bytes
-rwxr-xr-xtests/unit/test_lnurl_paybin21304 -> 21312 bytes
-rwxr-xr-xtests/unit/test_mcp_handlerbin38736 -> 63056 bytes
-rwxr-xr-xtests/unit/test_mint_healthbin0 -> 36792 bytes
-rwxr-xr-xtests/unit/test_nip04bin298776 -> 298792 bytes
-rwxr-xr-xtests/unit/test_tollgate_clientbin51992 -> 52072 bytes
12 files changed, 15 insertions, 1 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}
diff --git a/main/tollgate_api.c b/main/tollgate_api.c
index 22b30ee..997dd09 100644
--- a/main/tollgate_api.c
+++ b/main/tollgate_api.c
@@ -6,6 +6,7 @@
6#include "nucula_wallet.h" 6#include "nucula_wallet.h"
7#include "mint_health.h" 7#include "mint_health.h"
8#include "esp_log.h" 8#include "esp_log.h"
9#include "esp_system.h"
9#include "cJSON.h" 10#include "cJSON.h"
10#include "lwip/sockets.h" 11#include "lwip/sockets.h"
11#include "lwip/netdb.h" 12#include "lwip/netdb.h"
@@ -524,7 +525,8 @@ esp_err_t tollgate_api_start(void)
524 525
525 esp_err_t ret = httpd_start(&s_api_server, &config); 526 esp_err_t ret = httpd_start(&s_api_server, &config);
526 if (ret != ESP_OK) { 527 if (ret != ESP_OK) {
527 ESP_LOGE(TAG, "Failed to start API server: %s", esp_err_to_name(ret)); 528 ESP_LOGE(TAG, "Failed to start API server: %s (heap: %lu)", esp_err_to_name(ret), (unsigned long)esp_get_free_heap_size());
529 s_api_server = NULL;
528 return ret; 530 return ret;
529 } 531 }
530 532
diff --git a/main/tollgate_main.c b/main/tollgate_main.c
index 018d934..a39ccc9 100644
--- a/main/tollgate_main.c
+++ b/main/tollgate_main.c
@@ -5,6 +5,7 @@
5#include "esp_wifi.h" 5#include "esp_wifi.h"
6#include "esp_event.h" 6#include "esp_event.h"
7#include "esp_log.h" 7#include "esp_log.h"
8#include "esp_system.h"
8#include "nvs_flash.h" 9#include "nvs_flash.h"
9#include "esp_netif.h" 10#include "esp_netif.h"
10#include "lwip/netif.h" 11#include "lwip/netif.h"
diff --git a/tests/unit/test_cvm_server b/tests/unit/test_cvm_server
new file mode 100755
index 0000000..8f0b605
--- /dev/null
+++ b/tests/unit/test_cvm_server
Binary files differ
diff --git a/tests/unit/test_geohash b/tests/unit/test_geohash
index dc5045f..46d0e6f 100755
--- a/tests/unit/test_geohash
+++ b/tests/unit/test_geohash
Binary files differ
diff --git a/tests/unit/test_identity b/tests/unit/test_identity
index 277bb49..d0ff402 100755
--- a/tests/unit/test_identity
+++ b/tests/unit/test_identity
Binary files differ
diff --git a/tests/unit/test_lightning_payout b/tests/unit/test_lightning_payout
index b10888c..c6aaa5f 100755
--- a/tests/unit/test_lightning_payout
+++ b/tests/unit/test_lightning_payout
Binary files differ
diff --git a/tests/unit/test_lnurl_pay b/tests/unit/test_lnurl_pay
index 1f16293..61c9743 100755
--- a/tests/unit/test_lnurl_pay
+++ b/tests/unit/test_lnurl_pay
Binary files differ
diff --git a/tests/unit/test_mcp_handler b/tests/unit/test_mcp_handler
index b5d6a85..a001641 100755
--- a/tests/unit/test_mcp_handler
+++ b/tests/unit/test_mcp_handler
Binary files differ
diff --git a/tests/unit/test_mint_health b/tests/unit/test_mint_health
new file mode 100755
index 0000000..2a48ad2
--- /dev/null
+++ b/tests/unit/test_mint_health
Binary files differ
diff --git a/tests/unit/test_nip04 b/tests/unit/test_nip04
index cb52040..cbf4c80 100755
--- a/tests/unit/test_nip04
+++ b/tests/unit/test_nip04
Binary files differ
diff --git a/tests/unit/test_tollgate_client b/tests/unit/test_tollgate_client
index f9b0f7d..8077223 100755
--- a/tests/unit/test_tollgate_client
+++ b/tests/unit/test_tollgate_client
Binary files differ