Skip to content

Commit 2b5cb58

Browse files
committed
Fix VD-1301 and VD-1302 vulnerabilities
This patch was contributed by Maor Vermucht and Or Peles from VDOO Connected Trust.
1 parent 419ef44 commit 2b5cb58

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/modbus.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -832,8 +832,9 @@ int modbus_reply(modbus_t *ctx, const uint8_t *req,
832832
break;
833833
case _FC_WRITE_MULTIPLE_COILS: {
834834
int nb = (req[offset + 3] << 8) + req[offset + 4];
835+
int nb_bits = req[offset + 5];
835836

836-
if (nb < 1 || MODBUS_MAX_WRITE_BITS < nb) {
837+
if (nb < 1 || MODBUS_MAX_WRITE_BITS < nb || nb_bits * 8 < nb) {
837838
if (ctx->debug) {
838839
fprintf(stderr,
839840
"Illegal number of values %d in write_bits (max %d)\n",
@@ -842,7 +843,7 @@ int modbus_reply(modbus_t *ctx, const uint8_t *req,
842843
rsp_length = response_exception(
843844
ctx, &sft,
844845
MODBUS_EXCEPTION_ILLEGAL_DATA_VALUE, rsp);
845-
} else if ((address + nb) > mb_mapping->nb_bits) {
846+
} else if ((address + nb) > mb_mapping->nb_bits ) {
846847
if (ctx->debug) {
847848
fprintf(stderr, "Illegal data address %0X in write_bits\n",
848849
address + nb);
@@ -863,8 +864,9 @@ int modbus_reply(modbus_t *ctx, const uint8_t *req,
863864
break;
864865
case _FC_WRITE_MULTIPLE_REGISTERS: {
865866
int nb = (req[offset + 3] << 8) + req[offset + 4];
867+
int nb_bytes = req[offset + 5];
866868

867-
if (nb < 1 || MODBUS_MAX_WRITE_REGISTERS < nb) {
869+
if (nb < 1 || MODBUS_MAX_WRITE_REGISTERS < nb || nb_bytes * 8 < nb) {
868870
if (ctx->debug) {
869871
fprintf(stderr,
870872
"Illegal number of values %d in write_registers (max %d)\n",

0 commit comments

Comments
 (0)