patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Tal Shnaiderman <talshn@nvidia.com>
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
Subject: [dpdk-stable] [PATCH] eal/windows: fix incorrect free condition in getopt implementation
Date: Wed, 23 Sep 2020 17:15:38 +0300	[thread overview]
Message-ID: <20200923141538.9956-1-talshn@nvidia.com> (raw)

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 <talshn@nvidia.com>
---
 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


             reply	other threads:[~2020-09-23 14:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-23 14:15 Tal Shnaiderman [this message]
2020-09-24 23:17 ` Dmitry Kozlyuk
2020-09-25 16:59   ` Tal Shnaiderman

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=20200923141538.9956-1-talshn@nvidia.com \
    --to=talshn@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=dmitry.kozliuk@gmail.com \
    --cc=dmitrym@microsoft.com \
    --cc=navasile@linux.microsoft.com \
    --cc=pallavi.kadam@intel.com \
    --cc=ranjit.menon@intel.com \
    --cc=stable@dpdk.org \
    --cc=thomas@monjalon.net \
    /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).