From nobody Sat Feb 24 12:14:59 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 4Thm6D03hfz5CfR3; Sat, 24 Feb 2024 12:15:00 +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 4Thm6C6YTKz4pTx; Sat, 24 Feb 2024 12:14:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708776899; 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=VBCg4vgPDNSJll6bLJAvTERnmknuvCetjqo5fhYoFKM=; b=W//vbY/4b1Vp/qKjdtuuCg0nh6A6UrF2a9jXp7cKpSLSKmcX1JukM9e56cXeGVWTe0OMNk lZtRCfEVbaXTjnP7fBUpGPJU+I0Py0sHpdyPmayO8gVrA4kkboXWXIzIfbFbji2xr796zJ 4ROtSBSe8mzB0VlDgvokY7KT7mdsz9FaX2E6UsMv2DPng1v/xShxIki0uNpLYyKOemUwQ1 kcxyLNBUY96+hiYchRDELzbHmGHc1iUC7slAPAPD9OB60gT7sagKW+UOEiOoQ5ttU6mNAi u5oMwgPKrsidYXbNA1yiYFb9K2pzogsgVbEWKP2vDvY3eBZU0C0iX5a70wDb3w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708776899; a=rsa-sha256; cv=none; b=IrRBpAaf8Ol0ly469VED+zVEZOcWm4wOJdBIUyLGjxCmtFI7aGnYcY9bzGB11VCoobVzhc /+GcHeBG+yn00WJ59KxpeKRUtkCKnicfn2ek/EEBeB0lNNLt5+NZ+ntpeop6TIIc4vFCQp 4TE+ASbckWVWx0JcoCeiiZih8w0qZwhsBTcyDNfszyXitZe6xjtQNQIZ/xK9uRewRyeX8k ltxUuCQKqf2fHuUQpj/66OUw48LeY43QZgy52f+gQgTrlmB6AmlnrtpFuYH1VwXCLia7Vn v8dZNA4eY6n6aCOm9wtc5ssGembOAzaBZj6RjR55pJtPlYpVcRJFAa6M1p/2pw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708776899; 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=VBCg4vgPDNSJll6bLJAvTERnmknuvCetjqo5fhYoFKM=; b=ellKLZVCcrL0Z03IC4f82xqrtklfWQehnfc8OpXaZO4SRC8CHVAywSt3Ss0woPWhN46c4I a8dbgYH3gslFsvI9uAHnZMvOy46v8Cz7j7oJLKTzoQD+IziuNANPIyCJmmno48wuIm6ups fomOo4YHBc/ZfzG/FLDpT2mxksvy3ZbPiodO/+niSBcQNEMqZK2du4i8lDqCZgbhtlsPc4 edJ3LKfzOH04lGyfxjoyiG+Edoxgtf1MSdRRiD7ONQ/34BTIrHc5wyrCLdBdc4DbehRl7R WBx95H/qof5YMIoWyiy7wWl+QcC4ubKxH+kfbi3D4FiJa80hT/IeW/LzUWsxJQ== 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 4Thm6C5bTqz10Q2; Sat, 24 Feb 2024 12:14:59 +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 41OCExra085047; Sat, 24 Feb 2024 12:14:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41OCExdQ085044; Sat, 24 Feb 2024 12:14:59 GMT (envelope-from git) Date: Sat, 24 Feb 2024 12:14:59 GMT Message-Id: <202402241214.41OCExdQ085044@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: fa778f0ce5ef - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: fa778f0ce5ef2bee0ce288a7c8eef9a88ddda8be Auto-Submitted: auto-generated The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=fa778f0ce5ef2bee0ce288a7c8eef9a88ddda8be commit fa778f0ce5ef2bee0ce288a7c8eef9a88ddda8be Author: Dag-Erling Smørgrav AuthorDate: 2024-02-01 13:10:31 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2024-02-24 12:12:49 +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 (cherry picked from commit 5cb28f7979773715615cc2131fe40e0c5879ed1d) bintrans: Fix uninitialized variable. `prev` may be used uninitialized if `body` starts with a newline. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: bapt, emaste Differential Revision: https://reviews.freebsd.org/D43534 (cherry picked from commit bce34cba07bcfed9cd519a658e594c9910c8f210) bintrans: Add base64 to name list in manual page. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: 0mp, pstef Differential Revision: https://reviews.freebsd.org/D43558 (cherry picked from commit 64028ac3ba9668cff31bfe2c79d85a3b89e10953) bintrans: Remove unused variable. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D43559 (cherry picked from commit bc2913d1736c2b299a265741a779014d001bd108) --- usr.bin/bintrans/bintrans.1 | 9 ++++----- usr.bin/bintrans/qp.c | 5 ++--- usr.bin/bintrans/uudecode.c | 33 ++++++++++++++++++++++----------- usr.bin/bintrans/uuencode.c | 4 ++-- 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/usr.bin/bintrans/bintrans.1 b/usr.bin/bintrans/bintrans.1 index e7e7f4c56cdf..16ae66aa21d1 100644 --- a/usr.bin/bintrans/bintrans.1 +++ b/usr.bin/bintrans/bintrans.1 @@ -25,9 +25,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" From: @(#)uuencode.1 8.1 (Berkeley) 6/6/93 -.\" -.Dd April 18, 2022 +.Dd January 23, 2024 .Dt BINTRANS 1 .Os .Sh NAME @@ -35,8 +33,9 @@ .Nm uuencode , .Nm uudecode , .Nm b64encode , -.Nm b64decode -.Nd encode/decode a binary file +.Nm b64decode , +.Nm base64 +.Nd encode / decode a binary file .Sh SYNOPSIS .Nm .Op algorithm diff --git a/usr.bin/bintrans/qp.c b/usr.bin/bintrans/qp.c index 74fa1ec3ae90..c2c9dfa7a224 100644 --- a/usr.bin/bintrans/qp.c +++ b/usr.bin/bintrans/qp.c @@ -90,9 +90,9 @@ decode_quoted_printable(const char *body, FILE *fpo) static void encode_quoted_printable(const char *body, FILE *fpo) { - char prev; const char *end = body + strlen(body); size_t linelen = 0; + char prev = '\0'; while (*body != '\0') { if (linelen == 75) { @@ -138,12 +138,11 @@ qp(FILE *fp, FILE *fpo, bool encode) { char *line = NULL; size_t linecap = 0; - ssize_t linelen; void (*codec)(const char *line, FILE *f); codec = encode ? encode_quoted_printable : decode_quoted_printable ; - while ((linelen = getline(&line, &linecap, fp)) > 0) + while (getline(&line, &linecap, fp) > 0) codec(line, fpo); free(line); } diff --git a/usr.bin/bintrans/uudecode.c b/usr.bin/bintrans/uudecode.c index b0ab415486c8..6f716b0f2ec1 100644 --- a/usr.bin/bintrans/uudecode.c +++ b/usr.bin/bintrans/uudecode.c @@ -343,11 +343,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 @@ -361,9 +372,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 */ @@ -420,11 +431,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"))); } } @@ -442,9 +453,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; @@ -471,7 +482,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 267ab7deb8d1..d6a377fcabae 100644 --- a/usr.bin/bintrans/uuencode.c +++ b/usr.bin/bintrans/uuencode.c @@ -86,7 +86,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); } @@ -156,7 +156,7 @@ main_encode(int argc, char *argv[]) base64_encode(); else encode(); - if (ferror(output)) + if (fflush(output) != 0) errx(1, "write error"); exit(0); }