Article View: linux.kernel.git
Article #3909[PATCH v2 2/2] promisor-remote: fix crash without a repository
From: Christian Couder
Date: Thu, 26 Nov 2026 14:16
Date: Thu, 26 Nov 2026 14:16
144 lines
16588 bytes
16588 bytes
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
Technical Details
Message-ID:
<20261126141626.914848-6-christian.couder@gmail.com>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76452-linux-kernel-git=dewy.ruReferences:
<20261113000600.202744-2-christian.couder@gmail.com> <20261126141626.914848-4-christian.couder@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76452-linux-kernel-git=dewy.ru
From: christian.couder@gmail.com (Christian Couder)
Newsgroups: linux.kernel.git
Subject: [PATCH v2 2/2] promisor-remote: fix crash without a repository
Date: Thu, 26 Nov 2026 15:16:29 +0100
Organization: Usenet Network
Message-ID: <20261126141626.914848-6-christian.couder@gmail.com>
References: <20261113000600.202744-2-christian.couder@gmail.com>
<20261126141626.914848-4-christian.couder@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="482650"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:AniNDBiLSnIyc1fKRp/cMK2Kjwc= sha256:AKq/pBfw9VdM79MHPaKAoYpboKYTv1lSDLv6yr0Xpxo=
sha1:buviQxBXxaWunV3qR9d/6KuOeD0= sha256:qcJzSW7ObznlqxAqkBEsgt56Idmc+cMvrQjI5MJE83U=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 43CD7125EDC; Thu, 26 Nov 2026 17:17:10 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.948
X-Spam-Status: No, score=-1.948 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id q8xLm74n_VAf;
Thu, 26 Nov 2026 17:17:07 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-76452-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id D4376125EE2; Thu, 26 Nov 2026 17:16:58 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 38A70366E3; Thu, 26 Nov 2026 14:16:57 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1795702615;
b=kV+3x2Y506MOOJH3f9O5Jr9SvF0AXq/4qfizbrSKN1NTgvrr7rtvDIzTv80HpXs/1mA/
mMWs33ZuyLZeedo09x68AF3h7WJND6QLVVrzi/Ua4gRORgf4nFQgkzpdH1sYOabYLO25a
AEv4TAlR873hedG3p9obDWuRTKwGlU7HtUiGLcsaQnLwxfrYcedhB9dsJe0vPBnPrwhh2
g9V+p7fftwm/pSfmZ0z+mbJaAgHb+MUhmOf6LHR1Z+/4lZO/ecHiCI385AXmcD6QoqV8R
4+rE34fDQ5e23zY0ZmQSBZQ1Ibt0znPyDsadew5ME/dHAepS+T3Oar+Q1Y3BzpxDqdA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795702615;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=sM+AoiCmyZsHcA0ZO4/Gm7UdjU0FjigF8UJrOVzyAqw=;
b=u8wqWsTbUFAjx6H5t2bxDs6Qi4O2Sgh/B9SoROzDUAeuAIcFdapm6O/Aqj5G1kuTatuQ
Wjy7s6XkuFYPdP89XQBVQdrO2R8hiA94Jhw6kZaRPP+8pRs2BBj31nu6uXftwnMqJ9jxJ
yiUEwZ09/1WEGFr5JijE/yTDBrXy+er13dMt6ic6XcM2ZPVO+Su4eBh2eu2N0nczgbBZE
eDPyMqXesf+eaz5u110ZU5z4Jev8QUT0iQRWJ+0pFQFlJn8ZiW8XiKV7Wu6/2BdQC23Ie
rzJiKIFoLQl01ICUky9i4JKvYrW0VX61nz6sI4jBEtPhWzl0n5bSVnBcUzAZ+QAkK2A==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=aprhXTp9;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id E9A73606A336;
Thu, 26 Nov 2026 14:16:54 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=aprhXTp9
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.53
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795702614;
b=an3cqdOW6BwRJymLGNkDwG1Kv7+kvReFimjxQyNSYodK31/tV4Np5hHY3VQgJVr+fWlR
z/K9d+wVh7xfGou+UyU3loptKkycWjDcCq2OPHIfS3r2PnIHpi6zDcCfNULeyxnWTxthd
IJyLWcSjAZ2IV+whUWVYBjs8l9c7mS4LrtWdVDx8v5UHu9zoP1laJZa5QBDyigN3RkS9T
ap3oexqaZc889y2d7HOFnHGdLSP98zhKvFswfkE3ftDH1Qvc/PsL+OQDg/swXdH48Uaix
P1/vIZVdYj1nLtmXVHI0m4WEZAgNYr/pWnZ9WZSkt+RyCKBl0fc2nEgRqrP3KJgTBGw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795702614;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
Content-Transfer-Encoding;
bh=sM+AoiCmyZsHcA0ZO4/Gm7UdjU0FjigF8UJrOVzyAqw=;
b=e+glxzGGYznKxNgiMK93tpwRcOb4PXouEp1E5kb+mg74FAOxdSQcMR2Gxhq+UdWF4MXU
Ma21E57Md0HtiCnRNznjOsVFM8/n6mVMeLF5jPoc3Oey0PpaCOF7Xsirlp0XRPtSuq4hU
O6q0q7S7mxV1LtSgMmLHHTDbO3b0zzhIwIvh+ffUwNkMrFhdzg+5YWTJHTNTN0P41Kmnr
B1jjrhFlXmbuc1lBC36Jrr/nRycItR3NTUmInYRrG3IRkO0Zw0gQENqRLZT3EAm6oI5Pw
1SCZHRvR972lQkmrcJNE/rv7DwX41DvkgeM7FOkMa6Gh9js7OKhigyjQAXWHANDBMqg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=aprhXTp9;
arc=none smtp.remote-ip=209.85.128.53
X-Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA8C2606A31E
for <git@vger.kernel.org>; Thu, 26 Nov 2026 14:16:53 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BA8C2606A31E
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4a2d6d01ecbso38209105e9.0
for <git@vger.kernel.org>; Thu, 26 Nov 2026 06:16:53 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1795702612; x=1796307412; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=sM+AoiCmyZsHcA0ZO4/Gm7UdjU0FjigF8UJrOVzyAqw=;
b=aprhXTp9GeNlzGtXbMt9qOcRGlreYdeXbrk4T70ezzsQ3QD9ppN8FWStlGUHbg91sz
U7nQ8MG9MQ7Ic/LeJmxp2hqZM2uq3R6tZwLv531y8zoTmgVHeUKzw33MXJdxZNMU8k5D
Yxyy/rD8NA190dWQMPe3PWB24Qz5qn3znPM+HVRIeYjushP5bNCVkhkeiShrv7fAoIvA
5wbUSgTZM35fqXRE7MUiOFcjLfUOvUDevQeVrtipUKJiUegtAb0/oByJKEZyTsOS7ZXC
jmPoLFH2NFyX+2DdK9fN9WcSlqfsIDqMM9kNteIMsT+KVrqfuk7fRstTmV5gx1uHmA5R
YfnA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1795702612; x=1796307412;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
:to:cc:subject:date:message-id:reply-to:content-type;
bh=sM+AoiCmyZsHcA0ZO4/Gm7UdjU0FjigF8UJrOVzyAqw=;
b=oyt0qhJcgYfJjY1FfBtaAp8scYsCGNIoe7X7GuxLvPDG+mynhimq0izzQl7ilLeZmc
lAEzM8NAFIb9vSuH3XEdkU4V9W/AljgV9LAUZalzKcdK3oSk0gvODPi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Oq7t62NdfPviMbdqU5lELZWZ1XyeJu0f+rnCEdz1Uh3FFpJKH/TP1R0bLcLTHI
EnPgN0vh3hZBm6ZAtQm+Gwg/X2IgmB0kXB5VAVoUqBKzOJ8ovFMBH6W01fIRla+w==
X-Received: by 2002:a05:600c:1d09:b0:4bb:6b59:aac3 with SMTP id 5b1f17b1804b1-4bb88816050mr445900805e9.29.1795702611987;
Thu, 26 Nov 2026 06:16:51 -0800 (PST)
X-Received: from christian--20230123--2G7D3 ([62.35.114.108])
by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4b8e564e39asm10127999f8f.57.2026.11.26.06.16.49
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Thu, 26 Nov 2026 06:16:49 -0800 (PST)
X-Cc: Junio C Hamano <gitster@pobox.com>,
Patrick Steinhardt <ps@pks.im>,
Christian Couder <christian.couder@gmail.com>
X-Mailer: git-send-email 2.56.1.472.g808159e44e.dirty
X-In-Reply-To: <20261126141626.914848-4-christian.couder@gmail.com>
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list