qemu-e2k/scripts
Marc-André Lureau a0067da157 qapi: check invalid arguments on no-args commands
The generated marshal functions do not visit arguments from commands
that take no arguments. Thus they fail to catch invalid
members. Visit the arguments, if provided, to throw an error in case of
invalid members.

Currently, qmp_check_client_args() checks for invalid arguments and
correctly catches this case. When switching to qmp_dispatch() we want to
keep that behaviour. The commands using 'O' may have arbitrary
arguments, and must have 'gen': false in the qapi schema to skip the
generated checks.

Old/new diff:
 void qmp_marshal_stop(QDict *args, QObject **ret, Error **errp)
 {
     Error *err = NULL;
+    Visitor *v = NULL;

-    (void)args;
+    if (args) {
+        v = qmp_input_visitor_new(QOBJECT(args), true);
+        visit_start_struct(v, NULL, NULL, 0, &err);
+        if (err) {
+            goto out;
+        }
+
+        if (!err) {
+            visit_check_struct(v, &err);
+        }
+        visit_end_struct(v, NULL);
+        if (err) {
+            goto out;
+        }
+    }

     qmp_stop(&err);
+
+out:
     error_propagate(errp, err);
+    visit_free(v);
+    if (args) {
+        v = qapi_dealloc_visitor_new();
+        visit_start_struct(v, NULL, NULL, 0, NULL);
+
+        visit_end_struct(v, NULL);
+        visit_free(v);
+    }
 }

The new code closely resembles code for a command with arguments.
Differences:
- the visit of the argument and its cleanup struct don't visit any
  members (because there are none).
- the visit of the argument struct and its cleanup are conditional.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20160912091913.15831-14-marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-09-19 17:32:22 +02:00
..
coccinelle coccinelle: add a script to remove useless casts 2016-09-15 15:32:22 +03:00
kvm vmxcap: Add TSC scaling bit 2016-09-13 19:08:46 +02:00
qemu-guest-agent qemu-ga: sample fsfreeze hooks 2013-01-08 16:38:12 -06:00
qemugdb scripts/gdb: Fix a python exception in mtree.py 2015-12-22 16:01:08 +08:00
qmp scripts: ensure monitor socket has SO_REUSEADDR set 2016-07-22 13:23:35 +05:30
tracetool trace: add syslog tracing backend 2016-09-05 13:47:01 -04:00
analyse-9p-simpletrace.py scripts/analyse-9p-simpletrace.py: Add symbolic names for 9p operations. 2011-12-21 12:37:23 +05:30
analyze-inclusions scripts: add script to build QEMU and analyze inclusions 2016-05-19 12:09:28 +02:00
analyze-migration.py migration: fix analyze-migration.py script 2015-11-04 13:40:13 +01:00
check-qerror.sh qerror: add check-qerror.sh to verify alphabetical order 2012-01-18 10:23:39 -02:00
checkpatch.pl checkpatch: Fix whitespace checks for documentation code blocks 2016-09-13 19:09:44 +02:00
clean-header-guards.pl scripts: New clean-header-guards.pl 2016-07-12 16:19:16 +02:00
clean-includes os-posix: include sys/mman.h 2016-06-16 18:39:03 +02:00
cleanup-trace-events.pl cleanup-trace-events.pl: Tighten search for trace event call 2014-09-26 09:34:38 +01:00
cocci-macro-file.h coccinelle: add g_assert_cmp* to macro file 2016-05-23 16:53:46 +02:00
coverity-model.c coverity: Model g_memdup() 2015-12-17 17:33:49 +01:00
create_config build-sys: define QEMU_VERSION_{MAJOR, MINOR, MICRO} 2016-09-19 17:32:21 +02:00
disas-objdump.pl disas-objdump: Pass --adjust-vma to objdump 2013-08-24 07:26:45 +02:00
dump-guest-memory.py exec: hide mr->ram_addr from qemu_get_ram_ptr users 2016-05-29 09:11:12 +02:00
extract-vsssdk-headers Add a script to extract VSS SDK headers on POSIX system 2013-09-09 14:17:56 -05:00
feature_to_c.sh scripts: Use $(..) instead of deprecated `..` 2016-06-07 18:19:23 +03:00
get_maintainer.pl get_maintainer.pl: fall back to git if only lists are found 2016-02-09 17:07:55 +01:00
gtester-cat test makefile overhaul 2012-03-30 08:14:11 -05:00
hxtool vl.c: In qemu -h output, only print options for the arch we are running as 2011-12-19 10:27:33 -06:00
make-release make-release: Record SeaBIOS version 2014-03-31 15:02:04 +01:00
make_device_config.sh scripts: Use $(..) instead of deprecated `..` 2016-06-07 18:19:23 +03:00
ordereddict.py qapi: Clean up qapi.py per pep8 2015-10-12 18:44:54 +02:00
qapi-commands.py qapi: check invalid arguments on no-args commands 2016-09-19 17:32:22 +02:00
qapi-event.py qapi: Implement boxed types for commands/events 2016-07-19 13:21:08 +02:00
qapi-introspect.py qapi: Plumb in 'boxed' to qapi generator lower levels 2016-07-19 13:21:08 +02:00
qapi-types.py qapi: Add type.is_empty() helper 2016-07-19 13:21:08 +02:00
qapi-visit.py qapi: Drop useless gen_err_check() 2016-07-19 13:21:08 +02:00
qapi.py qapi: Implement boxed types for commands/events 2016-07-19 13:21:08 +02:00
qemu-binfmt-conf.sh scripts: Use $(..) instead of deprecated `..` 2016-06-07 18:19:23 +03:00
qemu-gdb.py gdb command: qemu handlers 2015-10-29 17:59:27 +00:00
qemu.py iotest: fix python based IO tests 2016-07-26 18:28:40 +02:00
qtest.py iotest: fix python based IO tests 2016-07-26 18:28:40 +02:00
refresh-pxe-roms.sh roms: rewrite scripts/refresh-pxe-roms.sh 2013-09-30 09:44:35 +02:00
shaderinclude.pl opengl: add shader build infrastructure 2015-05-05 09:03:32 +02:00
signrom.py linuxboot_dma: avoid guest ABI breakage on gcc vs. clang compilation 2016-08-09 22:57:36 +02:00
simpletrace.py simpletrace: add simpletrace.py --no-header option 2014-08-12 14:26:11 +01:00
switch-timer-api misc: Fix case Qemu -> QEMU 2014-02-15 16:10:25 +04:00
texi2pod.pl scripts/text2pod.pl: Escape left brace 2015-11-02 14:50:27 +01:00
tracetool.py Revert "tracetool: use Python 2.4-compatible exception handling syntax" 2016-02-08 17:29:54 +01:00
update-linux-headers.sh scripts: Use $(..) instead of deprecated `..` 2016-06-07 18:19:23 +03:00
vmstate-static-checker.py vmstate-static-checker: fix size mismatch detection in unused fields 2016-06-17 18:24:33 +05:30