add sanity checks for code

This commit is contained in:
technyon
2022-08-12 23:38:11 +02:00
parent 3de0802419
commit d1b8b5377f

View File

@@ -367,6 +367,7 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c
bool idExists = std::find(_keypadCodeIds.begin(), _keypadCodeIds.end(), id) != _keypadCodeIds.end();
int codeInt = code.toInt();
bool codeValid = codeInt > 100000 && (code.indexOf('0') == -1);
NukiLock::CmdResult result = (NukiLock::CmdResult)-1;
if(strcmp(command, "add") == 0)
@@ -381,6 +382,11 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c
_network->publishKeypadCommandResult("MissingParameterCode");
return;
}
if(!codeValid)
{
_network->publishKeypadCommandResult("CodeInvalid");
return;
}
NukiLock::NewKeypadEntry entry;
memset(&entry, 0, sizeof(entry));
@@ -414,6 +420,11 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c
_network->publishKeypadCommandResult("MissingParameterCode");
return;
}
if(!codeValid)
{
_network->publishKeypadCommandResult("CodeInvalid");
return;
}
if(!idExists)
{
_network->publishKeypadCommandResult("UnknownId");