add: relay endpoint
fix: discovery invalid read
This commit is contained in:
parent
1171ef22be
commit
a127a68e31
5 changed files with 61 additions and 2 deletions
endpoints
|
@ -197,6 +197,12 @@ api_v1_controllers_discover_POST(struct mg_connection *c, endpoint_args_t *args,
|
|||
uint16_t discovered_command_port = mpack_node_u16(mpack_node_map_uint(root, DISCOVERY_MAPPING_COMMAND_PORT));
|
||||
uint8_t discovered_relay_count = mpack_node_u8(mpack_node_map_uint(root, DISCOVERY_MAPPING_RELAY_COUNT));
|
||||
const char *discovered_name = mpack_node_str(mpack_node_map_uint(root, DISCOVERY_MAPPING_NAME));
|
||||
size_t discovered_name_len = mpack_node_strlen(mpack_node_map_uint(root, DISCOVERY_MAPPING_NAME));
|
||||
|
||||
if(discovered_name_len > MAX_NAME_LENGTH)
|
||||
{
|
||||
discovered_name_len = MAX_NAME_LENGTH;
|
||||
}
|
||||
|
||||
bool found_discovered_in_list = 0;
|
||||
|
||||
|
@ -207,7 +213,7 @@ api_v1_controllers_discover_POST(struct mg_connection *c, endpoint_args_t *args,
|
|||
if(uuid_compare(known_controllers[i]->uid, discovered_id) == 0)
|
||||
{
|
||||
known_controllers[i]->active = 1;
|
||||
strncpy(known_controllers[i]->name, discovered_name, MAX_NAME_LENGTH);
|
||||
strncpy(known_controllers[i]->name, discovered_name, discovered_name_len);
|
||||
known_controllers[i]->name[MAX_NAME_LENGTH] = '\0';
|
||||
known_controllers[i]->port = discovered_command_port;
|
||||
known_controllers[i]->relay_count = discovered_relay_count;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue