]> git.ipfire.org Git - thirdparty/git.git/commit - remote.c
remote: make match_refs() copy src ref before assigning to peer_ref
authorJay Soffian <jaysoffian@gmail.com>
Wed, 25 Feb 2009 08:32:16 +0000 (03:32 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 27 Feb 2009 23:19:08 +0000 (15:19 -0800)
commitcdf690e53b5f5af1ca8679b3f3e47ea198692c18
treec887e964a92bf0f6db1abc87e4af5e2fef55548d
parent4229f1fa325870d6b24fe2a4c7d2ed5f14c6f771
remote: make match_refs() copy src ref before assigning to peer_ref

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. This prevents
callers from freeing both the src and dst lists, as doing so would cause
a double-free since free_refs() frees the peer_ref.

As well, the following configuration causes two refs in the dst list to
have the same peer_ref, which can also lead to a double-free:

  push = refs/heads/master:refs/heads/backup
  push = refs/heads/master:refs/heads/master

Existing callers of match_heads() call it only once and then terminate,
w/o ever bothering to free the src or dst lists, so this is not
currently a problem.

This patch modifies match_refs() to first copy any refs it plucks from
the src list before assigning them as a peer_ref. This allows
builtin-remote, a future caller, to free the src and dst lists.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote.c