From 70ed65549a60fe1e441557f8f5f444c4e4045386 Mon Sep 17 00:00:00 2001 From: 94xhn <87560781+94xhn@users.noreply.github.com> Date: Sat, 11 Jul 2026 21:40:56 +0800 Subject: [PATCH] fix(WiFi/ESP32): check cb_event for NULL before calling on station connect/disconnect ARM_WIFI_Initialize() accepts a NULL cb_event when the caller doesn't need event callbacks, and this is documented as a valid usage. But AT_Notify() calls pCtrl->cb_event() unconditionally for AT_NOTIFY_STATION_CONNECTED/AT_NOTIFY_STATION_DISCONNECTED (which raise ARM_WIFI_EVENT_AP_CONNECT/ARM_WIFI_EVENT_AP_DISCONNECT), with no NULL check - a null pointer call if a station connects to or disconnects from the local AP while no callback was registered. Fixes #13. Signed-off-by: 94xhn <87560781+94xhn@users.noreply.github.com> --- WiFi/ESP32/WiFi_ESP32.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/WiFi/ESP32/WiFi_ESP32.c b/WiFi/ESP32/WiFi_ESP32.c index d961d08..a9f99fb 100644 --- a/WiFi/ESP32/WiFi_ESP32.c +++ b/WiFi/ESP32/WiFi_ESP32.c @@ -376,13 +376,17 @@ void AT_Notify (uint32_t event, void *arg) { /* Station connects to the local AP */ ex = AT_Resp_StaMac (mac); - pCtrl->cb_event (ARM_WIFI_EVENT_AP_CONNECT, mac); + if (pCtrl->cb_event != NULL) { + pCtrl->cb_event (ARM_WIFI_EVENT_AP_CONNECT, mac); + } } else if (event == AT_NOTIFY_STATION_DISCONNECTED) { /* Station disconnects from the local AP */ ex = AT_Resp_StaMac (mac); - pCtrl->cb_event (ARM_WIFI_EVENT_AP_DISCONNECT, mac); + if (pCtrl->cb_event != NULL) { + pCtrl->cb_event (ARM_WIFI_EVENT_AP_DISCONNECT, mac); + } } else if (event == AT_NOTIFY_CONNECTED) { /* Local station connected to an AP */