mirror of
https://github.com/esphome/esphome.git
synced 2025-09-02 19:32:19 +01:00
Ensure that all uses of strncpy in wifi component are safe. (#5636)
This commit is contained in:
@@ -261,8 +261,8 @@ void WiFiComponent::set_sta(const WiFiAP &ap) {
|
||||
void WiFiComponent::clear_sta() { this->sta_.clear(); }
|
||||
void WiFiComponent::save_wifi_sta(const std::string &ssid, const std::string &password) {
|
||||
SavedWifiSettings save{};
|
||||
strncpy(save.ssid, ssid.c_str(), sizeof(save.ssid));
|
||||
strncpy(save.password, password.c_str(), sizeof(save.password));
|
||||
strncpy(save.ssid, ssid.c_str(), sizeof(save.ssid) - 1);
|
||||
strncpy(save.password, password.c_str(), sizeof(save.password) - 1);
|
||||
this->pref_.save(&save);
|
||||
// ensure it's written immediately
|
||||
global_preferences->sync();
|
||||
|
Reference in New Issue
Block a user