mirror of
https://github.com/Laxilef/OTGateway.git
synced 2026-11-23 14:53:07 +05:00
fix: reject invalid hostnames safely
This commit is contained in:
1 parent
63aeb2fa25
commit
549dbf4985
2 files changed
+47
-28
No files matched your search
+7
-5
@@ -296,12 +296,14 @@ bool jsonToNetworkSettings(const JsonVariantConst src, NetworkSettings& dst) {
|
||||
bool changed = false;
|
||||
|
||||
// hostname
|
||||
if (!src[FPSTR(S_HOSTNAME)].isNull()) {
|
||||
String value = src[FPSTR(S_HOSTNAME)].as<String>();
|
||||
if (src[FPSTR(S_HOSTNAME)].is<JsonString>()) {
|
||||
const JsonString value = src[FPSTR(S_HOSTNAME)].as<JsonString>();
|
||||
|
||||
if (value.length() < sizeof(dst.hostname) && !value.equals(dst.hostname)) {
|
||||
strcpy(dst.hostname, value.c_str());
|
||||
changed = true;
|
||||
if (value.size() < sizeof(dst.hostname) && NetworkUtils::NetworkMgr::isHostnameValid(value.c_str())) {
|
||||
if (strcmp(value.c_str(), dst.hostname) != 0) {
|
||||
strcpy(dst.hostname, value.c_str());
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user