[dpdk-dev] [PATCH v2] example/vhost_blk: fix buffer not null terminated
Jin Yu
jin.yu at intel.com
Fri May 15 16:45:02 CEST 2020
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 at intel.com
Signed-off-by: Jin Yu <jin.yu at intel.com>
---
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
More information about the dev
mailing list