Skip to content

Fixes for two possible memcpy overflows #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/can_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ int fdcan_handler(FDCAN_HandleTypeDef * handle, uint8_t const opcode, uint8_t co
else if (opcode == CAN_TX_FRAME)
{
union x8h7_can_frame_message msg;
memcpy(&msg, data, size);
memcpy(&msg, data, min(size, sizeof(msg)));
dbg_printf("fdcan_handler: sending CAN message to %lx, size %d, content[0]=0x%02X\n", msg.field.id, msg.field.len, msg.field.data[0]);
return on_CAN_TX_FRAME_Request(handle, &msg);
}
Expand Down
4 changes: 2 additions & 2 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
struct complete_packet *rx_pkt = (struct complete_packet *)RX_Buffer;

/* Limit the amount of data copied to prevent buffer overflow. */
if (rx_pkt->header.size > sizeof(rx_pkt_userspace))
rx_pkt->header.size = sizeof(rx_pkt_userspace);
if (rx_pkt->header.size > SPI_DMA_BUFFER_SIZE)
rx_pkt->header.size = SPI_DMA_BUFFER_SIZE;

/* The SPI transfer is now complete, copy to userspace memory. */
memcpy((void *)rx_pkt_userspace, &(rx_pkt->data), rx_pkt->header.size);
Expand Down