Commit b4ef4c17d618eba0adccc4c7d9e9a1ef809fc9b6

Authored by Michael Heimpold
1 parent bd1c85f2

modbus_reply: fix copy & paste error in sanity check (fixes #614)

While handling MODBUS_FC_WRITE_AND_READ_REGISTERS, both address offsets
must be checked, i.e. the read and the write address must be within the
mapping range.

At the moment, only the read address was considered, it looks like a
simple copy and paste error, so let's fix it.

Signed-off-by: Michael Heimpold <mhei@heimpold.de>
Showing 1 changed file with 1 additions and 1 deletions
src/modbus.c
@@ -961,7 +961,7 @@ int modbus_reply(modbus_t *ctx, const uint8_t *req, @@ -961,7 +961,7 @@ int modbus_reply(modbus_t *ctx, const uint8_t *req,
961 nb_write, nb, MODBUS_MAX_WR_WRITE_REGISTERS, MODBUS_MAX_WR_READ_REGISTERS); 961 nb_write, nb, MODBUS_MAX_WR_WRITE_REGISTERS, MODBUS_MAX_WR_READ_REGISTERS);
962 } else if (mapping_address < 0 || 962 } else if (mapping_address < 0 ||
963 (mapping_address + nb) > mb_mapping->nb_registers || 963 (mapping_address + nb) > mb_mapping->nb_registers ||
964 - mapping_address < 0 || 964 + mapping_address_write < 0 ||
965 (mapping_address_write + nb_write) > mb_mapping->nb_registers) { 965 (mapping_address_write + nb_write) > mb_mapping->nb_registers) {
966 rsp_length = response_exception( 966 rsp_length = response_exception(
967 ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE, 967 ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_ADDRESS, rsp, FALSE,