From ca3fcb1c98755e8f44c33a910af4db3c799ee63e Mon Sep 17 00:00:00 2001 From: Stéphane Raimbault Date: Fri, 26 Jul 2019 16:01:30 +0200 Subject: [PATCH] Add unit tests for VD-1301 and VD-1302 vulnerabilities --- tests/unit-test-client.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/unit-test-client.c b/tests/unit-test-client.c index fdf5c26..e95ea69 100644 --- a/tests/unit-test-client.c +++ b/tests/unit-test-client.c @@ -802,7 +802,6 @@ int test_server(modbus_t *ctx, int use_backend) goto close; } - /* Modbus write and read multiple registers */ rc = send_crafted_request(ctx, MODBUS_FC_WRITE_AND_READ_REGISTERS, rw_raw_req, RW_RAW_REQ_LEN, MODBUS_MAX_WR_READ_REGISTERS + 1, 0, @@ -810,8 +809,6 @@ int test_server(modbus_t *ctx, int use_backend) if (rc == -1) goto close; - /* Modbus write multiple registers with large number of values but a set a - small number of bytes in requests (not nb * 2 as usual). */ rc = send_crafted_request(ctx, MODBUS_FC_WRITE_MULTIPLE_REGISTERS, write_raw_req, WRITE_RAW_REQ_LEN, MODBUS_MAX_WRITE_REGISTERS + 1, 6, @@ -826,6 +823,22 @@ int test_server(modbus_t *ctx, int use_backend) if (rc == -1) goto close; + /* Modbus write multiple registers with large number of values but a set a + small number of bytes in requests (not nb * 2 as usual). */ + rc = send_crafted_request(ctx, MODBUS_FC_WRITE_MULTIPLE_REGISTERS, + write_raw_req, WRITE_RAW_REQ_LEN, + MODBUS_MAX_WRITE_REGISTERS, 6, + backend_length, backend_offset); + if (rc == -1) + goto close; + + rc = send_crafted_request(ctx, MODBUS_FC_WRITE_MULTIPLE_COILS, + write_raw_req, WRITE_RAW_REQ_LEN, + MODBUS_MAX_WRITE_BITS, 6, + backend_length, backend_offset); + if (rc == -1) + goto close; + /* Test invalid function code */ modbus_send_raw_request(ctx, invalid_fc_raw_req, INVALID_FC_REQ_LEN * sizeof(uint8_t)); rc = modbus_receive_confirmation(ctx, rsp); -- libgit2 0.21.4