block: An empty filename counts as no filename
cover block: An empty filename counts as no filename
See patch 1 for what is happening when you try "qemu-img info ''" and for the fix.
(Patch 2 just adds a simple test.)
Max Reitz (2):
block: An empty filename counts as no filename
iotests/051: Add test for empty filename
block.c | 2 +- tests/qemu-iotests/051 | 1 + tests/qemu-iotests/051.out | 3 +++ tests/qemu-iotests/051.pc.out | 3 +++ 4 files changed, 8 insertions(+), 1 deletion(-)
Signature · 1 line
2.12.2
PATCH 1/2 block: An empty filename counts as no filename
Reproducer:
$ ./qemu-img info ''
qemu-img: ./block.c:1008: bdrv_open_driver: Assertion
`!drv->bdrv_needs_filename || bs->filename[0]' failed.
[1] 26105 abort (core dumped) ./qemu-img info ''This patch fixes this to be:
$ ./qemu-img info ''
qemu-img: Could not open '': The 'file' block driver requires a file
name--- block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block.c +1 -1
@@ -1167,7 +1167,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file, filename =qdict_get_try_str (options,"filename" ); } -if (drv->bdrv_needs_filename && !filename) { +if (drv->bdrv_needs_filename && (!filename || !filename[0 ])) {error_setg (errp,"The '%s' block driver requires a file name" , drv->format_name); ret = -EINVAL ;
Signature · 1 line
2.12.2
PATCH 2/2 iotests/051: Add test for empty filename
In reply to Max Reitz--- tests/qemu-iotests/051 | 1 + tests/qemu-iotests/051.out | 3 +++ tests/qemu-iotests/051.pc.out | 3 +++ 3 files changed, 7 insertions(+)
tests/qemu-iotests/051 +1 -0
@@ -231,6 +231,7 @@ echo === Leaving out required options === echo run_qemu -drive driver=file +run_qemu -drive driver=file,filename= run_qemu -drive driver=nbd run_qemu -drive driver=raw run_qemu -drive file.driver=file
tests/qemu-iotests/051.out +3 -0
@@ -221,6 +221,9 @@ QEMU X.Y.Z monitor - type 'help' for more information Testing: -drive driver=file QEMU_PROG: -drive driver=file: The 'file' block driver requires a file name +Testing: -drive driver=file,filename= +QEMU_PROG: -drive driver=file,filename=: The 'file' block driver requires a file name + Testing: -drive driver=nbd QEMU_PROG: -drive driver=nbd: NBD server address missing
tests/qemu-iotests/051.pc.out +3 -0
@@ -319,6 +319,9 @@ QEMU X.Y.Z monitor - type 'help' for more information Testing: -drive driver=file QEMU_PROG: -drive driver=file: The 'file' block driver requires a file name +Testing: -drive driver=file,filename= +QEMU_PROG: -drive driver=file,filename=: The 'file' block driver requires a file name + Testing: -drive driver=nbd QEMU_PROG: -drive driver=nbd: NBD server address missing
Signature · 1 line
2.12.2
Quoted 9 lines · Max Reitz
See patch 1 for what is happening when you try "qemu-img info ''" and for the fix.
(Patch 2 just adds a simple test.)
Max Reitz (2):
block: An empty filename counts as no filename
iotests/051: Add test for empty filename
Agree that this is not 2.9 material (but I see you cc'd qemu-stable for 1/2 going into 2.9.1, which is fine).
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Quoted 4 lines · Max Reitz
See patch 1 for what is happening when you try "qemu-img info ''" and for the fix.
(Patch 2 just adds a simple test.)
Hi Max,
Quoted 22 lines · Max Reitz
Reproducer:
$ ./qemu-img info '' qemu-img: ./block.c:1008: bdrv_open_driver: Assertion `!drv->bdrv_needs_filename || bs->filename[0]' failed. [1] 26105 abort (core dumped) ./qemu-img info ''This patch fixes this to be:
$ ./qemu-img info '' qemu-img: Could not open '': The 'file' block driver requires a file nameCc qemu-stable <[email protected]>Signed-off-by Max Reitz <[email protected]>--- block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block.c +0
-0
block.c static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file, · line 1170
Quoted 5 lines
block.c +1
-1@@ -1167,7 +1167,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file, filename =qdict_get_try_str (options,"filename" ); } -if (drv->bdrv_needs_filename && !filename) { +if (drv->bdrv_needs_filename && (!filename || !filename[0 ])) {
What do you think about adding an inline function in "qemu/option.h" like "is_valid_[option_]filename()" to avoid this bug template?
Anyway:
Quoted 4 lines
block.c +0
-0error_setg (errp,"The '%s' block driver requires a file name" , drv->format_name); ret = -EINVAL ;
Quoted 29 lines · Philippe Mathieu-Daudé
Hi Max,
Quoted 26 lines · Max Reitz
Reproducer:
$ ./qemu-img info '' qemu-img: ./block.c:1008: bdrv_open_driver: Assertion `!drv->bdrv_needs_filename || bs->filename[0]' failed. [1] 26105 abort (core dumped) ./qemu-img info ''This patch fixes this to be:
$ ./qemu-img info '' qemu-img: Could not open '': The 'file' block driver requires a file nameCc qemu-stable <[email protected]>Signed-off-by Max Reitz <[email protected]>--- block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block.c +0
-0@@ -1167,7 +1167,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file, filename =qdict_get_try_str (options,"filename" ); }
Quoted 5 lines
block.c static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file, · line 1170
Quoted 2 lines
block.c +1
-1-if (drv->bdrv_needs_filename && !filename) { +if (drv->bdrv_needs_filename && (!filename || !filename[0 ])) {What do you think about adding an inline function in "
qemu/option.h" like "is_valid_[option_]filename()" to avoid this bug template?
Well, I won't do it now but it's a good idea and if I hit this issue again (or maybe if/when I realize how much code there is that uses constructs like this...) I'll add it.
(Although it may actually be useful with a more common name, like string_is_empty(). Unfortunately, there isn't anything like g_strlen0(), apparently...)
Quoted 2 lines
Anyway:
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Thanks! (For your other reviews as well, of course.)
Max
Quoted 5 lines
Quoted 5 lines
block.c +0
-0error_setg (errp,"The '%s' block driver requires a file name" , drv->format_name);ret = -EINVAL;
Kevin Wolf
AppliedAm 13.04.2017 um 18:06 hat Max Reitz geschrieben:
Quoted 4 lines
See patch 1 for what is happening when you try "qemu-img info ''" and for the fix.
(Patch 2 just adds a simple test.)
Thanks, applied to my block-next branch.
Kevin