Skip to content

Commit

Permalink
drivers: sensor: fcx_mldx5 fix string_overflow issue
Browse files Browse the repository at this point in the history
This commit fixes Copy into fixed size buffer (STRING_OVERFLOW) by checking
the cmd_data_len

Signed-off-by: Jilay Pandya <[email protected]>
  • Loading branch information
jilaypandya committed Dec 2, 2024
1 parent 2376310 commit b758ded
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/sensor/fcx_mldx5/fcx_mldx5.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ static void fcx_mldx5_uart_send(const struct device *dev, enum fcx_mldx5_cmd cmd

buf[FCX_MLDX5_STX_INDEX] = FCX_MLDX5_STX;
memcpy(&buf[FCX_MLDX5_CMD_INDEX], fcx_mldx5_cmds[cmd], FCX_MLDX5_CMD_LEN);
if (cmd_data_len != 0 && cmd_data_len == fcx_mldx5_cmds_data_len[cmd]) {
if (cmd_data_len != 0 && cmd_data_len == fcx_mldx5_cmds_data_len[cmd] &&
cmd_data_len <= (FCX_MLDX5_MAX_FRAME_LEN - FCX_MLDX5_HEADER_LEN)) {
memcpy(&buf[FCX_MLDX5_DATA_INDEX], cmd_data, strlen(cmd_data));
}

Expand Down

0 comments on commit b758ded

Please sign in to comment.