From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XlECR-0006oo-MF for qemu-devel@nongnu.org; Mon, 03 Nov 2014 04:45:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XlECM-0000DW-Om for qemu-devel@nongnu.org; Mon, 03 Nov 2014 04:45:23 -0500 From: zhanghailiang Date: Mon, 3 Nov 2014 17:44:28 +0800 Message-ID: <1415007872-8228-2-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 1/5] qemu-char: fix parameter check for some 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 some qemu_chr_parse_* functions, we just check whether the parameter is NULL or not, not check its length. For example: qemu-system-x86_64 -chardev pipe,id=id,path= It will pass the check of NULL, and finds the error until trying to open it. So we should find the error by check its length, just like what qemu_chr_parse_udp does, it will help find what exactly is wrong. Signed-off-by: zhanghailiang --- qemu-char.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index bd0709b..04d747a 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -3419,7 +3419,7 @@ static void qemu_chr_parse_file_out(QemuOpts *opts, ChardevBackend *backend, { const char *path = qemu_opt_get(opts, "path"); - if (path == NULL) { + if (path == NULL || strlen(path) == 0) { error_setg(errp, "chardev: file: no filename given"); return; } @@ -3453,7 +3453,7 @@ static void qemu_chr_parse_parallel(QemuOpts *opts, ChardevBackend *backend, { const char *device = qemu_opt_get(opts, "path"); - if (device == NULL) { + if (device == NULL || strlen(device) == 0) { error_setg(errp, "chardev: parallel: no device path given"); return; } @@ -3466,7 +3466,7 @@ static void qemu_chr_parse_pipe(QemuOpts *opts, ChardevBackend *backend, { const char *device = qemu_opt_get(opts, "path"); - if (device == NULL) { + if (device == NULL || strlen(device) == 0) { error_setg(errp, "chardev: pipe: no device path given"); return; } @@ -3515,11 +3515,11 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, SocketAddress *addr; if (!path) { - if (!host) { + if (!host || strlen(host) == 0) { error_setg(errp, "chardev: socket: no host given"); return; } - if (!port) { + if (!port || strlen(port) == 0) { error_setg(errp, "chardev: socket: no port given"); return; } -- 1.7.12.4