]> source.dussan.org Git - jgit.git/commitdiff
AdvertisedRequestValidator: fix WantNotValidException caused by race 80/1201680/3 stable-6.6
authorMatthias Sohn <matthias.sohn@sap.com>
Tue, 24 Sep 2024 08:51:22 +0000 (10:51 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Wed, 25 Sep 2024 14:43:52 +0000 (16:43 +0200)
Fetch with protocol V2 failed under the following conditions
- fetch uses bidirectional protocol (git, ssh) which uses a shortcut
  to determine invalid wants
- not all wants are advertised
- race condition: wanted ref is updated during fetch by another thread
  after the thread serving upload-pack determined wants and before it
  checks not advertised wants

Fix this by calling
`new ReachableCommitRequestValidator().checkWants(up, wants)`
instead of throwing WantNotValidException in [1]
if this race happened in the same way like it's done for unidirectional
protocols (http) [2].

[1] https://github.com/eclipse-jgit/jgit/blob/stable-6.10/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java#L2002
[2] https://github.com/eclipse-jgit/jgit/blob/stable-6.10/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java#L2000

Bug: jgit-48
Change-Id: I32f28502923815dc49781aab5d810c9afbe7e7e6

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

index 3264f556fa2ec87f174673ea88036b1023083128..8b97ee10caeef94ff67e30b41433ec0c213d7266 100644 (file)
@@ -1968,10 +1968,9 @@ public class UploadPack implements Closeable {
                @Override
                public void checkWants(UploadPack up, List<ObjectId> wants)
                                throws PackProtocolException, IOException {
-                       if (!up.isBiDirectionalPipe())
+                       if (!up.isBiDirectionalPipe() || !wants.isEmpty()) {
                                new ReachableCommitRequestValidator().checkWants(up, wants);
-                       else if (!wants.isEmpty())
-                               throw new WantNotValidException(wants.iterator().next());
+                       }
                }
        }