qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [RESEND PATCH] monitor: properly handle illegal fd/vhostfd from command line
@ 2010-10-21 11:29 Jason Wang
  2010-10-22 12:44 ` [Qemu-devel] " Luiz Capitulino
  0 siblings, 1 reply; 2+ messages in thread
From: Jason Wang @ 2010-10-21 11:29 UTC (permalink / raw)
  To: qemu-devel; +Cc: lcapitulino, mst

When hanlding fd/vhostfd form command line through net_handle_fd_param(),
we need to check mon and return value of strtol() other than 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>
---
 net.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/net.c b/net.c
index ed74c7f..ab9c3bb 100644
--- a/net.c
+++ b/net.c
@@ -774,8 +774,8 @@ 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) {
@@ -785,7 +785,13 @@ int net_handle_fd_param(Monitor *mon, const char *param)
 
         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;
     }
 }
 

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-10-22 12:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-21 11:29 [Qemu-devel] [RESEND PATCH] monitor: properly handle illegal fd/vhostfd from command line Jason Wang
2010-10-22 12:44 ` [Qemu-devel] " Luiz Capitulino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).