From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.152 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796399245; b=FPsDPeMKTuYpAKuuvWDiEh0KF++RyelWJw9o2PO2lT7jISeUpLhjrOI8H0kQjpPm+h5+ 5FA8Tz5wAg98l11NwgdDRjo+B9kmyw2mzcHM0TKCwuMNH58qYjdN8xfydIVVJXmGGgfE7 PZGtrEWJHMpnna+0Z16iEJzYckskngOO4ZwiQhbHp3E1Zgvf72Wxo2bzWzpnnkWg5iIqu rkKQbKMgjtq1zV0NlARTLPg3QicT6d9gKZA6oNQU6N+nRxxfTHt2I4k24zHk5b9vrNRsa eCd4LRpwOLRTZ8udeEjW+JsOqV9A2rwTGHJ789D4OWqgQ2OXLtym1f0JWmU45DSKOdg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796399245; 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:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=iiX1QTspaxJEWTZA/wQYPrJ0N7bAZpZJgdarIOpETiE=; b=yC19BtLWVsPJjVOFKIIOIAVi2L9x8mEKdpfMyWKwVDluVwIwGmnGHgIPFxesasU2UYWJ N/3+GCTRdmwsj/A58odQaBhYEUNtdcNHgnRIckBt+Ibwb5gBZAp0eahclAbDHAJzZTqx6 5w4fIVfObcuHVHfED7Ys/UDnuY/2CLcubJgI287nZKOeK6uM43QiPKdtg1DDCkPOMjCFX Snb+y7CGKxvaA2mOK+m61swFYDs4I98XaTSDYcVk8rFSUMr8MH48oPJd+erFd8B87aTEA m6gDsfR7Vqv2VUaBoNTDfvvlWvkpuDUgxMNWqr0FURHtRVqGYCOQquPT4UKYdnQWP5Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass header.d=pks.im header.i=@pks.im header.a=rsa-sha256 header.s=fm1 header.b="ObvDk2/U"; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm1 header.b=m3m0fnny; arc=none smtp.remote-ip=103.168.172.152 Received: from fhigh-a1-smtp.messagingengine.com (fhigh-a1-smtp.messagingengine.com [103.168.172.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 585AB606A32F for ; Fri, 4 Dec 2026 15:47:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 585AB606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=pks.im header.i=@pks.im header.a=rsa-sha256 header.s=fm1 header.b=ObvDk2/U; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm1 header.b=m3m0fnny Received: from phl-compute-11.internal (phl-compute-11.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id 7BA33140013D for ; Fri, 4 Dec 2026 10:47:24 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-11.internal (MEProxy); Fri, 04 Dec 2026 10:47:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1796399244; x=1796485644; bh=iiX1QTspax JEWTZA/wQYPrJ0N7bAZpZJgdarIOpETiE=; b=ObvDk2/UOZo++6J5LdQWLOfrIf jD2ezkP1yh9/yz34cbKv/PXpn4oKhuDIELxBAp/Hp/e457RvQhHfIC/yneVW8xbY e/rWMkq7SU+eUFy+E6SsSA5VzYypH3BokDCqmVNtY7LoiEzN7OhKS5RdAEzrauzB nBRA/KQ/zHiTccCO482e/a6WmXTYLAAqvTnekx9M5IPLxnN87B3pv6qY5ufooMkR gGjr3SuFKhCWKwu38Z1AlVKCHz5TrLF9zDtEI56q8Cw61PbYugogyxvb/NQ1siTf IVaZHN2bUNtAvr55ng8OnkifBLteEXWKa6m3OpZRCl5jmcYq2j4dBCE79OlQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1796399244; x=1796485644; bh=iiX1QTspaxJEWTZA/wQYPrJ0N7bAZpZJgda rIOpETiE=; b=m3m0fnnyggti55ognUnidxy72aPIhiZY9C0kVoYcjzXxfkQllyY xw0Rnd3g6bVH9POqkEHbJPIXd/UTS8THCPVBwGRJNDjNbhv6sZuEZZsOASVVXTW7 yE5yVXwdDVHhOKcuVlBWdE9mIqrJ5xHTLXGQ287Jym3FTm40Hp+AdHAlHsX0zVlU N3TCPpEjWPxsnnSYQJidwYLQaPPcFNORAQn9LM0EbmyDkq/BsUwKBr60o6wBo4gy a+o5Uf39H0GpCRcGSPOKimihuIpRcHgGfPIBUshbtZRJ2pt3qkNYTOPSSaDuJbwZ 1FI8cwSugyozgWXdG76CGuadDDKAE/fSCsA== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=pks.im a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796399244; d=pks.im; mf=PHBzQHBrcy5pbT4=; rt=PGdpdEB2Z2VyLmtlcm5lbC5vcmc+; s=fm1:rsa-sha256:YKvhtcZHLmC4TBj9XUuHBufwQDrK0IU8AJDFQBPtwFyIgGz IodDcoaKFdCvyxp/KShW1LzcrzKl6qkS/xSgyKx6e+ZGhwUENVftbR5BwvOQD2P1 26DI39rLcCMRkhLlUSh8OtobkrJ9RS8FbY1O7YTtrHlRdqdM9D2Icp7V//wHo1AD 7c6/TGws90uYMA95p0U7maooUHdKV5T0SlzdkXvh14AxNX9t8oQeaLj5vfat9LV5 In56EQAROVtVaoZOLXOqG/Dm7XSnYfjLuLq3zyt99OuC3CVQ6MRD7pQd19789Y6U GHjcVa61EFhKyAzURfMyszvsFPWEfdOWKg4B8ag==; 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=12; hn=cc,content-disposition,content-type,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:Q6o6vvYpQgb2aiK9uzqGJDKN8qADh0t9Pb8lP/ORfJg=:lWt7FZT6oNnnTiLW1SJJsytQ5L5IIMhiITvY7EfcprY=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTE2CksDmoRZgaLvOYqeiL2yXDakirArXvoPlD061gq5H07h0TGDhwnzSsYkZyB/Hu Lrpt4v7X2c3rpFsfCGCUlGOPWjcn+n2knc+NVLdIS7N46OPZkcWJzO+FS1f4a9EoG5+65V hMwzIPr+GAe+R1wke2F9GgigIDxSjrnCAS7jhc1n6sph3tT7Uff3+RiTw0Xh6iO6bQJKvt 89BiRv8ASsmRcPl0ulkuu2honmlJQ7VaKJmdQ+MDd7FJkhxlxGJ44y9pQy7odWx/tgKY5+ PKUVQFp2WGMKjJV1iXV498BlYg2WEHrTowFnFA92hyIgsfgnq3qtIvj5Plyq0M+7mUiLlc BY28+omJA43dOSPSAaVmdJjXwz83MYmcQY+03l1nYsap8+LcPCdWSYcfKlNfabgiNsnZnx Y5lsWBE5SdijJd4uoJSIYPn4hL9DR4bd2rvcTI2HV2KED1uxSrWb7jhtzdJld66Giewraj DcUEXFkBs28qPduiGwGOFbcCUcuAmhkGORzCmsq3jLe09drUntmmOr8WINuGynM/2+AO/h cWB9IYhd1GF1ECdRRE05QKvPNc3YQxoKGGKub6axW9moCa+kXAoCirvrpHVNUY/0kX9c/8 qmcn/lSGP6hiM55r69uzAh8sTdMgZHvAtQZoQfSp5wtWRak2XXr3p/9GNI0Q X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 4 Dec 2026 10:47:23 -0500 (EST) Received: by mail (OpenSMTPD) with ESMTPSA id 4401a514 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 4 Dec 2026 15:47:22 +0000 (UTC) Date: Fri, 4 Dec 2026 16:47:20 +0100 From: Patrick Steinhardt To: Junio C Hamano Cc: git@vger.kernel.org Subject: Re: [PATCH 5/6] strbuf_getwholeline(): clear strbuf upon EOF Message-ID: References: <20261122140347.41990-1-gitster@pobox.com> <20261122140347.41990-6-gitster@pobox.com> X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261122140347.41990-6-gitster@pobox.com> On Sun, Nov 22, 2026 at 06:03:46AM -0800, Junio C Hamano wrote: > strbuf_getwholeline(), and its frontends like strbuf_getline_lf(), has > an early return upon seeing that the stream has reached EOF; curiously, > it does not touch the strbuf when it takes this early return code path. > > And indeed, a few callers of these functions make a false assumption > that their buffer will be cleared when the function returns EOF, and due > to that assumption, they are buggy, as we saw in the previous commits. > > Teach strbuf_getwholeline() to clear the buffer when taking the fast EOF > return path. By doing so, we fix all of these code paths, so we can > turn the test_expect_failure tests we added into test_expect_success. > > This would break existing callers that expect that strbuf_getwholeline() > or its frontends do not clear the buffer upon EOF, but such callers are > unlikely. If you call strbuf_getline(&buf), the normal thing to expect > is to lose what you originally had in buf. Expecting that the original > contents can be read back again when the call returns EOF is not really > sensible. There is indeed nobody that relies on the fact that the > original contents are still available to read. > > If strbuf_getwholeline() is "fixed" to clear the buffer upon EOF, "git > mailinfo" would call handle_body() with an empty 'line' upon feof(), but > if this were a header-only message that was sent as "format=flowed" > type, handle_filter_flowed() would get called and access .buf[len - 1] > for this empty line whose len == 0, reading out of bounds. This issue > has been addressed in an earlier patch to teach the code to never call > handle_body() after EOF with an empty line. This last paragraph reads a bit funny to me. I would have simply mentionde that there was one exception that indeed relied on the current behaviour, but that this was already fixed in a preceding patch. I think another good argument for this patch is that `strbuf_getwholeline_fd()` already does the reset unconditionally. So the fix here kind of aligns those two functions with one another. > diff --git a/strbuf.c b/strbuf.c > index c3baa47b3f..62abf01bfa 100644 > --- a/strbuf.c > +++ b/strbuf.c > @@ -643,8 +643,10 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term) > { > ssize_t r; > > - if (feof(fp)) > + if (feof(fp)) { > + strbuf_reset(sb); > return EOF; > + } > > /* Translate slopbuf to NULL, as we cannot call realloc on it */ > if (!sb->alloc) > @@ -688,10 +690,10 @@ int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term) > { > int ch; > > + strbuf_reset(sb); > if (feof(fp)) > return EOF; > > - strbuf_reset(sb); > flockfile(fp); > while ((ch = getc_unlocked(fp)) != EOF) { > if (!strbuf_avail(sb)) I was a bit puzzled at first why the function has two starts. But this is the two different implementations that depend on whether or not we have getdelim(3p). Do we maybe also want to update the function's documentation to mention that they reset the buffer on EOF? Patrick