git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH] Make UploadPack capability parsing more liberal

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jun 16, 2009, 18:59 UTC
Message-ID
<1245178765-7505-1-git-send-email-spearce@spearce.org>

Prior to 220a6626c86b ("Fix BaseFetchPackConnection's output of selected capabilities") the JGit pack client produced a capability request header that JGit itself can't parse, but C Git can. The parsing error was caused by a missing space after the want'd SHA-1 and before the first capability name.

Even though JGit's pack client has been fixed in more recent versions, we should still fix the server to be more libral in what it accepts from clients, so that older JGit client builds can still interoperate.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../src/org/spearce/jgit/transport/UploadPack.java |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/UploadPack.java b/org.spearce.jgit/src/org/spearce/jgit/transport/UploadPack.java
index fcc1ef7..159bd10 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/UploadPack.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/UploadPack.java
@@ -302,13 +302,13 @@ private void recvWants() throws IOException {
 			if (!line.startsWith("want ") || line.length() < 45)
 				throw new PackProtocolException("expected want; got " + line);
 
-			if (isFirst) {
-				final int sp = line.indexOf(' ', 45);
-				if (sp >= 0) {
-					for (String c : line.substring(sp + 1).split(" "))
-						options.add(c);
-					line = line.substring(0, sp);
-				}
+			if (isFirst && line.length() > 45) {
+				String opt = line.substring(45);
+				if (opt.startsWith(" "))
+					opt = opt.substring(1);
+				for (String c : opt.split(" "))
+					options.add(c);
+				line = line.substring(0, 45);
 			}
 
 			final ObjectId id = ObjectId.fromString(line.substring(5));
-- 
1.6.3.2.406.gd6a466
Message 1 of 1 in “Make UploadPack capability parsing more liberal”
  1. Make UploadPack capability parsing more liberalShawn O. Pearce, Jun 16, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.