Skip to content

Commit f4d8a48

Browse files
author
Juan Luis Leal Contreras
authored
Fixed #7406 crash on WiFi STA_DISCONNECTED event with reason 0 (#7414)
Fixed #7406 . The "reason2str" macro in WiFiGeneric.cpp tries to read memory from index "-1" in "system_event_reasons" array when handling STA_DISCONNECTED event with reason 0. Dealing with reason 0 as a reason 1 (WIFI_REASON_UNSPECIFIED) will solve the problem (the reason for this event to arrive with reason 0 is unknown). #7406
1 parent 2cebee4 commit f4d8a48

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

Diff for: libraries/WiFi/src/WiFiGeneric.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,9 @@ esp_err_t WiFiGenericClass::_eventCallback(arduino_event_t *event)
947947
//esp_netif_create_ip6_linklocal(esp_netifs[ESP_IF_WIFI_STA]);
948948
} else if(event->event_id == ARDUINO_EVENT_WIFI_STA_DISCONNECTED) {
949949
uint8_t reason = event->event_info.wifi_sta_disconnected.reason;
950+
// Reason 0 causes crash, use reason 1 (UNSPECIFIED) instead
951+
if(!reason)
952+
reason = WIFI_REASON_UNSPECIFIED;
950953
log_w("Reason: %u - %s", reason, reason2str(reason));
951954
if(reason == WIFI_REASON_NO_AP_FOUND) {
952955
WiFiSTAClass::_setStatus(WL_NO_SSID_AVAIL);

0 commit comments

Comments
 (0)