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 <[email protected]>
---
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