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 11FDBA00C3; Fri, 15 May 2020 09:07:06 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CFA821DA19; Fri, 15 May 2020 09:07:05 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 0B0121D9D8 for ; Fri, 15 May 2020 09:07:03 +0200 (CEST) IronPort-SDR: EzIK1k4zEMRvdsg0yqTDkDwev74VnGi7y2Gl/Mf//+u5dUr1ikYeiGgKG7j5edXJAJhxoJxbgo gZAIp0C6860Q== 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; 15 May 2020 00:07:03 -0700 IronPort-SDR: mU3E50xqIw64dXvU4KFgf5Kc58hmHmTDGg9NFqc1U1flb6dqIeEOntABbraywqeCEcJmtmI8Ib wRGmXcwlN0mw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,394,1583222400"; d="scan'208";a="410381281" Received: from storage36.sh.intel.com ([10.67.111.10]) by orsmga004.jf.intel.com with ESMTP; 15 May 2020 00:06:58 -0700 From: Jin Yu To: Maxime Coquelin , Zhihong Wang , Xiaolong Ye Cc: dev@dpdk.org, Jin Yu Date: Fri, 15 May 2020 22:45:02 +0800 Message-Id: <20200515144502.14043-1-jin.yu@intel.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200508130254.39929-1-jin.yu@intel.com> References: <20200508130254.39929-1-jin.yu@intel.com> Subject: [dpdk-dev] [PATCH v2] example/vhost_blk: fix buffer not null terminated 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" In vhost_blk_bdev_construct: The string buffer may not have a null terminator if the source string's length is equal to the buffer size. Fixes: 91d3e2d42997 ("examples/vhost_blk: refactor to increase readability") Cc: jin.yu@intel.com Signed-off-by: Jin Yu --- V2 - update the commit message --- examples/vhost_blk/vhost_blk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/vhost_blk/vhost_blk.c b/examples/vhost_blk/vhost_blk.c index 95a050855..f4c59437a 100644 --- a/examples/vhost_blk/vhost_blk.c +++ b/examples/vhost_blk/vhost_blk.c @@ -750,8 +750,9 @@ vhost_blk_bdev_construct(const char *bdev_name, if (!bdev) return NULL; - strncpy(bdev->name, bdev_name, sizeof(bdev->name)); - strncpy(bdev->product_name, bdev_serial, sizeof(bdev->product_name)); + snprintf(bdev->name, sizeof(bdev->name), "%s", bdev_name); + snprintf(bdev->product_name, sizeof(bdev->product_name), "%s", + bdev_serial); bdev->blocklen = blk_size; bdev->blockcnt = blk_cnt; bdev->write_cache = wce_enable; -- 2.17.2