example/vhost_blk: fix buffer not null terminated
PATCH 1/1 example/vhost_blk: fix buffer not null terminated
Fix the potential bug.
--- examples/vhost_blk/vhost_blk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
examples/vhost_blk/vhost_blk.c +3 -2
@@ -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;
Signature · 1 line
2.17.2
Quoted 1 line · Jin Yu
Fix the potential bug.
Could you describe more about the potential bug?
Fixes tag is needed here.
Thanks,
Xiaolong
Quoted 25 lines
Signed-off-by Jin Yu <[email protected]>---
examples/vhost_blk/vhost_blk.c| 5 +++--1 file changed, 3 insertions(+), 2 deletions(-)examples/vhost_blk/vhost_blk.c +3
-2@@ -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;Signature · 1 line
2.17.2
PATCH v2 1/1 example/vhost_blk: fix buffer not null terminated
In reply to Jin YuIn 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.
---
V2 - update the commit message
--- examples/vhost_blk/vhost_blk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
examples/vhost_blk/vhost_blk.c +3 -2
@@ -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;
Signature · 1 line
2.17.2
Quoted 33 lines · Jin Yu
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 <[email protected]>---
V2 - update the commit message
---examples/vhost_blk/vhost_blk.c| 5 +++--1 file changed, 3 insertions(+), 2 deletions(-)examples/vhost_blk/vhost_blk.c +3
-2@@ -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;Signature · 1 line
2.17.2
Maxime Coquelin
AppliedQuoted 7 lines · Jin Yu
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")
Quoted 6 lines
Signed-off-by Jin Yu <[email protected]>---
V2 - update the commit message--- examples/vhost_blk/vhost_blk.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
Applied to dpdk-next-virtio/master.
Thanks,
Maxime