From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36470) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlECK-0006d5-57 for qemu-devel@nongnu.org; Mon, 03 Nov 2014 04:45:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XlECF-0000BN-9t for qemu-devel@nongnu.org; Mon, 03 Nov 2014 04:45:16 -0500 From: zhanghailiang Date: Mon, 3 Nov 2014 17:44:30 +0800 Message-ID: <1415007872-8228-4-git-send-email-zhang.zhanghailiang@huawei.com> In-Reply-To: <1415007872-8228-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1415007872-8228-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH v2 3/5] spice-qemu-char: fix parameter checks for qemu_chr_parse_* functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-trivial@nongnu.org Cc: zhanghailiang , mjt@tls.msk.ru, peter.huangpeng@huawei.com, qemu-devel@nongnu.org, pbonzini@redhat.com For functions qemu_chr_parse_spice_vmc and qemu_chr_parse_spice_port, we should also check the length of parameter name, and it will help findind the wrong configure, such as 'qemu-system-x86_64 -chardev spiceport(or spiceport),id=id,name=' Also remove the superfluous parameter checks in qemu_chr_open_spice_* Signed-off-by: zhanghailiang --- spice-qemu-char.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/spice-qemu-char.c b/spice-qemu-char.c index 8106e06..48ee37f 100644 --- a/spice-qemu-char.c +++ b/spice-qemu-char.c @@ -290,11 +290,6 @@ CharDriverState *qemu_chr_open_spice_vmc(const char *type) { const char **psubtype = spice_server_char_device_recognized_subtypes(); - if (type == NULL) { - fprintf(stderr, "spice-qemu-char: missing name parameter\n"); - print_allowed_subtypes(); - return NULL; - } for (; *psubtype != NULL; ++psubtype) { if (strcmp(type, *psubtype) == 0) { break; @@ -315,11 +310,6 @@ CharDriverState *qemu_chr_open_spice_port(const char *name) CharDriverState *chr; SpiceCharDriver *s; - if (name == NULL) { - fprintf(stderr, "spice-qemu-char: missing name parameter\n"); - return NULL; - } - chr = chr_open("port", spice_port_set_fe_open); s = chr->opaque; s->sin.portname = g_strdup(name); @@ -345,8 +335,9 @@ static void qemu_chr_parse_spice_vmc(QemuOpts *opts, ChardevBackend *backend, { const char *name = qemu_opt_get(opts, "name"); - if (name == NULL) { + if (name == NULL || strlen(name) == 0) { error_setg(errp, "chardev: spice channel: no name given"); + print_allowed_subtypes(); return; } backend->spicevmc = g_new0(ChardevSpiceChannel, 1); @@ -358,7 +349,7 @@ static void qemu_chr_parse_spice_port(QemuOpts *opts, ChardevBackend *backend, { const char *name = qemu_opt_get(opts, "name"); - if (name == NULL) { + if (name == NULL || strlen(name) == 0) { error_setg(errp, "chardev: spice port: no name given"); return; } -- 1.7.12.4