qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-trivial] [PATCH v2 1/5] qemu-char: fix parameter check for some qe


From: zhanghailiang
Subject: [Qemu-trivial] [PATCH v2 1/5] qemu-char: fix parameter check for some qemu_chr_parse_* functions
Date: Mon, 3 Nov 2014 17:44:28 +0800

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 <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]