From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0DB01A0551; Mon, 17 Feb 2020 03:24:05 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DC2C41BC24; Mon, 17 Feb 2020 03:24:03 +0100 (CET) Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by dpdk.org (Postfix) with ESMTP id 0DBFA1B952 for ; Mon, 17 Feb 2020 03:24:03 +0100 (CET) Received: by mail-lj1-f195.google.com with SMTP id d10so16995601ljl.9 for ; Sun, 16 Feb 2020 18:24:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=dB2GoPOfhw80BOWZMgjXxd4o7oQx7atIHACYV4QJesw=; b=VTXlZHuxR0Hl2/EJGT6NYZtquzbHgdzWltLtk7o3Hcm0/G9ir7062W7WeTIxRNOZ5y uXkHoh7+YxCaUbCIbUFJ7h9uRtRTA0KXHX1ZPwiEyRPHuTGB8s73ZHqgESjwW6JmYVQq cLbTllJyHYbF2Y2tGOJL24FapuW7JrKpwjF9uMJsiWE3MZCrD8IbYlTcREbuWdTpSfVl VzaDdw3Z4xRORRhbLMDwJFNkWIc9hR8b2lXxaQeFB/YxULjQCAOLLdPQM0JZyuvPqXsk kv0CG+DPlsU9KQvBI4Ujas0inZ96D5qIO7C7ZlLsu0OoiDnGrJSPOmNE77lwvHL+TA7y RNnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=dB2GoPOfhw80BOWZMgjXxd4o7oQx7atIHACYV4QJesw=; b=I48sGkq05PGzSJXAC/iZgwEsJlYnwaBedGXR81UkCTea2E8U1IlEMXA1lL1OFSL7Y4 MMeVcOSWYJ8V5EUux6AKOhHaeD8joelMZbqp7AY4x4D3o7xMyqfKOuf0nI0peO7Em38k 1j15TZfYbS6upkWd3RDUEB/D2QPY9uGHxILmil9Bgz7lI39FkPeDQdjpytxwEOpTwShP qUvkuxvDgYxhu9Wkl9ORKquRyK5LwC7Ew6w15TGoWxfc38G8LIfcu9Ohkd6XRSbg+Jdu o/pkGeCiGnasnc6QP5foXhCifp9lP0UofR9ngPnTB3shzY4/gQBz5CACBeOuCAhZE10l QW8Q== X-Gm-Message-State: APjAAAUp8sA7rb8Z2/qllKxuKIFkLS0VbnCNC521gZvcweD2atbeoEBm ABMtIqdpQ6+wm/xxXroS/g9d26FVbtk= X-Google-Smtp-Source: APXvYqyGbUnA0FURaS1N8kA/heNbssXp3adW8vVomsbI2tFvVnZe70uDqvIVML25NaEhffB5nRSIpA== X-Received: by 2002:a2e:9e19:: with SMTP id e25mr9071690ljk.179.1581906242217; Sun, 16 Feb 2020 18:24:02 -0800 (PST) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.googlemail.com with ESMTPSA id z19sm6555446lfg.26.2020.02.16.18.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Feb 2020 18:24:01 -0800 (PST) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Dmitry Kozlyuk , Harini Ramakrishnan , Omar Cardona , Pallavi Kadam , Ranjit Menon Date: Mon, 17 Feb 2020 05:23:51 +0300 Message-Id: <20200217022351.59429-1-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] eal/windows: fix out-of-memory check X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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