mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-12 21:09:05 +08:00
Add check for command parameter, to be sure is the expected parameter and not a part of bigger one
Add check pin number and value number are actually number to use them in [ESP201] Add check on [ESPXXX command to recognize it when command start by [ESPXXX or something not bigger than`echo: [ESP` Thanks @treeplesk for raising these case
This commit is contained in:
parent
95ec8b39e9
commit
99b6261aa4
@ -66,6 +66,19 @@ const char * encodeString(const char * s){
|
|||||||
if (tmp =="") tmp=" ";
|
if (tmp =="") tmp=" ";
|
||||||
return tmp.c_str();
|
return tmp.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isValidNumber(String str)
|
||||||
|
{
|
||||||
|
boolean isNum=false;
|
||||||
|
if(!(str.charAt(0) == '+' || str.charAt(0) == '-' || isDigit(str.charAt(0)))) return false;
|
||||||
|
|
||||||
|
for(byte i=1;i<str.length();i++)
|
||||||
|
{
|
||||||
|
if(!(isDigit(str.charAt(i)) || str.charAt(i) == '.')) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
String COMMAND::get_param (String & cmd_params, const char * id, bool withspace)
|
String COMMAND::get_param (String & cmd_params, const char * id, bool withspace)
|
||||||
{
|
{
|
||||||
static String parameter;
|
static String parameter;
|
||||||
@ -85,6 +98,9 @@ String COMMAND::get_param (String & cmd_params, const char * id, bool withspace)
|
|||||||
if (start == -1 ) {
|
if (start == -1 ) {
|
||||||
return parameter;
|
return parameter;
|
||||||
}
|
}
|
||||||
|
if (start >0){
|
||||||
|
if (cmd_params[start-1]!=' ') return parameter;
|
||||||
|
}
|
||||||
//password and SSID can have space so handle it
|
//password and SSID can have space so handle it
|
||||||
//if no space expected use space as delimiter
|
//if no space expected use space as delimiter
|
||||||
if (!withspace) {
|
if (!withspace) {
|
||||||
@ -511,7 +527,7 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
|||||||
} else {
|
} else {
|
||||||
int pin = parameter.toInt();
|
int pin = parameter.toInt();
|
||||||
//check pin is valid
|
//check pin is valid
|
||||||
if ((pin >= 0) && (pin <= MAX_GPIO)) {
|
if ((pin >= 0) && (pin <= MAX_GPIO) && isValidNumber(parameter)) {
|
||||||
//check if analog or digital
|
//check if analog or digital
|
||||||
bool isdigital = true;
|
bool isdigital = true;
|
||||||
|
|
||||||
@ -573,6 +589,11 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
|
|||||||
} else {
|
} else {
|
||||||
//it is a set
|
//it is a set
|
||||||
int value = parameter.toInt();
|
int value = parameter.toInt();
|
||||||
|
if (!isValidNumber(parameter)){
|
||||||
|
ESPCOM::println (INCORRECT_CMD_MSG, output, espresponse);
|
||||||
|
response = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (isdigital) {
|
if (isdigital) {
|
||||||
//verify it is a 0 or a 1
|
//verify it is a 0 or a 1
|
||||||
if ( (value == 0) || (value == 1) ) {
|
if ( (value == 0) || (value == 1) ) {
|
||||||
@ -2059,7 +2080,7 @@ bool COMMAND::check_command (String buffer, tpipe output, bool handlelockserial,
|
|||||||
if (ESPpos == -1 && (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)) {
|
if (ESPpos == -1 && (CONFIG::GetFirmwareTarget() == SMOOTHIEWARE)) {
|
||||||
ESPpos = buffer.indexOf ("[esp");
|
ESPpos = buffer.indexOf ("[esp");
|
||||||
}
|
}
|
||||||
if (ESPpos > -1) {
|
if ((ESPpos > -1) && (ESPpos<strlen("echo: " ))){
|
||||||
//is there the second part?
|
//is there the second part?
|
||||||
int ESPpos2 = buffer.indexOf ("]", ESPpos);
|
int ESPpos2 = buffer.indexOf ("]", ESPpos);
|
||||||
if (ESPpos2 > -1) {
|
if (ESPpos2 > -1) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user