Skip to content

fix(mesh): null-check getMeshNode in handleFromRadio#10431

Open
DatanoiseTV wants to merge 2 commits into
meshtastic:developfrom
DatanoiseTV:fix/mesh-handlefromradio-nullcheck
Open

fix(mesh): null-check getMeshNode in handleFromRadio#10431
DatanoiseTV wants to merge 2 commits into
meshtastic:developfrom
DatanoiseTV:fix/mesh-handlefromradio-nullcheck

Conversation

@DatanoiseTV
Copy link
Copy Markdown
Contributor

NodeDB::getMeshNode returns nullptr legitimately under heap pressure
(see NodeDB::isFull and updateFrom early-out paths). The condition at
MeshService.cpp:97 dereferenced the result directly to read has_user,
so every received decoded packet from a new node could crash on a
device near pool exhaustion. Restructure with an init-statement so the
node is fetched once and the rest of the predicate short-circuits on
null.

Split out from #10424 per @thebentern's request — single-concern PR.

Build verification

pio run -e t-deck-tft succeeds, no new warnings.

Attestations

  • I have tested that my proposed changes behave as described — review/static-analysis only, not on-air.
  • On-hardware testing requested from community: build-verified t-deck-tft only.

NodeDB::getMeshNode returns nullptr legitimately under heap pressure
(see NodeDB::isFull and updateFrom early-out paths). The condition at
MeshService.cpp:97 dereferenced the result directly to read has_user,
so every received decoded packet from a new node could crash on a
device near pool exhaustion. Restructure with an init-statement so the
node is fetched once and the rest of the predicate short-circuits on
null.
@github-actions github-actions Bot added needs-review Needs human review bugfix Pull request that fixes bugs labels May 9, 2026
@thebentern thebentern requested a review from Copilot May 9, 2026 18:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a potential null-pointer dereference in MeshService::handleFromRadio() when processing decoded packets from nodes that may not be present in the NodeDB (e.g., under low-memory / full-DB conditions), preventing a crash while deciding whether to proactively send NodeInfo.

Changes:

  • Refactors the NodeInfo-send predicate to fetch the sender node once using a C++17 init-statement.
  • Adds a null check (senderNode && ...) before reading senderNode->has_user, ensuring safe short-circuiting when getMeshNode() returns nullptr.

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

Labels

bugfix Pull request that fixes bugs needs-review Needs human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants