]> source.dussan.org Git - jgit.git/commitdiff
WalkPushConnection: Sanitize paths given to transports 93/197493/3
authorJeremy T. Braun <jtbraun@cpan.org>
Tue, 6 Dec 2022 02:38:43 +0000 (20:38 -0600)
committerThomas Wolf <twolf@apache.org>
Thu, 15 Dec 2022 17:53:19 +0000 (12:53 -0500)
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

org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java

index 03ef852c7f80725119c486a1d565200b21eca193..a54fd8e14dde6425a3fc08ceb9ab08633a5d77fa 100644 (file)
@@ -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;
+       }
+
 }