From patchwork Tue Jun 14 17:45:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huawei Xie X-Patchwork-Id: 13806 X-Patchwork-Delegate: yuanhan.liu@linux.intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id C83EBC46C; Wed, 15 Jun 2016 11:40:29 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id A700AC40C for ; Wed, 15 Jun 2016 11:40:27 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP; 15 Jun 2016 02:40:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,475,1459839600"; d="scan'208";a="828447768" Received: from dpdk15.sh.intel.com ([10.239.129.25]) by orsmga003.jf.intel.com with ESMTP; 15 Jun 2016 02:40:24 -0700 From: Huawei Xie To: dev@dpdk.org Cc: yuanhan.liu@intel.com, michalx.k.jastrzebski@intel.com, Huawei Xie Date: Wed, 15 Jun 2016 01:45:23 +0800 Message-Id: <1465926323-30532-1-git-send-email-huawei.xie@intel.com> X-Mailer: git-send-email 1.8.1.4 Subject: [dpdk-dev] [PATCH] vhost: fix unchecked return value of fstat X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Value returned from fstat is not checked for errors before being used. Fixes the coverity issue: static uint64_t get_blk_size(int fd) { struct stat stat; fstat(fd, &stat); return (uint64_t)stat.st_blksize; >>> CID 107103 (#1 of 1): Unchecked return value from library (CHECKED_RETURN) >>> check_return: Calling fstat(fd, &stat) without checking return value. >>> This library function may fail and return an error code. Fixes: 8f972312b8f4 ("vhost: support vhost-user") Signed-off-by: Huawei Xie Acked-by: Yuanhan Liu --- lib/librte_vhost/vhost_user/virtio-net-user.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c index f5248bc..5803182 100644 --- a/lib/librte_vhost/vhost_user/virtio-net-user.c +++ b/lib/librte_vhost/vhost_user/virtio-net-user.c @@ -64,9 +64,10 @@ static uint64_t get_blk_size(int fd) { struct stat stat; + int ret; - fstat(fd, &stat); - return (uint64_t)stat.st_blksize; + ret = fstat(fd, &stat); + return ret == -1 ? (uint64_t)-1 : (uint64_t)stat.st_blksize; } static void @@ -162,6 +163,11 @@ user_set_mem_table(struct vhost_device_ctx ctx, struct VhostUserMsg *pmsg) * aligned. */ alignment = get_blk_size(pmsg->fds[idx]); + if (alignment == (uint64_t)-1) { + RTE_LOG(ERR, VHOST_CONFIG, + "couldn't get hugepage size through fstat\n"); + goto err_mmap; + } mapped_size = RTE_ALIGN_CEIL(mapped_size, alignment); mapped_address = (uint64_t)(uintptr_t)mmap(NULL,