From patchwork Sat Nov 10 13:45:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 10677139 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B8D2D15E9 for ; Sat, 10 Nov 2018 13:59:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A02BE2CEE3 for ; Sat, 10 Nov 2018 13:59:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9384E2987F; Sat, 10 Nov 2018 13:59:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 445092987F for ; Sat, 10 Nov 2018 13:59:04 +0000 (UTC) Received: from localhost ([::1]:38521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTmx-0002HA-MT for patchwork-qemu-devel@patchwork.kernel.org; Sat, 10 Nov 2018 08:59:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36770) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLTbe-0004wV-Nb for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLTbd-0001a8-TM for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38264) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gLTbd-0001Y0-NH for qemu-devel@nongnu.org; Sat, 10 Nov 2018 08:47:21 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1433B308625A; Sat, 10 Nov 2018 13:47:21 +0000 (UTC) Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5DD360C44; Sat, 10 Nov 2018 13:47:16 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Sat, 10 Nov 2018 17:45:46 +0400 Message-Id: <20181110134548.14741-12-marcandre.lureau@redhat.com> In-Reply-To: <20181110134548.14741-1-marcandre.lureau@redhat.com> References: <20181110134548.14741-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 10 Nov 2018 13:47:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.2 11/13] slirp: replace the poor-man string split with g_strsplit() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jan Kiszka , Jason Wang , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Samuel Thibault Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Use the glib function for the work, fix a potential crash on >256 words. Signed-off-by: Marc-André Lureau --- slirp/misc.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/slirp/misc.c b/slirp/misc.c index d9804f2a6d..dedc9bf6c3 100644 --- a/slirp/misc.c +++ b/slirp/misc.c @@ -130,11 +130,8 @@ err: int fork_exec(struct socket *so, const char *ex) { - const char *argv[256]; - /* don't want to clobber the original */ - char *bptr; - const char *curarg; - int opt, c, i, sp[2]; + char **argv; + int opt, c, sp[2]; pid_t pid; DEBUG_CALL("fork_exec"); @@ -161,19 +158,7 @@ fork_exec(struct socket *so, const char *ex) for (c = getdtablesize() - 1; c >= 3; c--) close(c); - i = 0; - bptr = g_strdup(ex); /* No need to free() this */ - do { - /* Change the string into argv[] */ - curarg = bptr; - while (*bptr != ' ' && *bptr != (char)0) - bptr++; - c = *bptr; - *bptr++ = (char)0; - argv[i++] = g_strdup(curarg); - } while (c); - - argv[i] = NULL; + argv = g_strsplit(ex, " ", -1); execvp(argv[0], (char **)argv); /* Ooops, failed, let's tell the user why */