]> git.proxmox.com Git - qemu.git/commitdiff
net: properly handle illegal fd/vhostfd from command line
authorJason Wang <jasowang@redhat.com>
Mon, 25 Oct 2010 05:39:59 +0000 (13:39 +0800)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 27 Oct 2010 16:54:02 +0000 (18:54 +0200)
When hanlding fd/vhostfd form command line through net_handle_fd_param(),
we need to check mon and return value of strtol() otherwise we could
get segmentation fault or invalid fd when user type an illegal fd/vhostfd.

This patch is based on the suggestions from
Luiz Capitulino <lcapitulino@redhat.com>.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
net.c

diff --git a/net.c b/net.c
index ed74c7f103bceb938c2c2a9336a7ad305b2d060c..c5e6063fcf24c0aabe7606f3e7238eb9fb701057 100644 (file)
--- a/net.c
+++ b/net.c
@@ -774,19 +774,25 @@ int qemu_find_nic_model(NICInfo *nd, const char * const *models,
 
 int net_handle_fd_param(Monitor *mon, const char *param)
 {
-    if (!qemu_isdigit(param[0])) {
-        int fd;
+    int fd;
+
+    if (!qemu_isdigit(param[0]) && mon) {
 
         fd = monitor_get_fd(mon, param);
         if (fd == -1) {
             error_report("No file descriptor named %s found", param);
             return -1;
         }
-
-        return fd;
     } else {
-        return strtol(param, NULL, 0);
+        char *endptr = NULL;
+
+        fd = strtol(param, &endptr, 10);
+        if (*endptr || (fd == 0 && param == endptr)) {
+            return -1;
+        }
     }
+
+    return fd;
 }
 
 static int net_init_nic(QemuOpts *opts,