[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 11/15] qemu-io-cmds: Assert that global and nofile co
From: |
Max Reitz |
Subject: |
[Qemu-block] [PULL 11/15] qemu-io-cmds: Assert that global and nofile commands don't use ct->perms |
Date: |
Mon, 3 Apr 2017 17:33:51 +0200 |
From: Peter Maydell <address@hidden>
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 <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
qemu-io-cmds.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 2c48f9ce1a..883f53b64d 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.12.1
- [Qemu-block] [PULL 02/15] nbd sockets vnc: Mark problematic address family tests TODO, (continued)
- [Qemu-block] [PULL 02/15] nbd sockets vnc: Mark problematic address family tests TODO, Max Reitz, 2017/04/03
- [Qemu-block] [PULL 01/15] block: add missed aio_context_acquire into release_drive, Max Reitz, 2017/04/03
- [Qemu-block] [PULL 04/15] io vnc sockets: Clean up SocketAddressKind switches, Max Reitz, 2017/04/03
- [Qemu-block] [PULL 03/15] char: Fix socket with "type": "vsock" address, Max Reitz, 2017/04/03
- [Qemu-block] [PULL 05/15] block: Document -drive problematic code and bugs, Max Reitz, 2017/04/03
- [Qemu-block] [PULL 06/15] gluster: Prepare for SocketAddressFlat extension, Max Reitz, 2017/04/03
- [Qemu-block] [PULL 07/15] qapi-schema: SocketAddressFlat variants 'vsock' and 'fd', Max Reitz, 2017/04/03
- [Qemu-block] [PULL 08/15] sockets: New helper socket_address_crumple(), Max Reitz, 2017/04/03
- [Qemu-block] [PULL 09/15] nbd: Tidy up blockdev-add interface, Max Reitz, 2017/04/03
- [Qemu-block] [PULL 10/15] sheepdog: Fix blockdev-add, Max Reitz, 2017/04/03
- [Qemu-block] [PULL 11/15] qemu-io-cmds: Assert that global and nofile commands don't use ct->perms,
Max Reitz <=
- [Qemu-block] [PULL 13/15] qcow2: Discard unaligned tail when wiping image, Max Reitz, 2017/04/03
- [Qemu-block] [PULL 12/15] iotests: fix 097 when run with qcow, Max Reitz, 2017/04/03
- [Qemu-block] [PULL 15/15] block/parallels: Avoid overflows, Max Reitz, 2017/04/03
- [Qemu-block] [PULL 14/15] iotests: Improve image-clear tests on non-aligned image, Max Reitz, 2017/04/03
- Re: [Qemu-block] [PULL 00/15] Block patches for rc3, Peter Maydell, 2017/04/03