]> Git Repo - qemu.git/commitdiff
qapi-commands.py: Don't call the output marshal on error
authorLuiz Capitulino <[email protected]>
Wed, 19 Oct 2011 16:51:14 +0000 (14:51 -0200)
committerLuiz Capitulino <[email protected]>
Thu, 27 Oct 2011 13:48:46 +0000 (11:48 -0200)
Today we generate something like this:

    int qmp_marshal_input_query_foo(...)

        ...

        retval = qmp_query_foo(errp);
        qmp_marshal_output_query_foo(retval, ret, errp);

        ...

However, if qmp_query_foo() fails 'retval' will probably be NULL,
which can cause a segfault as not all visitors check if 'retval'
is valid.

This commit fixes that by changing the code generator to only
call the output marshal if qmp_query_foo() succeeds, like this:

    retval = qmp_query_foo(errp);
    if (!error_is_set(errp)) {
        qmp_marshal_output_query_foo(retval, ret, errp);
    }

Signed-off-by: Luiz Capitulino <[email protected]>
scripts/qapi-commands.py

index c947ba4208c20986c6edad27e59b1d86874df90a..f7def1666273004cf914e31972c3666044126266 100644 (file)
@@ -62,7 +62,9 @@ def gen_sync_call(name, args, ret_type, indent=0):
                 name=c_var(name), args=arglist, retval=retval).rstrip()
     if ret_type:
         ret += "\n" + mcgen(''''
-%(marshal_output_call)s
+if (!error_is_set(errp)) {
+    %(marshal_output_call)s
+}
 ''',
                             marshal_output_call=gen_marshal_output_call(name, ret_type)).rstrip()
     pop_indent(indent)
This page took 0.026136 seconds and 4 git commands to generate.