]> git.proxmox.com Git - qemu.git/commit
qapi: qapi-commands: fix possible leaks on visitor dealloc
authorLuiz Capitulino <lcapitulino@redhat.com>
Thu, 11 Jul 2013 18:26:56 +0000 (14:26 -0400)
committerMichael Roth <mdroth@linux.vnet.ibm.com>
Tue, 13 Aug 2013 00:07:43 +0000 (19:07 -0500)
commitaa83f2e4271de7710ad40bc2e103cf562639c173
tree115fa8a15ab3dc7d567713bfe60b885a863bc275
parenta5d14facb1e4ef354b0a819e159e5f4564fbd15e
qapi: qapi-commands: fix possible leaks on visitor dealloc

In qmp-marshal.c the dealloc visitor calls use the same errp
pointer of the input visitor calls. This means that if any of
the input visitor calls fails, then the dealloc visitor will
return early, before freeing the object's memory.

Here's an example, consider this code:

int qmp_marshal_input_block_passwd(Monitor *mon, const QDict *qdict, QObject **ret)
{
[...]

    char * device = NULL;
    char * password = NULL;

    mi = qmp_input_visitor_new_strict(QOBJECT(args));
    v = qmp_input_get_visitor(mi);
    visit_type_str(v, &device, "device", errp);
    visit_type_str(v, &password, "password", errp);
    qmp_input_visitor_cleanup(mi);

    if (error_is_set(errp)) {
        goto out;
    }
    qmp_block_passwd(device, password, errp);

out:
    md = qapi_dealloc_visitor_new();
    v = qapi_dealloc_get_visitor(md);
    visit_type_str(v, &device, "device", errp);
    visit_type_str(v, &password, "password", errp);
    qapi_dealloc_visitor_cleanup(md);

[...]

    return 0;
}

Consider errp != NULL when the out label is reached, we're going
to leak device and password.

This patch fixes this by always passing errp=NULL for dealloc
visitors, meaning that we always try to free them regardless of
any previous failure. The above example would then be:

out:
    md = qapi_dealloc_visitor_new();
    v = qapi_dealloc_get_visitor(md);
    visit_type_str(v, &device, "device", NULL);
    visit_type_str(v, &password, "password", NULL);
    qapi_dealloc_visitor_cleanup(md);

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
(cherry picked from commit 8f91ad8a1b4702966d91ea58cd90bbde1faea1b3)

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
scripts/qapi-commands.py