mirror of
https://github.com/tzapu/WiFiManager.git
synced 2026-04-27 00:55:52 +03:00
[GH-ISSUE #1341] WiFiManagerParameter does not handle move constructor #1150
Labels
No labels
📶 WiFi
🕸️ HTTP
Branch
DEV Help Wanted
Discussion
Documentation
ESP32
Example
Good First Issue
Hotfix
In Progress
Incomplete
Needs Feeback
Priority
QA
Question
Task
Upstream/Dependancy
bug
duplicate
enhancement
invalid
pull-request
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/WiFiManager#1150
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @axlan on GitHub (Jan 22, 2022).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1341
Hardware
WiFimanager Branch/Release: Master commit
810f144Esp8266/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::vectoris calling the implicit move constructor: https://en.cppreference.com/w/cpp/language/move_constructorThis constructor doesn't correctly handle moving the
_valuedata 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 terminatedwith
value.toCharArray(_params[i]->_value.get(), _params[i]->_length+1); // length+1 null terminated@tablatronix commented on GitHub (Jan 22, 2022):
I see no issues switching to smart pointers, I might just need someone else to review this
@tablatronix commented on GitHub (Jan 22, 2022):
here is the issue for that change to copy operator
https://github.com/tzapu/WiFiManager/issues/1050
@tablatronix commented on GitHub (Feb 19, 2022):
FYI this is applied to branch
https://github.com/tzapu/WiFiManager/tree/parameter-smart-ptr
anyone test this?
@tablatronix commented on GitHub (Apr 7, 2022):
BUMP