Skip to contentSkip to conversation

qemu-img: Fix options leakage in img_rebase()

PATCH Applied Max Reitz 3 participants 5 messages May 28, 2019 – Jun 13, 2019

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

PATCH 1/1 qemu-img: Fix options leakage in img_rebase()

img_rebase() can leak a QDict in two occasions. Fix it.

Coverity: CID 1401416

Fixes d16699b64671466b42079c45b89127aeea1ca565
Fixes 330c72957196e0ae382abcaa97ebf4eb9bc8574f
---
 qemu-img.c | 3 +++
 1 file changed, 3 insertions(+)
qemu-img.c +3 -0
index b0535919b1..86e1923acf 100644
@@ -3347,6 +3347,7 @@ static int img_rebase(int argc, char **argv)
                                                              out_baseimg,
                                                              &local_err);
             if (local_err) {
+                qobject_unref(options);
                 error_reportf_err(local_err,
                                   "Could not resolve backing filename: ");
                 ret = -1;
@@ -3359,7 +3360,9 @@ static int img_rebase(int argc, char **argv)
              */
             prefix_chain_bs = bdrv_find_backing_image(bs, out_real_path);
             if (prefix_chain_bs) {
+                qobject_unref(options);
                 g_free(out_real_path);
+
                 blk_new_backing = blk_new(BLK_PERM_CONSISTENT_READ,
                                           BLK_PERM_ALL);
                 ret = blk_insert_bs(blk_new_backing, prefix_chain_bs,
Signature · 1 line
2.21.0
#1 lore raw

Am 28.05.2019 um 21:53 hat Max Reitz geschrieben:

Quoted 6 lines

img_rebase() can leak a QDict in two occasions. Fix it.

Coverity: CID 1401416

Fixes d16699b64671466b42079c45b89127aeea1ca565
Fixes 330c72957196e0ae382abcaa97ebf4eb9bc8574f

Is this based on some other patch? The second hunk doesn't apply.

Kevin

author
#2 lore raw
Quoted 9 lines · Kevin Wolf

Am 28.05.2019 um 21:53 hat Max Reitz geschrieben:

Quoted 6 lines

img_rebase() can leak a QDict in two occasions. Fix it.

Coverity: CID 1401416

Fixes d16699b64671466b42079c45b89127aeea1ca565
Fixes 330c72957196e0ae382abcaa97ebf4eb9bc8574f

Is this based on some other patch? The second hunk doesn't apply.

Yes, it’s based on 330c72957196e0ae382abcaa97ebf4eb9bc8574f, as the commit message says. At the time I sent this patch, that was just in my pull request, now it’s in master.

Max

Reviewed-by on v1 1/1
#3 lore raw
In reply to Max Reitz
Quoted 24 lines · Max Reitz

img_rebase() can leak a QDict in two occasions. Fix it.

Coverity: CID 1401416

Fixes d16699b64671466b42079c45b89127aeea1ca565
Fixes 330c72957196e0ae382abcaa97ebf4eb9bc8574f
---
 qemu-img.c | 3 +++
 1 file changed, 3 insertions(+)
qemu-img.c +1 -0
index b0535919b1..86e1923acf 100644
@@ -3347,6 +3347,7 @@ static int img_rebase(int argc, char **argv)
                                                              out_baseimg,
                                                              &local_err);
             if (local_err) {
+                qobject_unref(options);
                 error_reportf_err(local_err,
                                   "Could not resolve backing filename: ");
                 ret = -1;

qemu-img.c static int img_rebase(int argc, char **argv) · line 3368

Quoted 9 lines
qemu-img.c +2 -0
@@ -3359,7 +3360,9 @@ static int img_rebase(int argc, char **argv)
              */
             prefix_chain_bs = bdrv_find_backing_image(bs, out_real_path);
             if (prefix_chain_bs) {
+                qobject_unref(options);
                 g_free(out_real_path);
+
                 blk_new_backing = blk_new(BLK_PERM_CONSISTENT_READ,
                                           BLK_PERM_ALL);
                 ret = blk_insert_bs(blk_new_backing, prefix_chain_bs,

I was going to ask about the other branch after this one, but:
"The reference to the QDict belongs to the block layer after the call (even on failure)"

"Oh, well... OK."

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

img_rebase() can leak a QDict in two occasions. Fix it.

Coverity: CID 1401416

Fixes d16699b64671466b42079c45b89127aeea1ca565
Fixes 330c72957196e0ae382abcaa97ebf4eb9bc8574f
---
 qemu-img.c | 3 +++
 1 file changed, 3 insertions(+)

Applied to my block branch.

Max