Article View: linux.kernel.git
Article #466[PATCH v2 01/12] remote: validate --force-with-lease <refname> argument
From: Jon Simons
Date: Wed, 14 Oct 2026 03:13
Date: Wed, 14 Oct 2026 03:13
55 lines
7381 bytes
7381 bytes
Use check_refname_format() to validate the <refname> component of
'git push --force-with-lease=<refname>[:<expect>]'.
apply_push_cas() will silently ignore a lease entry that does not match
any remote ref. And today "./refs/heads/main" will happen to be matched
with "refs/heads/main" due to refname_match() usage of mkpath(), whose
cleanup_path() strips leading "./".
An upcoming commit removes mkpath() from refname_match(), after which
there is no unintentional match in this situation, so that the lease
is ignored instead of applied. Reject an invalid refname now to make
this situation fail fast both before and after that change.
Signed-off-by: Jon Simons <jon@jonsimons.org>
---
remote.c | 2 ++
t/t5533-push-cas.sh | 9 +++++++++
2 files changed, 11 insertions(+)
diff --git a/remote.c b/remote.c
index 71170f36a9..114d4d983c 100644
--- a/remote.c
+++ b/remote.c
@@ -2740,6 +2740,8 @@ static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, i
/* "--<option>=refname" or "--<option>=refname:value" */
colon = strchrnul(arg, ':');
entry = add_cas_entry(cas, arg, colon - arg);
+ if (check_refname_format(entry->refname, REFNAME_ALLOW_ONELEVEL))
+ return error(_("'%s' is not a valid refname"), entry->refname);
if (!*colon)
entry->use_tracking = 1;
else if (!colon[1])
diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh
index e6e1360a42..f6eafee7ad 100755
--- a/t/t5533-push-cas.sh
+++ b/t/t5533-push-cas.sh
@@ -63,6 +63,15 @@ test_expect_success setup '
test_commit C
'
+test_expect_success 'push --force-with-lease rejects invalid refname' '
+ setup_srcdst_basic &&
+ (
+ cd dst &&
+ test_must_fail git push --force-with-lease=./refs/heads/main origin main 2>err &&
+ test_grep "is not a valid refname" err
+ )
+'
+
test_expect_success 'push to update (protected)' '
setup_srcdst_basic &&
(
--
2.55.0
Technical Details
Message-ID:
<20261014031347.50433-2-jon@jonsimons.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-71926-linux-kernel-git=dewy.ruReferences:
<20261009192953.81794-1-jon@jonsimons.org> <20261014031347.50433-1-jon@jonsimons.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-71926-linux-kernel-git=dewy.ru From: jon@jonsimons.org (Jon Simons) Newsgroups: linux.kernel.git Subject: [PATCH v2 01/12] remote: validate --force-with-lease <refname> argument Date: Tue, 13 Oct 2026 23:13:36 -0400 Organization: Usenet Network Message-ID: <20261014031347.50433-2-jon@jonsimons.org> References: <20261009192953.81794-1-jon@jonsimons.org> <20261014031347.50433-1-jon@jonsimons.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2206935"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:VY81xGKCFB41Sl/u6ll5TzggWGw= sha256:erOAW1ZDz0UYle//ajPfFgkXE4ndvl1nHtgc0FzDmwA= sha1:Jo/E9vxwMh1CaSCcwuMsEC+gt20= sha256:aqKUV4pyjS6xj3OjIWH+NXz/AwVt1l+qQLOth74xs6I= 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 E533710FFCB; Wed, 14 Oct 2026 06:22:17 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -1.949 X-Spam-Status: No, score=-1.949 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, HEADER_FROM_DIFFERENT_DOMAINS=0.25, 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 (1024-bit key) header.d=jonsimons.org 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 cl_xfuxAQvoQ; Wed, 14 Oct 2026 06:22:15 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=git+bounces-71926-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=jonsimons.org X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 3A9FF10FFC7; Wed, 14 Oct 2026 06:22:07 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sin.lore.kernel.org (Postfix) with ESMTP id 2C4DE2DCD5; Wed, 14 Oct 2026 03:21:57 +0000 (UTC) X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D63DC3C5857; Wed, 14 Oct 2026 03:21:47 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=jonsimons.org header.i=@jonsimons.org header.b="YlsbqV2i" X-Received: from smtp113.iad3a.emailsrvr.com (smtp113.iad3a.emailsrvr.com [173.203.187.113]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 873D53C0601 for <git@vger.kernel.org>; Wed, 14 Oct 2026 03:21:45 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=173.203.187.113 X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791948106; cv=none; b=pg8C9zERk1c6kCudUn0KvC1STDGHsOFa+zmhd4d8Z3fF75IrAYLOcGaqrTgIyMs+kw7v0ysJfoqy+ny3WXWwTgRKfYbsljd0oYxROZEjdGN2AG0V1/KE8wUqkREMm6rOTrKLSsA6mhe9IW/+SNTFIKnoW4r+CfUOIro5CXqGwyg= X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791948106; c=relaxed/simple; bh=anPM7XW6e9BtAqeKvJqLBBgfSnjDT24XDk6TVJn/3yI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i/wiZZOnK2M9gFkDcMWFcmj1LcY1uDQkuRcsbVnwbJ1y2NCyG+5VUtThi82ldXc1Crzyp0sh/u+NJixT1tHsvchpb7oCqkD39ksjKvID20VAphcJij25/2bvYOxB59//wjvdCPoRvMP4DvZa1Ohqe2j7FHzMRlAaYLiHMCvvrGk= X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jonsimons.org; spf=pass smtp.mailfrom=jonsimons.org; dkim=pass (1024-bit key) header.d=jonsimons.org header.i=@jonsimons.org header.b=YlsbqV2i; arc=none smtp.client-ip=173.203.187.113 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=jonsimons.org X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=jonsimons.org X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=jonsimons.org; s=20200911-u7gnnm7o; t=1791947643; bh=anPM7XW6e9BtAqeKvJqLBBgfSnjDT24XDk6TVJn/3yI=; h=From:To:Subject:Date:From; b=YlsbqV2ieslIA0xX3NOuqfom5WTi1e22GocqEbFhCFN8ihXVewW10CFopL1exL0rT ptXG+/HR4NGzGDn2s8NVvuv1DFHSGjhMzp0EWxLwO5PH10gzm6qjLbC7J1rZ16AE0d 7pTb+13NDOR4pPLMYQdZfIUF92bZ9gOKyt7jJRRI= X-Auth-ID: jon@jonsimons.org X-Received: by smtp23.relay.iad3a.emailsrvr.com (Authenticated sender: jon-AT-jonsimons.org) with ESMTPSA id 4170C252A9; Tue, 13 Oct 2026 23:14:03 -0400 (EDT) X-Cc: Jon Simons <jon@jonsimons.org> X-Mailer: git-send-email 2.55.0 X-In-Reply-To: <20261014031347.50433-1-jon@jonsimons.org> X-Precedence: bulk X-Mailing-List: git@vger.kernel.org X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org> X-Classification-ID: 20ae8d58-78b7-4215-81c6-d8119c94fa7d-2-1