This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH][Libiberty] Support empty arguments in pex-win32


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  <ams@codesourcery.com>

	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);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]