Skip to content

Commit

Permalink
Merge branch 'bugfix/handle_invalid_args' into 'main'
Browse files Browse the repository at this point in the history
OT CLI: handle invalid args when processing an ip address

See merge request espressif/esp-thread-br!65
  • Loading branch information
chshu committed Jun 26, 2023
2 parents 8259ed6 + de25a8f commit dabfc9c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/esp_ot_cli_extension/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "0.4.5"
version: "0.4.6"
description: Espressif OpenThread CLI Extension
url: https://github.com/espressif/esp-thread-br/tree/main/components/esp_ot_cli_extension
dependencies:
Expand Down
10 changes: 10 additions & 0 deletions components/esp_ot_cli_extension/src/esp_ot_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ static void print_ip_address(void)

bool is_netif_exist(const char *if_name)
{
if (strlen(if_name) != 2) {
otCliOutputFormat("no such netif: %s\n", if_name);
return false;
}
struct netif *netif;
NETIF_FOREACH(netif)
{
Expand Down Expand Up @@ -136,12 +140,18 @@ otError esp_ot_process_ip(void *aContext, uint8_t aArgsLength, char *aArgs[])
if (strcmp(aArgs[0], "print") == 0) {
print_ip_address();
} else if (strcmp(aArgs[0], "add") == 0) {
if (aArgsLength != 3) {
return OT_ERROR_INVALID_ARGS;
}
char dest_addr[128];
strncpy(dest_addr, aArgs[2], strlen(aArgs[2]) + 1);
ip_event_add_ip6_t add_addr;
inet6_aton(dest_addr, &add_addr.addr);
esp_lwip_add_del_ip(&add_addr, aArgs[1], true);
} else if (strcmp(aArgs[0], "del") == 0) {
if (aArgsLength != 3) {
return OT_ERROR_INVALID_ARGS;
}
char dest_addr[128];
strncpy(dest_addr, aArgs[2], strlen(aArgs[2]));
ip_event_add_ip6_t add_addr;
Expand Down

0 comments on commit dabfc9c

Please sign in to comment.