Skip to content

Commit 6a0d735

Browse files
jilaypandyanashif
authored andcommitted
drivers: sensor: fcx_mldx5 fix string_overflow issue
This commit fixes Copy into fixed size buffer (STRING_OVERFLOW) by checking the cmd_data_len Signed-off-by: Jilay Pandya <[email protected]>
1 parent 5c4f7d9 commit 6a0d735

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/sensor/fcx_mldx5/fcx_mldx5.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,10 @@ static void fcx_mldx5_uart_send(const struct device *dev, enum fcx_mldx5_cmd cmd
235235

236236
buf[FCX_MLDX5_STX_INDEX] = FCX_MLDX5_STX;
237237
memcpy(&buf[FCX_MLDX5_CMD_INDEX], fcx_mldx5_cmds[cmd], FCX_MLDX5_CMD_LEN);
238-
if (cmd_data_len != 0) {
238+
if (cmd_data_len != 0 && cmd_data_len == fcx_mldx5_cmds_data_len[cmd]) {
239239
memcpy(&buf[FCX_MLDX5_DATA_INDEX], cmd_data, strlen(cmd_data));
240240
}
241+
241242
checksum = fcx_mldx5_calculate_checksum(&buf[FCX_MLDX5_CMD_INDEX],
242243
FCX_MLDX5_CMD_LEN + cmd_data_len);
243244
bin2hex(&checksum, 1, &buf[FCX_MLDX5_CHECKSUM_INDEX(frame_len)],

0 commit comments

Comments
 (0)