add sanity checks for code
This commit is contained in:
@@ -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();
|
bool idExists = std::find(_keypadCodeIds.begin(), _keypadCodeIds.end(), id) != _keypadCodeIds.end();
|
||||||
int codeInt = code.toInt();
|
int codeInt = code.toInt();
|
||||||
|
bool codeValid = codeInt > 100000 && (code.indexOf('0') == -1);
|
||||||
NukiLock::CmdResult result = (NukiLock::CmdResult)-1;
|
NukiLock::CmdResult result = (NukiLock::CmdResult)-1;
|
||||||
|
|
||||||
if(strcmp(command, "add") == 0)
|
if(strcmp(command, "add") == 0)
|
||||||
@@ -381,6 +382,11 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c
|
|||||||
_network->publishKeypadCommandResult("MissingParameterCode");
|
_network->publishKeypadCommandResult("MissingParameterCode");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(!codeValid)
|
||||||
|
{
|
||||||
|
_network->publishKeypadCommandResult("CodeInvalid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
NukiLock::NewKeypadEntry entry;
|
NukiLock::NewKeypadEntry entry;
|
||||||
memset(&entry, 0, sizeof(entry));
|
memset(&entry, 0, sizeof(entry));
|
||||||
@@ -414,6 +420,11 @@ void NukiWrapper::onKeypadCommandReceived(const char *command, const uint &id, c
|
|||||||
_network->publishKeypadCommandResult("MissingParameterCode");
|
_network->publishKeypadCommandResult("MissingParameterCode");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(!codeValid)
|
||||||
|
{
|
||||||
|
_network->publishKeypadCommandResult("CodeInvalid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(!idExists)
|
if(!idExists)
|
||||||
{
|
{
|
||||||
_network->publishKeypadCommandResult("UnknownId");
|
_network->publishKeypadCommandResult("UnknownId");
|
||||||
|
|||||||
Reference in New Issue
Block a user