From patchwork Thu Jul 1 19:21:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 57570 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 EBACEB70A7 for ; Fri, 2 Jul 2010 05:23:54 +1000 (EST) Received: from localhost ([127.0.0.1]:59363 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OUPMV-0006SD-BY for incoming@patchwork.ozlabs.org; Thu, 01 Jul 2010 15:23:51 -0400 Received: from [140.186.70.92] (port=37549 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OUPKq-0006Q4-CI for qemu-devel@nongnu.org; Thu, 01 Jul 2010 15:22:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OUPKi-0007H8-Q6 for qemu-devel@nongnu.org; Thu, 01 Jul 2010 15:22:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43057) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OUPKi-0007H0-I7 for qemu-devel@nongnu.org; Thu, 01 Jul 2010 15:22:00 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o61JLx6S003268 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 1 Jul 2010 15:21:59 -0400 Received: from localhost (vpn-10-238.rdu.redhat.com [10.11.10.238]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o61JLvUj015445; Thu, 1 Jul 2010 15:21:58 -0400 From: Luiz Capitulino To: aliguori@us.ibm.com Date: Thu, 1 Jul 2010 16:21:29 -0300 Message-Id: <1278012111-26227-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1278012111-26227-1-git-send-email-lcapitulino@redhat.com> References: <1278012111-26227-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Jan Kiszka , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 01/23] monitor: Fix leakage during completion processing 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 From: Jan Kiszka Given too many arguments or an invalid command, we were leaking the duplicated argument strings. Signed-off-by: Jan Kiszka Signed-off-by: Luiz Capitulino --- monitor.c | 23 +++++++++++++++-------- 1 files changed, 15 insertions(+), 8 deletions(-) diff --git a/monitor.c b/monitor.c index 170b269..42ae154 100644 --- a/monitor.c +++ b/monitor.c @@ -3882,8 +3882,9 @@ static void monitor_find_completion(const char *cmdline) next arg */ len = strlen(cmdline); if (len > 0 && qemu_isspace(cmdline[len - 1])) { - if (nb_args >= MAX_ARGS) - return; + if (nb_args >= MAX_ARGS) { + goto cleanup; + } args[nb_args++] = qemu_strdup(""); } if (nb_args <= 1) { @@ -3898,12 +3899,15 @@ static void monitor_find_completion(const char *cmdline) } } else { /* find the command */ - for(cmd = mon_cmds; cmd->name != NULL; cmd++) { - if (compare_cmd(args[0], cmd->name)) - goto found; + for (cmd = mon_cmds; cmd->name != NULL; cmd++) { + if (compare_cmd(args[0], cmd->name)) { + break; + } } - return; - found: + if (!cmd->name) { + goto cleanup; + } + ptype = next_arg_type(cmd->args_type); for(i = 0; i < nb_args - 2; i++) { if (*ptype != '\0') { @@ -3953,8 +3957,11 @@ static void monitor_find_completion(const char *cmdline) break; } } - for(i = 0; i < nb_args; i++) + +cleanup: + for (i = 0; i < nb_args; i++) { qemu_free(args[i]); + } } static int monitor_can_read(void *opaque)