* [Qemu-devel] [PATCH] qemu-io-cmds: Assert that global and nofile commands don't use ct->perms
@ 2017-03-31 13:38 Peter Maydell
2017-03-31 14:07 ` Max Reitz
0 siblings, 1 reply; 2+ messages in thread
From: Peter Maydell @ 2017-03-31 13:38 UTC (permalink / raw)
To: qemu-devel; +Cc: patches, Kevin Wolf, Max Reitz, qemu-block
It would be a bug for a command with the CMD_NOFILE_OK or
CMD_FLAG_GLOBAL flags set to also set the ct->perms field,
because the former says "OK for a file not to be open"
but the latter is a check on a file.
Add an assertion in qemuio_add_command() so we can catch that
sort of buggy command definition immediately rather than it
being a bug that only manifests when a particular set of
command line options is used.
(Coverity gets confused about this (CID 1371723) and reports
that we might dereference a NULL blk pointer in this case,
because it can't tell that that code path never happens with
the cmdinfo_t that we have. This commit won't help unconfuse
it, but it does fix the underlying issue.)
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
We could also try to add some kind of assert in command() to
persuade coverity that it can't get there with a NULL block
and ct->perms non-zero, but I think I'd rather just mark the
issue as a false-positive and move on.
qemu-io-cmds.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 2c48f9c..883f53b 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -35,6 +35,13 @@ static int compare_cmdname(const void *a, const void *b)
void qemuio_add_command(const cmdinfo_t *ci)
{
+ /* ci->perm assumes a file is open, but the GLOBAL and NOFILE_OK
+ * flags allow it not to be, so that combination is invalid.
+ * Catch it now rather than letting it manifest as a crash if a
+ * particular set of command line options are used.
+ */
+ assert(ci->perm == 0 ||
+ (ci->flags & (CMD_FLAG_GLOBAL | CMD_NOFILE_OK)) == 0);
cmdtab = g_renew(cmdinfo_t, cmdtab, ++ncmds);
cmdtab[ncmds - 1] = *ci;
qsort(cmdtab, ncmds, sizeof(*cmdtab), compare_cmdname);
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] qemu-io-cmds: Assert that global and nofile commands don't use ct->perms
2017-03-31 13:38 [Qemu-devel] [PATCH] qemu-io-cmds: Assert that global and nofile commands don't use ct->perms Peter Maydell
@ 2017-03-31 14:07 ` Max Reitz
0 siblings, 0 replies; 2+ messages in thread
From: Max Reitz @ 2017-03-31 14:07 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: patches, Kevin Wolf, qemu-block
[-- Attachment #1: Type: text/plain, Size: 1404 bytes --]
On 31.03.2017 15:38, Peter Maydell wrote:
> It would be a bug for a command with the CMD_NOFILE_OK or
> CMD_FLAG_GLOBAL flags set to also set the ct->perms field,
> because the former says "OK for a file not to be open"
> but the latter is a check on a file.
>
> Add an assertion in qemuio_add_command() so we can catch that
> sort of buggy command definition immediately rather than it
> being a bug that only manifests when a particular set of
> command line options is used.
>
> (Coverity gets confused about this (CID 1371723) and reports
> that we might dereference a NULL blk pointer in this case,
> because it can't tell that that code path never happens with
> the cmdinfo_t that we have. This commit won't help unconfuse
> it, but it does fix the underlying issue.)
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> We could also try to add some kind of assert in command() to
> persuade coverity that it can't get there with a NULL block
> and ct->perms non-zero, but I think I'd rather just mark the
> issue as a false-positive and move on.
I think having the assertion in qemuio_add_command() is nicer because if
we break it we will definitely notice just by launching qemu-io.
> qemu-io-cmds.c | 7 +++++++
> 1 file changed, 7 insertions(+)
Thanks, applied to my block branch:
https://github.com/XanClic/qemu/commits/block
Max
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 512 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-03-31 14:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-31 13:38 [Qemu-devel] [PATCH] qemu-io-cmds: Assert that global and nofile commands don't use ct->perms Peter Maydell
2017-03-31 14:07 ` Max Reitz
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.