Skip to content

Feature: Add test-only shim for bsc_node_parse_urls() to support unit testing - #1369

Merged
skarg merged 2 commits into
masterfrom
test/bsc-node-test-parse-urls
Jun 3, 2026
Merged

Feature: Add test-only shim for bsc_node_parse_urls() to support unit testing#1369
skarg merged 2 commits into
masterfrom
test/bsc-node-test-parse-urls

Conversation

@skarg

@skarg skarg commented May 30, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI 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.

Pull request overview

Adds a test-only entry point to exercise the internal BACnet/SC node URL parsing logic from unit tests, improving coverage of edge cases around URI length and count limits.

Changes:

  • Introduces a CONFIG_ZTEST-gated shim (bsc_node_test_parse_urls()) that exposes the internal static bsc_node_parse_urls() to tests.
  • Adds a new ztest suite (node_test_8) with targeted cases covering empty payloads, boundary lengths, truncation by URL count, and multi-URL parsing.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/bacnet/datalink/bsc-node/src/main.c Adds a new unit test suite validating URL parsing behavior across boundary conditions.
src/bacnet/datalink/bsc/bsc-node.c Adds a CONFIG_ZTEST-only shim function to expose the internal URL parser to unit tests.

Comment thread test/bacnet/datalink/bsc-node/src/main.c Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@skarg
skarg merged commit 3af8982 into master Jun 3, 2026
36 checks passed
@skarg
skarg deleted the test/bsc-node-test-parse-urls branch June 3, 2026 15:07
skarg added a commit that referenced this pull request Jun 25, 2026
* Fix buffer overflows in bsc_node_parse_urls()

Three bugs in the BACnet/SC Address Resolution ACK URL parser:

1. NUL terminator used absolute string position 'i' as array index
   instead of relative position 'i - start', writing past the
   129-byte utf8_urls buffer for URLs starting past position 128.

2. No bounds check on URL count index 'j', allowing writes past
   the 10-element utf8_urls array when parsing 11+ URLs, corrupting
   urls_num, fresh_timer, and adjacent structures.

3. Length check compared absolute position 'i' against the max URI
   size instead of the actual URL length '(i - start)', incorrectly
   rejecting valid short URLs at high string offsets.

Fixes all three by using relative lengths and adding array bounds
checks before every write.

Add test-only shim for bsc_node_parse_urls() to support unit testing (#1369)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants