Skip to content

Commit ca83b4d

Browse files
committed
pbuf: fix use after free possibility and fast return
After freeing packet the code uses packet->next Its more of an issue when task_woken is NULL meaning we are not in ISR Also added fast bail out with return to jump out of while loop
1 parent 7e8d832 commit ca83b4d

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/interfaces/csp_if_can_pbuf.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ void csp_can_pbuf_free(csp_can_interface_data_t * ifdata, csp_packet_t * buffer,
1919

2020
while (packet) {
2121

22+
csp_packet_t * next = packet->next;
23+
2224
/* Perform cleanup in used pbufs */
2325
if (packet == buffer) {
2426

2527
/* Erase from list prev->next = next */
2628
if (prev) {
27-
prev->next = packet->next;
29+
prev->next = next;
2830
} else {
29-
ifdata->pbufs = packet->next;
31+
ifdata->pbufs = next;
3032
}
3133

3234
if (buf_free) {
@@ -36,11 +38,11 @@ void csp_can_pbuf_free(csp_can_interface_data_t * ifdata, csp_packet_t * buffer,
3638
csp_buffer_free_isr(packet);
3739
}
3840
}
39-
41+
return;
4042
}
4143

4244
prev = packet;
43-
packet = packet->next;
45+
packet = next;
4446
}
4547

4648
}

0 commit comments

Comments
 (0)