mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-04 00:45:40 +03:00
coap_pdu.c: Report options with invalid length
Malformed PDUs were responsed to with a RST. Now request PDUs with invalid lengths are also reported with a 4.02 response. See RFC7252 5.4.3 and 5.4.1.
This commit is contained in:
1 parent
1f3f881656
commit
07c880b56e
5 files changed
+147
-20
No files matched your search
@@ -134,6 +134,7 @@ typedef enum coap_request_t {
|
||||
#define COAP_OPTION_ACCEPT 17 /* C___E__, uint, 0-2 B, RFC7252 */
|
||||
#define COAP_OPTION_Q_BLOCK1 19 /* CU__E_U, uint, 0-3 B, RFC9177 */
|
||||
#define COAP_OPTION_LOCATION_QUERY 20 /* ___RE__, String, 0-255 B, RFC7252 */
|
||||
#define COAP_OPTION_EDHOC 21 /* C_____U, empty, 0 B, RFC9668 */
|
||||
#define COAP_OPTION_BLOCK2 23 /* CU-_E_U, uint, 0-3 B, RFC7959 */
|
||||
#define COAP_OPTION_BLOCK1 27 /* CU-_E_U, uint, 0-3 B, RFC7959 */
|
||||
#define COAP_OPTION_SIZE2 28 /* __N_E_U, uint, 0-4 B, RFC7959 */
|
||||
|
||||
@@ -177,6 +177,27 @@ struct coap_pdu_t {
|
||||
coap_binary_t *data_free; /**< Data to be freed off by coap_delete_pdu() */
|
||||
};
|
||||
|
||||
/**
|
||||
* Parses @p data into the CoAP PDU structure given in @p result.
|
||||
* The target pdu must be large enough to hold the token, options and data.
|
||||
* This function returns @c 0 on error or a number greater than zero on success.
|
||||
*
|
||||
* @param proto Session's protocol
|
||||
* @param data The raw data to parse as CoAP PDU.
|
||||
* @param length The actual size of @p data.
|
||||
* @param pdu The PDU structure to fill. Note that the structure must
|
||||
* provide space to hold the token, optional options and
|
||||
* optional data.
|
||||
* @param error_opts Filled in with any options that have an error in the parsing.
|
||||
*
|
||||
* @return 1 on success or @c 0 on error.
|
||||
*/
|
||||
int coap_pdu_parse2(coap_proto_t proto,
|
||||
const uint8_t *data,
|
||||
size_t length,
|
||||
coap_pdu_t *pdu,
|
||||
coap_opt_filter_t *error_opts);
|
||||
|
||||
/**
|
||||
* Dynamically grows the size of @p pdu to @p new_size. The new size
|
||||
* must not exceed the PDU's configure maximum size. On success, this
|
||||
@@ -243,10 +264,11 @@ int coap_pdu_parse_header(coap_pdu_t *pdu, coap_proto_t proto);
|
||||
* marker.
|
||||
*
|
||||
* @param pdu The PDU structure to check.
|
||||
* @param error_opts Updated with error option(s) on failure.
|
||||
*
|
||||
* @return 1 on success or @c 0 on error.
|
||||
*/
|
||||
int coap_pdu_parse_opt(coap_pdu_t *pdu);
|
||||
int coap_pdu_parse_opt(coap_pdu_t *pdu, coap_opt_filter_t *error_opts);
|
||||
|
||||
/**
|
||||
* Clears any contents from @p pdu and resets @c used_size,
|
||||
|
||||
Reference in new issue
Block a user