Skip to content

Commit 11317b1

Browse files
authored
Merge pull request #112 from dwilliams27/master
fix: Validate registers_bytes before write in recv_read_registers_res
2 parents 035b8d5 + a3a67f7 commit 11317b1

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

nanomodbus.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ static nmbs_error recv_read_registers_res(nmbs_t* nmbs, uint16_t quantity, uint1
589589
const uint8_t registers_bytes = get_1(nmbs);
590590
NMBS_DEBUG_PRINT("b %d\t", registers_bytes);
591591

592-
if (registers_bytes > 250)
592+
if (registers_bytes > 250 || registers_bytes != quantity * 2)
593593
return NMBS_ERROR_INVALID_RESPONSE;
594594

595595
err = recv(nmbs, registers_bytes);
@@ -608,9 +608,6 @@ static nmbs_error recv_read_registers_res(nmbs_t* nmbs, uint16_t quantity, uint1
608608
if (err != NMBS_ERROR_NONE)
609609
return err;
610610

611-
if (registers_bytes != quantity * 2)
612-
return NMBS_ERROR_INVALID_RESPONSE;
613-
614611
return NMBS_ERROR_NONE;
615612
}
616613
#endif

0 commit comments

Comments
 (0)