From patchwork Thu Oct 29 07:19:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Huang X-Patchwork-Id: 82707 X-Patchwork-Delegate: qi.z.zhang@intel.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 64C9CA04B5; Thu, 29 Oct 2020 09:19:45 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AD3E0BE5B; Thu, 29 Oct 2020 09:19:31 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id E107CBE53 for ; Thu, 29 Oct 2020 09:19:28 +0100 (CET) IronPort-SDR: RKpRPcNoQ+XvagVGKdSK6BycGHETBlvlfUBwDkSvuozFQu4ysRYy6C6dvMdxb1Q8LNC+5TQfvh bz3WubiZDWOQ== X-IronPort-AV: E=McAfee;i="6000,8403,9788"; a="186175698" X-IronPort-AV: E=Sophos;i="5.77,429,1596524400"; d="scan'208";a="186175698" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2020 01:19:28 -0700 IronPort-SDR: i7T3wLrTQdICXoVWZNWp/WqbBdjjbaE1VERMWHnDuSpWyIZPFz4AUqjA790DKl3+ZPllJMWZ5w aLqf21WYY9Qw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,429,1596524400"; d="scan'208";a="469048495" Received: from unknown (HELO sh_lab5_1.sh.intel.com) ([10.238.175.190]) by orsmga004.jf.intel.com with ESMTP; 29 Oct 2020 01:19:27 -0700 From: Wei Huang To: dev@dpdk.org, rosen.xu@intel.com, qi.z.zhang@intel.com Cc: Wei Huang Date: Thu, 29 Oct 2020 03:19:25 -0400 Message-Id: <1603955966-29700-2-git-send-email-wei.huang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1603955966-29700-1-git-send-email-wei.huang@intel.com> References: <1603955966-29700-1-git-send-email-wei.huang@intel.com> Subject: [dpdk-dev] [PATCH v1 1/2] raw/ifpga: terminate string filled by readlink with null 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" readlink() does not terminate string, add a null character at the end of the string if readlink() succeeds. Fixes: 9c006c45d0c5 ("raw/ifpga: scan PCIe BDF device tree") Signed-off-by: Wei Huang --- drivers/raw/ifpga/ifpga_rawdev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c index 0385514..bf0613e 100644 --- a/drivers/raw/ifpga/ifpga_rawdev.c +++ b/drivers/raw/ifpga/ifpga_rawdev.c @@ -230,8 +230,9 @@ static int ifpga_rawdev_fill_info(struct ifpga_rawdev *ifpga_dev, memset(link, 0, sizeof(link)); memset(link1, 0, sizeof(link1)); ret = readlink(path, link, (sizeof(link)-1)); - if (ret == -1) + if ((ret < 0) || ((unsigned)ret > (sizeof(link)-1))) return -1; + link[ret] = 0; /* terminate string with null character */ strlcpy(link1, link, sizeof(link1)); memset(ifpga_dev->parent_bdf, 0, 16); point = strlen(link);