git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] promisor-remote: fix segfault when remote URL is missing
@ 2025-03-10  7:40 Christian Couder
  2025-03-10 16:29 ` Junio C Hamano
  2025-03-11 15:24 ` [PATCH v2] " Christian Couder
  0 siblings, 2 replies; 35+ messages in thread
From: Christian Couder @ 2025-03-10  7:40 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Patrick Steinhardt, Taylor Blau, Eric Sunshine,
	Karthik Nayak, Kristoffer Haugsbakk, brian m . carlson,
	Randall S . Becker, Christian Couder, Christian Couder

Pushing NULL into a 'strvec' results in a segfault, as 'strvec' is a
kind of NULL terminated array that is designed to be compatible with
'argv' variables used on the command line.

So when an URL is missing from the config, let's push an empty string
instead of NULL into the 'strvec' that stores URLs.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---

This is a fix for cc/lop-remote. Sorry for sending it late in the cycle.

 promisor-remote.c                     | 10 +++++++---
 t/t5710-promisor-remote-capability.sh | 16 ++++++++++++++++
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/promisor-remote.c b/promisor-remote.c
index 6a0a61382f..56567c6e45 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -323,11 +323,15 @@ static void promisor_info_vecs(struct repository *repo,
 	promisor_remote_init(repo);
 
 	for (r = repo->promisor_remote_config->promisors; r; r = r->next) {
-		char *url;
+		char *url = NULL;
+		const char *url_pushed = "";
 		char *url_key = xstrfmt("remote.%s.url", r->name);
 
+		if (!git_config_get_string(url_key, &url) && url)
+			url_pushed = url;
+
 		strvec_push(names, r->name);
-		strvec_push(urls, git_config_get_string(url_key, &url) ? NULL : url);
+		strvec_push(urls, url_pushed);
 
 		free(url);
 		free(url_key);
@@ -356,7 +360,7 @@ char *promisor_remote_info(struct repository *repo)
 			strbuf_addch(&sb, ';');
 		strbuf_addstr(&sb, "name=");
 		strbuf_addstr_urlencode(&sb, names.v[i], allow_unsanitized);
-		if (urls.v[i]) {
+		if (urls.v[i] && *urls.v[i]) {
 			strbuf_addstr(&sb, ",url=");
 			strbuf_addstr_urlencode(&sb, urls.v[i], allow_unsanitized);
 		}
diff --git a/t/t5710-promisor-remote-capability.sh b/t/t5710-promisor-remote-capability.sh
index d2cc69a17e..d9c5676e4d 100755
--- a/t/t5710-promisor-remote-capability.sh
+++ b/t/t5710-promisor-remote-capability.sh
@@ -193,6 +193,22 @@ test_expect_success "clone with 'KnownName' and different remote names" '
 	initialize_server 1 "$oid"
 '
 
+test_expect_success "clone with 'KnownName' and missing URL in the config" '
+	git -C server config promisor.advertise true &&
+
+	# Clone from server to create a client
+	GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
+		-c promisor.acceptfromserver=KnownName \
+		--no-local --filter="blob:limit=5k" server client &&
+	test_when_finished "rm -rf client" &&
+
+	# Check that the largest object is not missing on the server
+	check_missing_objects server 0 "" &&
+
+	# Reinitialize server so that the largest object is missing again
+	initialize_server 1 "$oid"
+'
+
 test_expect_success "clone with promisor.acceptfromserver set to 'KnownUrl'" '
 	git -C server config promisor.advertise true &&
 
-- 
2.49.0.rc1.84.gc0d5bab425.dirty


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

end of thread, other threads:[~2025-03-18 11:04 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-10  7:40 [PATCH] promisor-remote: fix segfault when remote URL is missing Christian Couder
2025-03-10 16:29 ` Junio C Hamano
2025-03-11 15:24   ` Christian Couder
2025-03-11 16:57     ` Junio C Hamano
2025-03-11 15:24 ` [PATCH v2] " Christian Couder
2025-03-11 16:59   ` Junio C Hamano
2025-03-12 11:48     ` Christian Couder
2025-03-11 20:48   ` Junio C Hamano
2025-03-12 11:47     ` Christian Couder
2025-03-11 23:06   ` Jeff King
2025-03-11 23:36     ` Junio C Hamano
2025-03-12 11:47     ` Christian Couder
2025-03-12 11:46   ` [PATCH v3] " Christian Couder
2025-03-12 17:02     ` Junio C Hamano
2025-03-13 10:39       ` Christian Couder
2025-03-13 16:40         ` Junio C Hamano
2025-03-14 14:09           ` Christian Couder
2025-03-14 17:28             ` Junio C Hamano
2025-03-13 10:38     ` [PATCH v4] " Christian Couder
2025-03-13 16:28       ` Junio C Hamano
2025-03-13 17:23         ` Junio C Hamano
2025-03-14 14:10         ` Christian Couder
2025-03-14 14:12       ` [PATCH v5 0/3] "promisor-remote" capability fixes Christian Couder
2025-03-14 14:12         ` [PATCH v5 1/3] promisor-remote: fix segfault when remote URL is missing Christian Couder
2025-03-14 18:59           ` Junio C Hamano
2025-03-18 11:03             ` Christian Couder
2025-03-14 14:12         ` [PATCH v5 2/3] promisor-remote: fix possible issue when no URL is advertised Christian Couder
2025-03-14 14:12         ` [PATCH v5 3/3] promisor-remote: compare remote names case sensitively Christian Couder
2025-03-14 17:28           ` Junio C Hamano
2025-03-18 11:04             ` Christian Couder
2025-03-18 11:00         ` [PATCH v6 0/4] "promisor-remote" capability fixes Christian Couder
2025-03-18 11:00           ` [PATCH v6 1/4] t5710: arrange to delete the client before cloning Christian Couder
2025-03-18 11:00           ` [PATCH v6 2/4] promisor-remote: fix segfault when remote URL is missing Christian Couder
2025-03-18 11:00           ` [PATCH v6 3/4] promisor-remote: fix possible issue when no URL is advertised Christian Couder
2025-03-18 11:00           ` [PATCH v6 4/4] promisor-remote: compare remote names case sensitively Christian Couder

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