@@ -1,71 +0,0 @@
1−https://savannah.gnu.org/bugs/?23922
2−
3−From 6f3684710a0f832533191f8657a57bc2fbba90ba Mon Sep 17 00:00:00 2001
4−From: eliz <eliz>
5−Date: Sat, 7 May 2011 08:29:13 +0000
6−Subject: [PATCH] job.c (construct_command_argv_internal): Don't assume
7− shellflags is always non-NULL. Escape-protect characters
8− special to the shell when copying the value of SHELL into
9− new_line. Fixes Savannah bug #23922.
10−
11−---
12− ChangeLog | 7 +++++++
13− job.c | 23 ++++++++++++++++-------
14− 2 files changed, 23 insertions(+), 7 deletions(-)
15−
16−diff --git job.c job.c
17−index 67b402d..c2ce84d 100644
18−--- job.c
19−+++ job.c
20−@@ -2844,12 +2844,12 @@ construct_command_argv_internal (char *line, char **restp, char *shell,
21−
22− unsigned int shell_len = strlen (shell);
23− unsigned int line_len = strlen (line);
24−- unsigned int sflags_len = strlen (shellflags);
25−+ unsigned int sflags_len = shellflags ? strlen (shellflags) : 0;
26− char *command_ptr = NULL; /* used for batch_mode_shell mode */
27− char *new_line;
28−
29− # ifdef __EMX__ /* is this necessary? */
30−- if (!unixy_shell)
31−+ if (!unixy_shell && shellflags)
32− shellflags[0] = '/'; /* "/c" */
33− # endif
34−
35−@@ -2911,19 +2911,28 @@ construct_command_argv_internal (char *line, char **restp, char *shell,
36−
37− new_argv = xmalloc (4 * sizeof (char *));
38− new_argv[0] = xstrdup(shell);
39−- new_argv[1] = xstrdup(shellflags);
40−+ new_argv[1] = xstrdup(shellflags ? shellflags : "");
41− new_argv[2] = line;
42− new_argv[3] = NULL;
43− return new_argv;
44− }
45−
46−- new_line = alloca (shell_len + 1 + sflags_len + 1
47−+ new_line = alloca ((shell_len*2) + 1 + sflags_len + 1
48− + (line_len*2) + 1);
49− ap = new_line;
50−- memcpy (ap, shell, shell_len);
51−- ap += shell_len;
52−+ /* Copy SHELL, escaping any characters special to the shell. If
53−+ we don't escape them, construct_command_argv_internal will
54−+ recursively call itself ad nauseam, or until stack overflow,
55−+ whichever happens first. */
56−+ for (p = shell; *p != '\0'; ++p)
57−+ {
58−+ if (strchr (sh_chars, *p) != 0)
59−+ *(ap++) = '\\';
60−+ *(ap++) = *p;
61−+ }
62− *(ap++) = ' ';
63−- memcpy (ap, shellflags, sflags_len);
64−+ if (shellflags)
65−+ memcpy (ap, shellflags, sflags_len);
66− ap += sflags_len;
67− *(ap++) = ' ';
68− command_ptr = ap;
69−--
70−1.7.12
71−