From nobody Thu Feb 01 13:11:09 2024 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 4TQfRd4vvDz58ccB; Thu, 1 Feb 2024 13:11:09 +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 4TQfRd2c8Vz4WB2; Thu, 1 Feb 2024 13:11:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706793069; 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=XzjHmnx9thCxlDcuibWDMNgbAayS5phXypDZ2FU2wuA=; b=jWYUkDkrtBogPyDQIcw080pt8bIDCNKAv8ZUSItLUvvuKh/o0/tPABIlM8kWCoZks8ExIP QfaQayPiT9bavIMmZPuf5G4wftawH2lQ+v6KzWKqKFskltzpwcCmvfEiHe1bgsfr9apBik ksMNDc8diThAd9bjF2mPrXNptCLDd55+TJSN5bpmCYHEn8zB45bHlrUSqp9e1WeGvRSTH0 O4c2XrU2+74blgTiZFfelcKqO8eKDNZWla92OJwHfL5Q3ROOzfUE/2NOJ7jneFPVqomkQu oGvSXW0l7ieRPIbzg08hotc+/4CLHAAxBtccgwd6Sla6ASsw83x95xOjJ9d5Aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1706793069; 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=XzjHmnx9thCxlDcuibWDMNgbAayS5phXypDZ2FU2wuA=; b=MQf+vJjwdVIAuWFuxJRn6r3R2vsgFN9UdAywdUivvyVlTAXOfdjS/bSDXeiGZS9Y0xL5dM izYkP32RDBoASrevGe9PZsUshKFy66PQJzVqR/LU+8bDYZ3687u6vmUTc8MHmI2R/TdLFw QxmLBu196nLRt8HsStFxu0u2SWcVv1wOaPlTqxtD5er3aCToHah1xP1q2Y98fcCmMt63ub AIDTD8YoitY3gP08mhQjlxODwpKtvhl/gtydmiDtwZdHIdvaHLyCKQnWamHov9hrJS4XL2 ssMK6elYV5922xLZ2pXjGdXG5ln18NPDbQ8bq5yv2ipoJoix3ohdbiMiqS9DdQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1706793069; a=rsa-sha256; cv=none; b=dZEHpIqb69n3cERdRphFdpric60svvvUhjlD/PdZSOgBCGetaJsuCvQgkPyD13DSw3w0jG KpF60tgCpAlLKahbDsi3z+PAyJNYDQKVwTxKR8maEnyrADvmY0WTVu1dqBF7JPUsXlyj7y 4PVYXPiyJFxyFR/X2EqIPFoykzgDvQfpkUp8jKMNCwhA17RS7gAVjvSVXxYnrAqXYAP4MS lc7e35Rcu35SLtqg1ApFe+46uer7gXanuyDlePuGjREwYgrtS1R2+Leg6c/I4IpQCku+1o yiVyipMduXObnDq4EbrluU9up+I2r+0ptcw9AM90Ue1vNgz3SdRl+wFEPTzEwQ== 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 4TQfRd1fpTz13lt; Thu, 1 Feb 2024 13:11:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 411DB9Bl039207; Thu, 1 Feb 2024 13:11:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 411DB9Bp039204; Thu, 1 Feb 2024 13:11:09 GMT (envelope-from git) Date: Thu, 1 Feb 2024 13:11:09 GMT Message-Id: <202402011311.411DB9Bp039204@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 5cb28f797977 - main - bintrans: Error out if writing to the output failed. 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: des X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5cb28f7979773715615cc2131fe40e0c5879ed1d Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=5cb28f7979773715615cc2131fe40e0c5879ed1d commit 5cb28f7979773715615cc2131fe40e0c5879ed1d Author: Dag-Erling Smørgrav AuthorDate: 2024-02-01 13:10:31 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-02-01 13:10:31 +0000 bintrans: Error out if writing to the output failed. - Cover all code paths. - When decoding, check all output files, not just the last one. - A simple `ferror()` check is not enough as an error may later occur while flushing whatever remains in the output buffer. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D43532 --- usr.bin/bintrans/uudecode.c | 33 ++++++++++++++++++++++----------- usr.bin/bintrans/uuencode.c | 4 ++-- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/usr.bin/bintrans/uudecode.c b/usr.bin/bintrans/uudecode.c index 56128d230b00..5a252b71055e 100644 --- a/usr.bin/bintrans/uudecode.c +++ b/usr.bin/bintrans/uudecode.c @@ -331,11 +331,22 @@ checkend(const char *ptr, const char *end, const char *msg) warnx("%s: %s: %s", infile, outfile, msg); return (1); } - if (fclose(outfp) != 0) { + return (0); +} + +static int +checkout(int rval) +{ + if (fflush(outfp) != 0) { warn("%s: %s", infile, outfile); - return (1); + rval = 1; } - return (0); + if (outfp != stdout) { + (void)fclose(outfp); + outfp = stdout; + } + outfile = "/dev/stdout"; + return (rval); } static int @@ -349,9 +360,9 @@ uu_decode(void) for (;;) { switch (get_line(buf, sizeof(buf))) { case 0: - return (0); + return (checkout(0)); case 1: - return (1); + return (checkout(1)); } #define DEC(c) (((c) - ' ') & 077) /* single character decode */ @@ -408,11 +419,11 @@ uu_decode(void) } switch (get_line(buf, sizeof(buf))) { case 0: - return (0); + return (checkout(0)); case 1: - return (1); + return (checkout(1)); default: - return (checkend(buf, "end", "no \"end\" line")); + return (checkout(checkend(buf, "end", "no \"end\" line"))); } } @@ -430,9 +441,9 @@ base64_decode(void) switch (get_line(inbuf + strlen(inbuf), sizeof(inbuf) - strlen(inbuf))) { case 0: - return (0); + return (checkout(0)); case 1: - return (1); + return (checkout(1)); } count = 0; @@ -459,7 +470,7 @@ base64_decode(void) break; fwrite(outbuf, 1, n, outfp); } - return (checkend(inbuf, "====", "error decoding base64 input stream")); + return (checkout(checkend(inbuf, "====", "error decoding base64 input stream"))); } static void diff --git a/usr.bin/bintrans/uuencode.c b/usr.bin/bintrans/uuencode.c index 221811c56d4d..db0419ef0dac 100644 --- a/usr.bin/bintrans/uuencode.c +++ b/usr.bin/bintrans/uuencode.c @@ -74,7 +74,7 @@ main_base64_encode(const char *in, const char *w) if (w != NULL) columns = arg_to_col(w); base64_encode(); - if (ferror(output)) + if (fflush(output) != 0) errx(1, "write error"); exit(0); } @@ -144,7 +144,7 @@ main_encode(int argc, char *argv[]) base64_encode(); else encode(); - if (ferror(output)) + if (fflush(output) != 0) errx(1, "write error"); exit(0); }