DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tianli Lai <laitianli@tom.com>
To: dev@dpdk.org
Cc: Reshma Pattan <reshma.pattan@intel.com>,
	Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH] app/dumpcap:fix coredump problem because pcap_dump 3th argument is null
Date: Fri,  1 Mar 2024 18:41:29 +0800	[thread overview]
Message-ID: <20240301104129.3725-1-laitianli@tom.com> (raw)

if rte_pktmbuf_read() return NULL, pcap_dump() would coredump.

Signed-off-by: Tianli Lai <laitianli@tom.com>
---
 app/dumpcap/main.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/app/dumpcap/main.c b/app/dumpcap/main.c
index d57db0589a..c941fb92bf 100644
--- a/app/dumpcap/main.c
+++ b/app/dumpcap/main.c
@@ -878,6 +878,7 @@ pcap_write_packets(pcap_dumper_t *dumper,
 	struct pcap_pkthdr header;
 	uint16_t i;
 	size_t total = 0;
+	const void *data;
 
 	gettimeofday(&header.ts, NULL);
 
@@ -886,9 +887,12 @@ pcap_write_packets(pcap_dumper_t *dumper,
 
 		header.len = rte_pktmbuf_pkt_len(m);
 		header.caplen = RTE_MIN(header.len, sizeof(temp_data));
-
-		pcap_dump((u_char *)dumper, &header,
-			  rte_pktmbuf_read(m, 0, header.caplen, temp_data));
+		data = rte_pktmbuf_read(m, 0, header.caplen, temp_data);
+		if (!data) {
+			rte_pktmbuf_free(m);
+			continue;
+		}
+		pcap_dump((u_char *)dumper, &header, data);
 
 		total += sizeof(header) + header.len;
 	}
-- 
2.27.0


             reply	other threads:[~2024-03-01  2:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-01 10:41 Tianli Lai [this message]
2024-03-01  3:36 ` Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240301104129.3725-1-laitianli@tom.com \
    --to=laitianli@tom.com \
    --cc=dev@dpdk.org \
    --cc=reshma.pattan@intel.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).