eal/windows: fix out-of-memory check
PATCH 1/1 eal/windows: fix out-of-memory check
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.
--- lib/librte_eal/windows/eal/include/rte_os.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
lib/librte_eal/windows/eal/include/rte_os.h +4 -2
@@ -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);
Signature · 1 line
2.25.0
PATCH v2 1/1 eal/windows: fix out-of-memory check
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.
--- 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'.
lib/librte_eal/windows/eal/include/rte_os.h +6 -3
@@ -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);
Signature · 1 line
2.25.0
Quoted 6 lines · Dmitry Kozlyuk
Check
vsnprintf()result to prevent callingmalloc()with negative size. Check actualmalloc()result and terminateasprintf()with documented error code to prevent the use of NULL pointer.Fixes e8428a9d8 ("eal/windows: add some basic functions and macros")
Quoted 8 lines
Signed-off-by Dmitry Kozlyuk <[email protected]>---
lib/librte_eal/windows/eal/include/rte_os.h| 9 ++++++---1 file changed, 6 insertions(+), 3 deletions(-)v2 Changes:
Checkvsnprintf()value before appending place for '\0'.
Thomas Monjalon
Applied18/02/2020 22:52, Ranjit Menon:
Quoted 12 lines · Dmitry Kozlyuk
Quoted 11 lines
Check
vsnprintf()result to prevent callingmalloc()with negative size. Check actualmalloc()result and terminateasprintf()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 <[email protected]>--- lib/librte_eal/windows/eal/include/rte_os.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
Quoted 4 lines
Quoted 3 lines
v2 Changes:
Checkvsnprintf()value before appending place for '\0'.Acked-by Ranjit Menon <[email protected]>
Applied, thanks.
Note: adding "in asprintf" to the title in order to give context.