threads / patch / 23259

patchremote-curl: Add sanity check for url

Subject: [PATCH] remote-curl: Add sanity check for url

## tl;dr

3 messages between Mar 30, 2010 and Mar 31, 2010. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Ramkumar Ramachandra· Mar 30, 2010, 20:08 UTC · lore

Previously, `git remote-http foo` and subsquent commands would try to work on a HTML page. This patch fixes the bug by making one assumption about the URL handled by libcurl: it must contain the string "://"

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 remote-curl.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
Show changes to remote-curl.c +3 −0
diff --git a/remote-curl.c b/remote-curl.c
index b76bfcb..9320897 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -112,6 +112,9 @@ static struct discovery* discover_refs(const char *service)
 	}
 	refs_url = strbuf_detach(&buffer, NULL);

+	/* sanity check: does this look like a url expected by libcurl? */
+	if (!strstr(url, "://"))
+		die("%s is not a url supported by this remote helper", url);
 	http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);

 	/* try again with "plain" url (no ? or & appended) */
-- 
1.7.0.3
Junio C Hamano· Mar 30, 2010, 23:45 UTC · re: Ramkumar Ramachandra · lore

Re: [PATCH] remote-curl: Add sanity check for url

Ramkumar Ramachandra <artagnon@gmail.com> writes:
> Previously, `git remote-http foo` and subsquent commands would try to
> work on a HTML page. This patch fixes the bug by making one assumption
> about the URL handled by libcurl: it must contain the string "://"
I may be being slow but I do not see the point of this patch.

I thought that remote-foo is never invoked directly from a command line with random arguments, and fetch/push frontends make the decision based on the shape of the "URL" (or whatever data used to reach the remote end) which helper to run.

I do not think your patch would _break_ anything, but my question is more about the reason why we would want a duplicated check here.

Ramkumar Ramachandra· Mar 31, 2010, 02:43 UTC · re: Junio C Hamano · lore

Re: [PATCH] remote-curl: Add sanity check for url

Hi,
> I may be being slow but I do not see the point of this patch.

Agreed, it's not a bug that any end-user would normally bump into. I bumped into this myself when I assumed that the remote `foo` exists, and invoked `git-remote-http foo`. Since remote_get() transparently creates a remote when one does not exist, remote-curl doesn't know if the remote `foo` ever really exists. Going off to fetch a HTML page when an expected remote doesn't exist is really ugly, so I thought I'd prepare this patch. Plus, it doesn't hurt to make sure that the remote helper conforms to the documentation- useful when a developer is calling it independently.

-- Ram

← back to recent threads