Commit 471a0d47 by Andrew Stubbs Committed by Andrew Stubbs

Fix zero-length parameter bug in pex_run.

2016-09-19  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.

From-SVN: r240229
parent 321e76fb
2016-09-19 Andrew Stubbs <ams@codesourcery.com>
* pex-win32.c (argv_to_cmdline): Quote zero-length parameters.
* testsuite/test-pexecute.c (main): Insert check for zero-length parameters.
2016-09-10 Mark Wielaard <mjw@redhat.com> 2016-09-10 Mark Wielaard <mjw@redhat.com>
* cp-demangle.c (d_substitution): Change struct demangle_component * cp-demangle.c (d_substitution): Change struct demangle_component
......
...@@ -370,6 +370,8 @@ argv_to_cmdline (char *const *argv) ...@@ -370,6 +370,8 @@ argv_to_cmdline (char *const *argv)
cmdline_len++; cmdline_len++;
} }
} }
if (j == 0)
needs_quotes = 1;
/* Trailing backslashes also need to be escaped because they will be /* Trailing backslashes also need to be escaped because they will be
followed by the terminating quote. */ followed by the terminating quote. */
if (needs_quotes) if (needs_quotes)
...@@ -394,6 +396,8 @@ argv_to_cmdline (char *const *argv) ...@@ -394,6 +396,8 @@ argv_to_cmdline (char *const *argv)
break; break;
} }
} }
if (j == 0)
needs_quotes = 1;
if (needs_quotes) if (needs_quotes)
{ {
......
...@@ -285,6 +285,20 @@ main (int argc, char **argv) ...@@ -285,6 +285,20 @@ main (int argc, char **argv)
ERROR ("echo exit status failed"); ERROR ("echo exit status failed");
pex_free (pex1); 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"); pex1 = TEST_PEX_INIT (PEX_USE_PIPES, "temp");
subargv[1] = "echo"; subargv[1] = "echo";
subargv[2] = "bar"; subargv[2] = "bar";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment