From: Dmitry Kozlyuk Date: Mon, 17 Feb 2020 23:56:16 +0000 (+0300) Subject: eal/windows: fix out-of-memory check in asprintf X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=6c45dff00aa65080bcfb161fc0f58e44f211cd11;p=dpdk.git eal/windows: fix out-of-memory check in asprintf 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 Acked-by: Ranjit Menon --- diff --git a/lib/librte_eal/windows/eal/include/rte_os.h b/lib/librte_eal/windows/eal/include/rte_os.h index 9e762617b1..c76be12168 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);