On Sun, 23 Feb 2025 22:41:23 +0100 Ariel Otilibili <ariel.otilib...@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. > > 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.otilib...@6wind.com> The convention (back from Unix) is that errno is only set on failure. Simpler fix would just to silently ignore NULL case. diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c index 16485b27cb..4a0aa6afe5 100644 --- a/lib/pcapng/rte_pcapng.c +++ b/lib/pcapng/rte_pcapng.c @@ -716,6 +716,7 @@ rte_pcapng_fdopen(int fd, void rte_pcapng_close(rte_pcapng_t *self) { - close(self->outfd); + if (self) + close(self->outfd);