Skip to content

Reject oversized byte counts in Write Multiple Coils requests - #887

Open
novadusk wants to merge 1 commit into
stephane:masterfrom
novadusk:fix/fc15-byte-count-883
Open

novadusk wants to merge 1 commit into
stephane:masterfrom
novadusk:fix/fc15-byte-count-883

Conversation

@novadusk

Copy link
Copy Markdown

modbus_reply() accepts FC 0x0F requests whose Byte Count exceeds the number of
bytes required by the coil quantity. Such requests receive a normal response and
modify the coil mapping. Require an exact, rounded-up byte count, as specified in
section 6.11 of the Modbus Application Protocol Specification V1.1b3.

Add regression tests for quantities 1, 8 and 9 that check the Illegal Data Value
exception and verify that the coil mapping remains unchanged. The setup writes
also exercise valid requests on either side of a byte boundary.

Fixes #883.

Validation:

  • make distcheck and final make check on x86_64 Linux: passed.
  • RK3576 / AArch64 Linux 6.1.118: full upstream TCP and TCP-PI suites passed.
  • An independent matrix of 21 cases per transport, over loopback TCP and PTY RTU:
    28/42 passed before the fix; 42/42 passed after it. Each case checks both the
    response and the resulting coil mapping.
  • The new upstream regression test fails against the unmodified library.

The full upstream RTU suite stops at an existing malformed FC 0x10 request in
this PTY setup, with both the unmodified and patched versions. The independent
FC 0x0F RTU matrix passes after the fix. No physical RS485 link was tested.

AI assistance was used to prepare the patch and run the validation. The
contributor reviewed the patch before submission.

Require the FC 0x0F byte count to equal the rounded-up number of bytes
needed by the coil quantity. Previously, larger byte counts were accepted
and the coil mapping was updated instead of returning Illegal Data Value.

Add regression tests for quantities 1, 8 and 9 that check the exception
response and confirm that the mapping is unchanged.

Fixes stephane#883.
@cla-bot

cla-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please fill https://forms.gle/5635zjphDo5JEJQSA to get added. Your document will be manually checked by the maintainer. Be patient...

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.

modbus_reply() accepts Write Multiple Coils with Byte Count larger than ceil(Quantity/8)

1 participant