Skip to content

fix: validate complete Modbus discovery responses - #4

Merged
KaiserIIII merged 1 commit into
mainfrom
codex/modbus-discovery-20261016
Oct 16, 2026
Merged

KaiserIIII merged 1 commit into
mainfrom
codex/modbus-discovery-20261016

Conversation

@KaiserIIII

Copy link
Copy Markdown
Owner

Discovery previously treated any nonempty TCP reply as Modbus and kept only the first recv fragment. HTTP text, unrelated transactions, wrong units and truncated frames could receive a Modbus label. Both discovery paths now assemble a bounded response and validate its request association before classification. Standard reads reuse the existing validator; the fixed basic-device-ID query checks its response structure and bounded object list. Basic pages must satisfy the fixed object0 query and make progress; reserved exception codes are refused. Valid exceptions are labelled as protocol reachability, while an open TCP port retains its connection result if protocol verification fails.

Request bytes, configured TCP0, scan limits, 0.45-second response budgets and 260-byte caps remain. The ID query reports only the first page and sends no follow-up. This does not authenticate hardware, infer vendor models or change HTTP, storage or task behavior.

Validation: 111 new focused tests, with the original implementation failing 46 / passing 18 before correction; review regressions separately recorded 24 failures and 22 passes, then passed after the two discovered gaps were fixed; all 386 local tests now pass. Cases include bad headers/PDU lengths, exceptions, deterministic fragmentation at every split, partial-frame interruptions, register fallback and real loopback TCP. Configuration validation and 23 offline checks pass. A zero-package parser smoke also checks 10,000 seeded structured byte inputs; these are property assertions, not additional pytest cases. Broad coverage is reported separately in the local evidence, without a claim of comprehensive security coverage.

Implementation, tests, review and documentation are AI-assisted. Tests use Fake byte sockets or loopback; no field devices were contacted and no dependencies were installed. Protocol reference: Modbus Application Protocol V1.1b3 §6.21/§7 and the TCP MBAP guide.

Correlate complete replies, bind basic-object pages to the fixed query,
and reject reserved TCP exception codes. Preserve TCP-only evidence.

AI-assisted implementation and independent review; 386 local tests passed.
@KaiserIIII
KaiserIIII merged commit 1060d04 into main Oct 16, 2026
8 checks passed
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.

1 participant