tapdisk2: initialize 'name' parameter of BLKTAP2_IOCTL_CREATE_DEVICE
PATCH 1/1 tapdisk2: initialize 'name' parameter of BLKTAP2_IOCTL_CREATE_DEVICE
This keeps the kernel driver from printing garbage.
tools/blktap2/drivers/tapdisk-control.c +1 -0
@@ -462,6 +462,7 @@ tapdisk_control_open_image(struct tapdis params.capacity = image.size; params.sector_size = image.secsize; +strncpy (params.name, vbd->name,BLKTAP2_MAX_MESSAGE_LEN ); err =ioctl (vbd->ring.fd,BLKTAP2_IOCTL_CREATE_DEVICE , ¶ms);if (err && errno !=EEXIST ) {
tapdisk2: initialize 'name' parameter of BLKTAP2_IOCTL_CREATE_DEVICE
This keeps the kernel driver from printing garbage.
tools/blktap2/drivers/tapdisk-control.c +1 -0
@@ -462,6 +462,7 @@ tapdisk_control_open_image(struct tapdis params.capacity = image.size; params.sector_size = image.secsize; +strncpy (params.name, vbd->name,BLKTAP2_MAX_MESSAGE_LEN ); err =ioctl (vbd->ring.fd,BLKTAP2_IOCTL_CREATE_DEVICE , ¶ms);if (err && errno !=EEXIST ) {
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Jan Beulich writes ("[Xen-devel] [PATCH] tapdisk2: initialize 'name' parameter of BLKTAP2_IOCTL_CREATE_DEVICE"):
Quoted 1 line
This keeps the kernel driver from printing garbage.
...
Review
Quoted 1 line
(quoted diff) +1
-0+ strncpy(params.name, vbd->name, BLKTAP2_MAX_MESSAGE_LEN);
I don't think this is right. As the FM for strncpy puts it:
| Warning: If there is no null byte among the first n bytes
| of src, the string placed in dest will not be null-terminated.
An easy fix would be to memset params to 0 first.
Ian.
Quoted 11 lines
Quoted 1 line
Quoted 1 line · Ian Jackson
Jan Beulich writes ("[Xen-devel] [PATCH] tapdisk2: initialize 'name' parameter of
BLKTAP2_IOCTL_CREATE_DEVICE"):Quoted 1 line
This keeps the kernel driver from printing garbage.
...
Review
Quoted 1 line
(quoted diff) +1
-0+ strncpy(params.name, vbd->name, BLKTAP2_MAX_MESSAGE_LEN);I don't think this is right. As the FM for strncpy puts it:
| Warning: If there is no null byte among the first n bytes
| of src, the string placed in dest will not be null-terminated.
That's actually expected here - the kernel code needs to be careful about no trailing NUL anyway.
Quoted 1 line
An easy fix would be to memset params to 0 first.
That would not help at all - if src is longer than available space, then there still wouldn't be a NUL in the end. On would additionally have to subtract 1 from the size argument. But as said, all that is unnecessary.
Jan
Jan Beulich writes ("Re: [Xen-devel] [PATCH] tapdisk2: initialize 'name' parameter of BLKTAP2_IOCTL_CREATE_DEVICE"):
Quoted 5 lines
Quoted 2 lines
| Warning: If there is no null byte among the first n bytes
| of src, the string placed in dest will not be null-terminated.That's actually expected here - the kernel code needs to be careful about no trailing NUL anyway.
Oh, OK.
Quoted 5 lines
Quoted 1 line
An easy fix would be to memset params to 0 first.
That would not help at all - if src is longer than available space, then there still wouldn't be a NUL in the end. On would additionally have to subtract 1 from the size argument. But as said, all that is unnecessary.
Yes, I realised that suggestion of mine was confused.
Ian.
Jan Beulich writes ("[Xen-devel] [PATCH] tapdisk2: initialize 'name' parameter of BLKTAP2_IOCTL_CREATE_DEVICE"):
Quoted 1 line
tapdisk2: initialize 'name' parameter of
BLKTAP2_IOCTL_CREATE_DEVICE