# [PATCH] remote.c: correct the check for a leading '/' in a remote name

2 messages from 2008-10-14 to 2008-10-14. Participants: Brandon Casey, Daniel Barkalow.
Thread: https://gitlist.dev/t/15898

## Brandon Casey, 2008-10-14 20:30

Subject: [PATCH] remote.c: correct the check for a leading '/' in a remote name
Message-ID: <J-KL1Cgc2b78Lced5uBNDhP0MHdg91do73K_0waicFQYbDZHjYkocw@cipher.nrlssc.navy.mil>
URL: https://gitlist.dev/e/J-KL1Cgc2b78Lced5uBNDhP0MHdg91do73K_0waicFQYbDZHjYkocw%40cipher.nrlssc.navy.mil

```
This test is supposed to disallow remote entries in the config file of the
form:

   [remote "/foobar"]
      ...

The leading slash in '/foobar' is not acceptable.

Instead it was incorrectly testing that the subkey had no leading '/', which
had no effect since the subkey pointer was made to point at a '.' in the
preceding lines.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
---


I stumbled across this code which looks like a mistake.
This patch seems like the correct fix.

-brandon


 remote.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/remote.c b/remote.c
index d5efadd..8a04066 100644
--- a/remote.c
+++ b/remote.c
@@ -341,13 +341,14 @@ static int handle_config(const char *key, const char *value, void *cb)
 	if (prefixcmp(key,  "remote."))
 		return 0;
 	name = key + 7;
+	if (*name == '/') {
+		warning("Config remote shorthand cannot begin with '/': %s",
+			name);
+		return 0;
+	}
 	subkey = strrchr(name, '.');
 	if (!subkey)
 		return error("Config with no key for remote %s", name);
-	if (*subkey == '/') {
-		warning("Config remote shorthand cannot begin with '/': %s", name);
-		return 0;
-	}
 	remote = make_remote(name, subkey - name);
 	if (!strcmp(subkey, ".mirror"))
 		remote->mirror = git_config_bool(key, value);
-- 
1.6.0.2.468.gd5b83

```

## Daniel Barkalow, 2008-10-14 20:35

Subject: Re: [PATCH] remote.c: correct the check for a leading '/' in a remote name
Message-ID: <alpine.LNX.1.00.0810141633321.19665@iabervon.org>
URL: https://gitlist.dev/e/alpine.LNX.1.00.0810141633321.19665%40iabervon.org
In-Reply-To: <J-KL1Cgc2b78Lced5uBNDhP0MHdg91do73K_0waicFQYbDZHjYkocw@cipher.nrlssc.navy.mil>

```
On Tue, 14 Oct 2008, Brandon Casey wrote:

> This test is supposed to disallow remote entries in the config file of the
> form:
> 
>    [remote "/foobar"]
>       ...
> 
> The leading slash in '/foobar' is not acceptable.
> 
> Instead it was incorrectly testing that the subkey had no leading '/', which
> had no effect since the subkey pointer was made to point at a '.' in the
> preceding lines.
> 
> Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>

Good catch; looks like I was checking for a mistake that nobody ever 
makes, but it's still good to check.

Acked-by: Daniel Barkalow <barkalow@iabervon.org>

```
