Open axlan opened 2 years ago
I see no issues switching to smart pointers, I might just need someone else to review this
here is the issue for that change to copy operator
FYI this is applied to branch https://github.com/tzapu/WiFiManager/tree/parameter-smart-ptr
anyone test this?
BUMP
Hardware
WiFimanager Branch/Release: Master commit 810f144
Esp8266/Esp32:
Hardware: D1-mini lite
Description
WiFiManagerParameter class does not properly handle the C++ move constructor resulting in a use after free error.
Reproduction Example
I added a log message to record the alloc/free's:
Solution
What's happening here is that the
std::vector
is calling the implicit move constructor: https://en.cppreference.com/w/cpp/language/move_constructorThis constructor doesn't correctly handle moving the
_value
data which is then freed. A similar issue is presumably why the copy constructor is made private.There are three fixes that I see.
WiFiManagerParameter(const WiFiManagerParameter&&) = delete;
Note: the copy constructor is implicitly deleted by the inclusion of the unique_ptr.
A simple copy constructor could be implemented with:
The only change to the rest of the project was replacing the line:
value.toCharArray(_params[i]->_value, _params[i]->_length+1); // length+1 null terminated
withvalue.toCharArray(_params[i]->_value.get(), _params[i]->_length+1); // length+1 null terminated