example/vhost_blk: fix buffer not null terminated

Message ID 20200508130254.39929-1-jin.yu@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series example/vhost_blk: fix buffer not null terminated |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-nxp-Performance success Performance Testing PASS
ci/travis-robot warning Travis build: failed
ci/Intel-compilation fail Compilation issues
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-testing fail Testing issues

Commit Message

Jin Yu May 8, 2020, 1:02 p.m. UTC
  Fix the potential bug.

Signed-off-by: Jin Yu <jin.yu@intel.com>
---
 examples/vhost_blk/vhost_blk.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Comments

Xiaolong Ye May 8, 2020, 8:43 a.m. UTC | #1
On 05/08, Jin Yu wrote:
>Fix the potential bug.

Could you describe more about the potential bug?

Fixes tag is needed here.

Thanks,
Xiaolong
>
>Signed-off-by: Jin Yu <jin.yu@intel.com>
>---
> 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 f08473f58..b5ce3332a 100644
>--- a/examples/vhost_blk/vhost_blk.c
>+++ b/examples/vhost_blk/vhost_blk.c
>@@ -757,8 +757,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
>
  

Patch

diff --git a/examples/vhost_blk/vhost_blk.c b/examples/vhost_blk/vhost_blk.c
index f08473f58..b5ce3332a 100644
--- a/examples/vhost_blk/vhost_blk.c
+++ b/examples/vhost_blk/vhost_blk.c
@@ -757,8 +757,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;