From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DC0DEA04B1; Wed, 23 Sep 2020 16:16:52 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 421F81D90B; Wed, 23 Sep 2020 16:16:51 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 98D521D702 for ; Wed, 23 Sep 2020 16:16:49 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from talshn@nvidia.com) with SMTP; 23 Sep 2020 17:16:44 +0300 Received: from nvidia.com (l-wincomp04-vm.mtl.labs.mlnx [10.237.1.5]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 08NEGicG026260; Wed, 23 Sep 2020 17:16:44 +0300 From: Tal Shnaiderman To: dev@dpdk.org Cc: thomas@monjalon.net, pallavi.kadam@intel.com, dmitry.kozliuk@gmail.com, ranjit.menon@intel.com, navasile@linux.microsoft.com, dmitrym@microsoft.com, stable@dpdk.org Date: Wed, 23 Sep 2020 17:15:38 +0300 Message-Id: <20200923141538.9956-1-talshn@nvidia.com> X-Mailer: git-send-email 2.16.1.windows.4 Subject: [dpdk-dev] [PATCH] eal/windows: fix incorrect free condition in getopt implementation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" In the Windows getopt_internal function the condition freeing the memory allocated by _dupenv_s is correct only for the first call to the function. the next callers will try to free the buffer even though the _dupenv_s call is skipped if the POSIXLY_CORRECT env isn't found (undefined behavior). Fixed by releasing the buffer in the scope of the same if statement calling _dupenv_s Fixes: 5e373e456e6acdc ("eal/windows: add getopt implementation") Cc: stable@dpdk.org Signed-off-by: Tal Shnaiderman --- lib/librte_eal/windows/getopt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/windows/getopt.c b/lib/librte_eal/windows/getopt.c index a08f7c109b..20da225a68 100644 --- a/lib/librte_eal/windows/getopt.c +++ b/lib/librte_eal/windows/getopt.c @@ -253,16 +253,17 @@ getopt_internal(int nargc, char **nargv, const char *options, * Disable GNU extensions if POSIXLY_CORRECT is set or options * string begins with a '+'. */ - if (posixly_correct == -1) + if (posixly_correct == -1) { posixly_correct = _dupenv_s(&buf, &len, "POSIXLY_CORRECT"); + if (!posixly_correct) + free(buf); + } if (!posixly_correct || *options == '+') flags &= ~FLAG_PERMUTE; else if (*options == '-') flags |= FLAG_ALLARGS; if (*options == '+' || *options == '-') options++; - if (!posixly_correct) - free(buf); /* * reset if requested */ -- 2.16.1.windows.4