Commit Graph
196 Commits
Author SHA1 Message Date
Alejandro Pacheco 92fc71e908 coap_block.c: Use get_func wherever a request body is added
For a request set up with coap_add_data_large_request_app(), the data
is provided by the application's get_func and there is no data pointer.
Three places still took the body from that NULL pointer, so
coap_add_data() was passed a NULL pointer:

- check_freshness(), re-sending the next block with the Echo option
  from a 4.01 response.
- coap_cancel_observe_lkd(), re-adding the observe request's body to
  the cancel request.
- coap_add_data_large_internal(), when the application sets a Block1
  option with a non-zero block number to send a single block.

Use get_func in all of these, as the other places that send a block of
an lg_xmit already do. The single block and the whole-body cases now
share add_get_func_data(), which also checks the allocation and no
longer leaks the buffer when get_func fails.

Add unit tests.
2026-10-16 14:14:20 +01:00
Alejandro Pacheco 85ed6ebb93 coap_proxy.c: Check every proxy entry in coap_proxy_remove_association()
With track_client_session set, an incoming session gets its own proxy
entry for each upstream server it uses. coap_proxy_remove_association()
returned after the first entry tracking the session, so the proxy
requests of that session held in later entries were left in place when
the session was deleted, and their upstream sessions were not released.
A later upstream response was then forwarded to the freed session.

Carry on with the remaining entries instead of returning.

Add a unit test.
2026-10-16 10:52:31 +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
Magdalena Szumny 97b8a1edd0 OSCORE: preserve recipient reference on noop attachment 2026-09-18 12:00:51 +02: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 d0fa34cf4f coap_resource.c: Update .well-known/core query matching
Support matching multiple, space separated, values, not limited to if=, rt= and rel=.

Fix OOB read if the last space separated value is shorter than the query.

Support matching against multiple queries.

Do not sent back empty 2.05 response if multicast.
2026-08-11 16:09:02 +01:00
ZT Winds 1c8c8bd3a7 oscore_cbor: fix infinite loop on large CBOR array/map counts
CBOR array and map counts can exceed UINT16_MAX. The uint16_t loop counters
then wrap and never reach the advertised count, causing a CWE-835 denial of
service.

Use size_t loop counters and reject counts that cannot fit in the remaining
buffer at the minimum encoding size of one byte per array element or two
bytes per map pair. Propagate malformed-value errors and cover large
malformed containers and valid values over 64 KiB with regression tests.
2026-08-08 16:11:20 +01:00
Jon Shallow 98805f70a5 Documentation tidy up
Add in codespell to pre-commit to help fix documentation errors.
2026-08-08 12:05:03 +01:00
Jon Shallow 0014440160 OSS-FUZZ: Stop actual packet transmissions
Make sure all packets are dropped in persist_target.c.
2026-07-25 13:58:10 +01:00
David Korczynski e2463f007f Add OSCORE CBOR fuzz harness to be consumed by OSS-Fuzz
The goal is to increase code coverage of the OSCORE CBOR reader in
src/oscore/oscore_cbor.c, which decodes attacker-reachable data (the
persisted observe/OSCORE association blob in coap_subscribe.c and the
OSCORE option kid_context in coap_oscore.c) but is currently largely
unexercised:
https://storage.googleapis.com/oss-fuzz-coverage/libcoap/reports/20260702/linux/src/libcoap/src/oscore/report.html

Signed-off-by: David Korczynski <david@adalogics.com>
2026-07-03 07:36:09 +01:00
Jon Shallow 6c5a0bcb4f TLS: Support client checking sent SNI to received server's PKI CN
For coap-client, if either -R or -C options are specified, then allowing
self-signed certificates is now disabled.
2026-06-27 12:20:00 +01:00
tlhc aa68d5f7e3 feat: add openHiTLS backend support
- Add openHiTLS DTLS/TLS backend
- Integrate openHiTLS crypto into libcoap (D)TLS and OSCORE paths.
- Extend TLS tests and add interop validation script.
2026-06-27 11:18:22 +01:00
Jon Shallow 2e995218f3 SendQueue: Match Mid and Token (if given) to remove entry from queue
For Empty ACK and RST do not do a token match.
2026-06-22 13:48:44 +01:00
Jon Shallow 4c3f4af1c0 OSS-FUZZ: Support different architectures and engines 2026-06-12 21:08:45 +01:00
Jon Shallow 46e505c430 OSCORE: Support using MbedTLS for OSCORE only (not (D)TLS)
New ./configure option

 --with-mbedtls-oscore

If --disable-dtls is set, then MbedTLS is used as the OSCORE backend, otherwise
the MbedTLS library is used for both (D)TLS and OSCORE.

New cmake option

 -DOSCORE_BACKEND=mbedtls

If -DENABLE_DTLS=OFF is set, then MbedTLS is used as the OSCORE backend, otherwise
the MbedTLS library is used for both (D)TLS and OSCORE.

New Zephyr option

 config MBEDTLS_OSCORE

If set to y and CONFIG_LIBCOAP_OSCORE_SUPPORT is set to y, then the Zephyr MbedTLS
backend will get used for the OSCORE backend (no (D)TLS).
2026-06-10 11:56:44 +01:00
Jon Shallow 193ec26ead Proxy: Check for non-safe options
Generally re-organize option handling, making use of enums etc.

This also updates critical options checks, and well as repeatable options.
2026-06-05 15:22:38 +01:00
David Korczynski bd47692407 Add proxy fuzz harness to be consumed by OSS-Fuzz
The goal is to increase code coverage of coap_proxy.c logic,
which currently stands at less than 2%:
https://storage.googleapis.com/oss-fuzz-coverage/libcoap/reports/20260518/linux/src/libcoap/src/report.html

Signed-off-by: David Korczynski <david@adalogics.com>
2026-06-01 16:05:55 +01:00
Jon Shallow eb73b10e64 oss-fuzz: Further support for running with threading support 2026-05-30 14:15:54 +01:00
David Korczynski c28f8f5e7a fix lint
Signed-off-by: David Korczynski <david@adalogics.com>
2026-05-30 09:47:56 +01:00
David Korczynski 0e03abc99c Adds extended coap_cache fuzzer to be consumed by OSS-Fuzz
The goal is to extend code coverage of libcoap. Can confirm from local
runs this provides a significant boost to coap_cache.c coverage.

Signed-off-by: David Korczynski <david@adalogics.com>
2026-05-30 09:47:56 +01:00
David Korczynski e909ff5dd5 Adds extended uri fuzzer to be consumed by OSS-Fuzz
Extends on the code coverage of the coap_uri.c module, which currently
has the code coverage:
https://storage.googleapis.com/oss-fuzz-coverage/libcoap/reports/20260512/linux/src/libcoap/src/coap_uri.c.html

Signed-off-by: David Korczynski <david@adalogics.com>
2026-05-25 11:39:43 +01:00
David Korczynski 574332f6e3 Add ws_frame fuzzer to be consumed by OSS-Fuzz
Signed-off-by: David Korczynski <david@adalogics.com>
2026-05-20 14:26:02 +01:00
Lucien Zuercher 855d53ef10 oscore: enable external credential storage and safe recipient cleanup
Add reference counting to recipient contexts so they can be safely removed
while still in use by active sessions. Expose callback hooks for credential
lookup, echo, and sequence storage to allow custom backends.
Expand example server to demonstrate the external storage via a simple
file based database. Expand coap_oscore_rcp_conf_t to enable settings
preconfigured echo value, sequence counter and window value as uint64
Enable temporary credentials returned by the find function and are destroyed
after use.
2026-05-20 13:09:24 +01:00
Jon Shallow 590570a465 oss-fuzz: Support testing with thread enabled builds 2026-05-18 12:06:58 +01:00
David Korczynski 57370405c8 OSS-Fuzz: Add new dtls harness
The goal is to increase code coverage, which is currently around 25%:
https://storage.googleapis.com/oss-fuzz-coverage/libcoap/reports/20260318/linux/report.html

Signed-off-by: David Korczynski <david@adalogics.com>
2026-05-18 11:37:41 +01:00
Jon Shallow 13139e7be9 Options: Check Uri-Path and Location-Path options for . or ..
Check incoming Uri-Path and Location-Path options for just . or .. (or %2e
hex encoded variants) and treat as being invalid.

Stop insertion of Uri-Path and Location-Path options that contain just
. or .. (or %2e hex encoded variants).
2026-05-11 19:41:17 +01:00
Arthur Chan 64e2a65ad0 OSS-Fuzz: Further fix block fuzzer on wellknown handling path
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-05-09 16:13:34 +01:00
Arthur Chan 2614649ecc OSS-Fuzz: Add fuzzer for persist storing
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-05-09 16:11:08 +01:00
Arthur Chan c99bf12801 OSS-Fuzz: Fix block fuzzer
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-05-08 09:33:36 +01:00
Arthur Chan be60f46ff0 OSS-Fuzz: Fix async fuzzer
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-05-08 09:32:36 +01:00
Arthur Chan 60dad69e95 OSS-Fuzz: Fix observe fuzzer
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-05-08 09:31:43 +01:00
Arthur Chan 76a793be5c OSS-Fuzz: Add a helper for fuzzing
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-05-07 19:36:44 +01:00
Arthur Chan feab110c7f OSS-Fuzz: Fix block_check_fuzzer
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-05-07 14:22:46 +01:00
Ernestas Kulik 766b852849 Implement support for LLC sockets
Useful in embedded contexts, where devices might only have a link-layer
connection, but still need to exchange information.
2026-04-18 09:11:19 +01:00
Arthur Chan caa7120cae OSS-Fuzz: Add fuzzer for block low level checking
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-03-28 10:44:50 +00:00
Arthur Chan f283c7b69b OSS-Fuzz: Fix block fuzzer
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-03-28 10:44:31 +00:00
Jon Shallow 80c37b7bc6 Coverity: Fix CID 1483550, 1670422-1670425
CID 1594475 is a false positive as multiple threads cannot execute in the same
code as global_lock is set.
2026-03-26 09:24:44 +00:00
Arthur Chan efec6cf653 OSS-Fuzz: Fix packet transmission checking for network related fuzzers
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-03-20 21:26:34 +00:00
Arthur Chan 407e6b06cf OSS-Fuzz: Add fuzzer targeting coap_async
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-03-20 16:09:12 +00:00
Florek, Bartlomiej 44e5c68c51 fix: OSCORE ACK retransmission handling 2026-03-19 15:13:32 +00:00
Arthur Chan 766711f62c OSS-Fuzz: Revamp block_fuzzer and add corpus seed
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-03-18 10:05:42 +00:00
Arthur Chan f39d2152b3 OSS-Fuzz: Add observe fuzzer
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-03-16 12:40:27 +00:00
Arthur Chan cc8de29bd4 OSS-Fuzz: Add more targets to network fuzzer
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-03-13 13:53:45 +00:00
Jon Shallow 40502ffebb oss-fuzz: Fix undefined-behavior
Analyzer run time does not like A -= B or A +=B even if A and B are uint32_t as there is potential
for overflow.

Analyzer run time does not like overflow when doing coap_tick_t - coap_tick_t.

Analyzer run time does not like (uint8_t << 24) as uint8_t is promoted as int, not u_int.

Analyzer run time does not like while(A--) {} even if A is uint32_t, as A is always decremented on
the test, even if the value of A is 0.

Fix potential overflow when analyzing an asn.1 tag.

Fix potential overflow when doing decode_segment() on a % hex value.
2026-03-10 11:09:10 +00:00
Jon Shallow fe41b51aab OSS-FUZZ: Fix build issue 2026-03-04 17:31:05 +00:00
Arthur Chan 099d9842da OSS-Fuzz: Simplify block_fuzzer
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-03-04 16:38:54 +00:00
Jon Shallow 30875ab127 OSS-FUZZ: Fix discovered issues 2026-03-04 16:18:15 +00:00
Arthur Chan bb639096ab OSS-Fuzz: Fix Makefile for fuzzer to include CFLAGS from OSS-Fuzz
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-03-04 11:05:56 +00:00
Arthur Chan ea9d1cb803 OSS-Fuzz: Fix bias condition
Signed-off-by: Arthur Chan <arthur.chan@adalogics.com>
2026-03-04 11:05:33 +00:00
Jon Shallow 210cbf378a ASN1: Check for buffer overflows when determining tags and length
Include oss-fuzzer checks.
2026-03-03 10:36:46 +00:00