If dumpcap (in legacy pcap mode) tried to handle a large segmented frame it would core dump because rte_pktmbuf_read() would return NULL. Fix by using same logic as in pcap PMD.
Fixes: cbb44143be74 ("app/dumpcap: add new packet capture application") Reported-by: Tianli Lai <laitia...@tom.com> Signed-off-by: Stephen Hemminger <step...@networkplumber.org> --- app/dumpcap/main.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c index 6feb8f5672..fcfaa19951 100644 --- a/app/dumpcap/main.c +++ b/app/dumpcap/main.c @@ -902,7 +902,7 @@ static ssize_t pcap_write_packets(pcap_dumper_t *dumper, struct rte_mbuf *pkts[], uint16_t n) { - uint8_t temp_data[RTE_MBUF_DEFAULT_BUF_SIZE]; + uint8_t temp_data[RTE_ETHER_MAX_JUMBO_FRAME_LEN]; struct pcap_pkthdr header; uint16_t i; size_t total = 0; @@ -911,14 +911,19 @@ pcap_write_packets(pcap_dumper_t *dumper, for (i = 0; i < n; i++) { struct rte_mbuf *m = pkts[i]; + size_t len, caplen; - header.len = rte_pktmbuf_pkt_len(m); - header.caplen = RTE_MIN(header.len, sizeof(temp_data)); + len = caplen = rte_pktmbuf_pkt_len(m); + if (unlikely(!rte_pktmbuf_is_contiguous(m) && len > sizeof(temp_data))) + caplen = sizeof(temp_data); + + header.len = len; + header.caplen = caplen; pcap_dump((u_char *)dumper, &header, - rte_pktmbuf_read(m, 0, header.caplen, temp_data)); + rte_pktmbuf_read(m, 0, caplen, temp_data)); - total += sizeof(header) + header.len; + total += sizeof(header) + caplen; } return total; -- 2.45.2