patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH] eal/windows: fix incorrect free condition in getopt implementation
@ 2020-09-23 14:15 Tal Shnaiderman
  2020-09-24 23:17 ` Dmitry Kozlyuk
  0 siblings, 1 reply; 3+ messages in thread
From: Tal Shnaiderman @ 2020-09-23 14:15 UTC (permalink / raw)
  To: dev
  Cc: thomas, pallavi.kadam, dmitry.kozliuk, ranjit.menon, navasile,
	dmitrym, stable

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


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

* Re: [dpdk-stable] [PATCH] eal/windows: fix incorrect free condition in getopt implementation
  2020-09-23 14:15 [dpdk-stable] [PATCH] eal/windows: fix incorrect free condition in getopt implementation Tal Shnaiderman
@ 2020-09-24 23:17 ` Dmitry Kozlyuk
  2020-09-25 16:59   ` Tal Shnaiderman
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Kozlyuk @ 2020-09-24 23:17 UTC (permalink / raw)
  To: Tal Shnaiderman
  Cc: dev, thomas, pallavi.kadam, ranjit.menon, navasile, dmitrym, stable

On Wed, 23 Sep 2020 17:15:38 +0300, Tal Shnaiderman wrote:
> 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.

Hi Tal,

a few days back Khoa To and me privately discussed a patch that makes MinGW
and Clang bith use getopt.c from librte_eal (now only Clang does). That patch
includes adjustments that just remove _dupenv_s() along with the bug. Just
discovered you were not Cc'd, sorry. I put your name in Reported-by and
mentioned the bug in commit message: http://patchwork.dpdk.org/patch/78765/

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

* Re: [dpdk-stable] [PATCH] eal/windows: fix incorrect free condition in getopt implementation
  2020-09-24 23:17 ` Dmitry Kozlyuk
@ 2020-09-25 16:59   ` Tal Shnaiderman
  0 siblings, 0 replies; 3+ messages in thread
From: Tal Shnaiderman @ 2020-09-25 16:59 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, NBU-Contact-Thomas Monjalon, pallavi.kadam, ranjit.menon,
	navasile, dmitrym, stable

> From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> On Wed, 23 Sep 2020 17:15:38 +0300, Tal Shnaiderman wrote:
> > 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.
> 
> Hi Tal,
> 
> a few days back Khoa To and me privately discussed a patch that makes
> MinGW and Clang bith use getopt.c from librte_eal (now only Clang does).
> That patch includes adjustments that just remove _dupenv_s() along with
> the bug. Just discovered you were not Cc'd, sorry. I put your name in
> Reported-by and mentioned the bug in commit message:
> https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpatch
> work.dpdk.org%2Fpatch%2F78765%2F&amp;data=02%7C01%7Ctalshn%40nvi
> dia.com%7Cab3a10f2d2ec458a7ef908d860e00e69%7C43083d15727340c1b7db
> 39efd9ccc17a%7C0%7C0%7C637365862717871619&amp;sdata=1xiI9JZ%2BUw
> sv2mj8rkAcff6%2B3KFNYZUiM72ZbnkyokY%3D&amp;reserved=0

Thanks for the update Dmitry, I'll mark this commit as superseded.

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

end of thread, other threads:[~2020-09-25 16:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-23 14:15 [dpdk-stable] [PATCH] eal/windows: fix incorrect free condition in getopt implementation Tal Shnaiderman
2020-09-24 23:17 ` Dmitry Kozlyuk
2020-09-25 16:59   ` Tal Shnaiderman

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