subsys/modbus: Fix potential memory overwrite (coverity)

The size of ctx->rx_adu.data is not CONFIG_MODBUS_BUFFER_SIZE. Coverity
flagged the potential overwrite so just use sizeof().

Fixes #33789
Fixes #33792
Fixes #33818

Signed-off-by: David Leach <david.leach@nxp.com>
This commit is contained in:
David Leach 2021-03-30 17:59:26 -05:00 committed by Anas Nashif
parent f2d8b4cc94
commit 3f0da93902

View file

@ -70,7 +70,7 @@ int modbus_raw_submit_rx(const int iface, const struct modbus_adu *adu)
ctx->rx_adu.unit_id = adu->unit_id;
ctx->rx_adu.fc = adu->fc;
memcpy(ctx->rx_adu.data, adu->data,
MIN(adu->length, CONFIG_MODBUS_BUFFER_SIZE));
MIN(adu->length, sizeof(ctx->rx_adu.data)));
k_work_submit(&ctx->server_work);
return 0;