From: Jeremy T. Braun Date: Tue, 6 Dec 2022 02:38:43 +0000 (-0600) Subject: WalkPushConnection: Sanitize paths given to transports X-Git-Tag: v6.5.0.202301111425-m1~21 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=514ebfdc7e81cabeb126e591ddf644730af1972f;p=jgit.git 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 --- 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; + } + }