tokio-modbus
tokio-modbus copied to clipboard
Missing validation of request PDU parameters
I've found that I can read at most 126 input registers with read_input_registers()
. But why 126? Which part of the source code should I read.
Limited by Modbus message size, please refer to the spec.
6.4 04 (0x04) Read Input Registers This function code is used to read from 1 to 125 contiguous input registers in a remote device.
But I can read 126 contiguous registers. one more than the spec.
This bug affects multiple function codes. Currently there are no semantic, client-side parameters according to the Modbus protocol validations in place. If a parameter value could technically be serialized it is accepted, even if the Modbus protocol specifies more restrictive, semantic bounds. Ideally servers should reject such non-standard requests.
Not a severe bug as clients are responsible for sending valid requests and servers are advised to reject invalid requests. Enforcing strict standard behavior by the library may even prevent using custom, vendor-specific extensions.
Not a bug, it's a "feature".
If those additional conformance checks are implemented then they should be hidden behind a feature flag. Not everyone might need or want them.
This affects both the client and the server.