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 22941A04DD; Tue, 26 Nov 2019 08:50:11 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id B91982A5D; Tue, 26 Nov 2019 08:50:09 +0100 (CET) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id ED9C6235; Tue, 26 Nov 2019 08:50:07 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Nov 2019 23:50:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,244,1571727600"; d="scan'208";a="408578102" Received: from storage36.sh.intel.com ([10.67.110.177]) by fmsmga005.fm.intel.com with ESMTP; 25 Nov 2019 23:50:05 -0800 From: Jin Yu To: Maxime Coquelin , Tiwei Bie , Zhihong Wang Cc: dev@dpdk.org, Jin Yu , stable@dpdk.org Date: Tue, 26 Nov 2019 23:32:14 +0800 Message-Id: <20191126153214.7952-1-jin.yu@intel.com> X-Mailer: git-send-email 2.17.2 Subject: [dpdk-dev] [PATCH] examples/vhost_blk: fix the TOCTOU 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" Fix the time of check time of use warning in example code Coverity issue: 350589 158663 Fixes: c19beb3f38cd ("examples/vhost_blk: introduce vhost storage sample") Cc: stable@dpdk.org Signed-off-by: Jin Yu --- examples/vhost_blk/vhost_blk.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/examples/vhost_blk/vhost_blk.c b/examples/vhost_blk/vhost_blk.c index 3182a488b..bcb4ebb0b 100644 --- a/examples/vhost_blk/vhost_blk.c +++ b/examples/vhost_blk/vhost_blk.c @@ -993,11 +993,7 @@ vhost_blk_ctrlr_construct(const char *ctrlr_name) } snprintf(dev_pathname, sizeof(dev_pathname), "%s/%s", path, ctrlr_name); - if (access(dev_pathname, F_OK) != -1) { - if (unlink(dev_pathname) != 0) - rte_exit(EXIT_FAILURE, "Cannot remove %s.\n", - dev_pathname); - } + unlink(dev_pathname); if (rte_vhost_driver_register(dev_pathname, 0) != 0) { fprintf(stderr, "socket %s already exists\n", dev_pathname); @@ -1040,8 +1036,7 @@ signal_handler(__rte_unused int signum) { struct vhost_blk_ctrlr *ctrlr; - if (access(dev_pathname, F_OK) == 0) - unlink(dev_pathname); + unlink(dev_pathname); if (g_should_stop != -1) { g_should_stop = 1; -- 2.17.2