qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] qemu-io-cmds: assert that we don't have .perm requested in no-blk case
@ 2021-05-19  9:05 Vladimir Sementsov-Ogievskiy
  2021-05-19 10:42 ` Kevin Wolf
  0 siblings, 1 reply; 2+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2021-05-19  9:05 UTC (permalink / raw)
  To: qemu-block
  Cc: qemu-devel, mreitz, kwolf, stefanha, Vladimir Sementsov-Ogievskiy

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

Fixes: Coverity CID 1453194
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 qemu-io-cmds.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 998b67186d..3b7cceecbf 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -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);
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] qemu-io-cmds: assert that we don't have .perm requested in no-blk case
  2021-05-19  9:05 [PATCH] qemu-io-cmds: assert that we don't have .perm requested in no-blk case Vladimir Sementsov-Ogievskiy
@ 2021-05-19 10:42 ` Kevin Wolf
  0 siblings, 0 replies; 2+ messages in thread
From: Kevin Wolf @ 2021-05-19 10:42 UTC (permalink / raw)
  To: Vladimir Sementsov-Ogievskiy; +Cc: stefanha, qemu-devel, qemu-block, mreitz

Am 19.05.2021 um 11:05 hat Vladimir Sementsov-Ogievskiy geschrieben:
> Coverity things blk may be NULL. It's a false-positive, as described in

s/things/thinks/

> a new comment.
> 
> Fixes: Coverity CID 1453194
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  qemu-io-cmds.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
> index 998b67186d..3b7cceecbf 100644
> --- a/qemu-io-cmds.c
> +++ b/qemu-io-cmds.c
> @@ -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

And here.

> +     * 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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-19 10:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-19  9:05 [PATCH] qemu-io-cmds: assert that we don't have .perm requested in no-blk case Vladimir Sementsov-Ogievskiy
2021-05-19 10:42 ` Kevin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).