From patchwork Mon Oct 25 05:39:59 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 69066 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1AE2AB70A8 for ; Mon, 25 Oct 2010 16:41:19 +1100 (EST) Received: from localhost ([127.0.0.1]:36888 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PAFo4-0006gU-4N for incoming@patchwork.ozlabs.org; Mon, 25 Oct 2010 01:41:16 -0400 Received: from [140.186.70.92] (port=43083 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PAFnA-0006gM-Mu for qemu-devel@nongnu.org; Mon, 25 Oct 2010 01:40:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PAFn9-0001gm-In for qemu-devel@nongnu.org; Mon, 25 Oct 2010 01:40:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10009) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PAFn9-0001gY-BQ for qemu-devel@nongnu.org; Mon, 25 Oct 2010 01:40:19 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9P5eHlJ022305 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 25 Oct 2010 01:40:17 -0400 Received: from dhcp-91-7.nay.redhat.com.englab.nay.redhat.com (dhcp-91-7.nay.redhat.com [10.66.91.7]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id o9P5eElQ000575; Mon, 25 Oct 2010 01:40:15 -0400 To: qemu-devel@nongnu.org, mst@redhat.com From: Jason Wang Date: Mon, 25 Oct 2010 13:39:59 +0800 Message-ID: <20101025053959.10150.69081.stgit@dhcp-91-7.nay.redhat.com.englab.nay.redhat.com> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: lcapitulino@redhat.com Subject: [Qemu-devel] [V3 PATCH] net: properly handle illegal fd/vhostfd from command line X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 . Signed-off-by: Jason Wang Reviewed-by: Luiz Capitulino --- net.c | 16 +++++++++++----- 1 files changed, 11 insertions(+), 5 deletions(-) diff --git a/net.c b/net.c index ed74c7f..c5e6063 100644 --- 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,