[GH-ISSUE #1528] A bug in the init() method of the WiFiManagerParameter class #1304

Closed
opened 2026-02-28 01:29:29 +03:00 by kerem · 3 comments
Owner

Originally created by @Mollayo on GitHub (Dec 1, 2022).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1528

I believe I found a bug in the init() method of the WiFiManagerParameter class.

In this init() method, the value of _length is set to 1 by default. See here:
github.com/tzapu/WiFiManager@9f5981e2fd/WiFiManager.cpp (L61)
The _value variable is also initialised to nullptr.

This init() method is then using the setValue() method to allocate the pointer for _value. However, the allocation is not made in case the length parameter in the init() function is set to 1 because of the condition "if(_length != length)" not being satisfied. See here:
github.com/tzapu/WiFiManager@9f5981e2fd/WiFiManager.cpp (L91)

In consequence, the _value variable is still equal to nullptr after calling the init() method, making WifiManager to crash.

One solution would be to write " _value = new char[_length + 1]; " instead of "_value = nullptr;" at this line:
github.com/tzapu/WiFiManager@fe9774fe0f/WiFiManager.cpp (L62)

Originally created by @Mollayo on GitHub (Dec 1, 2022). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1528 I believe I found a bug in the init() method of the WiFiManagerParameter class. In this init() method, the value of _length is set to 1 by default. See here: https://github.com/tzapu/WiFiManager/blob/9f5981e2fd40db86780299d5ba3a3840b891a998/WiFiManager.cpp#L61 The _value variable is also initialised to nullptr. This init() method is then using the setValue() method to allocate the pointer for _value. However, the allocation is not made in case the length parameter in the init() function is set to 1 because of the condition "if(_length != length)" not being satisfied. See here: https://github.com/tzapu/WiFiManager/blob/9f5981e2fd40db86780299d5ba3a3840b891a998/WiFiManager.cpp#L91 In consequence, the _value variable is still equal to nullptr after calling the init() method, making WifiManager to crash. One solution would be to write " _value = new char[_length + 1]; " instead of "_value = nullptr;" at this line: https://github.com/tzapu/WiFiManager/blob/fe9774fe0f231767f3fc59de1a03a9c44f06adc3/WiFiManager.cpp#L62
kerem 2026-02-28 01:29:29 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@tablatronix commented on GitHub (Dec 1, 2022):

Yeah there are 2 issues on this, I have not had a chance to look at it

#1504
#1521

<!-- gh-comment-id:1334377274 --> @tablatronix commented on GitHub (Dec 1, 2022): Yeah there are 2 issues on this, I have not had a chance to look at it #1504 #1521
Author
Owner

@tablatronix commented on GitHub (Dec 1, 2022):

or
if(_length != length || _value == nullptr){ perhaps?

<!-- gh-comment-id:1334396212 --> @tablatronix commented on GitHub (Dec 1, 2022): or ` if(_length != length || _value == nullptr){` perhaps?
Author
Owner

@tablatronix commented on GitHub (Dec 1, 2022):

I forget why I used length =1
I think 0 made it not possible to detect un-initialized params or out of scope objs.

at some point this will have to be rewritten with smart pointers or safer memory handling

<!-- gh-comment-id:1334411359 --> @tablatronix commented on GitHub (Dec 1, 2022): I forget why I used length =1 I think 0 made it not possible to detect un-initialized params or out of scope objs. at some point this will have to be rewritten with smart pointers or safer memory handling
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#1304
No description provided.