From nobody Wed Feb 09 15:26:15 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 1864F19BD1F5; Wed, 9 Feb 2022 15:26:16 +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 4Jv3cl6Zq6z3qPf; Wed, 9 Feb 2022 15:26:15 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644420376; 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=sAFJh4L8KN29H2sJTPyJDuYn6ZQo+M3vqo1G+4H/pt4=; b=iiPipDyLp+nzpF/iznUZLPZufHeaZJG3rgB9NhD/qeoUSSLYXTUnvwbLdhU9mD+g0n1t2I bRE5IISq7RN3ue100y95VEsk1Zs38G7BHu7eqBQJUMoNNBdqbpNJZTj3P3XyUNvnnTVxRC S+/9YuhWqlnHpBPiR2MhX/rWTLQBYOxI/qjvdNTFCPwc+FzAdchK7e3/3ig98iHWoEXT3E 7Pccfj91iwRI4vz+tKeWlkvuaNwub22JqmG9fRYVpcglZTZEjm7pFQKhseTSePxP/dRS7V 4HQslAn2WpPdAoljYq4Z5PH5II53qhPiILxPM00d5uuSxT4oUiT/2FB0xiv2+Q== 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 BAD6E776E; Wed, 9 Feb 2022 15:26:15 +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 219FQFWu058728; Wed, 9 Feb 2022 15:26:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 219FQFhq058727; Wed, 9 Feb 2022 15:26:15 GMT (envelope-from git) Date: Wed, 9 Feb 2022 15:26:15 GMT Message-Id: <202202091526.219FQFhq058727@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ed Maste Subject: git: 4cd49eda1f6e - stable/13 - ar: Avoid overwriting the stdout file stream pointer 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: emaste X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 4cd49eda1f6e5b8094279394e41560e515c5ca55 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644420376; 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=sAFJh4L8KN29H2sJTPyJDuYn6ZQo+M3vqo1G+4H/pt4=; b=hCq1Df8x1vJdBqXk1EiyEPQyPhlfz6M+kbb4/jjeR5U1Dgjntz+t+VNig+ayFWFVJLKV1M Xn3erzXl96Kqu3OBr5Wcw1BRKiK28BZDtdRvGe16iEbNqptrteGn5reAJW8vaDKvNkKVqw irIohuSHEJystrotUC3mtSt9qoARLA8enhrStAUYsvCto47/G7w/eWMLs+Aj86L2/nafGD 0Pgl2iDQQqcMKEZI/CRKMtm28kedyTq3tVj3tskf23yfBmefu8oVSbD7pPxizJAB4qjHwO ZCqQDiw19lppjhyanmRRI2y6X+Vwtkg3WvJmvE76PCbhAJzo/uZkgeWT2XCbcg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644420376; a=rsa-sha256; cv=none; b=j7o37GGUa8Fv19v2wS/eIPxTWkmFjHgy3byUvBgWef+/+kXgCGON0CrRh8wWm5QTcPb8G0 TFbkZy7z7+Qu2uYaDwTQGpnjy7drRWCGFNlF1XlRLOdkFzV2VzGp7ktHHLtSRgjHHN9K3f yqjAyJ/fa/cJ1NVZ+2n4JHs4rEqp7UGc0/+y7qVZFLW1RxFj1/ih5A+R0yJ81DCGUFAFKV lziIWEVp98+v4AgpSk0H74iV74sifdWS1oDxDXfY/a1yMthOX5LGXoHYKBHBgCukaQ3HWE jZgXEGdbWjinJjuHC3BljbOPu8zDggOa6FMmoUWzGtYF6ZDnqi9CzL8s5L5Efg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=4cd49eda1f6e5b8094279394e41560e515c5ca55 commit 4cd49eda1f6e5b8094279394e41560e515c5ca55 Author: Mark Johnston AuthorDate: 2022-01-27 22:10:17 +0000 Commit: Ed Maste CommitDate: 2022-02-09 15:25:28 +0000 ar: Avoid overwriting the stdout file stream pointer This doesn't work with musl, which defines stdout as FILE * const. Instead, explicitly pass the desired output stream to ar_read_archive(). No functional change intended. Reviewed by: emaste MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34064 (cherry picked from commit 41e6398f9bc1bba4ed872118e742096d692fdfec) --- usr.bin/ar/acpyacc.y | 14 ++++++-------- usr.bin/ar/ar.c | 2 +- usr.bin/ar/ar.h | 2 +- usr.bin/ar/read.c | 18 +++++++++--------- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/usr.bin/ar/acpyacc.y b/usr.bin/ar/acpyacc.y index 34156e1d2d58..1ce7197ef222 100644 --- a/usr.bin/ar/acpyacc.y +++ b/usr.bin/ar/acpyacc.y @@ -406,7 +406,7 @@ arscp_extract(struct list *list) if (!arscp_target_exist()) return; arscp_mlist2argv(list); - ar_read_archive(bsdar, 'x'); + ar_read_archive(bsdar, 'x', stdout); arscp_free_argv(); arscp_free_mlist(list); } @@ -422,7 +422,7 @@ arscp_list(void) bsdar->argv = NULL; /* Always verbose. */ bsdar->options |= AR_V; - ar_read_archive(bsdar, 't'); + ar_read_archive(bsdar, 't', stdout); bsdar->options &= ~AR_V; } @@ -433,10 +433,9 @@ arscp_dir(char *archive, struct list *list, char *rlt) FILE *out; /* If rlt != NULL, redirect output to it */ - out = NULL; + out = stdout; if (rlt) { - out = stdout; - if ((stdout = fopen(rlt, "w")) == NULL) + if ((out = fopen(rlt, "w")) == NULL) bsdar_errc(bsdar, errno, "fopen %s failed", rlt); } @@ -449,13 +448,12 @@ arscp_dir(char *archive, struct list *list, char *rlt) } if (verbose) bsdar->options |= AR_V; - ar_read_archive(bsdar, 't'); + ar_read_archive(bsdar, 't', out); bsdar->options &= ~AR_V; if (rlt) { - if (fclose(stdout) == EOF) + if (fclose(out) == EOF) bsdar_errc(bsdar, errno, "fclose %s failed", rlt); - stdout = out; free(rlt); } free(archive); diff --git a/usr.bin/ar/ar.c b/usr.bin/ar/ar.c index 4353efcb0ff2..93887ebebcfb 100644 --- a/usr.bin/ar/ar.c +++ b/usr.bin/ar/ar.c @@ -331,7 +331,7 @@ main(int argc, char **argv) exitcode = ar_write_archive(bsdar, bsdar->mode); break; case 'p': case 't': case 'x': - exitcode = ar_read_archive(bsdar, bsdar->mode); + exitcode = ar_read_archive(bsdar, bsdar->mode, stdout); break; default: bsdar_usage(); diff --git a/usr.bin/ar/ar.h b/usr.bin/ar/ar.h index bcccf93a6016..66a7888c3e1c 100644 --- a/usr.bin/ar/ar.h +++ b/usr.bin/ar/ar.h @@ -115,7 +115,7 @@ struct bsdar { }; void ar_mode_script(struct bsdar *ar); -int ar_read_archive(struct bsdar *ar, int mode); +int ar_read_archive(struct bsdar *ar, int mode, FILE *out); int ar_write_archive(struct bsdar *ar, int mode); void bsdar_errc(struct bsdar *, int _code, const char *fmt, ...) __dead2; void bsdar_warnc(struct bsdar *, int _code, const char *fmt, ...); diff --git a/usr.bin/ar/read.c b/usr.bin/ar/read.c index 81e0bfce1b7e..84b94a1f4d77 100644 --- a/usr.bin/ar/read.c +++ b/usr.bin/ar/read.c @@ -47,7 +47,7 @@ __FBSDID("$FreeBSD$"); * Handle read modes: 'x', 't' and 'p'. */ int -ar_read_archive(struct bsdar *bsdar, int mode) +ar_read_archive(struct bsdar *bsdar, int mode, FILE *out) { struct archive *a; struct archive_entry *entry; @@ -123,18 +123,18 @@ ar_read_archive(struct bsdar *bsdar, int mode) size = archive_entry_size(entry); mtime = archive_entry_mtime(entry); (void)strmode(md, buf); - (void)fprintf(stdout, "%s %6d/%-6d %8ju ", + (void)fprintf(out, "%s %6d/%-6d %8ju ", buf + 1, uid, gid, (uintmax_t)size); tp = localtime(&mtime); (void)strftime(buf, sizeof(buf), "%b %e %H:%M %Y", tp); - (void)fprintf(stdout, "%s %s", buf, name); + (void)fprintf(out, "%s %s", buf, name); } else - (void)fprintf(stdout, "%s", name); + (void)fprintf(out, "%s", name); r = archive_read_data_skip(a); if (r == ARCHIVE_WARN || r == ARCHIVE_RETRY || r == ARCHIVE_FATAL) { - (void)fprintf(stdout, "\n"); + (void)fprintf(out, "\n"); bsdar_warnc(bsdar, archive_errno(a), "%s", archive_error_string(a)); } @@ -142,14 +142,14 @@ ar_read_archive(struct bsdar *bsdar, int mode) if (r == ARCHIVE_FATAL) break; - (void)fprintf(stdout, "\n"); + (void)fprintf(out, "\n"); } else { /* mode == 'x' || mode = 'p' */ if (mode == 'p') { if (bsdar->options & AR_V) { - (void)fprintf(stdout, "\n<%s>\n\n", + (void)fprintf(out, "\n<%s>\n\n", name); - fflush(stdout); + fflush(out); } r = archive_read_data_into_fd(a, 1); } else { @@ -172,7 +172,7 @@ ar_read_archive(struct bsdar *bsdar, int mode) } if (bsdar->options & AR_V) - (void)fprintf(stdout, "x - %s\n", name); + (void)fprintf(out, "x - %s\n", name); /* Disallow absolute paths. */ if (name[0] == '/') { bsdar_warnc(bsdar, 0,