From d51457ffd135cfb8a4f1116bc3827eecb56a2905 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Mon, 8 Aug 2011 12:13:29 -0700
Subject: [RHEL6 qemu-kvm PATCH 1/7] spice: add sanity check for spice ports

RH-Author: Gerd Hoffmann <kraxel@redhat.com>
Message-id: <1312805609-9379-3-git-send-email-kraxel@redhat.com>
Patchwork-id: 31066
O-Subject: [RHEL-6.2 kvm PATCH 2/2] spice: add sanity check for spice ports
Bugzilla: 715582 717958
RH-Acked-by: Alon Levy <alevy@redhat.com>
RH-Acked-by: Yonit Halperin <yhalperi@redhat.com>
RH-Acked-by: Arnon Gilboa <agilboa@redhat.com>

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>
(cherry picked from commit df9cb669425051f4f4364cffb19c9b8089e04297)

bugzilla: 717958 - qemu-kvm start vnc even though -spice ... is supplied
bugzilla: 715582 - qemu-kvm doesn't report error when supplied negative
                   spice port value
---
 ui/spice-core.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 ui/spice-core.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/ui/spice-core.c b/ui/spice-core.c
index 2d2729d..03167a6 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -509,7 +509,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");
 
-- 
1.7.3.2