1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

examples/gcoap: Fix shell parameter validation

Executing the shell command with an URI-Path that doesn't start with a
slash results in an assertion error while composing the client side
message. This is suboptimal user experience, so add an explicit check
for a valid URI-Path and a dedicated error message.
This commit is contained in:
Marian Buschsieweke 2023-01-15 22:18:07 +01:00
parent b8b1a605a9
commit 21ae657e92
No known key found for this signature in database
GPG Key ID: CB8E3238CE715A94

View File

@ -294,6 +294,11 @@ int gcoap_cli_cmd(int argc, char **argv)
uri_len = strlen(argv[apos+1]);
}
if (uri && ((uri_len <= 0) || (uri[0] != '/'))) {
puts("ERROR: URI-Path must start with a \"/\"");
return _print_usage(argv);
}
if (_proxied) {
sock_udp_ep_t tmp_remote;
if (sock_udp_name2ep(&tmp_remote, argv[apos]) != 0) {
@ -329,7 +334,7 @@ int gcoap_cli_cmd(int argc, char **argv)
gcoap_req_init(&pdu, &buf[0], CONFIG_GCOAP_PDU_BUF_SIZE, code_pos, NULL);
}
else{
else {
gcoap_req_init(&pdu, &buf[0], CONFIG_GCOAP_PDU_BUF_SIZE, code_pos, uri);
}
coap_hdr_set_type(pdu.hdr, msg_type);