]> source.dussan.org Git - jgit.git/commitdiff
Hooks: avoid problems with backslashes in paths 14/155014/1
authorThomas Wolf <thomas.wolf@paranor.ch>
Tue, 24 Dec 2019 11:13:29 +0000 (12:13 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Tue, 24 Dec 2019 12:31:23 +0000 (13:31 +0100)
Calling sh -c with a script path containing backslashes may fail since
the shell may try to process them as escape characters.

Instead of calling

  sh.exe -c 'C:\path\script "$@"' 'C:\path\script' other args

call

  sh.exe -c '$0 "$@"' 'C:\path\script' other args

which avoids this escape processing.

Note that this is not specific to Windows. If the path or the script
name contain backslashes, this also occurs on Unix.

Bug: 558577
Change-Id: I47d63db6f8644f956c55c42b07dbcad7d7f305aa
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java
org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java

index 7c170ac4eb637751697f3af2450b214aca8e0463..5c2d8277cd12487adcef2251e2f353f7200a51f2 100644 (file)
@@ -261,7 +261,7 @@ public class FS_POSIX extends FS {
                List<String> argv = new ArrayList<>(4 + args.length);
                argv.add("sh"); //$NON-NLS-1$
                argv.add("-c"); //$NON-NLS-1$
-               argv.add(cmd + " \"$@\""); //$NON-NLS-1$
+               argv.add("$0 \"$@\""); //$NON-NLS-1$
                argv.add(cmd);
                argv.addAll(Arrays.asList(args));
                ProcessBuilder proc = new ProcessBuilder();
index 4efa9888f7a746d464560b4069dcda3cbd36705e..ac3248cb63a4e2e39288321e6c4b121557e3ebee 100644 (file)
@@ -149,7 +149,7 @@ public class FS_Win32_Cygwin extends FS_Win32 {
                List<String> argv = new ArrayList<>(4 + args.length);
                argv.add("sh.exe"); //$NON-NLS-1$
                argv.add("-c"); //$NON-NLS-1$
-               argv.add(cmd + " \"$@\""); //$NON-NLS-1$
+               argv.add("$0 \"$@\""); //$NON-NLS-1$
                argv.add(cmd);
                argv.addAll(Arrays.asList(args));
                ProcessBuilder proc = new ProcessBuilder();