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: 91d3e2d429 ("examples/vhost_blk: refactor to increase readability")

Signed-off-by: Jin Yu <jin.yu@intel.com>
Reviewed-by: Xiaolong Ye <xiaolong.ye@intel.com>
This commit is contained in:
Jin Yu 2020-05-15 22:45:02 +08:00 committed by Ferruh Yigit
parent f50560a54b
commit e2b4cfd6a4

View file

@ -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;