Skip to content

Commit

Permalink
add sanity check for incoming can frames
Browse files Browse the repository at this point in the history
  • Loading branch information
devcoons committed Nov 22, 2024
1 parent 4065502 commit f04ceb7
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/lib_iso15765.c
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ n_rslt iso15765_init(iso15765_t* instance)
*/
n_rslt iso15765_enqueue(iso15765_t* instance, canbus_frame_t* frame)
{
if (instance == NULL)
if (instance == NULL || frame == NULL)
{
return N_NULL;
}
Expand All @@ -1019,6 +1019,29 @@ n_rslt iso15765_enqueue(iso15765_t* instance, canbus_frame_t* frame)
return N_ERROR;
}

if (frame->fr_format == CBUS_FR_FRM_STD)
{
if (frame->dlc == 0 || frame->dlc > 8)
{
return N_ERROR;
}
}
else if (frame->fr_format == CBUS_FR_FRM_FD)
{
if (frame->dlc == 0 ||
(frame->dlc > 8 && frame->dlc != 12 && frame->dlc != 16 &&
frame->dlc != 20 && frame->dlc != 24 && frame->dlc != 32 &&
frame->dlc != 48 && frame->dlc != 64))
{
return N_ERROR;
}
}
else
{
return N_ERROR;
}


return iqueue_enqueue(&instance->inqueue, frame) == I_OK
? N_OK : N_BUFFER_OVFLW;
}
Expand Down

0 comments on commit f04ceb7

Please sign in to comment.