OSDN Git Service

spice: add sanity check for spice ports
authorGerd Hoffmann <kraxel@redhat.com>
Thu, 7 Jul 2011 15:04:17 +0000 (17:04 +0200)
committerGerd Hoffmann <kraxel@redhat.com>
Wed, 20 Jul 2011 08:08:53 +0000 (10:08 +0200)
Make sure at least one port (port=.. or tls-port=...)
is specified.  Also apply range checks to the port numbers.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
ui/spice-core.c

index e142452..1100417 100644 (file)
@@ -480,7 +480,16 @@ void qemu_spice_init(void)
     port = qemu_opt_get_number(opts, "port", 0);
     tls_port = qemu_opt_get_number(opts, "tls-port", 0);
     if (!port && !tls_port) {
-        return;
+        fprintf(stderr, "neither port nor tls-port specified for spice.");
+        exit(1);
+    }
+    if (port < 0 || port > 65535) {
+        fprintf(stderr, "spice port is out of range");
+        exit(1);
+    }
+    if (tls_port < 0 || tls_port > 65535) {
+        fprintf(stderr, "spice tls-port is out of range");
+        exit(1);
     }
     password = qemu_opt_get(opts, "password");