From 514ebfdc7e81cabeb126e591ddf644730af1972f Mon Sep 17 00:00:00 2001 From: "Jeremy T. Braun" Date: Mon, 5 Dec 2022 20:38:43 -0600 Subject: [PATCH] WalkPushConnection: Sanitize paths given to transports These paths are given to the underlying URI-based transports (s3, sftp, http), all of which expect forward-slash as the path separator character. Change-Id: I3cbb5928c9531a4da4691411bd8ac248fdf47ef2 --- .../jgit/transport/WalkPushConnection.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java index 03ef852c7f..a54fd8e14d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java @@ -230,7 +230,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection { // offsets from appearing to clients. // dest.writeInfoPacks(packNames.keySet()); - dest.deleteFile(idx.getPath()); + dest.deleteFile(sanitizedPath(idx)); } // Write the pack file, then the index, as readers look the @@ -238,13 +238,13 @@ class WalkPushConnection extends BaseConnection implements PushConnection { // String wt = "Put " + pack.getName().substring(0, 12); //$NON-NLS-1$ try (OutputStream os = new BufferedOutputStream( - dest.writeFile(pack.getPath(), monitor, + dest.writeFile(sanitizedPath(pack), monitor, wt + "." + pack.getPackExt().getExtension()))) { //$NON-NLS-1$ writer.writePack(monitor, monitor, os); } try (OutputStream os = new BufferedOutputStream( - dest.writeFile(idx.getPath(), monitor, + dest.writeFile(sanitizedPath(idx), monitor, wt + "." + idx.getPackExt().getExtension()))) { //$NON-NLS-1$ writer.writeIndex(os); } @@ -269,7 +269,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection { private void safeDelete(File path) { if (path != null) { try { - dest.deleteFile(path.getPath()); + dest.deleteFile(sanitizedPath(path)); } catch (IOException cleanupFailure) { // Ignore the deletion failure. We probably are // already failing and were just trying to pick @@ -366,4 +366,13 @@ class WalkPushConnection extends BaseConnection implements PushConnection { } return updates.get(0).getRemoteName(); } + + private static String sanitizedPath(File file) { + String path = file.getPath(); + if (File.separatorChar != '/') { + path = path.replace(File.separatorChar, '/'); + } + return path; + } + } -- 2.39.5