diff options
Diffstat (limited to 'pcap-linux.c')
-rw-r--r-- | pcap-linux.c | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/pcap-linux.c b/pcap-linux.c index e931f84f..52decc31 100644 --- a/pcap-linux.c +++ b/pcap-linux.c @@ -3936,20 +3936,41 @@ static int pcap_handle_packet_mmap( * does happen.) * * Update this if Linux adds more flag - * bits to the fd_flags field or uses - * either of the reserved fields for - * FD frames. + * bits to the fd_flags field, uses the + * len8_dlc field for CAN FD frames, or + * uses the reserved frame for CAN FD + * frames. */ canhdr->fd_flags &= ~(CANFD_FDF|CANFD_ESI|CANFD_BRS); - canhdr->reserved1 = 0; - canhdr->reserved2 = 0; + canhdr->len8_dlc = 0; + canhdr->reserved = 0; } else { /* - * Clear CANFD_FDF if it's set (probably - * again meaning that that field is - * uninitialized junk). + * The FD flags field is CAN FD-only, + * so it should be zero. + * + * If it's not zero, or the reserved + * field is not zero, or the len8_dlc + * field does not have a value between + * 8 and 15, assume the header was not + * initialized past the payload_length + * field, and zero out the len8_dlc field. + * + * Then zero out the fd_flags and reserved + * fields. + * + * Update this if Linux uses the fd_flags + * field or the reserved field, or puts + * values not between 8 and 15 in the + * len8_dlc field, for classic CAN frames. */ - canhdr->fd_flags &= ~CANFD_FDF; + if (canhdr->fd_flags != 0 || + canhdr->reserved != 0 || + (canhdr->len8_dlc < 8 || + canhdr->len8_dlc > 15)) + canhdr->len8_dlc = 0; + canhdr->fd_flags = 0; + canhdr->reserved = 0; } } } |