Article View: linux.kernel.git
Article #3583[PATCH 0/6] getwholeline should clear the buffer upon EOF
From: Junio C Hamano
Date: Sun, 22 Nov 2026 14:03
Date: Sun, 22 Nov 2026 14:03
54 lines
14932 bytes
14932 bytes
This series, which is structured in a somewhat unusual way, addresses various issues that are caused by a long-standing API bug that the strbuf_getwholeline() family of functions shared for quite some time. When they see feof() on their input stream, they immediately return EOF without reading anything (which is good), but they do not clear the output buffer. It is not strictly *wrong* per se, but it proved to be a rather error-prone API contract, as we see in the early part of this series. Patches 2 (shortlog), 3 (clean -i), and 4 (fast-import) explain the existing bugs in various commands and add test(s) to trigger the bugs, but the fix is left for patch 5, and the fix happens in code far away from where these bugs exist. The usual "describe the fix and demonstrate it with new test_expect_success" pattern is deliberately not followed. This is because doing the usual thing would force reviewers to understand the details of three unrelated commands illustrated in patches 2, 3, and 4, as well as the solution in patch 5 at the same time. Because the code that caused the existing bugs does not appear in any of these steps, the log messages of patches 2-4 instead give detailed walkthroughs and are rather long, which is another reason why the nature of this series discourages following the usual pattern and doing everything in one step. Then there is a bonus patch 6, which illustrates two additional issues in "clean" and "fast-import" that cannot have test_expect_failure tests that are safe to include before the problem is fixed, because these breakages are infinite loops. Patch 1, by the way, is what I posted elsewhere already. This is a caller that implicitly relied on strbuf_getwholeline() not clearing the buffer upon feof(), and it is fixed in such a way that it does not matter if strbuf_getwholeline() clears or leaves the buffer upon feof() so "mailinfo" keeps working before or after patch 5 of this series. 1/6: mailinfo: do not call handle_body() when headers end at EOF 2/6: t4201: demonstrate shortlog reusing stale buffer on EOF 3/6: t7301: demonstrate "clean -i" ask mode deleting past EOF 4/6: t9300: demonstrate fast-import re-parsing heredoc delimiter at EOF 5/6: strbuf_getwholeline(): clear strbuf upon EOF 6/6: t7301, t9300: test EOF loops fixed by clearing strbuf upon EOF mailinfo.c | 18 +++++++---- strbuf.c | 6 ++-- t/t4201-shortlog.sh | 29 +++++++++++++++++ t/t5100-mailinfo.sh | 18 +++++++++++ t/t7301-clean-interactive.sh | 31 +++++++++++++++++++ t/t9300-fast-import.sh | 60 ++++++++++++++++++++++++++++++++++++ 6 files changed, 154 insertions(+), 8 deletions(-) -- 2.56.1-766-g80003c9184
Technical Details
Message-ID:
<20261122140347.41990-1-gitster@pobox.com>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76083-linux-kernel-git=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76083-linux-kernel-git=dewy.ru
From: gitster@pobox.com (Junio C Hamano)
Newsgroups: linux.kernel.git
Subject: [PATCH 0/6] getwholeline should clear the buffer upon EOF
Date: Sun, 22 Nov 2026 06:03:41 -0800
Organization: Usenet Network
Message-ID: <20261122140347.41990-1-gitster@pobox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="3648791"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:7eHoaoUEx/jzJiO0s8Ea0IXPRzs= sha256:8vh5n2b5gTYNyKsk0rx+Y6blMeS7ZTI2EY0cXrsuZ1k=
sha1:YAH10mE70c+mGpnaoLoYe4guBto= sha256:VYMO0xdPGxs9B/cQUg7euTdXz9R6IhHEenOqSjFDBRI=
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 9F196125D7F; Sun, 22 Nov 2026 17:04:10 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
tests=[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, 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=pobox.com header.b=XoQfYbct; dkim=pass (2048-bit key)
header.d=messagingengine.com header.b=lUvGlTLK
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 VIKWinGI70nk;
Sun, 22 Nov 2026 17:04:07 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76083-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=pobox.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id B9AFB125D77; Sun, 22 Nov 2026 17:03:53 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 58B5028B38; Sun, 22 Nov 2026 14:03:52 +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=1795356232;
b=d+TbwlJllnGWtIIJg4YLDFg0W5q0Ip/3eknv5afOtfgGu6YCfRQKcn0INF0keHZ98nkp
wjzuYIbeUHArKT2/eQEQiV0I55+RyxnMYUE/4tVkTZLVTJ4v1In6PtHEEuRtqpt3zcxRQ
jjKM8nOZKmu7kt5c9v6lQRmeebGTIhZm11XyV1USxQCxsqMaM8UpuktKKziP32ZDyeAMp
T/6nt+ngLLowC3OYUQtE3dvHZE7VE+fOWp1BShd2727LJG6GAz1PG5b355X7PFhNKSVPc
faIRRv8StaDjX7UBwt1+bT4T9hbE6oLRbEPIFlkNVLKt8YOzi6dNG3C7EYgIqmrSU2Q==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795356232;
h=X-Original-To:Received:DMARC-Filter:Received:Received:DKIM-Signature:
DKIM-Signature:X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:
Message-Instance:X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:
X-ME-Proxy:Feedback-ID:Received:From:To:Subject:Date:Message-ID:
X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=arrrYtOakUIDUD5PQplM8OOBFcjyegn9kR+9IsdblTk=;
b=Hj6U2m1muIQFaTwU782EYxxX4yxLKrR5JbjyAZE99HiJ+SL7/Yz3DcjgBbwUs6cTpe9x
aCRE4CJk4P5dn296EwxMfEb2VnnwDw2wFGei8PEBGAHRWbV5FRuPRdxSHrFsmqJmYLEJa
lr5+BCPibUoBWttX2Hy6POLj5M3rDKCnAeLihV7C2El6LJyjqr5qvEZmxocXkioZvZ983
w5J1WF6S+qjVVizn5GhJ7FXlzRaRYJDBYiFNCgcd0058N7kqQFLGnvNywlGv1zP48L6p3
ZxBLgJjGaHjnhgAi6lFVN1O7rMYPsH5UCj8h4Q3LxrSrFpgXtVQ3Srzsquur1WtDlUQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm2 header.b=XoQfYbct;
dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=lUvGlTLK;
dmarc=pass header.from=pobox.com;
spf=pass smtp.mailfrom=pobox.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 2FC60606A334;
Sun, 22 Nov 2026 14:03:52 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm2 header.b=XoQfYbct;
dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=lUvGlTLK
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.155
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795356231;
b=Kxym8cQhisBDL/fuTwkfZqsgqH8m95BKPFJ2lDv3ns67v89g/31BtwGv4yzhbEoQ/kJc
xr24c4JNkJKQ29/NxU+gvWQC6h+D9g48xW5NyTJgzKjH1E8VRTwPoWNNwUfhrrQxROaoZ
C/rKN2ndcCBmJjF4UAt+RXBWkAFWk4n+DjS4/nEQnM0Xvr5DS8xjeHJM1B0n1rrxs5USC
Z4Yq76BOuXiLf56vLil1wroKlvzSBFY3wV1DM6dahNuHOJRud9e8wSgzFJrIoSPTm4qqb
DUchODOqYREqBsfU8x3i8y7qWK1uq67RSlwl2lp3zBA0bH3MvDPmFEDyucmAd8Fpjjg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795356231;
h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature:
X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance:
X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID:
Received:From:To:Subject:Date:Message-ID:X-Mailer:MIME-Version:
Content-Transfer-Encoding;
bh=arrrYtOakUIDUD5PQplM8OOBFcjyegn9kR+9IsdblTk=;
b=lzI5sGhnVzzsJL9DtGT/8ILAEguABHbffVb4HzXsuXczlTVkdeWFssu1gswKfNuAbfLh
Xf7yfrOlX18+MrGEXyWLbPwz2IB2Ueb/DPxrM7l0ipOMuHZRVqlJ4ZF4CZH3hvMc6HhKI
cwKRZAVicWuaql50ySAvjwqYAVZi8TQDSXi8hzw5cjY8c/YLjAUVnBfBnjhsgMTFYKBXA
ZVL4+8tsPM7GE7k0KtbCfsT4FMh7ozIRZUvYs6qEkmEEbQ1qmOIqALiWYi9ZBCjvj5Fn3
1e7yZpGFsUoqME5byxbVNzBQN0k5AthBgOne1vaMFQf3Idz1K7wnOIaURsLfpKNvm5A==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=pobox.com;
spf=pass smtp.mailfrom=pobox.com;
dkim=pass header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm2 header.b=XoQfYbct;
dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=lUvGlTLK;
arc=none smtp.remote-ip=103.168.172.155
X-Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAAB8606A32A
for <git@vger.kernel.org>; Sun, 22 Nov 2026 14:03:50 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AAAB8606A32A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com
X-Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44])
by mailfhigh.phl.internal (Postfix) with ESMTP id A04E31400247
for <git@vger.kernel.org>; Sun, 22 Nov 2026 09:03:49 -0500 (EST)
X-Received: from phl-frontend-02 ([10.202.2.161])
by phl-compute-04.internal (MEProxy); Sun, 22 Nov 2026 09:03:49 -0500
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; h=cc
:content-transfer-encoding:content-type:date:date:from:from
:in-reply-to:message-id:mime-version:reply-to:subject:subject:to
:to; s=fm2; t=1795356229; x=1795442629; bh=arrrYtOakUIDUD5PQplM8
OOBFcjyegn9kR+9IsdblTk=; b=XoQfYbctKOnV5fKzXMSyRpW2OkASUDlyVPAsv
mbo919aFkatWuxvkjKwTgICsZPGIHJg5AJLlynGbhK1J8xyXcToT4I1QcWYJjBV+
WJ3rsbLWBYFCe/i173fwpU+jCiw9BiySSmRF5D5r5uW3OcloHUj/CF92v2i5cHw3
F6c8Nj6NDs+Q80jk3RA5mihvwT8hDNcUoPSo1w9egeT1jWKL89/UFwD+yGeMakB2
qP3QLPG+apy4k87AJna5knlYQcBWLbshJxOqFU+o3eEmxWq+KZxmSLPrXeS2PUPP
88Iv30KSyXD/XhjgR/4rg/LoCrAA1IRZZJbS6rXtCiiToV+Iw==
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
messagingengine.com; h=cc:content-transfer-encoding:content-type
:date:date:feedback-id:feedback-id:from:from:in-reply-to
:message-id:mime-version:reply-to:subject:subject:to:to
:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=
1795356229; x=1795442629; bh=arrrYtOakUIDUD5PQplM8OOBFcjyegn9kR+
9IsdblTk=; b=lUvGlTLKWbz1coc9ejXJP6TZcRJbJGU+XwqDxOlYRsy1/E8Zsw1
Zc4AMIcMTOYcCtwtNco3uD2I1hP9iOtsL/VUTnSu1ELf7Qntvl6t1M5dI7xvlY7p
4qkTfSSX7n3w5kTZsSXrZ6VzA/rwKk3ACWO0QYL23NFG12kXepO9PjsCmZH759TI
G86ACi7wiXuqwsEf8LvD3D7XVvER711lmp0fQudiS+qYZ/0q4ZJYPRt3KyvPNgDY
wjyrqNUkA0SRavfnbUWdezaJHt4Bc37CyxOoPxH/emVlMd17k3pwIFr4SkJyzYID
st1G+6YLKx/83QQ++/qlUdHm+9swVjbodPw==
X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09;
repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox;
action=sign d=pobox.com a=rsa-sha256;
X-DKIM2-Signature: i=1; m=1; t=1795356229; d=pobox.com;
mf=PGdpdHN0ZXJAcG9ib3guY29tPg==;
rt=PGdpdEB2Z2VyLmtlcm5lbC5vcmc+;
s=fm2:rsa-sha256:ju83m2DSWtJEIy5iSO72RLG/puS3ZGZW2Z1A+8Qt/FMwJFz
UlglVoAIbv6Yo4Ew/gZacTUXP2x9qozNkmE26Hr3HPIG+A94rXgwhaXlSJgsUArd
JyRiOIuG+EvBPtOdbD9YkcsSfm12ApmAKXuHSeyPB3xfLPrf5DLOdQ4PRbYrHyAd
dLMMn7dRv7+Qwkak4GF4LkmS7oZdRYK9BriecUx6Lj7JoAn44DzCq/fZ8wKhWXRr
PI294Og5IMLzbttMzSkfJCnfxoAcVuCzMsop8deABIXuAwz0NM7GEb8uPiS9fZMB
iGeae7a+d+1MEmJuG0kEF2c50v7GbEow9IOtAkQ==;
X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09;
repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox;
action=mi-m=1; hc=8;
hn=content-transfer-encoding,date,feedback-id,from,message-id,
mime-version,subject,to;
X-Message-Instance: m=1; h=sha256:sH8oapzkHBNXa2YRKoK5kIWqacgN0Bei4otRiYfZI68=:y1K3xtN4Yq9t/s099wggyWRJ0gZ/vwxMNozpSL5A90g=;
X-ME-Sender: <xms:RfYCa7lT1fz-K761aHVXsv0ylnR9Rwe1l6efvKt3cwjCnhg0FX01yw>
<xme:RfYCa017LMUwn6rNDkPDefKPbd7BLSPy-BlIZH5gud2T9u3xWixBsh8uDFJxcOHCY
xG77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Y7T1OSWYg1xw>
<xmx:RfYCa2EBSrI3bYcrKVHXqt877NLUsnpBJJwBy1A-fuvJsmYZARGDnw>
<xmx:RfYCa2-yozTBEZi-SRj1m2PSOp9BD0zi9fDLjXiAQr3l2LBFFjFhYpjn>
X-Feedback-ID: if26b431b:Fastmail
X-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun,
22 Nov 2026 09:03:49 -0500 (EST)
X-Mailer: git-send-email 2.56.1-766-g80003c9184
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