aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Stubbs <ams@codesourcery.com>2016-09-19 10:02:56 +0000
committerAndrew Stubbs <ams@codesourcery.com>2016-09-19 10:02:56 +0000
commit21cc9a4c576976726b3d9a50b4a74ab40fda2802 (patch)
tree25eb5fbad302b98d985cc4c7ec67c84c7fbe74b5
parentf3a8a2b98ba910f0fc152a349b2aa8a09b7fd2c5 (diff)
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. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@240229 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--libiberty/ChangeLog5
-rw-r--r--libiberty/pex-win32.c4
-rw-r--r--libiberty/testsuite/test-pexecute.c14
3 files changed, 23 insertions, 0 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index 68609599786..5934bc1fa8a 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,8 @@
+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>
* cp-demangle.c (d_substitution): Change struct demangle_component
diff --git a/libiberty/pex-win32.c b/libiberty/pex-win32.c
index 66d2f1157c7..4c15b0d11a0 100644
--- a/libiberty/pex-win32.c
+++ b/libiberty/pex-win32.c
@@ -370,6 +370,8 @@ argv_to_cmdline (char *const *argv)
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 @@ argv_to_cmdline (char *const *argv)
break;
}
}
+ if (j == 0)
+ needs_quotes = 1;
if (needs_quotes)
{
diff --git a/libiberty/testsuite/test-pexecute.c b/libiberty/testsuite/test-pexecute.c
index 8e01fda479a..f62239d49b8 100644
--- a/libiberty/testsuite/test-pexecute.c
+++ b/libiberty/testsuite/test-pexecute.c
@@ -285,6 +285,20 @@ main (int argc, char **argv)
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";