Commit Graph
3422 Commits
Author SHA1 Message Date
Jon Shallow cd9f19055b CI: Add in sanitizer runs for 32 and 64 bits 2026-10-05 10:30:56 +01:00
Jon Shallow b2ba5ff454 OpenSSL: Fix trust store for Ubuntu 26.04 (OpenSSL 3.5.0e-dev) 2026-10-05 10:12:56 +01:00
Jon Shallow 75a532c1f7 Ubuntu 26.04.1: Fix new compiler warnings
Update pre-commit versions as well.
2026-10-02 12:38:54 +01:00
Magdalena Szumny c63c8f7cb7 Make max latency configurable 2026-09-29 13:35:41 +01:00
Jon Shallow bbeb8c1d6a coap_prng: Support use of getentropy() if getrandom() is not available 2026-09-28 18:34:07 +01:00
Jon Shallow dad3028d6f Zephyr: Make it easier to change Zephyr base branch 2026-09-28 17:19:51 +01:00
Jon Shallow 15bba8e9f7 coap_block.c: Limit the number of lg_srcv tracking (Q-)Block1 input
Reduce value of partial timeout if there are a lot of outstanding
large block receipts that are not active.

Add function coap_context_set_max_bodies_ram() to define an upper memory
limit usage across all active body receipts.
2026-09-28 15:24:18 +01:00
Jon Shallow 79e52246d6 Contiki-NG: Update to release/v5.2 2026-09-23 15:04:23 +01:00
Jon Shallow 2f55206fee src/coap_block.c: Handle missing Size1 option
Handle when Size1 is smaller than actual indicated size.
2026-09-23 09:36:03 +01:00
Jon Shallow 2b1ec9f270 coap-client: Always define a token when doing a subscribe
Some servers insist there being a token when a subscription
Observe is initiated.
2026-09-22 20:27:57 +01:00
Jon Shallow 0583a6734a coap_block.c: Do not return timeout value of 0 for lg_xmit timeouts
This can cause a process to wait forever before retransmitting if
there is no input.
2026-09-22 17:07:43 +01:00
Jon Shallow 5ce12ab656 coap_block.c: Remove unnecessary uri_path memory allocation 2026-09-21 16:15:15 +01:00
Jon Shallow dd0c1e8c2c 32 bit build: Support building 32 bit executables
On a linux system

./configure --host=i386

Currently TLS support is not available.

Fix a 32 bit CBOR issue.
2026-09-21 11:14:01 +01:00
Guancheng Wang 19bc71e620 cmake: build/install examples only when the library mode they require is enabled
Examples are only built when the library mode they depend on is enabled,
otherwise their link step fails with undefined references. The tiny example
is gated on client mode only.

Signed-off-by: warter666 <271496918+warter666@users.noreply.github.com>
2026-09-20 15:47:27 +01:00
Guancheng Wang 53e1bcaeba proxy: guard coap_proxy_get_add_list_entry() against two NULL sessions
`coap_proxy_get_add_list_entry(incoming, ongoing, ...)` dereferences `ongoing->context` when `incoming == NULL`. Current in-tree callers always pass exactly one non-NULL session, but the function is a public-ish internal helper and a future caller passing both NULL would dereference NULL immediately. cppcheck flags exactly this (`nullPointer` on `ongoing`).

This adds an explicit early `return NULL` when both arguments are NULL - defensive only, no behavior change for existing callers.

Signed-off-by: warter666 <121139223+Warterkk@users.noreply.github.com>
2026-09-19 12:25:46 +02:00
Guancheng Wang f6b20b0d3d debug: fix printf format mismatches reported by -Wextra
Three format-string/argument type mismatches in `src/coap_debug.c`, all reported by `-Wall -Wextra` (fatal under -Werror):

1. `msg_code_string()`: `"%u.%02u"` receives `int` expressions (uint16_t promotes to int) - cast both to `unsigned`.
2. `print_content_format()`: `"%d"` receives `unsigned int format_type` - use `%u`.
3. block-size printing: `"%u"` receives the `int` expression `1 << (...)` - make the shift and cast unsigned.

No behavior change on any realistic input; only the int-vs-unsigned variance is fixed.

Signed-off-by: warter666 <121139223+Warterkk@users.noreply.github.com>
2026-09-19 12:23:40 +02:00
Guancheng Wang 6cb2addb1e block: compile full_match() only when client support is enabled
With `-DENABLE_CLIENT_MODE=OFF` (i.e. `COAP_CLIENT_SUPPORT=0`), `full_match()` in `src/coap_block.c` is defined but its only caller is compiled out, producing `-Wunused-function` (fatal in -Werror builds):

```
src/coap_block.c:479:1: error: unused function 'full_match' [-Werror=-Wunused-function]
```

Wrap the static-inline definition in the same `#if COAP_CLIENT_SUPPORT` guard as its caller.

Signed-off-by: warter666 <121139223+Warterkk@users.noreply.github.com>
2026-09-19 12:19:59 +02:00
Guancheng Wang 899a9e533a ws: fix NULL dereference on a malformed client-handshake status line
In `coap_ws_rd_http_header_client()` the first header (the HTTP status line) is split by `coap_ws_split_rd_header()`, which returns NULL when the buffered line contains no space/tab separator. The second call site checks for NULL, but the first one does not:

```c
value = coap_ws_split_rd_header(session);

if (strcmp((char *)ws->http_hdr, "HTTP/1.1") != 0 ||
    atoi(value) != 101) {
```

If the HTTP header buffer is exactly `"HTTP/1.1"` (no trailing space), `strcmp()` returns 0, the `||` short-circuit does not apply, and `atoi(NULL)` is called - a remote crash in the WS client handshake when a malicious or broken server sends a truncated status line.

Fix: return 0 when `value` is NULL, mirroring the second call site.

The library builds cleanly after the change (cmake -DENABLE_DTLS=OFF, gcc/clang, 0 warnings).

Signed-off-by: warter666 <121139223+Warterkk@users.noreply.github.com>
2026-09-19 11:09:15 +02:00
Magdalena Szumny 97b8a1edd0 OSCORE: preserve recipient reference on noop attachment 2026-09-18 12:00:51 +02:00
Jon Shallow 93694e6c24 RIOT: Add in TCP support
Need to make use of LwIP interface for TCP.
2026-09-16 15:03:45 +02:00
Denis Begun 274767a29c Mbed TLS: Return the total bytes written over TLS
When a message spans multiple mbedTLS records, coap_tls_write() returns
only the final mbedtls_ssl_write() result despite sending the entire
message. Its caller treats the PDU as partially written and queues an
already transmitted suffix.

Update the successful return value to the accumulated byte count.
Preserve the existing nonblocking retry and fatal-error handling.

Validated with native mbedTLS 3.6.2 loopback transfers and a focused
ASan/UBSan harness covering record boundaries and WANT_READ/WANT_WRITE.
2026-09-16 10:21:30 +02:00
Jon Shallow 18df85af6d Nits: Fix documentation 2026-09-14 09:52:17 +02:00
Jon Shallow 9c5983b3f2 Responses: RST sent only for CON or NON
Also RST response packets that have no response handling context.
2026-09-14 09:30:18 +02:00
Jon Shallow 68849057f1 Delayqueue: Add delayqueue_tail to coap_session to avoid scanning long queues 2026-09-11 12:30:08 +01:00
Mario Kicherer b20841965e Fix callback data handling for TCP BERT
TCP BERT payloads can exceed the 1024-byte callback scratch buffer. Allocate a temporary buffer sized to the requested chunk, pass it to the large-data callback, and release it after the PDU has copied the data. Preserve the stack buffer for regular block transfers and report allocation failures explicitly.
2026-09-10 17:13:20 +01:00
Jon Shallow fab32682ea coap_pdu_duplicate: Make max size of duplicated PDU same as original
When calling coap_pdu_check_resize(), start with a smaller size for embedded
systems.
2026-09-10 14:59:45 +01:00
Jon Shallow 64211f744e Block1: Handle concurrent transfers over the same session 2026-09-09 14:12:28 +01:00
Jon Shallow 9a27dbd0be OSCORE: Delete association on error response 2026-09-09 14:09:35 +01:00
Magdalena Szumny b61cb7683a Use cryptographic safe entropy for Zephyr 2026-09-08 19:42:10 +01:00
Michiel De Witte e61c8c8ef7 Preserve the observe request's local address for notifications
Packets from the same peer can overwrite a session's local address with a
multicast destination. Save the address when an observation is created or
renewed and restore it before generating notifications, so deferred responses
snapshot the correct address instead of being dropped as invalid multicast.

Add regression coverage for CON and NON observations, including renewals and
the local address captured by a notification's async response.

Validation: 215 unit tests passed (1712 assertions).
2026-09-07 15:58:29 +01:00
Jon Shallow 421107b4b7 Resource: Caution about setting up resources in thread-safe manner 2026-09-07 15:53:01 +01:00
Jon Shallow 73bd9fa543 OSCORE: Remove unnecessary CBOR assert()
Report error when creating AAD or External AAD when CBOR fails.
2026-09-07 15:27:52 +01:00
Michiel De WitteandClaude Opus 5 5e86d78e6d coap_net.c: Do not send an Empty message as a separate response
A request handler that leaves the response code unset asks for no
response to be sent.  That is honoured for a piggybacked ACK (the token
gets stripped, so an empty ACK goes out) and for a non-confirmable or
reliable response (dropped in no_response()), but not for a separate
response set up with coap_register_async().

There the response is turned into a CON, and a 0.00 CON was put on the
wire.  An Empty message is a ping (RFC 7252 4.2), not a response, and the
PDU still carries the request's token, which RFC 7252 4.1 does not allow.
Being confirmable, it was then retransmitted up to MAX_RETRANSMIT times,
usually at a client port that had long gone away.

Drop it like the other two cases, delete it without logging it as a
dropped response since the application asked for this, and document in
coap_handler(3) that a separate response is not sent either.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 15:22:26 +01:00
Jon Shallow 05e9a9caf4 Epoll: Handle server side read errors
Models that done for clients.
2026-09-02 12:59:47 +01:00
Jon Shallow 741729de08 Q-Block: Faster recovery times
Initiate a request for missing blocks if there are missing blocks and the
last 2 blocks of a PAYLOAD_SET are in.
2026-09-02 08:50:49 +01:00
Jon Shallow fcbd803828 Q-Block: Better recovery for lossy networks
Following the principles laid out in RFC9177.
2026-09-02 08:50:49 +01:00
Jon Shallow 2029e51727 coap_pdu.c: Check option lengths when adding options
Support adding options to CSM PDUs.
2026-09-01 20:47:57 +01:00
Jon Shallow 24ae8f2ee8 Block: Make sure SizeX option is added for small sizes with blocks 2026-09-01 20:46:45 +01:00
Jon Shallow dbeedd59b4 OSCORE: Fix observe cancellation when doing Appendix B.2 2026-09-01 15:57:49 +01:00
Jon Shallow 9cb8f45f4f PSK: Support keys in hex notation in matching files
coap-server options
-i match_identiity_file
-s match_psk_sni_file

coap-client option
-h match_hint_file
2026-09-01 11:29:49 +01:00
Jon Shallow beb924545f OSCORE: Fix observe cancellation
Also remove unnecessary COAP_EVENT_XMIT_BLOCK_FAIL events being triggered.
2026-08-31 11:28:30 +01:00
Jon Shallow 44e02b8693 LwIP: Allow smaller initial PDU buffer allocations 2026-08-31 10:46:47 +01:00
Jon Shallow d0605cc5e7 Block: Check for ETag/RTag option size overflow
This is not network exploitable as any incoming packet will fail the
coap_pdu_parse() / coap_pdu_parse_opt_base() check when building the CoAP PDU.
2026-08-29 09:22:01 +01:00
Jon Shallow ee764d94b4 Q-Block: Check for required options
RFC9177 section-4.3.
Q-Block1: Size1 and RTag required.

RFC9177 section-4.4.
Q-Block2: Size2 and ETag required.
2026-08-25 07:49:16 +01:00
Michiel De WitteandClaude Fable 5 091f189e7a Restore the request's local address when a triggered async fires
Server sessions are keyed on (remote address, local port) only, and
session->addr_info.local is overwritten by the destination of every
received packet. When a unicast CON request is parked in a coap_async_t
for a separate response and a multicast packet from the same peer
arrives before the async fires, the re-invoked handle_request() sees a
multicast local address, drops the CON per RFC7252 8.1 ("Invalid
multicast packet received"), and coap_check_async() frees the async:
the response is silently never sent.

Snapshot the local address in coap_register_async() and restore it on
the session before the async fires, so the deferred request is handled
(and its response source selected) against the address it actually
arrived on.

Seen in the field with a CoAP remote control whose GET /endpoint was
answered via the async path while it also multicast periodic
announcements from the same source port: the device received the empty
ACK and then never got the response.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-24 16:35:51 +01:00
Jon Shallow 9d407dd083 Documentation: Updates 2026-08-22 17:42:40 +01:00
Jon Shallow f325f6a4b0 coap_net.c: Enforce response Content-Format matches request Accept option
Only if the request includes the Accept Option and it is not an empty ACK.
2026-08-22 15:09:26 +01:00
Jon Shallow dfe1cd2b93 coap_net.c: Check block options for invalid SZX = 7 2026-08-22 15:06:39 +01:00
Jon Shallow ea841dd0c7 coap_mutex_internal.h: Fix LwIP coap_mutex_destroy 2026-08-20 10:31:27 +01:00
Jon Shallow 850748ca14 Recovery: Support dropping incoming packets for testing 2026-08-20 09:56:09 +01:00