Skip to content

Commit

Permalink
Resolves issue #54
Browse files Browse the repository at this point in the history
Changed the strncmp functions to check against the length of the command we wish to match against
  • Loading branch information
kebab01 committed Aug 24, 2023
1 parent 16a462d commit 5f35aad
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ BaseType_t CLIConfigIntervals::enter_cli(char *pcWriteBuffer,
memset(pcWriteBuffer, 0, xWriteBufferLen);
param = FreeRTOS_CLIGetParameter(pcCommandString, paramNum, &paramLen);
if (param != nullptr && paramLen > 0) {
if (!strncmp("list", param, paramLen)) {
if (!strncmp("list", param, strlen("list"))) {
response_buffer.clear();
dump(response_buffer);
return pdTRUE;
}

if (!strncmp("measure", param, paramLen)) {
if (!strncmp("measure", param, strlen("measure"))) {
uint16_t i = 0;
paramNum++;
param = FreeRTOS_CLIGetParameter(pcCommandString, paramNum, &paramLen);
Expand All @@ -134,7 +134,7 @@ BaseType_t CLIConfigIntervals::enter_cli(char *pcWriteBuffer,
return pdFALSE;
}

if (!strncmp("uplink", param, paramLen)) {
if (!strncmp("uplink", param, strlen("uplink"))) {
uint16_t i = 0;
paramNum++;
param = FreeRTOS_CLIGetParameter(pcCommandString, paramNum, &paramLen);
Expand All @@ -160,7 +160,7 @@ BaseType_t CLIConfigIntervals::enter_cli(char *pcWriteBuffer,
return pdFALSE;
}

if (!strncmp("clockmult", param, paramLen)) {
if (!strncmp("clockmult", param, strlen("clockmult"))) {
memset(pcWriteBuffer, 0, xWriteBufferLen);

float sleepMultiplier = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion firmware/wombat/src/cli/device_config/cli_power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ BaseType_t CLIPower::enter_cli(char *pcWriteBuffer, size_t xWriteBufferLen,
memset(pcWriteBuffer, 0, xWriteBufferLen);
param = FreeRTOS_CLIGetParameter(pcCommandString, paramNum, &paramLen);
if (param != nullptr && paramLen > 0) {
if (!strncmp("show", param, paramLen)) {
if (!strncmp("show", param, strlen("show"))) {
response_buffer_.clear();
float bv = BatteryMonitor::get_voltage();
float bi = BatteryMonitor::get_current();
Expand Down
16 changes: 8 additions & 8 deletions firmware/wombat/src/cli/device_config/config_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,39 +71,39 @@ BaseType_t CLIConfig::enter_cli(char *pcWriteBuffer, size_t xWriteBufferLen,
memset(pcWriteBuffer, 0, xWriteBufferLen);
param = FreeRTOS_CLIGetParameter(pcCommandString, paramNum, &paramLen);
if (param != nullptr && paramLen > 0) {
if (!strncmp("list", param, paramLen)) {
if (!strncmp("list", param, strlen("list"))) {
response_buffer_.clear();
config.dumpConfig(response_buffer_);
response_buffer_.println("\r\nOK");
return pdTRUE;
}

if (!strncmp("load", param, paramLen)) {
if (!strncmp("load", param, strlen("load"))) {
config.load();
config.dumpConfig(response_buffer_);
response_buffer_.println("\r\nOK");
return pdTRUE;
}

if (!strncmp("save", param, paramLen)) {
if (!strncmp("save", param, strlen("save"))) {
config.save();
strncpy(pcWriteBuffer, "Configuration saved\r\nOK\r\n", xWriteBufferLen - 1);
return pdFALSE;
}

if (!strncmp("dto", param, 3)) {
if (!strncmp("dto", param, strlen("dto"))) {
timeout_active = false;
strncpy(pcWriteBuffer, "Timeout disabled\r\nOK\r\n", xWriteBufferLen - 1);
return pdFALSE;
}

if (!strncmp("eto", param, 3)) {
if (!strncmp("eto", param, strlen("eto"))) {
timeout_active = true;
strncpy(pcWriteBuffer, "Timeout enabled\r\nOK\r\n", xWriteBufferLen - 1);
return pdFALSE;
}

if (!strncmp("ota", param, paramLen)) {
if (!strncmp("ota", param, strlen("ota"))) {
// If force is true the version number in wombat.sha1 is not checked.
// Use "config ota 1" to force the update.
bool force = false;
Expand Down Expand Up @@ -145,7 +145,7 @@ BaseType_t CLIConfig::enter_cli(char *pcWriteBuffer, size_t xWriteBufferLen,
return pdFALSE;
}

if (!strncmp("sdi12defn", param, paramLen)) {
if (!strncmp("sdi12defn", param, strlen("sdi12defn"))) {
bool success = false;
if (cat_m1.make_ready()) {
if (connect_to_internet()) {
Expand All @@ -164,7 +164,7 @@ BaseType_t CLIConfig::enter_cli(char *pcWriteBuffer, size_t xWriteBufferLen,
return pdFALSE;
}

if (!strncmp("reboot", param, paramLen)) {
if (!strncmp("reboot", param, strlen("reboot"))) {
strncpy(pcWriteBuffer, "Rebooting\r\nOK\r\n", xWriteBufferLen - 1);
shutdown();
esp_restart();
Expand Down
14 changes: 7 additions & 7 deletions firmware/wombat/src/cli/device_config/ftp_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ BaseType_t CLIFTP::enter_cli(char *pcWriteBuffer, size_t xWriteBufferLen,
memset(pcWriteBuffer, 0, xWriteBufferLen);
param = FreeRTOS_CLIGetParameter(pcCommandString, paramNum, &paramLen);
if (param != nullptr && paramLen > 0) {
if (!strncmp("list", param, paramLen)) {
if (!strncmp("list", param, strlen("list"))) {
response_buffer_.clear();
dump(response_buffer_);
return pdTRUE;
}

if (!strncmp("host", param, paramLen)) {
if (!strncmp("host", param, strlen("host"))) {
paramNum++;
param = FreeRTOS_CLIGetParameter(pcCommandString, paramNum, &paramLen);
if (param != nullptr && paramLen > 0) {
Expand All @@ -99,7 +99,7 @@ BaseType_t CLIFTP::enter_cli(char *pcWriteBuffer, size_t xWriteBufferLen,
return pdFALSE;
}

if (!strncmp("user", param, paramLen)) {
if (!strncmp("user", param, strlen("user"))) {
paramNum++;
param = FreeRTOS_CLIGetParameter(pcCommandString, paramNum, &paramLen);
if (param != nullptr && paramLen > 0) {
Expand All @@ -115,7 +115,7 @@ BaseType_t CLIFTP::enter_cli(char *pcWriteBuffer, size_t xWriteBufferLen,
return pdFALSE;
}

if (!strncmp("password", param, paramLen)) {
if (!strncmp("password", param, strlen("password"))) {
paramNum++;
param = FreeRTOS_CLIGetParameter(pcCommandString, paramNum, &paramLen);
if (param != nullptr && paramLen > 0) {
Expand All @@ -131,19 +131,19 @@ BaseType_t CLIFTP::enter_cli(char *pcWriteBuffer, size_t xWriteBufferLen,
return pdFALSE;
}

if (!strncmp("login", param, paramLen)) {
if (!strncmp("login", param, strlen("login"))) {
bool rc = ftp_login();
snprintf(pcWriteBuffer, xWriteBufferLen - 1, "\r\n%s\r\n", rc ? "OK" : "ERROR");
return pdFALSE;
}

if (!strncmp("logout", param, paramLen)) {
if (!strncmp("logout", param, strlen("logout"))) {
bool rc = ftp_logout();
snprintf(pcWriteBuffer, xWriteBufferLen - 1, "\r\n%s\r\n", rc ? "OK" : "ERROR");
return pdFALSE;
}

if (!strncmp("get", param, paramLen)) {
if (!strncmp("get", param, strlen("get"))) {
paramNum++;
param = FreeRTOS_CLIGetParameter(pcCommandString, paramNum, &paramLen);
if (param != nullptr && paramLen > 0) {
Expand Down
18 changes: 9 additions & 9 deletions firmware/wombat/src/cli/device_config/mqtt_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ BaseType_t CLIMQTT::enter_cli(char *pcWriteBuffer, size_t xWriteBufferLen,
memset(pcWriteBuffer, 0, xWriteBufferLen);
param = FreeRTOS_CLIGetParameter(pcCommandString, paramNum, &paramLen);
if (param != nullptr && paramLen > 0) {
if (!strncmp("list", param, paramLen)) {
if (!strncmp("list", param, strlen("list"))) {
response_buffer_.clear();
dump(response_buffer_);
return pdTRUE;
}

if (!strncmp("host", param, paramLen)) {
if (!strncmp("host", param, strlen("host"))) {
paramNum++;
param = FreeRTOS_CLIGetParameter(pcCommandString, paramNum, &paramLen);
if (param != nullptr && paramLen > 0) {
Expand All @@ -104,7 +104,7 @@ BaseType_t CLIMQTT::enter_cli(char *pcWriteBuffer, size_t xWriteBufferLen,
return pdFALSE;
}

if (!strncmp("port", param, paramLen)) {
if (!strncmp("port", param, strlen("port"))) {
uint16_t i = 0;
paramNum++;
param = FreeRTOS_CLIGetParameter(pcCommandString, paramNum, &paramLen);
Expand All @@ -130,7 +130,7 @@ BaseType_t CLIMQTT::enter_cli(char *pcWriteBuffer, size_t xWriteBufferLen,
}
}

if (!strncmp("user", param, paramLen)) {
if (!strncmp("user", param, strlen("user"))) {
paramNum++;
param = FreeRTOS_CLIGetParameter(pcCommandString, paramNum, &paramLen);
if (param != nullptr && paramLen > 0) {
Expand All @@ -146,7 +146,7 @@ BaseType_t CLIMQTT::enter_cli(char *pcWriteBuffer, size_t xWriteBufferLen,
return pdFALSE;
}

if (!strncmp("password", param, paramLen)) {
if (!strncmp("password", param, strlen("password"))) {
paramNum++;
param = FreeRTOS_CLIGetParameter(pcCommandString, paramNum, &paramLen);
if (param != nullptr && paramLen > 0) {
Expand All @@ -162,7 +162,7 @@ BaseType_t CLIMQTT::enter_cli(char *pcWriteBuffer, size_t xWriteBufferLen,
return pdFALSE;
}

if (!strncmp("topic", param, paramLen)) {
if (!strncmp("topic", param, strlen("topic"))) {
paramNum++;
param = FreeRTOS_CLIGetParameter(pcCommandString, paramNum, &paramLen);
if (param != nullptr && paramLen > 0) {
Expand All @@ -182,19 +182,19 @@ BaseType_t CLIMQTT::enter_cli(char *pcWriteBuffer, size_t xWriteBufferLen,
return pdFALSE;
}

if (!strncmp("login", param, paramLen)) {
if (!strncmp("login", param, strlen("login"))) {
bool rc = mqtt_login();
snprintf(pcWriteBuffer, xWriteBufferLen-1, "\r\n%s\r\n", rc ? "OK" : "ERROR");
return pdFALSE;
}

if (!strncmp("logout", param, paramLen)) {
if (!strncmp("logout", param, strlen("logout"))) {
bool rc = mqtt_logout();
snprintf(pcWriteBuffer, xWriteBufferLen-1, "\r\n%s\r\n", rc ? "OK" : "ERROR");
return pdFALSE;
}

if (!strncmp("publish", param, paramLen)) {
if (!strncmp("publish", param, strlen("publish"))) {
String topic(config.mqtt_topic_template);
bool rc = mqtt_publish(topic, "ABCDEF", 6);
snprintf(pcWriteBuffer, xWriteBufferLen-1, "\r\n%s\r\n", rc ? "OK" : "ERROR");
Expand Down

0 comments on commit 5f35aad

Please sign in to comment.