Skip to content

Commit b49df4c

Browse files
committed
make: Fix support for shell paths with spaces
GNU Make incorrectly processes shell paths that contain a space on all supported platforms. This is a common case on Windows after resolving the shell's absolute path (e.g. "Documents and Settings" or "Program Files"). The space is not escaped when constructing the shell command, and then the shell path is truncated when splitting on the space. Adding a space to sh_chars causes construct_command_argv_internal to recurse indefinitely, so instead add a special case when copying the shell path into the command.
1 parent 9a97c6d commit b49df4c

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,9 @@ RUN cat $PREFIX/src/gdb-*.patch | patch -d/gdb-$GDB_VERSION -p1 \
381381
&& cp gdb/.libs/gdb.exe gdbserver/gdbserver.exe $PREFIX/bin/
382382

383383
WORKDIR /make
384-
RUN /make-$MAKE_VERSION/configure \
384+
COPY src/make-*.patch $PREFIX/src/
385+
RUN cat $PREFIX/src/make-*.patch | patch -d/make-$MAKE_VERSION -p1 \
386+
&& /make-$MAKE_VERSION/configure \
385387
--host=$ARCH \
386388
--disable-nls \
387389
CFLAGS="-std=gnu17 -Os" \

src/make-shell-space.patch

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Fix support for shell paths containing spaces
2+
3+
GNU Make incorrectly processes shell paths that contain a space on all
4+
supported platforms. This is a common case on Windows after resolving
5+
the shell's absolute path (e.g. "Documents and Settings" or "Program
6+
Files"). The space is not escaped when constructing the shell command,
7+
and then the shell path is truncated when splitting on the space.
8+
9+
Adding a space to sh_chars causes construct_command_argv_internal to
10+
recurse indefinitely, so instead add a special case when copying the
11+
shell path into the command.
12+
13+
--- a/src/job.c
14+
+++ b/src/job.c
15+
@@ -3474,5 +3474,5 @@
16+
for (cp = shell; *cp != '\0'; ++cp)
17+
{
18+
- if (strchr (sh_chars, *cp) != 0)
19+
+ if (strchr (sh_chars, *cp) != 0 || ISSPACE (*cp))
20+
*(ap++) = '\\';
21+
*(ap++) = *cp;

0 commit comments

Comments
 (0)