From patchwork Sat Apr 19 19:40:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ray Donnelly X-Patchwork-Id: 340493 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7333D1400CF for ; Sun, 20 Apr 2014 05:41:30 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=yf9+vyn3X5/QTcTnmME9QyJGhluMnQHE6gdM5ENN6ylY8BEnd0N0Q xeDe8pwTVJWeG5NBzjqbOcP42ReUldLaaneB7kACXqHtVcY06Z1rMMG32GGOfvKs gSbop3mnnKUB/QakrQAeJPcV/tSNaqkLgxj40a8PaLpLS+N1Izrl2s= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=oSVCjBkQE/zF6k8FEK6Fgt2rhLA=; b=Nc2h1wFBREeqNYrG2xTc uLoPzefjX4Gf3qBRmC7A+BN04/ZsX7GTmGrfQqhSW85KAuO0lW8ho8xXWyqSQTkw HtGK/0HR6RV9l62aI5sBGdjWcW1P2MUqhlzeRlRb8Dttj+9AovyMRjIn/uSYcmIT Zbt8RrRW9foa82vJ4Oqthkw= Received: (qmail 7947 invoked by alias); 19 Apr 2014 19:41:12 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 7913 invoked by uid 89); 19 Apr 2014 19:41:12 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-we0-f172.google.com Received: from mail-we0-f172.google.com (HELO mail-we0-f172.google.com) (74.125.82.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 19 Apr 2014 19:41:11 +0000 Received: by mail-we0-f172.google.com with SMTP id t61so2595233wes.31 for ; Sat, 19 Apr 2014 12:41:08 -0700 (PDT) X-Received: by 10.180.8.66 with SMTP id p2mr7604538wia.37.1397936467997; Sat, 19 Apr 2014 12:41:07 -0700 (PDT) Received: from ArchVMl702x.Workgroup (cpc65057-bagu12-2-0-cust801.1-3.cable.virginm.net. [82.1.59.34]) by mx.google.com with ESMTPSA id ll1sm49241377wjc.6.2014.04.19.12.41.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 19 Apr 2014 12:41:07 -0700 (PDT) From: Ray Donnelly To: gcc-patches@gcc.gnu.org Cc: ktietz70@gmail.com, mingw.android@gmail.com Subject: [PATCH 1/2] Windows libibery: Don't quote args unnecessarily Date: Sat, 19 Apr 2014 20:40:23 +0100 Message-Id: <1397936424-2290-2-git-send-email-mingw.android@gmail.com> In-Reply-To: <1397936424-2290-1-git-send-email-mingw.android@gmail.com> References: <1397936424-2290-1-git-send-email-mingw.android@gmail.com> We only quote arguments that contain spaces, \n \t \v or " characters to prevent wasting 2 characters per argument of the CreateProcess() 32,768 limit. libiberty/ * pex-win32.c (argv_to_cmdline): Don't quote args unnecessarily --- libiberty/ChangeLog | 5 +++++ libiberty/pex-win32.c | 48 +++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index d9a208b..f6a4f8f 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,8 @@ +2014-04-14 Ray Donnelly + + * pex-win32.c (argv_to_cmdline): Don't quote + args unnecessarily. + 2014-04-17 Jakub Jelinek PR sanitizer/56781 diff --git a/libiberty/pex-win32.c b/libiberty/pex-win32.c index eae72c5..775b53c 100644 --- a/libiberty/pex-win32.c +++ b/libiberty/pex-win32.c @@ -340,17 +340,26 @@ argv_to_cmdline (char *const *argv) char *p; size_t cmdline_len; int i, j, k; + int needs_quotes; cmdline_len = 0; for (i = 0; argv[i]; i++) { - /* We quote every last argument. This simplifies the problem; - we need only escape embedded double-quotes and immediately + /* We only quote arguments that contain spaces, \n \t \v or " characters + to prevent wasting 2 chars per argument of the CreateProcess 32k char + limit We need only escape embedded double-quotes and immediately preceeding backslash characters. A sequence of backslach characters that is not follwed by a double quote character will not be escaped. */ + needs_quotes = 0; for (j = 0; argv[i][j]; j++) { + if (argv[i][j] == ' ' || argv[i][j] == '\n' || + argv[i][j] == '\t' || argv[i][j] == '"' ) + { + needs_quotes = 1; + } + if (argv[i][j] == '"') { /* Escape preceeding backslashes. */ @@ -362,16 +371,34 @@ argv_to_cmdline (char *const *argv) } /* Trailing backslashes also need to be escaped because they will be followed by the terminating quote. */ - for (k = j - 1; k >= 0 && argv[i][k] == '\\'; k--) - cmdline_len++; + if (needs_quotes) + { + for (k = j - 1; k >= 0 && argv[i][k] == '\\'; k--) + cmdline_len++; + } cmdline_len += j; - cmdline_len += 3; /* for leading and trailing quotes and space */ + /* for leading and trailing quotes and space */ + cmdline_len += needs_quotes * 2 + 1; } cmdline = XNEWVEC (char, cmdline_len); p = cmdline; for (i = 0; argv[i]; i++) { - *p++ = '"'; + needs_quotes = 0; + for (j = 0; argv[i][j]; j++) + { + if (argv[i][j] == ' ' || argv[i][j] == '\n' || + argv[i][j] == '\t' || argv[i][j] == '"' ) + { + needs_quotes = 1; + break; + } + } + + if (needs_quotes) + { + *p++ = '"'; + } for (j = 0; argv[i][j]; j++) { if (argv[i][j] == '"') @@ -382,9 +409,12 @@ argv_to_cmdline (char *const *argv) } *p++ = argv[i][j]; } - for (k = j - 1; k >= 0 && argv[i][k] == '\\'; k--) - *p++ = '\\'; - *p++ = '"'; + if (needs_quotes) + { + for (k = j - 1; k >= 0 && argv[i][k] == '\\'; k--) + *p++ = '\\'; + *p++ = '"'; + } *p++ = ' '; } p[-1] = '\0';