* [PATCH] promisor-remote: fix crash without a repository
@ 2026-11-13 0:06 Christian Couder
2026-11-13 19:42 ` Junio C Hamano
2026-11-26 14:16 ` [PATCH v2 0/2] Fix crash without a repository in ls-remote Christian Couder
0 siblings, 2 replies; 8+ messages in thread
From: Christian Couder @ 2026-11-13 0:06 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Christian Couder
When `git ls-remote` is run outside a repo with some promisor remote
related config options that make it write to its config, namely:
- "promisor.acceptFromServerUrl", which makes it auto-create a
remote, or
- "promisor.acceptFromServer" with "promisor.storeFields", which
makes it store fields,
it crashes in configure_auto_promisor_remote() or store_one_field(), as
the `repo` argument passed to these functions has its `gitdir` member
set to NULL.
This has been happening since 3e20258d11 (promisor-remote: allow a
client to store fields, 2026-02-16) for the `storeFields` case, and
since 7a56394fc6 (promisor-remote: auto-configure unknown remotes,
2026-05-27) for the auto-creation case.
Let's fix that by checking if `repo->gitdir` is NULL at the beginning
of filter_promisor_remote() and returning from it right away in that
case. It doesn't make sense to further process the promisor remote
advertisement as `git ls-remote` currently has no use for promisor
remotes anyway.
Note that `git ls-remote` seems to be the only command that can run
outside a repo and still process the "promisor-remote" capability
advertised by the server, as sending the `ls-refs` protocol v2
command makes it call send_capabilities(), which processes that
advertisement.
Let's also add tests in t5710 for both cases where a crash happened.
Signed-off-by: Christian Couder <christian.couder@gmail.com>
---
This is a fix for another bug found during the NVIDIA hackathon
following the Gerrit User Summit 2026.
promisor-remote.c | 7 +++++-
t/t5710-promisor-remote-capability.sh | 31 +++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/promisor-remote.c b/promisor-remote.c
index 316d9950aa..9c405847bb 100644
--- a/promisor-remote.c
+++ b/promisor-remote.c
@@ -1310,9 +1310,14 @@ static void filter_promisor_remote(struct repository *repo,
struct store_info *store_info = NULL;
struct string_list_item *item;
bool reload_config = false;
- enum accept_promisor accept = accept_from_server(repo);
+ enum accept_promisor accept;
struct string_list accept_urls = STRING_LIST_INIT_DUP;
+ if (!repo->gitdir)
+ return;
+
+ accept = accept_from_server(repo);
+
/* Load and validate the acceptFromServerUrl config */
load_accept_from_server_url(repo, &accept_urls);
diff --git a/t/t5710-promisor-remote-capability.sh b/t/t5710-promisor-remote-capability.sh
index 463e9e00b0..50a73ec8b0 100755
--- a/t/t5710-promisor-remote-capability.sh
+++ b/t/t5710-promisor-remote-capability.sh
@@ -813,6 +813,37 @@ test_expect_success "clone with invalid promisor.acceptFromServerUrl" '
initialize_server 1 "$oid"
'
+test_expect_success "ls-remote without a repo doesn't auto-configure" '
+ git -C server config promisor.advertise true &&
+
+ nongit git -c promisor.acceptFromServerUrl="$ENCODED_TRASH_DIRECTORY_URL/*" \
+ ls-remote "$TRASH_DIRECTORY_URL/server" >out 2>&1 &&
+
+ # Refs are properly listed
+ test_grep "refs/heads/" out &&
+
+ # No remote is configured
+ test_grep ! "Auto-creating" out
+'
+
+test_expect_success "ls-remote without a repo doesn't store fields" '
+ git -C server config promisor.advertise true &&
+ test_config -C server promisor.sendFields token &&
+ test_config -C server remote.lop.token "fooBar" &&
+
+ nongit git -c promisor.acceptFromServer=All \
+ -c promisor.storeFields=token \
+ -c remote.lop.promisor=true \
+ -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \
+ ls-remote "$TRASH_DIRECTORY_URL/server" >out 2>&1 &&
+
+ # Refs are properly listed
+ test_grep "refs/heads/" out &&
+
+ # No field is stored
+ test_grep ! "Storing new token" out
+'
+
test_expect_success "clone with promisor.sendFields" '
git -C server config promisor.advertise true &&
test_when_finished "rm -rf client" &&
base-commit: 1891de46f79dc444a47db1c87bd0c8c76b5463f2
--
2.56.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH] promisor-remote: fix crash without a repository 2026-11-13 0:06 [PATCH] promisor-remote: fix crash without a repository Christian Couder @ 2026-11-13 19:42 ` Junio C Hamano 2026-11-16 6:35 ` Patrick Steinhardt 2026-11-26 14:16 ` [PATCH v2 0/2] Fix crash without a repository in ls-remote Christian Couder 1 sibling, 1 reply; 8+ messages in thread From: Junio C Hamano @ 2026-11-13 19:42 UTC (permalink / raw) To: Christian Couder; +Cc: git, Patrick Steinhardt Christian Couder <christian.couder@gmail.com> writes: > When `git ls-remote` is run outside a repo with some promisor remote > related config options that make it write to its config, namely: > > - "promisor.acceptFromServerUrl", which makes it auto-create a > remote, or > - "promisor.acceptFromServer" with "promisor.storeFields", which > makes it store fields, > > it crashes in configure_auto_promisor_remote() or store_one_field(), as > the `repo` argument passed to these functions has its `gitdir` member > set to NULL. It is tricky that "ls-remote" wants to work outside a repository. > This has been happening since 3e20258d11 (promisor-remote: allow a > client to store fields, 2026-02-16) for the `storeFields` case, and > since 7a56394fc6 (promisor-remote: auto-configure unknown remotes, > 2026-05-27) for the auto-creation case. > > Let's fix that by checking if `repo->gitdir` is NULL at the beginning > of filter_promisor_remote() and returning from it right away in that > case. It doesn't make sense to further process the promisor remote > advertisement as `git ls-remote` currently has no use for promisor > remotes anyway. Another possibility is to nip this higher in the callchain. If we know, as you said, "ls-remote" has no need to talk about promisors, turning promisor_remote_reply() into a NOOP outside a repository might be better, but the function does not take a repository parameter to be able to tell if we have a repository in the first place---perhaps we should add one? An illustration patch below. The callers (there are only two) should of course be updated. In any case, we should comment and say why we punt when '.gitdir' is NULL and why it is safe to punt. In the illustration patch below, I only covered the former but not the latter. promisor-remote.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git c/promisor-remote.c w/promisor-remote.c index 316d9950aa..702c53c2c4 100644 --- c/promisor-remote.c +++ w/promisor-remote.c @@ -1373,11 +1373,20 @@ static void filter_promisor_remote(struct repository *repo, } } -void promisor_remote_reply(const char *info, char **accepted_out) +void promisor_remote_reply(struct repository *repo, const char *info, char **accepted_out) { struct string_list accepted_remotes = STRING_LIST_INIT_NODUP; - filter_promisor_remote(the_repository, &accepted_remotes, info); + /* + * "ls-remote" has no business talking about promisors, and worse yet, + * it can be run outside a repository. + */ + if (!repo->gitdir) { + if (accepted_out) + *accepted_out = NULL; + return; + } + filter_promisor_remote(repo, &accepted_remotes, info); if (accepted_out) { if (accepted_remotes.nr) { ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] promisor-remote: fix crash without a repository 2026-11-13 19:42 ` Junio C Hamano @ 2026-11-16 6:35 ` Patrick Steinhardt 2026-11-16 15:29 ` Junio C Hamano 0 siblings, 1 reply; 8+ messages in thread From: Patrick Steinhardt @ 2026-11-16 6:35 UTC (permalink / raw) To: Junio C Hamano; +Cc: Christian Couder, git On Fri, Nov 13, 2026 at 11:42:47AM -0800, Junio C Hamano wrote: > Christian Couder <christian.couder@gmail.com> writes: > > > When `git ls-remote` is run outside a repo with some promisor remote > > related config options that make it write to its config, namely: > > > > - "promisor.acceptFromServerUrl", which makes it auto-create a > > remote, or > > - "promisor.acceptFromServer" with "promisor.storeFields", which > > makes it store fields, > > > > it crashes in configure_auto_promisor_remote() or store_one_field(), as > > the `repo` argument passed to these functions has its `gitdir` member > > set to NULL. > > It is tricky that "ls-remote" wants to work outside a repository. > > > This has been happening since 3e20258d11 (promisor-remote: allow a > > client to store fields, 2026-02-16) for the `storeFields` case, and > > since 7a56394fc6 (promisor-remote: auto-configure unknown remotes, > > 2026-05-27) for the auto-creation case. > > > > Let's fix that by checking if `repo->gitdir` is NULL at the beginning > > of filter_promisor_remote() and returning from it right away in that > > case. It doesn't make sense to further process the promisor remote > > advertisement as `git ls-remote` currently has no use for promisor > > remotes anyway. > > Another possibility is to nip this higher in the callchain. If we > know, as you said, "ls-remote" has no need to talk about promisors, > turning promisor_remote_reply() into a NOOP outside a repository > might be better, but the function does not take a repository > parameter to be able to tell if we have a repository in the first > place---perhaps we should add one? An illustration patch below. > The callers (there are only two) should of course be updated. I was wondering myself whether a better fix would be to start passing down the repository and then detect this case by checking for `!repo` instead. From my point of view it's nowadays a bit of a code smell to check whether the passed repository itself is actually an initialized one or not: if we aren't operating inside a repository, then the caller shouldn't pass one. That may be a bigger refactoring though, so depending on its scope I'm happy to live with the easier fix for now. > diff --git c/promisor-remote.c w/promisor-remote.c > index 316d9950aa..702c53c2c4 100644 > --- c/promisor-remote.c > +++ w/promisor-remote.c > @@ -1373,11 +1373,20 @@ static void filter_promisor_remote(struct repository *repo, > } > } > > -void promisor_remote_reply(const char *info, char **accepted_out) > +void promisor_remote_reply(struct repository *repo, const char *info, char **accepted_out) > { > struct string_list accepted_remotes = STRING_LIST_INIT_NODUP; > > - filter_promisor_remote(the_repository, &accepted_remotes, info); > + /* > + * "ls-remote" has no business talking about promisors, and worse yet, > + * it can be run outside a repository. > + */ > + if (!repo->gitdir) { > + if (accepted_out) > + *accepted_out = NULL; > + return; > + } But in any case, we should also detect the case where `!repo`, I'd say. Otherwise we'll have to adapt this code again once this funciton's call chains get rid of `the_repository`. Thanks! Patrick ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] promisor-remote: fix crash without a repository 2026-11-16 6:35 ` Patrick Steinhardt @ 2026-11-16 15:29 ` Junio C Hamano 2026-11-26 14:25 ` Christian Couder 0 siblings, 1 reply; 8+ messages in thread From: Junio C Hamano @ 2026-11-16 15:29 UTC (permalink / raw) To: Patrick Steinhardt; +Cc: Christian Couder, git Patrick Steinhardt <ps@pks.im> writes: > I was wondering myself whether a better fix would be to start passing > down the repository and then detect this case by checking for `!repo` > instead. That would be the most sensible way forward, as it would potentially allow us to help more code paths free from the_repository. > From my point of view it's nowadays a bit of a code smell to > check whether the passed repository itself is actually an initialized > one or not: if we aren't operating inside a repository, then the caller > shouldn't pass one. > > That may be a bigger refactoring though, so depending on its scope I'm > happy to live with the easier fix for now. Yes. >> + /* >> + * "ls-remote" has no business talking about promisors, and worse yet, >> + * it can be run outside a repository. >> + */ >> + if (!repo->gitdir) { >> + if (accepted_out) >> + *accepted_out = NULL; >> + return; >> + } > > But in any case, we should also detect the case where `!repo`, I'd say. > Otherwise we'll have to adapt this code again once this funciton's call > chains get rid of `the_repository`. Yes, again, but as long as we have sufficient test coverage right now, the dereference repo->gitdir would immediately segfault when our caller stops passing the_repository and instead passes NULL when it notices that we are not in a repository ;-) ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] promisor-remote: fix crash without a repository 2026-11-16 15:29 ` Junio C Hamano @ 2026-11-26 14:25 ` Christian Couder 0 siblings, 0 replies; 8+ messages in thread From: Christian Couder @ 2026-11-26 14:25 UTC (permalink / raw) To: Junio C Hamano; +Cc: Patrick Steinhardt, git On Mon, Nov 16, 2026 at 4:29 PM Junio C Hamano <gitster@pobox.com> wrote: > > Patrick Steinhardt <ps@pks.im> writes: > > > I was wondering myself whether a better fix would be to start passing > > down the repository and then detect this case by checking for `!repo` > > instead. > > That would be the most sensible way forward, as it would potentially > allow us to help more code paths free from the_repository. This is implemented in the v2 I just sent. > > From my point of view it's nowadays a bit of a code smell to > > check whether the passed repository itself is actually an initialized > > one or not: if we aren't operating inside a repository, then the caller > > shouldn't pass one. > > > > That may be a bigger refactoring though, so depending on its scope I'm > > happy to live with the easier fix for now. > > Yes. I have just added a small preparatory refactoring patch in v2. I think there is no need to do more than that in this series. > >> + /* > >> + * "ls-remote" has no business talking about promisors, and worse yet, > >> + * it can be run outside a repository. > >> + */ > >> + if (!repo->gitdir) { > >> + if (accepted_out) > >> + *accepted_out = NULL; > >> + return; > >> + } Thanks for the suggestion. It looks mostly like this in the v2. > > But in any case, we should also detect the case where `!repo`, I'd say. > > Otherwise we'll have to adapt this code again once this funciton's call > > chains get rid of `the_repository`. > > Yes, again, but as long as we have sufficient test coverage right > now, the dereference repo->gitdir would immediately segfault when > our caller stops passing the_repository and instead passes NULL when > it notices that we are not in a repository ;-) The check is `!repo || !repo->gitdir` in v2. Even if we have test coverage, I think it doesn't cost much and it's a bit better to be ready for when NULL will be passed. Thanks both. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 0/2] Fix crash without a repository in ls-remote 2026-11-13 0:06 [PATCH] promisor-remote: fix crash without a repository Christian Couder 2026-11-13 19:42 ` Junio C Hamano @ 2026-11-26 14:16 ` Christian Couder 2026-11-26 14:16 ` [PATCH v2 1/2] promisor-remote: pass a repository to promisor_remote_reply() Christian Couder 2026-11-26 14:16 ` [PATCH v2 2/2] promisor-remote: fix crash without a repository Christian Couder 1 sibling, 2 replies; 8+ messages in thread From: Christian Couder @ 2026-11-26 14:16 UTC (permalink / raw) To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Christian Couder When `git ls-remote` is run outside a repo, it can crash when trying to reply to the "promisor-remote" advertisement from a server, if it's configured to save some information from the server into a repo config it doesn't have. Instead it should not try to reply at all. This is a fix for another bug found during the NVIDIA hackathon following the Gerrit User Summit 2026. Overview of the patches ======================= - Patch 1/2 is new in this v2. It adds a new `struct repository *repo` argument to promisor_remote_reply(), and makes its callers pass `the_repository` through it, instead of using that variable itself. It's a small refactoring to prepare for the fix in the next patch, and to prepare a bit for when we won't use `the_repository` anymore. - Patch 2/2 is the actual fix. It adds checks in promisor_remote_reply() to return right away, without replying to the server's advertisement, if it isn't passed a real repository. This series applies cleanly to 'maint'. But it conflicts trivially with my "cc/fetch-promisor-remote-reply" series, which replaces both promisor_remote_reply() callers. To help with this, I can rebase one series on top of the other when that other series graduates. Changes compared to v1 ====================== Thanks to Junio and Patrick for reviewing v1. - This v2 is rebased on top of current 'master' to get the recently merged CI fixes (though some macOS jobs still didn't run, see below). - Patch 1/2 is new (see above). I thought it was cleaner to have the mechanical changes to add a new `struct repository *repo` argument to promisor_remote_reply() (as suggested by Junio) and to change its callers in a preparatory patch. - Patch 2/2 has a number of changes: - The check for a real repo is now made at the beginning of promisor_remote_reply() rather than in filter_promisor_remote() to make sure we don't do anything if there is no real repo. And this check now has a code comment to explain it. - We check for `!repo` too as suggested by Patrick, to make it possible for callers to just pass a NULL `repo` when they are not in a repository, once the call chains leading to promisor_remote_reply() stop using `the_repository`. - We also properly set `*accepted_out` to `NULL` in the no real repo case. - In "promisor-remote.h", we document the new `repo` argument and what happens when it's NULL or not a real repository. - The commit message is improved, especially by: - explaining why it's safe not to reply, quoting gitprotocol-v2(5), and - moving up the paragraph about `git ls-remote` being the only command that can run outside a repo and still process the "promisor-remote" capability. CI tests ======== The osx-meson (macos-15) and osx-clang (macos-15) jobs never ran at all as no runners were available. Otherwise all the test jobs succeeded, see: https://github.com/chriscool/git/actions/runs/45808010154 Christian Couder (2): promisor-remote: pass a repository to promisor_remote_reply() promisor-remote: fix crash without a repository connect.c | 2 +- fetch-pack.c | 2 +- promisor-remote.c | 17 +++++++++++++-- promisor-remote.h | 16 +++++++++----- t/t5710-promisor-remote-capability.sh | 31 +++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 9 deletions(-) Range-diff against v1: -: ---------- > 1: 04e4ff85eb promisor-remote: pass a repository to promisor_remote_reply() 1: d599b50dce ! 2: 72be57dd95 promisor-remote: fix crash without a repository @@ Commit message since 7a56394fc6 (promisor-remote: auto-configure unknown remotes, 2026-05-27) for the auto-creation case. - Let's fix that by checking if `repo->gitdir` is NULL at the beginning - of filter_promisor_remote() and returning from it right away in that - case. It doesn't make sense to further process the promisor remote - advertisement as `git ls-remote` currently has no use for promisor - remotes anyway. - Note that `git ls-remote` seems to be the only command that can run outside a repo and still process the "promisor-remote" capability advertised by the server, as sending the `ls-refs` protocol v2 command makes it call send_capabilities(), which processes that advertisement. - Let's also add tests in t5710 for both cases where a crash happened. + Let's fix that by checking, at the beginning of + promisor_remote_reply(), if the repository it is passed is NULL or + has its `gitdir` member set to NULL, and by returning right away + without accepting any promisor remote in that case. + + It doesn't make sense to further process the promisor remote + advertisement there, as `git ls-remote` currently has no use for + promisor remotes anyway. And not replying is fine, as + gitprotocol-v2(5) says that if the client doesn't want to use any + promisor remote the server advertised, it shouldn't advertise the + "promisor-remote" capability at all in its reply. + + Checking for a NULL repository isn't needed yet, as all the callers + currently pass `the_repository`, but it will make it possible for + callers to just pass NULL when they are not in a repository, once + the call chains leading to promisor_remote_reply() stop using + `the_repository`. This would avoid having to check whether the + repository passed is a real one. + While at it, let's document the behavior when `repo` is NULL or not + a real repository in "promisor-remote.h", and let's add tests in + t5710 for both cases where a crash happened. + + Helped-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Christian Couder <christian.couder@gmail.com> ## promisor-remote.c ## -@@ promisor-remote.c: static void filter_promisor_remote(struct repository *repo, - struct store_info *store_info = NULL; - struct string_list_item *item; - bool reload_config = false; -- enum accept_promisor accept = accept_from_server(repo); -+ enum accept_promisor accept; - struct string_list accept_urls = STRING_LIST_INIT_DUP; +@@ promisor-remote.c: void promisor_remote_reply(struct repository *repo, + { + struct string_list accepted_remotes = STRING_LIST_INIT_NODUP; -+ if (!repo->gitdir) ++ /* ++ * We can be called outside a repository, for example by ++ * "git ls-remote", which has no use for promisor remotes. ++ * Not replying is fine then (see gitprotocol-v2(5)). ++ */ ++ if (!repo || !repo->gitdir) { ++ if (accepted_out) ++ *accepted_out = NULL; + return; ++ } + -+ accept = accept_from_server(repo); -+ - /* Load and validate the acceptFromServerUrl config */ - load_accept_from_server_url(repo, &accept_urls); + filter_promisor_remote(repo, &accepted_remotes, info); + if (accepted_out) { + + ## promisor-remote.h ## +@@ promisor-remote.h: char *promisor_remote_info(struct repository *repo); + /* + * Prepare a reply to a "promisor-remote" advertisement from a server. + * Check the value of "promisor.acceptfromserver" and maybe the +- * configured promisor remotes, if any, to prepare the reply. If the +- * `accepted_out` argument is not NULL, it is set to either NULL or to +- * the names of the accepted promisor remotes separated by ';' if +- * any. See gitprotocol-v2(5). ++ * configured promisor remotes, if any, to prepare the reply. ++ * ++ * If the `accepted_out` argument is not NULL, it is set to either ++ * NULL or to the names of the accepted promisor remotes separated by ++ * ';' if any. See gitprotocol-v2(5). ++ * ++ * `repo` may be NULL, or not a real repository, and in that case ++ * nothing is accepted and `*accepted_out` is set to NULL. + */ + void promisor_remote_reply(struct repository *repo, + const char *info, ## t/t5710-promisor-remote-capability.sh ## @@ t/t5710-promisor-remote-capability.sh: test_expect_success "clone with invalid promisor.acceptFromServerUrl" ' base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe -- 2.56.0 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 1/2] promisor-remote: pass a repository to promisor_remote_reply() 2026-11-26 14:16 ` [PATCH v2 0/2] Fix crash without a repository in ls-remote Christian Couder @ 2026-11-26 14:16 ` Christian Couder 2026-11-26 14:16 ` [PATCH v2 2/2] promisor-remote: fix crash without a repository Christian Couder 1 sibling, 0 replies; 8+ messages in thread From: Christian Couder @ 2026-11-26 14:16 UTC (permalink / raw) To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Christian Couder promisor_remote_reply() uses `the_repository` when it calls filter_promisor_remote(), even though filter_promisor_remote() already takes a `struct repository *` argument. Let's add a `struct repository *repo` parameter to promisor_remote_reply() and pass it down to filter_promisor_remote(). Its two callers, send_capabilities() in "connect.c" and do_fetch_pack_v2() in "fetch-pack.c", pass `the_repository` for now. This is a small step towards getting rid of `the_repository`, and it prepares for a following commit that will make promisor_remote_reply() check the repository it is passed, to fix a crash when it's called outside a repository. No functional change intended. Signed-off-by: Christian Couder <christian.couder@gmail.com> --- connect.c | 2 +- fetch-pack.c | 2 +- promisor-remote.c | 6 ++++-- promisor-remote.h | 4 +++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/connect.c b/connect.c index 87d2e8bccd..bcd9d65f6e 100644 --- a/connect.c +++ b/connect.c @@ -520,7 +520,7 @@ static void send_capabilities(int fd_out, struct packet_reader *reader) } if (server_feature_v2("promisor-remote", &promisor_remote_info)) { char *reply; - promisor_remote_reply(promisor_remote_info, &reply); + promisor_remote_reply(the_repository, promisor_remote_info, &reply); if (reply) { packet_write_fmt(fd_out, "promisor-remote=%s", reply); free(reply); diff --git a/fetch-pack.c b/fetch-pack.c index 55d311c0c3..ff14c28f08 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -1699,7 +1699,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, fsck_options_init(&fsck_options, the_repository, FSCK_OPTIONS_MISSING_GITMODULES); if (server_feature_v2("promisor-remote", &promisor_remote_config)) - promisor_remote_reply(promisor_remote_config, NULL); + promisor_remote_reply(the_repository, promisor_remote_config, NULL); if (args->filter_options.choice == LOFC_AUTO) { struct strbuf errbuf = STRBUF_INIT; diff --git a/promisor-remote.c b/promisor-remote.c index 316d9950aa..85adb66c80 100644 --- a/promisor-remote.c +++ b/promisor-remote.c @@ -1373,11 +1373,13 @@ static void filter_promisor_remote(struct repository *repo, } } -void promisor_remote_reply(const char *info, char **accepted_out) +void promisor_remote_reply(struct repository *repo, + const char *info, + char **accepted_out) { struct string_list accepted_remotes = STRING_LIST_INIT_NODUP; - filter_promisor_remote(the_repository, &accepted_remotes, info); + filter_promisor_remote(repo, &accepted_remotes, info); if (accepted_out) { if (accepted_remotes.nr) { diff --git a/promisor-remote.h b/promisor-remote.h index 301f5ac5cb..198fe768e5 100644 --- a/promisor-remote.h +++ b/promisor-remote.h @@ -65,7 +65,9 @@ char *promisor_remote_info(struct repository *repo); * the names of the accepted promisor remotes separated by ';' if * any. See gitprotocol-v2(5). */ -void promisor_remote_reply(const char *info, char **accepted_out); +void promisor_remote_reply(struct repository *repo, + const char *info, + char **accepted_out); /* * Set the 'accepted' flag for some promisor remotes. Useful on the -- 2.56.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v2 2/2] promisor-remote: fix crash without a repository 2026-11-26 14:16 ` [PATCH v2 0/2] Fix crash without a repository in ls-remote Christian Couder 2026-11-26 14:16 ` [PATCH v2 1/2] promisor-remote: pass a repository to promisor_remote_reply() Christian Couder @ 2026-11-26 14:16 ` Christian Couder 1 sibling, 0 replies; 8+ messages in thread From: Christian Couder @ 2026-11-26 14:16 UTC (permalink / raw) To: git; +Cc: Junio C Hamano, Patrick Steinhardt, Christian Couder When `git ls-remote` is run outside a repo with some promisor remote related config options that make it write to its config, namely: - "promisor.acceptFromServerUrl", which makes it auto-create a remote, or - "promisor.acceptFromServer" with "promisor.storeFields", which makes it store fields, it crashes in configure_auto_promisor_remote() or store_one_field(), as the `repo` argument passed to these functions has its `gitdir` member set to NULL. This has been happening since 3e20258d11 (promisor-remote: allow a client to store fields, 2026-02-16) for the `storeFields` case, and since 7a56394fc6 (promisor-remote: auto-configure unknown remotes, 2026-05-27) for the auto-creation case. Note that `git ls-remote` seems to be the only command that can run outside a repo and still process the "promisor-remote" capability advertised by the server, as sending the `ls-refs` protocol v2 command makes it call send_capabilities(), which processes that advertisement. Let's fix that by checking, at the beginning of promisor_remote_reply(), if the repository it is passed is NULL or has its `gitdir` member set to NULL, and by returning right away without accepting any promisor remote in that case. It doesn't make sense to further process the promisor remote advertisement there, as `git ls-remote` currently has no use for promisor remotes anyway. And not replying is fine, as gitprotocol-v2(5) says that if the client doesn't want to use any promisor remote the server advertised, it shouldn't advertise the "promisor-remote" capability at all in its reply. Checking for a NULL repository isn't needed yet, as all the callers currently pass `the_repository`, but it will make it possible for callers to just pass NULL when they are not in a repository, once the call chains leading to promisor_remote_reply() stop using `the_repository`. This would avoid having to check whether the repository passed is a real one. While at it, let's document the behavior when `repo` is NULL or not a real repository in "promisor-remote.h", and let's add tests in t5710 for both cases where a crash happened. Helped-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Christian Couder <christian.couder@gmail.com> --- promisor-remote.c | 11 ++++++++++ promisor-remote.h | 12 +++++++---- t/t5710-promisor-remote-capability.sh | 31 +++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/promisor-remote.c b/promisor-remote.c index 85adb66c80..b37ec23a3f 100644 --- a/promisor-remote.c +++ b/promisor-remote.c @@ -1379,6 +1379,17 @@ void promisor_remote_reply(struct repository *repo, { struct string_list accepted_remotes = STRING_LIST_INIT_NODUP; + /* + * We can be called outside a repository, for example by + * "git ls-remote", which has no use for promisor remotes. + * Not replying is fine then (see gitprotocol-v2(5)). + */ + if (!repo || !repo->gitdir) { + if (accepted_out) + *accepted_out = NULL; + return; + } + filter_promisor_remote(repo, &accepted_remotes, info); if (accepted_out) { diff --git a/promisor-remote.h b/promisor-remote.h index 198fe768e5..2811950d48 100644 --- a/promisor-remote.h +++ b/promisor-remote.h @@ -60,10 +60,14 @@ char *promisor_remote_info(struct repository *repo); /* * Prepare a reply to a "promisor-remote" advertisement from a server. * Check the value of "promisor.acceptfromserver" and maybe the - * configured promisor remotes, if any, to prepare the reply. If the - * `accepted_out` argument is not NULL, it is set to either NULL or to - * the names of the accepted promisor remotes separated by ';' if - * any. See gitprotocol-v2(5). + * configured promisor remotes, if any, to prepare the reply. + * + * If the `accepted_out` argument is not NULL, it is set to either + * NULL or to the names of the accepted promisor remotes separated by + * ';' if any. See gitprotocol-v2(5). + * + * `repo` may be NULL, or not a real repository, and in that case + * nothing is accepted and `*accepted_out` is set to NULL. */ void promisor_remote_reply(struct repository *repo, const char *info, diff --git a/t/t5710-promisor-remote-capability.sh b/t/t5710-promisor-remote-capability.sh index 463e9e00b0..50a73ec8b0 100755 --- a/t/t5710-promisor-remote-capability.sh +++ b/t/t5710-promisor-remote-capability.sh @@ -813,6 +813,37 @@ test_expect_success "clone with invalid promisor.acceptFromServerUrl" ' initialize_server 1 "$oid" ' +test_expect_success "ls-remote without a repo doesn't auto-configure" ' + git -C server config promisor.advertise true && + + nongit git -c promisor.acceptFromServerUrl="$ENCODED_TRASH_DIRECTORY_URL/*" \ + ls-remote "$TRASH_DIRECTORY_URL/server" >out 2>&1 && + + # Refs are properly listed + test_grep "refs/heads/" out && + + # No remote is configured + test_grep ! "Auto-creating" out +' + +test_expect_success "ls-remote without a repo doesn't store fields" ' + git -C server config promisor.advertise true && + test_config -C server promisor.sendFields token && + test_config -C server remote.lop.token "fooBar" && + + nongit git -c promisor.acceptFromServer=All \ + -c promisor.storeFields=token \ + -c remote.lop.promisor=true \ + -c remote.lop.url="$TRASH_DIRECTORY_URL/lop" \ + ls-remote "$TRASH_DIRECTORY_URL/server" >out 2>&1 && + + # Refs are properly listed + test_grep "refs/heads/" out && + + # No field is stored + test_grep ! "Storing new token" out +' + test_expect_success "clone with promisor.sendFields" ' git -C server config promisor.advertise true && test_when_finished "rm -rf client" && -- 2.56.0 ^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-11-26 14:25 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-13 0:06 [PATCH] promisor-remote: fix crash without a repository Christian Couder 2026-11-13 19:42 ` Junio C Hamano 2026-11-16 6:35 ` Patrick Steinhardt 2026-11-16 15:29 ` Junio C Hamano 2026-11-26 14:25 ` Christian Couder 2026-11-26 14:16 ` [PATCH v2 0/2] Fix crash without a repository in ls-remote Christian Couder 2026-11-26 14:16 ` [PATCH v2 1/2] promisor-remote: pass a repository to promisor_remote_reply() Christian Couder 2026-11-26 14:16 ` [PATCH v2 2/2] promisor-remote: fix crash without a repository Christian Couder
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox