From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 725C0462AC for ; Mon, 24 Feb 2025 16:42:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4154F410D5; Mon, 24 Feb 2025 16:42:58 +0100 (CET) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by mails.dpdk.org (Postfix) with ESMTP id B9458410D5 for ; Mon, 24 Feb 2025 16:42:56 +0100 (CET) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-220c92c857aso78151515ad.0 for ; Mon, 24 Feb 2025 07:42:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1740411776; x=1741016576; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=LWcBPrYEWLZrD8gj0aiCzHYKr55miImNOIz8cPwqC+0=; b=yZjFjAiHIvRVoov2zDPD+jhfiCJVI8VbZawzhxj8Umf9Ji2/0n/ki+7sFCp4B50Xrs jrsEC4FNvAAlWLw4cQ09kY83Khh/V31pZdmlhPxOQtBInhWQ1EcLQZTNflZVCEDZIYRm 8xJdWCzOg7UWyvqsLeJwUreZaZUeIlH6R8DMumlRaK/vFreZvzeJINxiLCHdzJ+r7WAD mGLX3gHaPbsShNABbzraLcytiyv4acHQMS2I7FIe0IbF4rm3QI6bx7wXtEhuIozJ2azq kedPgLJJAaf8M7hOuUO/cwZQZpc2M8FJUUuUnTKpMkiar8mFMywD7aEnIRvQ23y+E8cg 77Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740411776; x=1741016576; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LWcBPrYEWLZrD8gj0aiCzHYKr55miImNOIz8cPwqC+0=; b=DAU6SzVQzTNdV6Q+AJgQoP/PuUluE6Y1c2KX92yWiuonfBlVnOSpvWCPCmqICA293z Tn6nkRt2ULXqLde+YHgpEzJjeT2MbjYf5wE7zdh0O5LuJNbwnjbGYn39RK5AFs5vQQVW y3fIN9xY5ltBo2RKMmL5RTNGSGsdFdVdJC21hbI2ejQ9vrFOsuy4bmUcXYE3L2UURS0q nr5Lwyu5/enIFcVYgWmXZPNNZrUZVOJIBzC0qepRoQnXH9RDZdP04E8iWxEYFEVaPzWL Ec34bIOAo7W0fUbFG8gT4QR5SmcRVNBi1TAaj1IjjwRdjJvWz2ys7GCwAw/hgiRHsgbi 4lkA== X-Forwarded-Encrypted: i=1; AJvYcCXTpn5J6ULPAXg0abiIkBkaGZw5ka0AnTBqTHuRbewfbU+P/zOI7cPDtVdpqpKViFfGztOXLjQ=@dpdk.org X-Gm-Message-State: AOJu0Yw4YajBoksk+sB/7UVRHMN+BVb3d4/qIAefhAgPScqmlFbIxcf1 Nl3++gnhUNM53vCvIuBqP+HSbBdmz4TsvqMfiGnQe5ydNvLJPnnqn810H8bmSM8= X-Gm-Gg: ASbGncshDwdbtNwTypkg3gY0/jPeJllr+tt1vkZFoUntvHgVMwNVYC9ijjBGV7RgqTt AFQSNk3dctlluaTzqmK6E19oe2IP5R+R/JcGzvPmq6LoCmbcnuwTlp7bkzrgMmChIsafTFB9uMP gxCYpYnKQdC37L0yV1OuNDSAHFjtXhXbPyIUGCQGkEP2ZQg/7y4efBWAE3WxRndqxU+x32sOCZj XV0+Lb4O6Ic8auFMbsW3hp0GFBSQVvepa93kX+1PdeqaiE3y1Uf7s2NK9na6qM8FuNQJcxgu4Ut Oj7u2bVtrLpMdobTvy7g/n89T+Axq9Z81Sj+8vV/ClRc66SlPoEUYdp4uZ1slGGq5XVa2ddRbuP Y1UE= X-Google-Smtp-Source: AGHT+IGXPHjeGEkJGzUHw5GppxkVH9eHuBAW8tzwq0UXtjoyIqMbrA4u4xMTpwmPM5RDa+cJps0/gQ== X-Received: by 2002:a17:902:e551:b0:215:a56f:1e50 with SMTP id d9443c01a7336-2219ff862e9mr249419535ad.8.1740411775720; Mon, 24 Feb 2025 07:42:55 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d53491f7sm180368905ad.38.2025.02.24.07.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Feb 2025 07:42:55 -0800 (PST) Date: Mon, 24 Feb 2025 07:42:53 -0800 From: Stephen Hemminger To: Ariel Otilibili Cc: dev@dpdk.org, Thomas Monjalon , David Marchand , Reshma Pattan , stable@dpdk.org Subject: Re: [PATCH v2 1/1] pcapng: warn if NULL is passed to rte_pcapng_close Message-ID: <20250224074253.3df64dff@hermes.local> In-Reply-To: <20250223214123.447579-2-ariel.otilibili@6wind.com> References: <20250216160833.3216001-1-ariel.otilibili@6wind.com> <20250223214123.447579-1-ariel.otilibili@6wind.com> <20250223214123.447579-2-ariel.otilibili@6wind.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org On Sun, 23 Feb 2025 22:41:23 +0100 Ariel Otilibili 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 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);