From patchwork Fri Sep 16 16:31:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Stubbs X-Patchwork-Id: 670969 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 3sbLQP48pcz9s36 for ; Sat, 17 Sep 2016 02:31:38 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=fgcuouUO; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=YcLLKaIt0DxXX124lLOJb2zktsXvI93MAVu/PBTejHTfxV0bRas5N JhYDfNFBQ6dFSzWYI3STjY4uThgCvu3teKCBa2BIg6nreaI1axhNteV81EePy1SB RU/Tb/osGXd67cBCV00imaT6CDBAWYn6g0OFiBfb8Barfd+7GTQ+lI= 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 :subject:to:message-id:date:mime-version:content-type; s= default; bh=D0X1kyqp1q9GH+Nnxk61wEnCoN4=; b=fgcuouUOjwWbjW8XmV/S Z9QZoGQGpGnfBkuaehjAe+NQ62i9gU7lwb7tDg7oVeaIrUhedh8/vkWHPSFhmg9e bfF/4I8JoUlPJn6T42MtIuuiWbtTSxjzB56Jx8VGKnNKd3ckqUJgPG+/CBFlguD8 g6f337qlDtMtTM2f5EazeLw= Received: (qmail 76428 invoked by alias); 16 Sep 2016 16:31:30 -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 76412 invoked by uid 89); 16 Sep 2016 16:31:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=no version=3.3.2 spammy= X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Sep 2016 16:31:20 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=svr-ies-mbx-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1bkw2n-000155-Gz from Andrew_Stubbs@mentor.com for gcc-patches@gcc.gnu.org; Fri, 16 Sep 2016 09:31:17 -0700 Received: from [172.30.88.176] (137.202.0.87) by svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Fri, 16 Sep 2016 17:31:13 +0100 From: Andrew Stubbs Subject: [PATCH][Libiberty] Support empty arguments in pex-win32 To: "gcc-patches@gcc.gnu.org" Message-ID: <5b3ddb94-fa8e-4880-2ba4-bae3e22796e1@codesourcery.com> Date: Fri, 16 Sep 2016 17:31:08 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) Hi, This patch fixes a libiberty bug in which zero-length arguments to "pex_run" subprocesses were silently dropped on MinGW. Basically, the code does not quote parameters unless it has to, but this corner-case was forgotten. OK? Andrew 2016-09-16 Andrew Stubbs libiberty/ * pex-win32.c (argv_to_cmdline): Quote zero-length parameters. libiberty/testsuite/ * test-pexecute.c (main): Insert check for zero-length parameters. Index: libiberty/pex-win32.c =================================================================== --- libiberty/pex-win32.c (revision 240189) +++ libiberty/pex-win32.c (working copy) @@ -370,6 +370,8 @@ cmdline_len++; } } + if (j == 0) + needs_quotes = 1; /* Trailing backslashes also need to be escaped because they will be followed by the terminating quote. */ if (needs_quotes) @@ -394,6 +396,8 @@ break; } } + if (j == 0) + needs_quotes = 1; if (needs_quotes) { Index: libiberty/testsuite/test-pexecute.c =================================================================== --- libiberty/testsuite/test-pexecute.c (revision 240189) +++ libiberty/testsuite/test-pexecute.c (working copy) @@ -285,8 +285,22 @@ ERROR ("echo exit status failed"); pex_free (pex1); + /* Check empty parameters don't get lost. */ pex1 = TEST_PEX_INIT (PEX_USE_PIPES, "temp"); subargv[1] = "echo"; + subargv[2] = "foo"; + subargv[3] = ""; + subargv[4] = "bar"; + subargv[5] = NULL; + TEST_PEX_RUN (pex1, 0, "./test-pexecute", subargv, NULL, NULL); + e = TEST_PEX_READ_OUTPUT (pex1); + CHECK_LINE (e, "foo bar"); /* Two spaces! */ + if (TEST_PEX_GET_STATUS_1 (pex1) != 0) + ERROR ("echo exit status failed"); + pex_free (pex1); + + pex1 = TEST_PEX_INIT (PEX_USE_PIPES, "temp"); + subargv[1] = "echo"; subargv[2] = "bar"; subargv[3] = NULL; TEST_PEX_RUN (pex1, PEX_SUFFIX, "./test-pexecute", subargv, ".x", NULL);