Skip to contentSkip to conversation

qemu-io-cmds: assert that we don't have .perm requested in no-blk case

PATCH Applied Vladimir Sementsov-Ogievskiy 2 participants 2 messages May 19, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu-io-cmds: assert that we don't have .perm requested in no-blk case

Coverity things blk may be NULL. It's a false-positive, as described in a new comment.

Fixes Coverity CID 1453194
---
 qemu-io-cmds.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
qemu-io-cmds.c +12 -2
index 998b67186d..3b7cceecbf 100644
@@ -92,9 +92,19 @@ static int command(BlockBackend *blk, const cmdinfo_t *ct, int argc,
         return -EINVAL;
     }
 
-    /* Request additional permissions if necessary for this command. The caller
+    /*
+     * Request additional permissions if necessary for this command. The caller
      * is responsible for restoring the original permissions afterwards if this
-     * is what it wants. */
+     * is what it wants.
+     *
+     * Coverity things that blk may be NULL in the following if condition. It's
+     * not so: in init_check_command() we fail if blk is NULL for command with
+     * both CMD_FLAG_GLOBAL and CMD_NOFILE_OK flags unset. And in
+     * qemuio_add_command() we assert that command with non-zero .perm field
+     * doesn't set this flags. So, the following assertion is to silence
+     * Coverity:
+     */
+    assert(blk || !ct->perm);
     if (ct->perm && blk_is_available(blk)) {
         uint64_t orig_perm, orig_shared_perm;
         blk_get_perm(blk, &orig_perm, &orig_shared_perm);
Signature · 1 line
2.29.2
Applied
#1 lore raw

Am 19.05.2021 um 11:05 hat Vladimir Sementsov-Ogievskiy geschrieben:

Quoted 1 line

Coverity things blk may be NULL. It's a false-positive, as described in

s/things/thinks/

Quoted 14 lines

a new comment.

Fixes Coverity CID 1453194
---
 qemu-io-cmds.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
qemu-io-cmds.c +0 -0
index 998b67186d..3b7cceecbf 100644
@@ -92,9 +92,19 @@ static int command(BlockBackend *blk, const cmdinfo_t *ct, int argc,
         return -EINVAL;

qemu-io-cmds.c static int command(BlockBackend *blk, const cmdinfo_t *ct, int argc, · line 100

Quoted 10 lines
qemu-io-cmds.c +5 -2
     }
 
-    /* Request additional permissions if necessary for this command. The caller
+    /*
+     * Request additional permissions if necessary for this command. The caller
      * is responsible for restoring the original permissions afterwards if this
-     * is what it wants. */
+     * is what it wants.
+     *
+     * Coverity things that blk may be NULL in the following if condition. It's

And here.

qemu-io-cmds.c static int command(BlockBackend *blk, const cmdinfo_t *ct, int argc, · line 110

Quoted 10 lines
qemu-io-cmds.c +7 -0
+     * not so: in init_check_command() we fail if blk is NULL for command with
+     * both CMD_FLAG_GLOBAL and CMD_NOFILE_OK flags unset. And in
+     * qemuio_add_command() we assert that command with non-zero .perm field
+     * doesn't set this flags. So, the following assertion is to silence
+     * Coverity:
+     */
+    assert(blk || !ct->perm);
     if (ct->perm && blk_is_available(blk)) {
         uint64_t orig_perm, orig_shared_perm;
         blk_get_perm(blk, &orig_perm, &orig_shared_perm);

Thanks, applied with the typo fixed up.

Kevin