Skip to content

examples: nrf24l01_btle: Fix RX terminator bounds#3596

Open
Old-Ding wants to merge 1 commit into
apache:masterfrom
Old-Ding:codex/nrf24l01-btle-rx-terminator
Open

examples: nrf24l01_btle: Fix RX terminator bounds#3596
Old-Ding wants to merge 1 commit into
apache:masterfrom
Old-Ding:codex/nrf24l01-btle-rx-terminator

Conversation

@Old-Ding

@Old-Ding Old-Ding commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • reserve one extra byte for the RX buffer terminator
  • keep the nRF24L01 read length capped at NRF24L01_MAX_PAYLOAD_LEN
  • dump only the bytes actually received in the debug path

Why

nrf24_read() appends a NUL terminator after reading a packet. The local buffer was exactly 32 bytes, which is the nRF24L01 maximum payload length. A full-size payload can therefore return 32 and make rbuf[ret] = '\0' write one byte past the buffer.

Testing

  • git diff --check origin/master..HEAD
  • git show --check --stat --oneline HEAD
  • local compile/checkpatch not run: this Windows environment has no usable gcc/clang/make or WSL/bash shell

nrf24_read() reads up to the nRF24L01 maximum payload length and then appends a NUL terminator for the receive buffer. A full 32-byte payload can therefore write one byte past the local rbuf[32].

Reserve one extra byte for the terminator while keeping the read length capped at NRF24L01_MAX_PAYLOAD_LEN. Dump the number of bytes actually received in the debug path.

Signed-off-by: Old-Ding <35417409+Old-Ding@users.noreply.github.com>

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Old-Ding, looks good, please update git commit signature to valid email :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants