From: Jay Soffian <jaysoffian@gmail.com>
To: git@vger.kernel.org
Cc: Jay Soffian <jaysoffian@gmail.com>, gitster@pobox.com
Subject: [PATCH] remote.c: make match_refs() copy src ref before assigning to peer_ref
Date: Mon, 23 Feb 2009 23:05:34 -0500 [thread overview]
Message-ID: <1235448334-36310-1-git-send-email-jaysoffian@gmail.com> (raw)
In-Reply-To: <7vzlgcmsan.fsf@gitster.siamese.dyndns.org>
In some instances, match_refs() sets the peer_ref field of refs in the
dst list such that it points to a ref in the src list. Were a caller to
free both the src and dst lists, this would cause a double-free as
free_refs() frees the peer_ref.
A double-free would also occur freeing just the dst list under the
following configuration:
push = refs/heads/master:refs/heads/backup
push = refs/heads/master:refs/heads/master
Since such a configuration would cause two refs in the dst list to have
the same peer_ref.
This patch corrects the problem by copying the ref when it has been
plucked from the src list.
This issue has gone undetected as the existing callers of match_heads()
call it only once and then terminate, w/o ever bothering to free the src
or dst lists.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
remote.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/remote.c b/remote.c
index d7079c6..98575be 100644
--- a/remote.c
+++ b/remote.c
@@ -927,6 +927,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
struct refspec *rs)
{
struct ref *matched_src, *matched_dst;
+ int copy_src;
const char *dst_value = rs->dst;
char *dst_guess;
@@ -937,6 +938,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
matched_src = matched_dst = NULL;
switch (count_refspec_match(rs->src, src, &matched_src)) {
case 1:
+ copy_src = 1;
break;
case 0:
/* The source could be in the get_sha1() format
@@ -946,6 +948,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
matched_src = try_explicit_object_name(rs->src);
if (!matched_src)
return error("src refspec %s does not match any.", rs->src);
+ copy_src = 0;
break;
default:
return error("src refspec %s matches more than one.", rs->src);
@@ -991,7 +994,7 @@ static int match_explicit(struct ref *src, struct ref *dst,
return error("dst ref %s receives from more than one src.",
matched_dst->name);
else {
- matched_dst->peer_ref = matched_src;
+ matched_dst->peer_ref = copy_src ? copy_ref(matched_src) : matched_src;
matched_dst->force = rs->force;
}
return 0;
@@ -1099,7 +1102,7 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
dst_peer = make_linked_ref(dst_name, dst_tail);
hashcpy(dst_peer->new_sha1, src->new_sha1);
}
- dst_peer->peer_ref = src;
+ dst_peer->peer_ref = copy_ref(src);
dst_peer->force = pat->force;
free_name:
free(dst_name);
--
1.6.2.rc1.291.g83eb
next prev parent reply other threads:[~2009-02-24 4:07 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-23 6:28 [PATCH 00/13] New output style for git remote show Jay Soffian
2009-02-23 6:28 ` [PATCH 01/13] remote: rename variable and eliminate redundant function call Jay Soffian
2009-02-23 6:28 ` [PATCH 02/13] remote: remove unused code in get_ref_states Jay Soffian
2009-02-23 6:28 ` [PATCH 03/13] remote: fix two inconsistencies in the output of "show <remote>" Jay Soffian
2009-02-23 6:28 ` [PATCH 04/13] remote: make get_remote_ref_states() always populate states.tracked Jay Soffian
2009-02-24 1:34 ` Junio C Hamano
2009-02-24 3:09 ` Jay Soffian
2009-02-24 3:13 ` Jay Soffian
2009-02-23 6:28 ` [PATCH 05/13] remote: name remote_refs consistently Jay Soffian
2009-02-23 6:28 ` [PATCH 06/13] string-list: new for_each_string_list() function Jay Soffian
2009-02-23 6:28 ` [PATCH 07/13] remote: new show output style Jay Soffian
2009-02-23 6:46 ` Jeff King
2009-02-23 23:11 ` Marc Branchaud
2009-02-23 6:28 ` [PATCH 08/13] refactor duplicated get_local_heads() to remote.c Jay Soffian
2009-02-23 6:28 ` [PATCH 09/13] refactor duplicated ref_newer() " Jay Soffian
2009-02-23 6:45 ` Jeff King
2009-02-23 7:29 ` [PATCH v2 " Jay Soffian
2009-02-23 8:53 ` Johannes Sixt
2009-02-23 13:41 ` Jay Soffian
2009-02-23 6:28 ` [PATCH 10/13] remote.c: make match_refs() copy src ref before assigning to peer_ref Jay Soffian
2009-02-24 1:34 ` Junio C Hamano
2009-02-24 3:06 ` Jay Soffian
2009-02-24 3:23 ` Junio C Hamano
2009-02-24 4:05 ` Jay Soffian [this message]
2009-02-24 6:17 ` [PATCH] " Junio C Hamano
2009-02-24 6:53 ` Jay Soffian
2009-02-24 7:12 ` Junio C Hamano
2009-02-23 6:28 ` [PATCH 11/13] remote.c: don't short-circuit match_refs() when error in match_explicit_refs() Jay Soffian
2009-02-24 1:34 ` Junio C Hamano
2009-02-24 3:07 ` Jay Soffian
2009-02-23 6:29 ` [PATCH 12/13] remote.c: refactor get_remote_ref_states() Jay Soffian
2009-02-23 6:50 ` Jeff King
2009-02-23 7:55 ` Jay Soffian
2009-02-23 8:31 ` Jay Soffian
2009-02-24 1:05 ` Jeff King
2009-02-23 6:29 ` [PATCH 13/13] remote: new show output style for push refspecs Jay Soffian
2009-02-23 6:59 ` [PATCH 00/13] New output style for git remote show Jeff King
2009-02-23 7:56 ` Jay Soffian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1235448334-36310-1-git-send-email-jaysoffian@gmail.com \
--to=jaysoffian@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).