DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] eal/windows: fix out-of-memory check
@ 2020-02-17  2:23 Dmitry Kozlyuk
  2020-02-17 23:56 ` [dpdk-dev] [PATCH v2] " Dmitry Kozlyuk
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Kozlyuk @ 2020-02-17  2:23 UTC (permalink / raw)
  To: dev
  Cc: Dmitry Kozlyuk, Harini Ramakrishnan, Omar Cardona, Pallavi Kadam,
	Ranjit Menon

Check vsnprintf() result to prevent calling malloc() with negative size.
Check actual malloc() result and terminate asprintf() with documented
error code to prevent the use of NULL pointer.

Fixes: e8428a9d8 ("eal/windows: add some basic functions and macros")

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/windows/eal/include/rte_os.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/librte_eal/windows/eal/include/rte_os.h b/lib/librte_eal/windows/eal/include/rte_os.h
index 9e762617b..69e8f4733 100644
--- a/lib/librte_eal/windows/eal/include/rte_os.h
+++ b/lib/librte_eal/windows/eal/include/rte_os.h
@@ -66,10 +66,12 @@ asprintf(char **buffer, const char *format, ...)
 	va_start(arg, format);
 	size = vsnprintf(NULL, 0, format, arg) + 1;
 	va_end(arg);
+	if (size < 0)
+		return -1;
 
 	*buffer = malloc(size);
-	if (buffer == NULL)
-		printf("Cannot allocate memory");
+	if (*buffer == NULL)
+		return -1;
 
 	va_start(arg, format);
 	ret = vsnprintf(*buffer, size, format, arg);
-- 
2.25.0


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

* [dpdk-dev] [PATCH v2] eal/windows: fix out-of-memory check
  2020-02-17  2:23 [dpdk-dev] [PATCH] eal/windows: fix out-of-memory check Dmitry Kozlyuk
@ 2020-02-17 23:56 ` Dmitry Kozlyuk
  2020-02-18 21:52   ` Ranjit Menon
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Kozlyuk @ 2020-02-17 23:56 UTC (permalink / raw)
  To: dev
  Cc: Dmitry Kozlyuk, Harini Ramakrishnan, Omar Cardona, Pallavi Kadam,
	Ranjit Menon

Check vsnprintf() result to prevent calling malloc() with negative size.
Check actual malloc() result and terminate asprintf() with documented
error code to prevent the use of NULL pointer.

Fixes: e8428a9d8 ("eal/windows: add some basic functions and macros")

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_eal/windows/eal/include/rte_os.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

v2 Changes:
    Check vsnprintf() value before appending place for '\0'.

diff --git a/lib/librte_eal/windows/eal/include/rte_os.h b/lib/librte_eal/windows/eal/include/rte_os.h
index 9e762617b..c76be1216 100644
--- a/lib/librte_eal/windows/eal/include/rte_os.h
+++ b/lib/librte_eal/windows/eal/include/rte_os.h
@@ -64,12 +64,15 @@ asprintf(char **buffer, const char *format, ...)
 	va_list arg;
 
 	va_start(arg, format);
-	size = vsnprintf(NULL, 0, format, arg) + 1;
+	size = vsnprintf(NULL, 0, format, arg);
 	va_end(arg);
+	if (size < 0)
+		return -1;
+	size++;
 
 	*buffer = malloc(size);
-	if (buffer == NULL)
-		printf("Cannot allocate memory");
+	if (*buffer == NULL)
+		return -1;
 
 	va_start(arg, format);
 	ret = vsnprintf(*buffer, size, format, arg);
-- 
2.25.0


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

* Re: [dpdk-dev] [PATCH v2] eal/windows: fix out-of-memory check
  2020-02-17 23:56 ` [dpdk-dev] [PATCH v2] " Dmitry Kozlyuk
@ 2020-02-18 21:52   ` Ranjit Menon
  2020-02-21 16:37     ` Thomas Monjalon
  0 siblings, 1 reply; 4+ messages in thread
From: Ranjit Menon @ 2020-02-18 21:52 UTC (permalink / raw)
  To: Dmitry Kozlyuk; +Cc: Harini Ramakrishnan, Omar Cardona, Pallavi Kadam, dev

On 2/17/2020 3:56 PM, Dmitry Kozlyuk wrote:
> Check vsnprintf() result to prevent calling malloc() with negative size.
> Check actual malloc() result and terminate asprintf() with documented
> error code to prevent the use of NULL pointer.
>
> Fixes: e8428a9d8 ("eal/windows: add some basic functions and macros")
>
> Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> ---
>   lib/librte_eal/windows/eal/include/rte_os.h | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
>
> v2 Changes:
>      Check vsnprintf() value before appending place for '\0'.
>
Acked-by: Ranjit Menon <ranjit.menon@intel.com>


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

* Re: [dpdk-dev] [PATCH v2] eal/windows: fix out-of-memory check
  2020-02-18 21:52   ` Ranjit Menon
@ 2020-02-21 16:37     ` Thomas Monjalon
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Monjalon @ 2020-02-21 16:37 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, Harini Ramakrishnan, Omar Cardona, Pallavi Kadam, dev, Ranjit Menon

18/02/2020 22:52, Ranjit Menon:
> On 2/17/2020 3:56 PM, Dmitry Kozlyuk wrote:
> > Check vsnprintf() result to prevent calling malloc() with negative size.
> > Check actual malloc() result and terminate asprintf() with documented
> > error code to prevent the use of NULL pointer.
> >
> > Fixes: e8428a9d8 ("eal/windows: add some basic functions and macros")
> >
> > Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
> > ---
> >   lib/librte_eal/windows/eal/include/rte_os.h | 9 ++++++---
> >   1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > v2 Changes:
> >      Check vsnprintf() value before appending place for '\0'.
> >
> Acked-by: Ranjit Menon <ranjit.menon@intel.com>

Applied, thanks.

Note: adding "in asprintf" to the title in order to give context.



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

end of thread, other threads:[~2020-02-21 16:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-17  2:23 [dpdk-dev] [PATCH] eal/windows: fix out-of-memory check Dmitry Kozlyuk
2020-02-17 23:56 ` [dpdk-dev] [PATCH v2] " Dmitry Kozlyuk
2020-02-18 21:52   ` Ranjit Menon
2020-02-21 16:37     ` Thomas Monjalon

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