From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=59137 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P9Gyu-00077q-Dl for qemu-devel@nongnu.org; Fri, 22 Oct 2010 08:44:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P9Gyt-0004sM-8d for qemu-devel@nongnu.org; Fri, 22 Oct 2010 08:44:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34977) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P9Gyt-0004sD-1y for qemu-devel@nongnu.org; Fri, 22 Oct 2010 08:44:23 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9MCiLrh031926 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 22 Oct 2010 08:44:21 -0400 Date: Fri, 22 Oct 2010 10:44:15 -0200 From: Luiz Capitulino Message-ID: <20101022104415.0cad400a@doriath> In-Reply-To: <20101021112902.2539.21785.stgit@dhcp-91-7.nay.redhat.com.englab.nay.redhat.com> References: <20101021112902.2539.21785.stgit@dhcp-91-7.nay.redhat.com.englab.nay.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [RESEND PATCH] monitor: properly handle illegal fd/vhostfd from command line List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jason Wang Cc: qemu-devel@nongnu.org, mst@redhat.com On Thu, 21 Oct 2010 19:29:02 +0800 Jason Wang wrote: > 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 . > > Signed-off-by: Jason Wang > --- > 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; Better to add a space here. > + 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; > } You can put 'return fd' here and drop the two above, also this is not a monitor patch, it's a networking one. Otherwise looks ok to me. > } > >