Commit c6e0bd9b authored by Kevin Wolf's avatar Kevin Wolf
Browse files

blockdev: Fix NULL pointer dereference in blockdev-add



If aio=native, we check that cache.direct is set as well. If however
cache wasn't specified at all, qemu just segfaulted.

The old condition didn't make any sense anyway because it effectively
only checked for the default cache mode case, but not for an explicitly
set cache.direct=off mode.

Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Reviewed-by: default avatarBenoit Canet <benoit@irqsave.net>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
parent 8ae8e904
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -2283,8 +2283,10 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
     *
     * For now, simply forbidding the combination for all drivers will do. */
    if (options->has_aio && options->aio == BLOCKDEV_AIO_OPTIONS_NATIVE) {
        bool direct = options->cache->has_direct && options->cache->direct;
        if (!options->has_cache && !direct) {
        bool direct = options->has_cache &&
                      options->cache->has_direct &&
                      options->cache->direct;
        if (!direct) {
            error_setg(errp, "aio=native requires cache.direct=true");
            goto fail;
        }