From 5fb71fb54e5d1bc2f5164c7f1ffdfacfa6a69b62 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Fri, 13 Aug 2021 09:36:26 +0200 Subject: [PATCH] Ensure FS#searchPath only selects executable files On Posix non executable files on the path should be ignored, on Windows File#canExecute always returns true. While we are here also add missing braces. Bug: 575385 Change-Id: I80cd5057bdf9632a17f103db6f1356e975b6e150 --- org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java index 0946f645f..4a4034794 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java @@ -1267,7 +1267,8 @@ private File defaultUserHomeImpl() { /** * Searches the given path to see if it contains one of the given files. - * Returns the first it finds. Returns null if not found or if path is null. + * Returns the first it finds which is executable. Returns null if not found + * or if path is null. * * @param path * List of paths to search separated by File.pathSeparator @@ -1277,14 +1278,15 @@ private File defaultUserHomeImpl() { * @since 3.0 */ protected static File searchPath(String path, String... lookFor) { - if (path == null) + if (path == null) { return null; + } for (String p : path.split(File.pathSeparator)) { for (String command : lookFor) { final File file = new File(p, command); try { - if (file.isFile()) { + if (file.isFile() && file.canExecute()) { return file.getAbsoluteFile(); } } catch (SecurityException e) {