DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 0/1] pcapng: fix null dereference in rte_pcapng_close
@ 2025-02-16 16:08 Ariel Otilibili
  2025-02-16 16:08 ` [PATCH 1/1] " Ariel Otilibili
  2025-02-23 21:41 ` [PATCH v2 0/1] warn if NULL is passed to rte_pcapng_close Ariel Otilibili
  0 siblings, 2 replies; 6+ messages in thread
From: Ariel Otilibili @ 2025-02-16 16:08 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, David Marchand, Ariel Otilibili, Reshma Pattan,
	Stephen Hemminger, stable

Hello,

This patch fixes a null dereference warning; it was found by static analysis, courtesy of Stephen Hemminger.

Thank you,

Ariel Otilibili (1):
  pcapng: fix null dereference in rte_pcapng_close

 .mailmap                | 2 +-
 lib/pcapng/rte_pcapng.c | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/1] pcapng: fix null dereference in rte_pcapng_close
  2025-02-16 16:08 [PATCH 0/1] pcapng: fix null dereference in rte_pcapng_close Ariel Otilibili
@ 2025-02-16 16:08 ` Ariel Otilibili
  2025-02-16 16:51   ` Stephen Hemminger
  2025-02-23 21:41 ` [PATCH v2 0/1] warn if NULL is passed to rte_pcapng_close Ariel Otilibili
  1 sibling, 1 reply; 6+ messages in thread
From: Ariel Otilibili @ 2025-02-16 16:08 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, David Marchand, Ariel Otilibili, Reshma Pattan,
	Stephen Hemminger, stable

rte_pcapng_close() might dereference a null pointer; as example,
PVS-Studio gives its usage in test_pcapng.c: indeed, that call to
rte_pcapng_close() might receive a null pointer.

Link: https://pvs-studio.com/en/docs/warnings/v522/
Link: https://github.com/DPDK/dpdk/blob/e5176f23ae8b31437c3e5eb875c81f95bf3a9942/app/test/test_pcapng.c#L438
Fixes: 8d23ce8f5ee9 ("pcapng: add new library for writing pcapng files")
Signed-off-by: Ariel Otilibili <ariel.otilibili@6wind.com>
---
 .mailmap                | 2 +-
 lib/pcapng/rte_pcapng.c | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/.mailmap b/.mailmap
index a03d3cfb591b..ea68d6180ccc 100644
--- a/.mailmap
+++ b/.mailmap
@@ -135,7 +135,7 @@ Anupam Kapoor <anupam.kapoor@gmail.com>
 Apeksha Gupta <apeksha.gupta@nxp.com>
 Archana Muniganti <marchana@marvell.com> <muniganti.archana@caviumnetworks.com>
 Archit Pandey <architpandeynitk@gmail.com>
-Ariel Otilibili <otilibil@eurecom.fr> <ariel.otilibili@6wind.com>
+Ariel Otilibili <ariel.otilibili@6wind.com> <otilibil@eurecom.fr>
 Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
 Arkadiusz Kusztal <arkadiuszx.kusztal@intel.com>
 Arnaud Fiorini <arnaud.fiorini@polymtl.ca>
diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c
index 16485b27cb46..efd96a16ede7 100644
--- a/lib/pcapng/rte_pcapng.c
+++ b/lib/pcapng/rte_pcapng.c
@@ -716,6 +716,9 @@ rte_pcapng_fdopen(int fd,
 void
 rte_pcapng_close(rte_pcapng_t *self)
 {
+	if (!self)
+		return;
+
 	close(self->outfd);
 	free(self);
 }
-- 
2.30.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/1] pcapng: fix null dereference in rte_pcapng_close
  2025-02-16 16:08 ` [PATCH 1/1] " Ariel Otilibili
@ 2025-02-16 16:51   ` Stephen Hemminger
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2025-02-16 16:51 UTC (permalink / raw)
  To: Ariel Otilibili
  Cc: dev, Thomas Monjalon, David Marchand, Reshma Pattan, stable

On Sun, 16 Feb 2025 17:08:33 +0100
Ariel Otilibili <ariel.otilibili@6wind.com> wrote:

> rte_pcapng_close() might dereference a null pointer; as example,
> PVS-Studio gives its usage in test_pcapng.c: indeed, that call to
> rte_pcapng_close() might receive a null pointer.
> 
> Link: https://pvs-studio.com/en/docs/warnings/v522/
> Link: https://github.com/DPDK/dpdk/blob/e5176f23ae8b31437c3e5eb875c81f95bf3a9942/app/test/test_pcapng.c#L438
> Fixes: 8d23ce8f5ee9 ("pcapng: add new library for writing pcapng files")
> Signed-off-by: Ariel Otilibili <ariel.otilibili@6wind.com>

Not sure this is necessary.
The analgous function is fclose() and calling fclose() with NULL will crash.

I would rather update the documentation than silently ignore buggy programs.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 0/1] warn if NULL is passed to rte_pcapng_close
  2025-02-16 16:08 [PATCH 0/1] pcapng: fix null dereference in rte_pcapng_close Ariel Otilibili
  2025-02-16 16:08 ` [PATCH 1/1] " Ariel Otilibili
@ 2025-02-23 21:41 ` Ariel Otilibili
  2025-02-23 21:41   ` [PATCH v2 1/1] pcapng: " Ariel Otilibili
  1 sibling, 1 reply; 6+ messages in thread
From: Ariel Otilibili @ 2025-02-23 21:41 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, David Marchand, Reshma Pattan,
	Stephen Hemminger, stable, Ariel Otilibili

Hello,

This patch addresses a warning found by static analysis; courtesy of Stephen Hemminger.

Thank you,
---
v2
* rather change documentation than work around the bug (Stephen Hemminger)
* changed cover letter and commit message

v1 (https://inbox.dpdk.org/dev/20250216160833.3216001-1-ariel.otilibili@6wind.com/)

Ariel Otilibili (1):
  pcapng: warn if NULL is passed to rte_pcapng_close

 .mailmap                | 2 +-
 lib/pcapng/rte_pcapng.c | 3 +++
 lib/pcapng/rte_pcapng.h | 2 ++
 3 files changed, 6 insertions(+), 1 deletion(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/1] pcapng: warn if NULL is passed to rte_pcapng_close
  2025-02-23 21:41 ` [PATCH v2 0/1] warn if NULL is passed to rte_pcapng_close Ariel Otilibili
@ 2025-02-23 21:41   ` Ariel Otilibili
  2025-02-23 22:04     ` Dmitry Kozlyuk
  0 siblings, 1 reply; 6+ messages in thread
From: Ariel Otilibili @ 2025-02-23 21:41 UTC (permalink / raw)
  To: dev
  Cc: Thomas Monjalon, David Marchand, Ariel Otilibili, Reshma Pattan,
	Stephen Hemminger, stable

rte_pcapng_close() might dereference a null pointer; as example,
PVS-Studio gives its usage in test_pcapng.c: indeed, that call to
rte_pcapng_close() might receive a null pointer.

In that case, rte_errno is set to EINVAL. The API is updated accordingly.

Link: https://pvs-studio.com/en/docs/warnings/v522/
Link: https://github.com/DPDK/dpdk/blob/e5176f23ae8b31437c3e5eb875c81f95bf3a9942/app/test/test_pcapng.c#L438
Fixes: 8d23ce8f5ee9 ("pcapng: add new library for writing pcapng files")
Signed-off-by: Ariel Otilibili <ariel.otilibili@6wind.com>
---
 .mailmap                | 2 +-
 lib/pcapng/rte_pcapng.c | 3 +++
 lib/pcapng/rte_pcapng.h | 2 ++
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/.mailmap b/.mailmap
index a03d3cfb591b..ea68d6180ccc 100644
--- a/.mailmap
+++ b/.mailmap
@@ -135,7 +135,7 @@ Anupam Kapoor <anupam.kapoor@gmail.com>
 Apeksha Gupta <apeksha.gupta@nxp.com>
 Archana Muniganti <marchana@marvell.com> <muniganti.archana@caviumnetworks.com>
 Archit Pandey <architpandeynitk@gmail.com>
-Ariel Otilibili <otilibil@eurecom.fr> <ariel.otilibili@6wind.com>
+Ariel Otilibili <ariel.otilibili@6wind.com> <otilibil@eurecom.fr>
 Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
 Arkadiusz Kusztal <arkadiuszx.kusztal@intel.com>
 Arnaud Fiorini <arnaud.fiorini@polymtl.ca>
diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c
index 16485b27cb46..d2cbcea42885 100644
--- a/lib/pcapng/rte_pcapng.c
+++ b/lib/pcapng/rte_pcapng.c
@@ -716,6 +716,9 @@ rte_pcapng_fdopen(int fd,
 void
 rte_pcapng_close(rte_pcapng_t *self)
 {
+	if (!self)
+		rte_errno = EINVAL;
+
 	close(self->outfd);
 	free(self);
 }
diff --git a/lib/pcapng/rte_pcapng.h b/lib/pcapng/rte_pcapng.h
index 48f2b5756430..f7b976987320 100644
--- a/lib/pcapng/rte_pcapng.h
+++ b/lib/pcapng/rte_pcapng.h
@@ -60,6 +60,8 @@ rte_pcapng_fdopen(int fd,
  *
  * @param self
  *  handle to library
+
+ * If self is NULL, rte_errno is set to EINVAL.
  */
 void
 rte_pcapng_close(rte_pcapng_t *self);
-- 
2.30.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/1] pcapng: warn if NULL is passed to rte_pcapng_close
  2025-02-23 21:41   ` [PATCH v2 1/1] pcapng: " Ariel Otilibili
@ 2025-02-23 22:04     ` Dmitry Kozlyuk
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitry Kozlyuk @ 2025-02-23 22:04 UTC (permalink / raw)
  To: Ariel Otilibili
  Cc: dev, Thomas Monjalon, David Marchand, Reshma Pattan,
	Stephen Hemminger, stable

2025-02-23 22:41 (UTC+0100), Ariel Otilibili:
> diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c
> index 16485b27cb46..d2cbcea42885 100644
> --- a/lib/pcapng/rte_pcapng.c
> +++ b/lib/pcapng/rte_pcapng.c
> @@ -716,6 +716,9 @@ rte_pcapng_fdopen(int fd,
>  void
>  rte_pcapng_close(rte_pcapng_t *self)
>  {
> +	if (!self)
> +		rte_errno = EINVAL;
> +
>  	close(self->outfd);
>  	free(self);
>  }

Still dereferencing self == NULL.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-02-23 22:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-16 16:08 [PATCH 0/1] pcapng: fix null dereference in rte_pcapng_close Ariel Otilibili
2025-02-16 16:08 ` [PATCH 1/1] " Ariel Otilibili
2025-02-16 16:51   ` Stephen Hemminger
2025-02-23 21:41 ` [PATCH v2 0/1] warn if NULL is passed to rte_pcapng_close Ariel Otilibili
2025-02-23 21:41   ` [PATCH v2 1/1] pcapng: " Ariel Otilibili
2025-02-23 22:04     ` Dmitry Kozlyuk

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).