From: Jin Yu Date: Fri, 15 May 2020 14:45:02 +0000 (+0800) Subject: examples/vhost_blk: fix not null-terminated buffer X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=e2b4cfd6a40d9361928c60834ef676e75d9be9bd;p=dpdk.git examples/vhost_blk: fix not null-terminated buffer 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") Signed-off-by: Jin Yu Reviewed-by: Xiaolong Ye --- diff --git a/examples/vhost_blk/vhost_blk.c b/examples/vhost_blk/vhost_blk.c index 95a0508554..f4c59437a0 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;