From nobody Thu Mar 31 15:32:53 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 656D01A55E1A; Thu, 31 Mar 2022 15:32:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KTnPL1Yncz4T1X; Thu, 31 Mar 2022 15:32:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648740774; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mAnzH7VSjmigbMabHRwu/gFdc2r0gjJ4efkR65b1zDY=; b=OpO1k0kL+lCG819nEbHGv2S+O3gPFJ1q4vEvJO6AYm8tAGFrWU7hvxp1KB5HId1B3PGDfr ImiRRi+8K5Yuw2nOOcM+G8569HW/PqX6FKxQH9N881KZMTax1eroPcEudCVJz/gl3ZbWAI aYbpC312jkhLEcW/A+wheJF1VVoYy0fl1EJSymlYwyjgSjEGMjBb1iF84Cpt2x5rzIeg9t Vv8ihbEE9OLzIXcmJW2XY0Nsfy84GsTLqoCczNElV1yNyJDs0ROgy5naDy8QGRWA3tNK15 nW/g5l/DBv+FnQ6GOowMzzdWBHGrjrCTj8dF1bpU/Zd5Ah81a/mDYd9VFrtQ9A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 166AB2A2B0; Thu, 31 Mar 2022 15:32:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 22VFWrcc053354; Thu, 31 Mar 2022 15:32:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22VFWr8x053353; Thu, 31 Mar 2022 15:32:53 GMT (envelope-from git) Date: Thu, 31 Mar 2022 15:32:53 GMT Message-Id: <202203311532.22VFWr8x053353@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 7be0c792c46c - stable/13 - libc: Restore fp state upon flush error in fputc List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 7be0c792c46c5a1faf46b611058953aa85b192d6 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648740774; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mAnzH7VSjmigbMabHRwu/gFdc2r0gjJ4efkR65b1zDY=; b=tVN6x0FSSw8yFaE+Z+4p/fcEZClxOV7aYX96Rs+Y+fbA1gU+LP46/TRoL0orGdfHcVQ9am iqGdpz/GytNCh0puBWBEDD5ilFg7fi2pThUQg5G/fB39jcyZKXCC8yPUseAOO3dbNeFtTM 0ZFQyBf2Tcx/knGEw74/oJVpt5SvIvzDXdNaCubAWe90rKwyhVE/oZ3yJphJLCOLT9NUun 63zFScWa/w5BqzVdrqtg7m2jW8HifJI7XJVAvr42RbbYXF08egjb3xlvj6yDSKzOwr149l HFvYQZbUlsRf+z+PdpPIDP5O6ILa9ayoMr4u98Lp4eTi/1fX8/4PkBwLGWL72w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648740774; a=rsa-sha256; cv=none; b=U4s4U+rFct1D5CWq+Wa0Jys8Kk+aUv8UWbbHuZHuL8KO9RenZ7JFed6NEHImNvVHmex5Jd D6wUH2YrnPl2VrMFPKrQNhjC2h2J7n2JX7CMuWuJSfSqgG2N7r9h5nV2UVwPyB6rVpkUeC GRO/lgSuO9j1Hy2RBWWFO4xZi6zk/owC5lg5nvDEln2DFX40MRLqqQD5Wcq22igJbt8J1t zk2aavBF7Ogz3g6DWM5NqZUY9Z9dB1hSvB+f+MHyJkK6JxEQSS22EIYg5mdWDzGx/zsBvk rsTiHEas3iAV4PEuxIHKnUfiCh/2CdjQmPWvs56pYUUm6fNidTwOZjhYYj0lkg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=7be0c792c46c5a1faf46b611058953aa85b192d6 commit 7be0c792c46c5a1faf46b611058953aa85b192d6 Author: Mark Johnston AuthorDate: 2022-03-25 14:46:24 +0000 Commit: Mark Johnston CommitDate: 2022-03-31 15:21:48 +0000 libc: Restore fp state upon flush error in fputc This is akin to commit bafaa70b6f9098d83d074968c8e6747ecec1e118. Reported by: Guy Yur Fixes: 86a16ada1ea6 Sponsored by: The FreeBSD Foundation (cherry picked from commit 6e13794fbe6e82c21365d0fd66769bf8b19c0197) --- lib/libc/stdio/wbuf.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/libc/stdio/wbuf.c b/lib/libc/stdio/wbuf.c index e1aa70243e94..6cd75145a271 100644 --- a/lib/libc/stdio/wbuf.c +++ b/lib/libc/stdio/wbuf.c @@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$"); int __swbuf(int c, FILE *fp) { + unsigned char *old_p; int n; /* @@ -87,8 +88,15 @@ __swbuf(int c, FILE *fp) } fp->_w--; *fp->_p++ = c; - if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n')) - if (__fflush(fp)) + old_p = fp->_p; + if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n')) { + if (__fflush(fp)) { + if (fp->_p == old_p) { + fp->_p--; + fp->_w++; + } return (EOF); + } + } return (c); }