Skip to contentSkip to conversation

block: An empty filename counts as no filename

PATCH Applied Max Reitz 5 participants 8 messages Apr 13, 2017 – Apr 19, 2017

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

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
author
#1 lore raw

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
index 1fbbb8d606..46da908c93 100644
@@ -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
author
#4 lore raw

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
index 630cb7a114..4fe676019b 100755
@@ -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
index 7524c62025..57bee086f0 100644
@@ -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
index c6f4eef215..19426e5eda 100644
@@ -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
Reviewed-by on the v1 series
#5 lore raw
In reply to Max Reitz
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
Reviewed-by on v1 1/2
#2 lore raw
In reply to Max Reitz

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
    name
---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block.c +0 -0
index 1fbbb8d606..46da908c93 100644

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 -0
         error_setg(errp, "The '%s' block driver requires a file name",
                    drv->format_name);
         ret = -EINVAL;
author
#3 lore raw
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
    name
---
 block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block.c +0 -0
index 1fbbb8d606..46da908c93 100644
@@ -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:

Thanks! (For your other reviews as well, of course.)

Max

Quoted 5 lines
Quoted 5 lines
block.c +0 -0
         error_setg(errp, "The '%s' block driver requires a file name",
                    drv->format_name);
         ret = -EINVAL;
Applied
#7 lore raw
In reply to Max Reitz

Am 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