🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #225

[PATCH 01/15] remote: validate --force-with-lease <refname> argument

#225
From: Jon Simons
Date: Fri, 09 Oct 2026 19:29
55 lines
7279 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: <20261009192953.81794-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-71631-linux-kernel-git=dewy.ru
References: <20261009192953.81794-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-71631-linux-kernel-git=dewy.ru
From: jon@jonsimons.org (Jon Simons)
Newsgroups: linux.kernel.git
Subject: [PATCH 01/15] remote: validate --force-with-lease <refname> argument
Date: Fri,  9 Oct 2026 15:29:39 -0400
Organization: Usenet Network
Message-ID: <20261009192953.81794-2-jon@jonsimons.org>
References: <20261009192953.81794-1-jon@jonsimons.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1183854"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:dbbPsb5xrRjxGfmVbj5IVM2RAzs= sha256:vgu7LmYjHvHtn/+SMvWLx3WS2Xrt1KA8hsY3xP996yI=
	sha1:IinGuvQmxk2mAPXUSXZCPtse/0o= sha256:AoXcUCqvEIcK6jN72yrloebYx2bAQJSm5L/EtEgEuo8=
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 EDD4B10F7D8; Fri,  9 Oct 2026 22:51:00 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: 0.349
X-Spam-Status: No, score=0.349 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.249, MAILING_LIST_MULTI=-1,
	SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=no 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 g93N-p7B9lH4;
	Fri,  9 Oct 2026 22:50:57 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-71631-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 9440710F7C0; Fri,  9 Oct 2026 22:50:54 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by sea.lore.kernel.org (Postfix) with ESMTP id 810FB6861B; Fri,  9 Oct 2026 19:37:28 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id AA9DC4F4D1F;
	Fri,  9 Oct 2026 19:37:17 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=jonsimons.org header.i=@jonsimons.org header.b="RvMzDri4"
X-Received: from smtp89.iad3b.emailsrvr.com (smtp89.iad3b.emailsrvr.com [146.20.161.89])
	(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 A1EA34EFFBD
	for <git@vger.kernel.org>; Fri,  9 Oct 2026 19:37:03 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=146.20.161.89
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1791574635; cv=none; b=HE/CjuIUiXkNE/MZpBguJKZvFob1ro7gTuT2sXV9TlGUD/4S6wBkLemm2Va+bRvmo8DbvQaPlj10atIiDYZxCh0UGDa4vw6m+0/HrfHEFcdWkPZV+y/2743XAN2l5AMOkHRSl+Y1rg9isXBAt1g3J/SF2p/RhZf01rIHM5dL20o=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1791574635; c=relaxed/simple;
	bh=anPM7XW6e9BtAqeKvJqLBBgfSnjDT24XDk6TVJn/3yI=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version; b=na5PzLNO4o8xT3SsGo3poZVzbz0tq2KikvaMuiYMfya22uxbzVRjwSihOsj3/zhOAqW7SNI3SNBcEBDffY0IFNDbQwjwyPq33/TLSjH2FLDJIkZqGMjVkRz3/9cMtuENByaHIP8x20KIdIzZupgBq1WGF5oLeOAIWMwW8Ll36h0=
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=RvMzDri4; arc=none smtp.client-ip=146.20.161.89
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=1791574220;
	bh=anPM7XW6e9BtAqeKvJqLBBgfSnjDT24XDk6TVJn/3yI=;
	h=From:To:Subject:Date:From;
	b=RvMzDri4dMwfmKLhSaMjCfjo8B6+RMcjrenxiNflwLek1on9E4qbSJMW4STFZrMS1
	 tZLhV9NRkzZUyHKNCu9056NBcOl51LNVU8Ruyf8zIrAqN3M4Sq5xG3rihqIcA80NMA
	 K+eXcfbz/BrODUIG9XG+T6qlsnYWJPqelOI4q0Yk=
X-Auth-ID: jon@jonsimons.org
X-Received: by smtp4.relay.iad3b.emailsrvr.com (Authenticated sender: jon-AT-jonsimons.org) with ESMTPSA id D19702038A;
	Fri,  9 Oct 2026 15:30:19 -0400 (EDT)
X-Cc: Jon Simons <jon@jonsimons.org>
X-Mailer: git-send-email 2.55.0
X-In-Reply-To: <20261009192953.81794-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: 523ad08c-aaf2-41d9-9ffc-58ea03a01763-2-1