git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / Atom feed
* [PATCH] remote: check config validity before creating rewrite struct
@ 2019-01-11 19:30 Jeff King
  2019-01-12  2:36 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Jeff King @ 2019-01-11 19:30 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

When parsing url.foo.insteadOf, we call make_rewrite() and only then
check to make sure the value is a string (and return an error if it
isn't). This isn't quite a leak, because the struct we allocate is part
of a global array, but it does leave a funny half-finished struct.

In practice, it doesn't make much difference because we exit soon after
due to the config error anyway. But let's flip the order here to avoid
leaving a trap for somebody in the future.

Signed-off-by: Jeff King <peff@peff.net>
---
This was a minor cleanup I mentioned in:

  https://public-inbox.org/git/20181122173109.GI28192@sigill.intra.peff.net/

but didn't get picked up.

 remote.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/remote.c b/remote.c
index 670dd44813..9cc3b07d21 100644
--- a/remote.c
+++ b/remote.c
@@ -337,14 +337,14 @@ static int handle_config(const char *key, const char *value, void *cb)
 		if (!name)
 			return 0;
 		if (!strcmp(subkey, "insteadof")) {
-			rewrite = make_rewrite(&rewrites, name, namelen);
 			if (!value)
 				return config_error_nonbool(key);
+			rewrite = make_rewrite(&rewrites, name, namelen);
 			add_instead_of(rewrite, xstrdup(value));
 		} else if (!strcmp(subkey, "pushinsteadof")) {
-			rewrite = make_rewrite(&rewrites_push, name, namelen);
 			if (!value)
 				return config_error_nonbool(key);
+			rewrite = make_rewrite(&rewrites_push, name, namelen);
 			add_instead_of(rewrite, xstrdup(value));
 		}
 	}
-- 
2.20.1.651.g2d41a78c67

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] remote: check config validity before creating rewrite struct
  2019-01-11 19:30 [PATCH] remote: check config validity before creating rewrite struct Jeff King
@ 2019-01-12  2:36 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2019-01-12  2:36 UTC (permalink / raw)
  To: Jeff King; +Cc: git

Jeff King <peff@peff.net> writes:

> This was a minor cleanup I mentioned in:
>
>   https://public-inbox.org/git/20181122173109.GI28192@sigill.intra.peff.net/
>
> but didn't get picked up.

Yeah, that does sound vaguely familiar ;-)  Thanks, will queue.

>
>  remote.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/remote.c b/remote.c
> index 670dd44813..9cc3b07d21 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -337,14 +337,14 @@ static int handle_config(const char *key, const char *value, void *cb)
>  		if (!name)
>  			return 0;
>  		if (!strcmp(subkey, "insteadof")) {
> -			rewrite = make_rewrite(&rewrites, name, namelen);
>  			if (!value)
>  				return config_error_nonbool(key);
> +			rewrite = make_rewrite(&rewrites, name, namelen);
>  			add_instead_of(rewrite, xstrdup(value));
>  		} else if (!strcmp(subkey, "pushinsteadof")) {
> -			rewrite = make_rewrite(&rewrites_push, name, namelen);
>  			if (!value)
>  				return config_error_nonbool(key);
> +			rewrite = make_rewrite(&rewrites_push, name, namelen);
>  			add_instead_of(rewrite, xstrdup(value));
>  		}
>  	}

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-11 19:30 [PATCH] remote: check config validity before creating rewrite struct Jeff King
2019-01-12  2:36 ` Junio C Hamano

git@vger.kernel.org list mirror (unofficial, one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox