• M
    qapi: add visit_start_union and visit_end_union · 96c6cf6d
    Michael Roth 提交于
    In some cases an input visitor might bail out on filling out a
    struct for various reasons, such as missing fields when running
    in strict mode. In the case of a QAPI Union type, this may lead
    to cases where the .kind field which encodes the union type
    is uninitialized. Subsequently, other visitors, such as the
    dealloc visitor, may use this .kind value as if it were
    initialized, leading to assumptions about the union type which
    in this case may lead to segfaults. For example, freeing an
    integer value.
    
    However, we can generally rely on the fact that the always-present
    .data void * field that we generate for these union types will
    always be NULL in cases where .kind is uninitialized (at least,
    there shouldn't be a reason where we'd do this purposefully).
    
    So pass this information on to Visitor implementation via these
    optional start_union/end_union interfaces so this information
    can be used to guard against the situation above. We will make
    use of this information in a subsequent patch for the dealloc
    visitor.
    
    Cc: qemu-stable@nongnu.org
    Reported-by: NFam Zheng <famz@redhat.com>
    Suggested-by: NPaolo Bonzini <pbonzini@redhat.com>
    Reviewed-by: NPaolo Bonzini <pbonzini@redhat.com>
    Reviewed-by: NEric Blake <eblake@redhat.com>
    Signed-off-by: NMichael Roth <mdroth@linux.vnet.ibm.com>
    Signed-off-by: NLuiz Capitulino <lcapitulino@redhat.com>
    (cherry picked from commit cee2dedb)
    Signed-off-by: NMichael Roth <mdroth@linux.vnet.ibm.com>
    96c6cf6d
qapi-visit-core.c 7.5 KB