git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] promisor-remote: skip move_to_tail when n=1
@ 2019-09-25 21:37 Emily Shaffer
  2019-09-26  7:55 ` Jeff King
  2019-09-26 21:31 ` [PATCH v2] promisor-remote: skip move_to_tail when no-op Emily Shaffer
  0 siblings, 2 replies; 10+ messages in thread
From: Emily Shaffer @ 2019-09-25 21:37 UTC (permalink / raw)
  To: git; +Cc: Emily Shaffer, Christian Couder

Previously, when promisor_remote_move_to_tail() is called for a
promisor_remote which is currently the *only* element in promisors, a
cycle is created in the promisors linked list. This cycle leads to a
double free later on in promisor_remote_clear(): promisors is set to
promisors->next (a no-op, as promisors->next == promisors); the previous
value of promisors is free()'d; then the new value of promisors (which
is equal to the previous value of promisors) is also free()'d. This
double-free error was unrecoverable for the user without removing the
filter or re-cloning the repo and hoping to miss this edge case.

Now, when promisor_remote_move_to_tail() would be a no-op, just do a
no-op. In cases of promisor_remote_move_to_tail() where n>1, it works
correctly.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
---
This change showed up for us in a user bugreport; I'm actually fairly
unfamiliar with the codebase here but given the drastic nature of the
failure, I wanted to get a fix up quickly. I'm still working on how to
reproduce this exact case in the test suite (and actually would
appreciate any pointers). Specifically, it looks like we only really
break if we have a single promisor_remote in the linked list, call
move_to_tail() on it at least once, and then call clear() on it without
adding another promisor_remote first.

 promisor-remote.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/promisor-remote.c b/promisor-remote.c
index 9bc296cdde..dccd697c2d 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -89,6 +89,9 @@ static struct promisor_remote *promisor_remote_lookup(const char *remote_name,
 static void promisor_remote_move_to_tail(struct promisor_remote *r,
 					 struct promisor_remote *previous)
 {
+	if (promisors == r && promisors->next == NULL)
+		return;
+
 	if (previous)
 		previous->next = r->next;
 	else
-- 
2.23.0.351.gc4317032e6-goog


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

end of thread, other threads:[~2019-10-01  5:12 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-25 21:37 [PATCH] promisor-remote: skip move_to_tail when n=1 Emily Shaffer
2019-09-26  7:55 ` Jeff King
2019-09-26 17:53   ` Emily Shaffer
2019-09-26 18:06     ` Jeff King
2019-09-26 21:31 ` [PATCH v2] promisor-remote: skip move_to_tail when no-op Emily Shaffer
2019-09-27  0:32   ` Jeff King
2019-09-30 20:28   ` [PATCH v3] " Emily Shaffer
2019-09-30 21:27     ` Jeff King
2019-09-30 22:03     ` [PATCH v4] " Emily Shaffer
2019-10-01  5:12       ` Christian Couder

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).