Skip to contentSkip to conversation

block/amend: Check whether the node exists

PATCH Applied Max Reitz 3 participants 5 messages Jul 10, 2020 – Jul 24, 2020 Block layer

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

PATCH 1/1 block/amend: Check whether the node exists

We should check whether the user-specified node-name actually refers to a node. The simplest way to do that is to use bdrv_lookup_bs() instead of bdrv_find_node() (the former wraps the latter, and produces an error message if necessary).

Reported-by Coverity (CID 1430268)
Fixes ced914d0ab9fb2c900f873f6349a0b8eecd1fdbe
---
 block/amend.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
block/amend.c +5 -1
index f4612dcf08..392df9ef83 100644
@@ -69,8 +69,12 @@ void qmp_x_blockdev_amend(const char *job_id,
     BlockdevAmendJob *s;
     const char *fmt = BlockdevDriver_str(options->driver);
     BlockDriver *drv = bdrv_find_format(fmt);
-    BlockDriverState *bs = bdrv_find_node(node_name);
+    BlockDriverState *bs;
 
+    bs = bdrv_lookup_bs(NULL, node_name, errp);
+    if (!bs) {
+        return;
+    }
 
     if (!drv) {
         error_setg(errp, "Block driver '%s' not found or not supported", fmt);
Signature · 1 line
2.26.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Max Reitz

We should check whether the user-specified node-name actually refers to a node. The simplest way to do that is to use bdrv_lookup_bs() instead of bdrv_find_node() (the former wraps the latter, and produces an error message if necessary).

Reported-by Coverity (CID 1430268)
Fixes ced914d0ab9fb2c900f873f6349a0b8eecd1fdbe
---
 block/amend.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
block/amend.c +0 -0
index f4612dcf08..392df9ef83 100644
@@ -69,8 +69,12 @@ void qmp_x_blockdev_amend(const char *job_id,
     BlockdevAmendJob *s;
     const char *fmt = BlockdevDriver_str(options->driver);
     BlockDriver *drv = bdrv_find_format(fmt);

block/amend.c void qmp_x_blockdev_amend(const char *job_id, · line 80

Quoted 10 lines
block/amend.c +5 -1
-    BlockDriverState *bs = bdrv_find_node(node_name);
+    BlockDriverState *bs;
 
+    bs = bdrv_lookup_bs(NULL, node_name, errp);
+    if (!bs) {
+        return;
+    }
 
     if (!drv) {
         error_setg(errp, "Block driver '%s' not found or not supported", fmt);

Yep, this looks like a real bug, sorry about that.

Best regards,
Maxim Levitsky

#2 lore raw
In reply to Max Reitz
Quoted 9 lines · Max Reitz

We should check whether the user-specified node-name actually refers to a node. The simplest way to do that is to use bdrv_lookup_bs() instead of bdrv_find_node() (the former wraps the latter, and produces an error message if necessary).

Reported-by Coverity (CID 1430268)
Fixes ced914d0ab9fb2c900f873f6349a0b8eecd1fdbe

Hi; has this patch got lost? (I'm just running through the Coverity issues marked as fix-submitted to check the patches made it into master, and it looks like this one hasn't yet.)

thanks
-- PMM

author
#3 lore raw
Quoted 7 lines · Peter Maydell
Quoted 6 lines · Max Reitz

We should check whether the user-specified node-name actually refers to a node. The simplest way to do that is to use bdrv_lookup_bs() instead of bdrv_find_node() (the former wraps the latter, and produces an error message if necessary).

Quoted 7 lines
Quoted 3 lines
Reported-by Coverity (CID 1430268)
Fixes ced914d0ab9fb2c900f873f6349a0b8eecd1fdbe

Hi; has this patch got lost? (I'm just running through the Coverity issues marked as fix-submitted to check the patches made it into master, and it looks like this one hasn't yet.)

Well, not strictly speaking lost, but I did forget to merge it, yes. Thanks for the reminder!

Max

author Applied
#4 lore raw
In reply to Max Reitz
Quoted 11 lines · Max Reitz

We should check whether the user-specified node-name actually refers to a node. The simplest way to do that is to use bdrv_lookup_bs() instead of bdrv_find_node() (the former wraps the latter, and produces an error message if necessary).

Reported-by Coverity (CID 1430268)
Fixes ced914d0ab9fb2c900f873f6349a0b8eecd1fdbe
---
 block/amend.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Applied to my block branch.