Hi…I am working on an application built from the gcoap_dtls example and I am working on the 2022.01 version of RIOT OS.
- Suppose I want to get some data from Server using COAP GET.On the server side,inside the resourse handler function,we need to return the sumof metadata length and payload length. for eg.
static ssize_t _riot_board_handler(coap_pkt_t *pdu, uint8_t *buf, size_t len, void *ctx)
{
(void)ctx;
gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT);
coap_opt_add_format(pdu, COAP_FORMAT_TEXT);
size_t resp_len = coap_opt_finish(pdu, COAP_OPT_FINISH_PAYLOAD);
/* write the data in the response buffer */
if (pdu->payload_len >= strlen(temp_buf)) {
printf("pdu->payload_len:%d\n",pdu->payload_len);
memcpy(pdu->payload, temp_buf, strlen(temp_buf));
return resp_len + strlen(temp_buf);
}
else {
puts("gcoap_cli: msg buffer too small");
return gcoap_response(pdu, buf, len, COAP_CODE_INTERNAL_SERVER_ERROR);
}
}
when resp_len + strlen(temp_buf) is greater than 91 bytes ,server crashes with *** stack smashing detected ***: terminated
- Similary on on the client side,when using COAP PUT method to a resource in server.
bytes_sent = gcoap_req_send(buf, len, remote, _resp_handler, NULL); len is the sum of payload and metadata length.
when len is greater than 91 bytes,client also crashes with *** stack smashing detected ***: terminated.
- another interesting point is,even though the server and client crashes when the length is greater than 91 bytes, both send the payload to the other side.So payload is sent to the client in COAP GET method from server and client can also send payload to a resource in server using COAP PUT method. After the payload is send,the system crashes.
Could anyone help me to resolve this issue ?