From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by dpdk.org (Postfix) with ESMTP id 6D481235 for ; Tue, 21 Nov 2017 14:25:27 +0100 (CET) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id EE21420B26; Tue, 21 Nov 2017 08:25:26 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute1.internal (MEProxy); Tue, 21 Nov 2017 08:25:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fridaylinux.org; h=cc:date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=qewWwj37OHnnA2TDC U/HX64Mb6JAObamqdKkVBto8Dg=; b=o21xSlsK7xF+n6jAKQYNkRQd5jqRCy2Um sWaq/pCR/eCG7qTLmqtojnX6VuOwsHMnB+a9nVjTL7MXsmGq+lAYyKDx0FURTAip 1VBhtdJnWFAKMhEUrxxsn14+AqI1Y3dxv+bzsJDnRu/WO4gKvlNDtijsL27npC/6 Go27PopsSoLr1kvoZXKgv+1NrJYH3K1V3e1mo0cKCdshN0QrpwLlZN5+zA82chhs eYxFggwi1/scfEGSeYcBsXxA+Af692g+2AowjYIoZmrLTj3BX/vBiFgLQIRF9x3r v7bCAckNxQGCXdEzlE5y5a9DOXv/MKjCd5Bq4iFhwxCzeE4xaldqw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=qewWwj37OHnnA2TDCU/HX64Mb6JAObamqdKkVBto8Dg=; b=qz822Pcn dI+G24SJxKHczNYw8zusTk5zff+WKZBK/BW+s8M4Mkbd3kA7+jNtGr8rfSkYR4jx riu8jPVqcYI4hEOhvK32Rt3MQIvBoHBdDPukECYrW6Ib4z/jWIvIUBxok2WDpDL9 EyvejFZo+H18+9barw+uRBND2N6ZRbUu5ZOLpYGjcKYAICs1/L6PKdl0+W4ajh2x XRNyr8WJqh8FXurJ+55Rm+Xt6tjLPQtTlh/2tpPq6Vx7bPH0l5MBfuN4JthJyghB 2c3GJjea8whYXJq/CbUh8OGM97OpV+A3Rg3Unm0u6hA/uO7uR7C20XQK4ZaZSTZZ iuPOF+6jxOxlmQ== X-ME-Sender: Received: from localhost.localdomain (unknown [180.158.62.0]) by mail.messagingengine.com (Postfix) with ESMTPA id 60B4924631; Tue, 21 Nov 2017 08:25:23 -0500 (EST) From: Yuanhan Liu To: Daniel Mrzyglod Cc: Beilei Xing , dpdk stable Date: Tue, 21 Nov 2017 21:17:18 +0800 Message-Id: <1511270333-31002-96-git-send-email-yliu@fridaylinux.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511270333-31002-1-git-send-email-yliu@fridaylinux.org> References: <1511270333-31002-1-git-send-email-yliu@fridaylinux.org> Subject: [dpdk-stable] patch 'app/testpmd: fix DDP package filesize detection' has been queued to stable release 17.08.1 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Nov 2017 13:25:27 -0000 Hi, FYI, your patch has been queued to stable release 17.08.1 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 11/24/17. So please shout if anyone has objections. Thanks. --yliu --- >>From dff8618c859364a3ebf92e7f8956cd81601d0c78 Mon Sep 17 00:00:00 2001 From: Daniel Mrzyglod Date: Fri, 18 Aug 2017 16:17:36 +0200 Subject: [PATCH] app/testpmd: fix DDP package filesize detection [ upstream commit ce6e3f816d847153299e597467a0f104a493cb82 ] This issue was about passing unsigned argument where should be signed number. In reality this is about wrong usage of fseek and ftell to determine filesize. This patch is compliant to suggestions from FIO19-C: "Do not use fseek() and ftell() to compute the size of a regular file" Coverity issue: 143454 Fixes: a92a5a2cbbff ("app/testpmd: add command for loading DDP") Signed-off-by: Daniel Mrzyglod Acked-by: Beilei Xing --- app/test-pmd/config.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 14131d6..56d706a 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -40,6 +40,10 @@ #include #include +#include +#include +#include +#include #include #include @@ -3297,46 +3301,43 @@ port_dcb_info_display(uint8_t port_id) uint8_t * open_ddp_package_file(const char *file_path, uint32_t *size) { - FILE *fh = fopen(file_path, "rb"); - uint32_t pkg_size; + int fd = open(file_path, O_RDONLY); + off_t pkg_size; uint8_t *buf = NULL; int ret = 0; + struct stat st_buf; if (size) *size = 0; - if (fh == NULL) { + if (fd == -1) { printf("%s: Failed to open %s\n", __func__, file_path); return buf; } - ret = fseek(fh, 0, SEEK_END); - if (ret < 0) { - fclose(fh); + if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) { + close(fd); printf("%s: File operations failed\n", __func__); return buf; } - pkg_size = ftell(fh); + pkg_size = st_buf.st_size; + if (pkg_size < 0) { + close(fd); + printf("%s: File operations failed\n", __func__); + return buf; + } buf = (uint8_t *)malloc(pkg_size); if (!buf) { - fclose(fh); + close(fd); printf("%s: Failed to malloc memory\n", __func__); return buf; } - ret = fseek(fh, 0, SEEK_SET); + ret = read(fd, buf, pkg_size); if (ret < 0) { - fclose(fh); - printf("%s: File seek operation failed\n", __func__); - close_ddp_package_file(buf); - return NULL; - } - - ret = fread(buf, 1, pkg_size, fh); - if (ret < 0) { - fclose(fh); + close(fd); printf("%s: File read operation failed\n", __func__); close_ddp_package_file(buf); return NULL; @@ -3345,7 +3346,7 @@ open_ddp_package_file(const char *file_path, uint32_t *size) if (size) *size = pkg_size; - fclose(fh); + close(fd); return buf; } -- 2.7.4