* [PATCH] remote.c: free previous results when looking for a ref match
@ 2016-10-07 23:58 Stefan Beller
2016-10-08 13:38 ` René Scharfe
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Beller @ 2016-10-07 23:58 UTC (permalink / raw)
To: gitster; +Cc: git, Stefan Beller
Signed-off-by: Stefan Beller <sbeller@google.com>
---
remote.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/remote.c b/remote.c
index ad6c542..5f9afb4 100644
--- a/remote.c
+++ b/remote.c
@@ -833,6 +833,8 @@ static int match_name_with_pattern(const char *key, const char *name,
strbuf_add(&sb, value, vstar - value);
strbuf_add(&sb, name + klen, namelen - klen - ksuffixlen);
strbuf_addstr(&sb, vstar + 1);
+ if (*result)
+ free(*result);
*result = strbuf_detach(&sb, NULL);
}
return ret;
@@ -1262,6 +1264,8 @@ static char *get_ref_match(const struct refspec *rs, int rs_nr, const struct ref
*/
if (!send_mirror && !starts_with(ref->name, "refs/heads/"))
return NULL;
+ if (name)
+ free(name);
name = xstrdup(ref->name);
}
if (ret_pat)
--
2.10.1.353.g1629400
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] remote.c: free previous results when looking for a ref match
2016-10-07 23:58 [PATCH] remote.c: free previous results when looking for a ref match Stefan Beller
@ 2016-10-08 13:38 ` René Scharfe
2016-10-10 17:03 ` Stefan Beller
0 siblings, 1 reply; 3+ messages in thread
From: René Scharfe @ 2016-10-08 13:38 UTC (permalink / raw)
To: Stefan Beller, gitster; +Cc: git
Am 08.10.2016 um 01:58 schrieb Stefan Beller:
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
> remote.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/remote.c b/remote.c
> index ad6c542..5f9afb4 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -833,6 +833,8 @@ static int match_name_with_pattern(const char *key, const char *name,
> strbuf_add(&sb, value, vstar - value);
> strbuf_add(&sb, name + klen, namelen - klen - ksuffixlen);
> strbuf_addstr(&sb, vstar + 1);
> + if (*result)
> + free(*result);
free(3) can handle NULL pointers; this check is not necessary.
Is it wise to release memory for callers? I'd expect them to be
responsible for that. Some of them can pass uninitialized pointers;
this is not allowed anymore after the change.
> *result = strbuf_detach(&sb, NULL);
> }
> return ret;
> @@ -1262,6 +1264,8 @@ static char *get_ref_match(const struct refspec *rs, int rs_nr, const struct ref
> */
> if (!send_mirror && !starts_with(ref->name, "refs/heads/"))
> return NULL;
> + if (name)
> + free(name);
Again, this check is not necessary. If I read the code correctly the
pointer could be uninitialized at that point, though, causing free(3) to
crash.
> name = xstrdup(ref->name);
> }
> if (ret_pat)
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] remote.c: free previous results when looking for a ref match
2016-10-08 13:38 ` René Scharfe
@ 2016-10-10 17:03 ` Stefan Beller
0 siblings, 0 replies; 3+ messages in thread
From: Stefan Beller @ 2016-10-10 17:03 UTC (permalink / raw)
To: René Scharfe; +Cc: Junio C Hamano, git@vger.kernel.org
On Sat, Oct 8, 2016 at 6:38 AM, René Scharfe <l.s.r@web.de> wrote:
>
> Again, this check is not necessary. If I read the code correctly the
> pointer could be uninitialized at that point, though, causing free(3) to
> crash.
yep, this patch is bogus.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-10-10 17:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-07 23:58 [PATCH] remote.c: free previous results when looking for a ref match Stefan Beller
2016-10-08 13:38 ` René Scharfe
2016-10-10 17:03 ` Stefan Beller
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).