summaryrefslogtreecommitdiff
path: root/nt
diff options
context:
space:
mode:
authorNoam Postavsky <npostavs@gmail.com>2014-10-25 12:12:01 +0300
committerEli Zaretskii <eliz@gnu.org>2014-10-25 12:12:01 +0300
commita91ff4f4b1d835cc2c723429c06ddcb357f807c8 (patch)
treef32ac836d8644b60cbd6408acd4de9967c70e53a /nt
parentb5dc75aed71ecb2310a6689e2f7082243aa7e4ab (diff)
Fix bug #18745 with invoking Windows batch files with embedded whitespace.
src/w32proc.c (create_child): If calling a quoted batch file, pass NULL for exe. nt/cmdproxy.c (batch_file_p): New function. (spawn): If calling a quoted batch file pass NULL for progname. test/automated/process-tests.el (process-test-quoted-batfile): New test.
Diffstat (limited to 'nt')
-rw-r--r--nt/ChangeLog6
-rw-r--r--nt/cmdproxy.c29
2 files changed, 35 insertions, 0 deletions
diff --git a/nt/ChangeLog b/nt/ChangeLog
index 632c373949..c4e01a38c2 100644
--- a/nt/ChangeLog
+++ b/nt/ChangeLog
@@ -1,3 +1,9 @@
+2014-10-22 Noam Postavsky <npostavs@users.sourceforget.net>
+
+ * nt/cmdproxy.c (batch_file_p): New function.
+ (spawn): If calling a quoted batch file pass NULL for progname.
+ (Bug#18745)
+
2014-10-20 Glenn Morris <rgm@gnu.org>
* Merge in all changes up to 24.4 release.
diff --git a/nt/cmdproxy.c b/nt/cmdproxy.c
index e48ca63a25..d8f7ae3c41 100644
--- a/nt/cmdproxy.c
+++ b/nt/cmdproxy.c
@@ -220,6 +220,28 @@ get_next_token (char * buf, const char ** pSrc)
return o - buf;
}
+/* Return TRUE if PROGNAME is a batch file. */
+BOOL
+batch_file_p (const char *progname)
+{
+ const char *exts[] = {".bat", ".cmd"};
+ int n_exts = sizeof (exts) / sizeof (char *);
+ int i;
+
+ const char *ext = strrchr (progname, '.');
+
+ if (ext)
+ {
+ for (i = 0; i < n_exts; i++)
+ {
+ if (stricmp (ext, exts[i]) == 0)
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
/* Search for EXEC file in DIR. If EXEC does not have an extension,
DIR is searched for EXEC with the standard extensions appended. */
int
@@ -470,6 +492,13 @@ spawn (const char *progname, char *cmdline, const char *dir, int *retcode)
memset (&start, 0, sizeof (start));
start.cb = sizeof (start);
+ /* CreateProcess handles batch files as progname specially. This
+ special handling fails when both the batch file and arguments are
+ quoted. We pass NULL as progname to avoid the special
+ handling. */
+ if (progname != NULL && cmdline[0] == '"' && batch_file_p (progname))
+ progname = NULL;
+
if (CreateProcess (progname, cmdline, &sec_attrs, NULL, TRUE,
0, envblock, dir, &start, &child))
{