From 21ae657e92d4492d07c97b7020fba0dcfd5ba96a Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Sun, 15 Jan 2023 22:18:07 +0100 Subject: [PATCH] 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. --- examples/gcoap/client.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/gcoap/client.c b/examples/gcoap/client.c index 8c4275c485..ee9416bec4 100644 --- a/examples/gcoap/client.c +++ b/examples/gcoap/client.c @@ -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);