From nobody Sun Nov 13 05:38:09 2022 X-Original-To: dev-commits-src-branches@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 4N91SK4bzTz4d7LD; Sun, 13 Nov 2022 05:38: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 4N91SK2f8Rz3Jg5; Sun, 13 Nov 2022 05:38:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668317889; 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=+GNgTZwKbeKVqSG4J74nrq38L1gAAKs1hck9pbCL0SQ=; b=JkRqKopdCQyjGj30QoYu4Jf25FJObvyeGVh8GcbvpvplIZ/NCkqr9Q55jytLR0LlHIG/zV mJq/mZpk2TbCdBBCM9+WA0Tug/SsgZxVStdqkD5EDBQ2TuVTvHLhXBnbh2BabaDB6eT3KJ hfW9zPi/WpFfaeOHWpk463J3wY7eHaK+IuPOqPRvOY47kwy0UszrVB08D2NKvA3Ra34rQD bDgntpm1aXfIVc0SunUEwKOKFsOY3KkUbhip6Dqxrgc2w+i9HE7QJQNAB+hqEvAIje/6WN 5C5odtmatsk1uFP7pttIPiIhfXBEiLQdA54uZBqr43svahnxgQxvIC/qZAPG5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1668317889; 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=+GNgTZwKbeKVqSG4J74nrq38L1gAAKs1hck9pbCL0SQ=; b=R16hCSL6CtlX1QMi+eTdGkiito0dl7wwWT4g9f/N+J8Syy4iUGaV+Zcz+e7owcuVZjmqVe bmwBJmrGb6Gqiauy5+qoIRIEexxJzYs69UzrWtC4x3w9l7rOtTqDcAyp8qLQZW9GR0gVuO m7lmlHoKXYCjD5Y1DvKBZXwPHZpucTSxHkiJ1M//8EuGIdO2mJLh6th4Qe4/lLQGafF9iU rX0oGSdQje9gRecD59V+nR+xqluacLOjfE1YIRXyTDFv5Bxzvb2OTn/I0pW1n76VYBzjwZ 4u8vDy+i8xrxTWLZkSBP71zBJtiktH/spvUwZXJe33OnouDgD0TvRRf+IZNEgQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1668317889; a=rsa-sha256; cv=none; b=sYFEP9TaYh/PEnzF7DAbbjmtJbX83kUnkSRf3Xq5cwL3K+JK4ChgA1+VhTMdMa9zBoqHTA aWBVaxQtNR04/5N2tssqwi+vpDl953m9/NFot9LIc7n3uqYBKzrtMN7D0+vm70gb/sQy23 fX2hA0h0GorRvPATw7ZNm6NO8DjU26azc0UltHrFjODu2GJ0F536FjD99cZ8RHR/056FOK cR/9aJ2da8KIohyGuBqg5YVAHKFy/6wh7dfJGFD190rJCJ6G/OW/RrzEzQQn//9+3DDpEG tFN2ImCXSVb7zLU3cckWyngRjPYHAxMh5DdpSME9NtAR0QNs/z1WBW40hSNtCw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4N91SK0hYdzrHK; Sun, 13 Nov 2022 05:38:09 +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 2AD5c97q096672; Sun, 13 Nov 2022 05:38:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AD5c9BH096671; Sun, 13 Nov 2022 05:38:09 GMT (envelope-from git) Date: Sun, 13 Nov 2022 05:38:09 GMT Message-Id: <202211130538.2AD5c9BH096671@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: fa4ac142ef99 - stable/13 - mktemp: don't double up on trailing slashes for -t paths List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: fa4ac142ef99d271f5045595cf978ab0c406af10 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=fa4ac142ef99d271f5045595cf978ab0c406af10 commit fa4ac142ef99d271f5045595cf978ab0c406af10 Author: Kyle Evans AuthorDate: 2022-11-02 20:29:16 +0000 Commit: Kyle Evans CommitDate: 2022-11-13 05:37:36 +0000 mktemp: don't double up on trailing slashes for -t paths This is a minor cosmetic change; re-organize slightly to set tmpdir to _PATH_TMP if we didn't otherwise have a tmpdir candidate, then check the trailing char before appending another slash. While we're here, remove some bogus whitespace and add a test case for this change. Obtained from: https://github.com/apple-oss-distributions/shell_cmds Sponsored by: Klara, Inc. (cherry picked from commit a6346c02f646c6b74f007c64a9b546deb06182ae) --- usr.bin/mktemp/mktemp.c | 8 ++++++-- usr.bin/mktemp/tests/mktemp_test.sh | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/usr.bin/mktemp/mktemp.c b/usr.bin/mktemp/mktemp.c index 77245d2fa0d3..b61db66070dc 100644 --- a/usr.bin/mktemp/mktemp.c +++ b/usr.bin/mktemp/mktemp.c @@ -126,6 +126,7 @@ main(int argc, char **argv) if (tflag) { const char *envtmp; + size_t len; envtmp = NULL; @@ -137,7 +138,10 @@ main(int argc, char **argv) if (envtmp != NULL) tmpdir = envtmp; if (tmpdir == NULL) - asprintf(&name, "%s%s.XXXXXXXX", _PATH_TMP, prefix); + tmpdir = _PATH_TMP; + len = strlen(tmpdir); + if (len > 0 && tmpdir[len - 1] == '/') + asprintf(&name, "%s%s.XXXXXXXX", tmpdir, prefix); else asprintf(&name, "%s/%s.XXXXXXXX", tmpdir, prefix); /* if this fails, the program is in big trouble already */ @@ -148,7 +152,7 @@ main(int argc, char **argv) errx(1, "cannot generate template"); } } - + /* generate all requested files */ while (name != NULL || argc > 0) { if (name == NULL) { diff --git a/usr.bin/mktemp/tests/mktemp_test.sh b/usr.bin/mktemp/tests/mktemp_test.sh index c424030fac4f..505c60536b34 100755 --- a/usr.bin/mktemp/tests/mktemp_test.sh +++ b/usr.bin/mktemp/tests/mktemp_test.sh @@ -109,10 +109,24 @@ tmpdir_pflag_noarg_body() atf_check -o match:"^$tmpdir/foo\..+$" cat tmpname } +atf_test_case tmpdir_tflag_oneslash +tmpdir_tflag_oneslash_body() +{ + + tmpdir="$PWD" + + # Provided a trailing slash, we shouldn't end up with two trailing + # slashes. + atf_check -o save:tmpname \ + env TMPDIR="$tmpdir/" mktemp -t foo + atf_check -o match:"^$tmpdir/foo\..+$" cat tmpname +} + atf_init_test_cases() { atf_add_test_case tmpdir_env atf_add_test_case tmpdir_pflag atf_add_test_case tmpdir_pflag_dir atf_add_test_case tmpdir_pflag_noarg + atf_add_test_case tmpdir_tflag_oneslash }