Skip to content

Commit e19543e

Browse files
stephanefacchinm
authored andcommittedOct 9, 2023
Fix VD-1301 and VD-1302 vulnerabilities
This patch was contributed by Maor Vermucht and Or Peles from VDOO Connected Trust.
1 parent 2551e03 commit e19543e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed
 

‎src/libmodbus/modbus.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -897,9 +897,10 @@ int modbus_reply(modbus_t *ctx, const uint8_t *req,
897897
break;
898898
case MODBUS_FC_WRITE_MULTIPLE_COILS: {
899899
int nb = (req[offset + 3] << 8) + req[offset + 4];
900+
int nb_bits = req[offset + 5];
900901
int mapping_address = address - mb_mapping->start_bits;
901902

902-
if (nb < 1 || MODBUS_MAX_WRITE_BITS < nb) {
903+
if (nb < 1 || MODBUS_MAX_WRITE_BITS < nb || nb_bits * 8 < nb) {
903904
/* May be the indication has been truncated on reading because of
904905
* invalid address (eg. nb is 0 but the request contains values to
905906
* write) so it's necessary to flush. */
@@ -928,9 +929,10 @@ int modbus_reply(modbus_t *ctx, const uint8_t *req,
928929
break;
929930
case MODBUS_FC_WRITE_MULTIPLE_REGISTERS: {
930931
int nb = (req[offset + 3] << 8) + req[offset + 4];
932+
int nb_bytes = req[offset + 5];
931933
int mapping_address = address - mb_mapping->start_registers;
932934

933-
if (nb < 1 || MODBUS_MAX_WRITE_REGISTERS < nb) {
935+
if (nb < 1 || MODBUS_MAX_WRITE_REGISTERS < nb || nb_bytes * 8 < nb) {
934936
rsp_length = response_exception(
935937
ctx, &sft, MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, rsp, TRUE,
936938
"Illegal number of values %d in write_registers (max %d)\n",

0 commit comments

Comments
 (0)
Please sign in to comment.