Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Tan2018-05-03 00:17:04 +0000
committerJonathan Nieder2018-06-05 05:08:21 +0000
commit2f608043961fc0902b1904adb77631ec1ebc4833 (patch)
treee9a00f8fd98076b940ddda499e50739242db8195
parentf7e501c36c83c9e7a516d154ee96afd12cbc0498 (diff)
downloadjgit-2f608043961fc0902b1904adb77631ec1ebc4833.tar.gz
jgit-2f608043961fc0902b1904adb77631ec1ebc4833.tar.xz
jgit-2f608043961fc0902b1904adb77631ec1ebc4833.zip
Disallow unknown args to "fetch" in protocol v2
JGit's implementation of the fetch command of protocol v2, unlike its implementation of ls-refs, currently tolerates unknown arguments. Tighten fetch to not allow unrecognized arguments and add tests to verify this behavior for both ls-refs and fetch. Change-Id: I321161d568bd638252fab1a47b06b924d472a669 Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java23
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java4
2 files changed, 26 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
index 45ea7fafd9..6550f1a52c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java
@@ -15,6 +15,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringWriter;
+import org.eclipse.jgit.errors.PackProtocolException;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector;
import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
@@ -514,6 +515,17 @@ public class UploadPackTest {
assertTrue(pckIn.readString() == PacketLineIn.END);
}
+ @Test
+ public void testV2LsRefsUnrecognizedArgument() throws Exception {
+ thrown.expect(PackProtocolException.class);
+ thrown.expectMessage("unexpected invalid-argument");
+ uploadPackV2(
+ "command=ls-refs\n",
+ PacketLineIn.DELIM,
+ "invalid-argument\n",
+ PacketLineIn.END);
+ }
+
/*
* Parse multiplexed packfile output from upload-pack using protocol V2
* into the client repository.
@@ -973,6 +985,17 @@ public class UploadPackTest {
assertThat(pckIn.readString(), theInstance(PacketLineIn.END));
}
+ @Test
+ public void testV2FetchUnrecognizedArgument() throws Exception {
+ thrown.expect(PackProtocolException.class);
+ thrown.expectMessage("unexpected invalid-argument");
+ uploadPackV2(
+ "command=fetch\n",
+ PacketLineIn.DELIM,
+ "invalid-argument\n",
+ PacketLineIn.END);
+ }
+
private static class RejectAllRefFilter implements RefFilter {
@Override
public Map<String, Ref> filter(Map<String, Ref> refs) {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
index f38dfe485c..8a4cae4bae 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
@@ -1022,8 +1022,10 @@ public class UploadPack {
throw new PackProtocolException(
JGitText.get().deepenSinceWithDeepen);
}
+ } else {
+ throw new PackProtocolException(MessageFormat
+ .format(JGitText.get().unexpectedPacketLine, line));
}
- // else ignore it
}
rawOut.stopBuffering();

Back to the top