]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
qemu-options: Bail out on unsupported options instead of silently ignoring them
authorThomas Huth <thuth@redhat.com>
Fri, 4 May 2018 17:01:07 +0000 (19:01 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 8 May 2018 22:13:39 +0000 (00:13 +0200)
The dangling remainder of the -tdf option revealed a deficiency in our
option parsing: Options that have been declared, but are not supported
in the switch-case statement in vl.c and not handled in the OS-specifc
os_parse_cmd_args() functions are currently silently ignored. We should
rather tell the users that they specified something that we can not
handle, so let's print an error message and exit instead.

Reported-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-Id: <1525453270-23074-3-git-send-email-thuth@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
include/qemu-common.h
os-posix.c
os-win32.c
vl.c

index 8a4f63c9def2af387aa19398e83a4b387e71ccb1..85f4749aefb73a5e19d2da5a7e930cc05c640c04 100644 (file)
@@ -137,7 +137,7 @@ char *qemu_find_file(int type, const char *name);
 /* OS specific functions */
 void os_setup_early_signal_handling(void);
 char *os_find_datadir(void);
-void os_parse_cmd_args(int index, const char *optarg);
+int os_parse_cmd_args(int index, const char *optarg);
 
 #include "qemu/module.h"
 
index 24eb7007dcabc0d15ecd1c734049bdccfeba9c6f..9ce6f74513020cea1fe6996d5f130767c7103c5d 100644 (file)
@@ -165,7 +165,7 @@ static bool os_parse_runas_uid_gid(const char *optarg)
  * Parse OS specific command line options.
  * return 0 if option handled, -1 otherwise
  */
-void os_parse_cmd_args(int index, const char *optarg)
+int os_parse_cmd_args(int index, const char *optarg)
 {
     switch (index) {
 #ifdef CONFIG_SLIRP
@@ -199,7 +199,11 @@ void os_parse_cmd_args(int index, const char *optarg)
         fips_set_state(true);
         break;
 #endif
+    default:
+        return -1;
     }
+
+    return 0;
 }
 
 static void change_process_uid(void)
index 586a7c7d49374002fef4a7671262749d1dcb9bd2..0674f94b573fb1bcd6c4c0e641f9dd9f4e71bbf8 100644 (file)
@@ -93,9 +93,9 @@ void os_set_line_buffering(void)
  * Parse OS specific command line options.
  * return 0 if option handled, -1 otherwise
  */
-void os_parse_cmd_args(int index, const char *optarg)
+int os_parse_cmd_args(int index, const char *optarg)
 {
-    return;
+    return -1;
 }
 
 int qemu_create_pidfile(const char *filename)
diff --git a/vl.c b/vl.c
index b928e3e439e4203124468df0d35d072e92938ed6..a23acb2861d1886f9d54014676a4ee0728db6a85 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -4033,7 +4033,10 @@ int main(int argc, char **argv, char **envp)
                 }
                 break;
             default:
-                os_parse_cmd_args(popt->index, optarg);
+                if (os_parse_cmd_args(popt->index, optarg)) {
+                    error_report("Option not supported in this build");
+                    exit(1);
+                }
             }
         }
     }