Replace strcpy by strlcpy
This commit is contained in:
parent
abcabf7fb6
commit
66c28a2e6e
@ -240,21 +240,21 @@ void WebApiMqttClass::onMqttAdminPost(AsyncWebServerRequest* request)
|
|||||||
config.Mqtt_Enabled = root[F("mqtt_enabled")].as<bool>();
|
config.Mqtt_Enabled = root[F("mqtt_enabled")].as<bool>();
|
||||||
config.Mqtt_Retain = root[F("mqtt_retain")].as<bool>();
|
config.Mqtt_Retain = root[F("mqtt_retain")].as<bool>();
|
||||||
config.Mqtt_Tls = root[F("mqtt_tls")].as<bool>();
|
config.Mqtt_Tls = root[F("mqtt_tls")].as<bool>();
|
||||||
strcpy(config.Mqtt_RootCaCert, root[F("mqtt_root_ca_cert")].as<String>().c_str());
|
strlcpy(config.Mqtt_RootCaCert, root[F("mqtt_root_ca_cert")].as<String>().c_str(), sizeof(config.Mqtt_RootCaCert));
|
||||||
config.Mqtt_Port = root[F("mqtt_port")].as<uint>();
|
config.Mqtt_Port = root[F("mqtt_port")].as<uint>();
|
||||||
strcpy(config.Mqtt_Hostname, root[F("mqtt_hostname")].as<String>().c_str());
|
strlcpy(config.Mqtt_Hostname, root[F("mqtt_hostname")].as<String>().c_str(), sizeof(config.Mqtt_Hostname));
|
||||||
strcpy(config.Mqtt_Username, root[F("mqtt_username")].as<String>().c_str());
|
strlcpy(config.Mqtt_Username, root[F("mqtt_username")].as<String>().c_str(), sizeof(config.Mqtt_Username));
|
||||||
strcpy(config.Mqtt_Password, root[F("mqtt_password")].as<String>().c_str());
|
strlcpy(config.Mqtt_Password, root[F("mqtt_password")].as<String>().c_str(), sizeof(config.Mqtt_Password));
|
||||||
strcpy(config.Mqtt_Topic, root[F("mqtt_topic")].as<String>().c_str());
|
strlcpy(config.Mqtt_Topic, root[F("mqtt_topic")].as<String>().c_str(), sizeof(config.Mqtt_Topic));
|
||||||
strcpy(config.Mqtt_LwtTopic, root[F("mqtt_lwt_topic")].as<String>().c_str());
|
strlcpy(config.Mqtt_LwtTopic, root[F("mqtt_lwt_topic")].as<String>().c_str(), sizeof(config.Mqtt_LwtTopic));
|
||||||
strcpy(config.Mqtt_LwtValue_Online, root[F("mqtt_lwt_online")].as<String>().c_str());
|
strlcpy(config.Mqtt_LwtValue_Online, root[F("mqtt_lwt_online")].as<String>().c_str(), sizeof(config.Mqtt_LwtValue_Online));
|
||||||
strcpy(config.Mqtt_LwtValue_Offline, root[F("mqtt_lwt_offline")].as<String>().c_str());
|
strlcpy(config.Mqtt_LwtValue_Offline, root[F("mqtt_lwt_offline")].as<String>().c_str(), sizeof(config.Mqtt_LwtValue_Offline));
|
||||||
config.Mqtt_PublishInterval = root[F("mqtt_publish_interval")].as<uint32_t>();
|
config.Mqtt_PublishInterval = root[F("mqtt_publish_interval")].as<uint32_t>();
|
||||||
config.Mqtt_Hass_Enabled = root[F("mqtt_hass_enabled")].as<bool>();
|
config.Mqtt_Hass_Enabled = root[F("mqtt_hass_enabled")].as<bool>();
|
||||||
config.Mqtt_Hass_Expire = root[F("mqtt_hass_expire")].as<bool>();
|
config.Mqtt_Hass_Expire = root[F("mqtt_hass_expire")].as<bool>();
|
||||||
config.Mqtt_Hass_Retain = root[F("mqtt_hass_retain")].as<bool>();
|
config.Mqtt_Hass_Retain = root[F("mqtt_hass_retain")].as<bool>();
|
||||||
config.Mqtt_Hass_IndividualPanels = root[F("mqtt_hass_individualpanels")].as<bool>();
|
config.Mqtt_Hass_IndividualPanels = root[F("mqtt_hass_individualpanels")].as<bool>();
|
||||||
strcpy(config.Mqtt_Hass_Topic, root[F("mqtt_hass_topic")].as<String>().c_str());
|
strlcpy(config.Mqtt_Hass_Topic, root[F("mqtt_hass_topic")].as<String>().c_str(), sizeof(config.Mqtt_Hass_Topic));
|
||||||
Configuration.write();
|
Configuration.write();
|
||||||
|
|
||||||
retMsg[F("type")] = F("success");
|
retMsg[F("type")] = F("success");
|
||||||
@ -273,7 +273,7 @@ String WebApiMqttClass::getRootCaCertInfo(const char* cert)
|
|||||||
|
|
||||||
mbedtls_x509_crt global_cacert;
|
mbedtls_x509_crt global_cacert;
|
||||||
|
|
||||||
strcpy(rootCaCertInfo, "Can't parse root ca");
|
strlcpy(rootCaCertInfo, "Can't parse root ca", sizeof(rootCaCertInfo));
|
||||||
|
|
||||||
mbedtls_x509_crt_init(&global_cacert);
|
mbedtls_x509_crt_init(&global_cacert);
|
||||||
int ret = mbedtls_x509_crt_parse(&global_cacert, const_cast<unsigned char*>((unsigned char*)cert), 1 + strlen(cert));
|
int ret = mbedtls_x509_crt_parse(&global_cacert, const_cast<unsigned char*>((unsigned char*)cert), 1 + strlen(cert));
|
||||||
|
|||||||
@ -185,9 +185,9 @@ void WebApiNetworkClass::onNetworkAdminPost(AsyncWebServerRequest* request)
|
|||||||
config.WiFi_Dns2[1] = dns2[1];
|
config.WiFi_Dns2[1] = dns2[1];
|
||||||
config.WiFi_Dns2[2] = dns2[2];
|
config.WiFi_Dns2[2] = dns2[2];
|
||||||
config.WiFi_Dns2[3] = dns2[3];
|
config.WiFi_Dns2[3] = dns2[3];
|
||||||
strcpy(config.WiFi_Ssid, root[F("ssid")].as<String>().c_str());
|
strlcpy(config.WiFi_Ssid, root[F("ssid")].as<String>().c_str(), sizeof(config.WiFi_Ssid));
|
||||||
strcpy(config.WiFi_Password, root[F("password")].as<String>().c_str());
|
strlcpy(config.WiFi_Password, root[F("password")].as<String>().c_str(), sizeof(config.WiFi_Password));
|
||||||
strcpy(config.WiFi_Hostname, root[F("hostname")].as<String>().c_str());
|
strlcpy(config.WiFi_Hostname, root[F("hostname")].as<String>().c_str(), sizeof(config.WiFi_Hostname));
|
||||||
if (root[F("dhcp")].as<bool>()) {
|
if (root[F("dhcp")].as<bool>()) {
|
||||||
config.WiFi_Dhcp = true;
|
config.WiFi_Dhcp = true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -123,9 +123,9 @@ void WebApiNtpClass::onNtpAdminPost(AsyncWebServerRequest* request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
CONFIG_T& config = Configuration.get();
|
CONFIG_T& config = Configuration.get();
|
||||||
strcpy(config.Ntp_Server, root[F("ntp_server")].as<String>().c_str());
|
strlcpy(config.Ntp_Server, root[F("ntp_server")].as<String>().c_str(), sizeof(config.Ntp_Server));
|
||||||
strcpy(config.Ntp_Timezone, root[F("ntp_timezone")].as<String>().c_str());
|
strlcpy(config.Ntp_Timezone, root[F("ntp_timezone")].as<String>().c_str(), sizeof(config.Ntp_Timezone));
|
||||||
strcpy(config.Ntp_TimezoneDescr, root[F("ntp_timezone_descr")].as<String>().c_str());
|
strlcpy(config.Ntp_TimezoneDescr, root[F("ntp_timezone_descr")].as<String>().c_str(), sizeof(config.Ntp_TimezoneDescr));
|
||||||
Configuration.write();
|
Configuration.write();
|
||||||
|
|
||||||
retMsg[F("type")] = F("success");
|
retMsg[F("type")] = F("success");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user