[GH-ISSUE #1539] millis() logic error in waitForConnectResult() #1313

Open
opened 2026-02-28 01:29:32 +03:00 by kerem · 0 comments
Owner

Originally created by @realA10001986 on GitHub (Dec 31, 2022).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1539

In WiFiManager::waitForConnectResult(), there is the following code (lines 1236+):

unsigned long timeoutmillis = millis() + timeout;
...
while(millis() < timeoutmillis) {
...

If (millis()+timeout) overflows the unsigned long type, the value is less than the current millis(), which leads to a wrong timeout assumption. The correct way to do this is:

unsigned long now = millis();
...
while(millis() - now < timeout) {

I haven't looked into the entire code, this issue might be present at other places, too.

Originally created by @realA10001986 on GitHub (Dec 31, 2022). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1539 In WiFiManager::waitForConnectResult(), there is the following code (lines 1236+): ``` unsigned long timeoutmillis = millis() + timeout; ... while(millis() < timeoutmillis) { ... ``` If (millis()+timeout) overflows the unsigned long type, the value is less than the current millis(), which leads to a wrong timeout assumption. The correct way to do this is: ``` unsigned long now = millis(); ... while(millis() - now < timeout) { ``` I haven't looked into the entire code, this issue might be present at other places, too.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1313
No description provided.