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 2DF83A0554; Tue, 18 Feb 2020 00:56:28 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6206D1DA76; Tue, 18 Feb 2020 00:56:27 +0100 (CET) Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by dpdk.org (Postfix) with ESMTP id 60BA01DA75 for ; Tue, 18 Feb 2020 00:56:26 +0100 (CET) Received: by mail-lj1-f196.google.com with SMTP id q8so20727570ljj.11 for ; Mon, 17 Feb 2020 15:56:26 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=RgVbV8nrsUFSQGfSxphfiZJQdFrftNLmCplIDQUyYPc=; b=YGg4lnKkj5vKgKENQzjpZ4JeHcKkfK7I3PGNYPAuRsZCbdVNYKpJ82qAAUTkewudT+ fNZOQVWTu7oBACN+IR5nH3A8cwJAG9y35p1kHqRtvOncVIzg+NRUMwyxVBAoz6HO1Euv 78jl+WNwPlUB7fwt90l78FEVj05I+O8Axz31ybpe08kqMgqIHrok5V5dOPRpUEFNZGLn Tu1gTmEtAXDTAAn1JPp9fKiIZ6SqVgcpB9qhMiPFLHIEqhhUkELqoKKZlKUhPSUZrIHO jFs5/hwUjtkODOpw19qaw4y55F3a5giIpzaryXfV3CrTy6vzUc3uqIVpxdxBHbdIunDN UchQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=RgVbV8nrsUFSQGfSxphfiZJQdFrftNLmCplIDQUyYPc=; b=ZEBwzO0WaC5VuJUi+m3pC96j4eGhFEC+PnnJSiRUOnpIso0HSqDUCUjLgLdutcpGPJ c3XD+wZggGQOng/076hFe1Klz7HR2/47UjwUzZX2RzRbHR1zi/zALI86U2W9sgFpw3m4 S92qmjQoNHEECkh/gdP4Xrn9OmaYU3Xt3Sv2fAzo8jRUFa43nlF2mcDM9y4Mejc9jzLq JaKktRNIPr1pJSY/tkzR9EN+jvwc+czFdxHZY7/0uzFuzwVSxtRps6fHHpDbKtn6CQ5F VPbJueKV/5aG5RGa8STAkIivAMpCBIgLTH6J/BYLeU2oaNwLekgXx1xBoeGL2GUQN4sg 4Jag== X-Gm-Message-State: APjAAAVt8I0CbEhJslUV0ZU8T2XsT7jyaMvr47AD24807Ely4axhJpKj OLDot33ZDKTw6Mhhk5Xih+hC3srySYA= X-Google-Smtp-Source: APXvYqw8RfX5HQiElOihuHPvc/aV65Wem+lKNRNDMZPFiv+LiUOQ9NR0xgUpNzH2cxni+3geZPntLA== X-Received: by 2002:a2e:1459:: with SMTP id 25mr11519909lju.189.1581983785659; Mon, 17 Feb 2020 15:56:25 -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 j7sm1085694lfh.25.2020.02.17.15.56.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 15:56:25 -0800 (PST) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Dmitry Kozlyuk , Harini Ramakrishnan , Omar Cardona , Pallavi Kadam , Ranjit Menon Date: Tue, 18 Feb 2020 02:56:16 +0300 Message-Id: <20200217235616.85746-1-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217022351.59429-1-dmitry.kozliuk@gmail.com> References: <20200217022351.59429-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2] 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 | 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