From nobody Sat May 31 12:28:31 2025 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 4b8fXc64fkz5wxpl; Sat, 31 May 2025 12:28:32 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4b8fXb6p45z3fqS; Sat, 31 May 2025 12:28:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1748694512; 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=fBF/3f+w3DMWIseazgawKP6jDehnoOcfQ5YjbW1lJLM=; b=AcSx/j6AVuWrXo8JMAtmWxdZ//PA3G9tWu3uCCx//opY3ZNjYIAR3wtOBr19XQ/bf+3EN0 7jDZ3sjwkOnPjGID86oxy7GOsS3tHRc7ZE9AEMoTNQW4of3cXiPhT+9AbPoixch1adYKw2 C0ECoFyCrCgolkbN6iZYklKzNwrfHSpK1n3Znj/BjcwuQHpCIePhglIKdEUNYlBjqs3lL5 3nZWRslU+jU9ae2vGVUdWCAzF9iuBG4zIkL8jowPgy04BfNkAm3fjwVCoWTkSY6iUsNbqt liBLwRFBy3eTvjVokcrth5d6FkDeKLPBZtOCR5VBbQVw5qzSANxI/lqkKgX/qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1748694512; 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=fBF/3f+w3DMWIseazgawKP6jDehnoOcfQ5YjbW1lJLM=; b=ebMde67TjZ/S+fVEOQlfX2FkdO4atUVFSWDua9ep1EfNuvsueucjnl94CHgESlcYNZPzkG 3vHpEiVL7JBztXM8vbSmYTYoOqqJA0WUeFRbDS/NYC/uVKXeeD3nxD0MgMuqr/wLiYf+sd 4GwX3ZZQV3exjXsC4fxu0A+EkcOTEtdoVtBj0AWZf/6q1xntKoO0rYoqlCfqny7tmtDLUX BRSqJBe1YKwxnhJhEo9vLLA+ujB6KZoiWk8y9D0NYyaNYit56rWtsgagf9EsK0cGq4h7RX WOtM4O7BsNCOiayMcEG6+HWEVERTyLCFnSifJH+ie3gBqRY9Lc8ne12m6vv9Gg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1748694512; a=rsa-sha256; cv=none; b=cdpsVQxBK/FqQdCh2/tc1Hz7MeD0qQ6GKSp5rANVtrARkSDEt66OpcfNplVSAX1iATDBrF TQgKJ5vzLYW6KsI0kIdW/p/mdvLfL/FBNZAKIsxfrsEK33y2RE/xmBGLtMbeJ8j401ypxx 910lG7F3qab+3AuQxdla4FOpNXknL8yNNTbn9BhrUKfOAHYEAP5NwW9EegCAbVMPokLR37 9dglLhNeAjbb1ldtx5OL0584E/PkmCLPoaxSaMfOixMhMBHEdnFan08ELVQ6SJSNFzNGsq hGixa/DWpzePQhmW4wTekui1kn/bBFdFOVgkqsF5JAnnWLF/KHvmuaXI1OcX7w== 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 4b8fXb38Yrzdxm; Sat, 31 May 2025 12:28:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 54VCSVi9086182; Sat, 31 May 2025 12:28:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54VCSVZd086179; Sat, 31 May 2025 12:28:31 GMT (envelope-from git) Date: Sat, 31 May 2025 12:28:31 GMT Message-Id: <202505311228.54VCSVZd086179@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: 93aeb68a8933 - stable/14 - atf: Don't be deterred by weird umasks. 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-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: 93aeb68a8933e7458c795b31589900cbeae49e38 Auto-Submitted: auto-generated The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=93aeb68a8933e7458c795b31589900cbeae49e38 commit 93aeb68a8933e7458c795b31589900cbeae49e38 Author: Dag-Erling Smørgrav AuthorDate: 2025-05-24 10:03:22 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-05-31 12:28:28 +0000 atf: Don't be deterred by weird umasks. If the current umask is weird, ATF goes to great lengths to tell us that it can't possibly work in these conditions, instead of just dealing with it. This makes it unreasonably hard to use ATF to test how our own code handles unusual umasks. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: igoro, kevans, ngie Differential Revision: https://reviews.freebsd.org/D50267 (cherry picked from commit 1a6a36a98ad5dc86862541b91686b00cf88e9f76) --- contrib/atf/atf-c/check_test.c | 8 +--- contrib/atf/atf-c/detail/fs.c | 91 ++++-------------------------------- contrib/atf/atf-c/detail/fs_test.c | 44 ++++++++--------- contrib/atf/atf-sh/atf-check_test.sh | 24 +++++----- 4 files changed, 43 insertions(+), 124 deletions(-) diff --git a/contrib/atf/atf-c/check_test.c b/contrib/atf/atf-c/check_test.c index adaca649be25..06e2fad2d9a4 100644 --- a/contrib/atf/atf-c/check_test.c +++ b/contrib/atf/atf-c/check_test.c @@ -458,8 +458,7 @@ ATF_TC(exec_umask); ATF_TC_HEAD(exec_umask, tc) { atf_tc_set_md_var(tc, "descr", "Checks that atf_check_exec_array " - "correctly reports an error if the umask is too " - "restrictive to create temporary files"); + "works regardless of umask"); } ATF_TC_BODY(exec_umask, tc) { @@ -473,10 +472,7 @@ ATF_TC_BODY(exec_umask, tc) argv[2] = NULL; umask(0222); - atf_error_t err = atf_check_exec_array(argv, &result); - ATF_CHECK(atf_is_error(err)); - ATF_CHECK(atf_error_is(err, "invalid_umask")); - atf_error_free(err); + RE(atf_check_exec_array(argv, &result)); atf_fs_path_fini(&process_helpers); } diff --git a/contrib/atf/atf-c/detail/fs.c b/contrib/atf/atf-c/detail/fs.c index 5ff7648c3c7e..6ea825aa8e56 100644 --- a/contrib/atf/atf-c/detail/fs.c +++ b/contrib/atf/atf-c/detail/fs.c @@ -54,71 +54,13 @@ * Prototypes for auxiliary functions. * --------------------------------------------------------------------- */ -static bool check_umask(const mode_t, const mode_t); static atf_error_t copy_contents(const atf_fs_path_t *, char **); -static mode_t current_umask(void); static atf_error_t do_mkdtemp(char *); static atf_error_t normalize(atf_dynstr_t *, char *); static atf_error_t normalize_ap(atf_dynstr_t *, const char *, va_list); static void replace_contents(atf_fs_path_t *, const char *); static const char *stat_type_to_string(const int); -/* --------------------------------------------------------------------- - * The "invalid_umask" error type. - * --------------------------------------------------------------------- */ - -struct invalid_umask_error_data { - /* One of atf_fs_stat_*_type. */ - int m_type; - - /* The original path causing the error. */ - /* XXX: Ideally this would be an atf_fs_path_t, but if we create it - * from the error constructor, we cannot delete the path later on. - * Can't remember why atf_error_new does not take a hook for - * deletion. */ - char m_path[1024]; - - /* The umask that caused the error. */ - mode_t m_umask; -}; -typedef struct invalid_umask_error_data invalid_umask_error_data_t; - -static -void -invalid_umask_format(const atf_error_t err, char *buf, size_t buflen) -{ - const invalid_umask_error_data_t *data; - - PRE(atf_error_is(err, "invalid_umask")); - - data = atf_error_data(err); - snprintf(buf, buflen, "Could not create the temporary %s %s because " - "it will not have enough access rights due to the current " - "umask %05o", stat_type_to_string(data->m_type), - data->m_path, (unsigned int)data->m_umask); -} - -static -atf_error_t -invalid_umask_error(const atf_fs_path_t *path, const int type, - const mode_t failing_mask) -{ - atf_error_t err; - invalid_umask_error_data_t data; - - data.m_type = type; - - strncpy(data.m_path, atf_fs_path_cstring(path), sizeof(data.m_path)); - data.m_path[sizeof(data.m_path) - 1] = '\0'; - - data.m_umask = failing_mask; - - err = atf_error_new("invalid_umask", &data, sizeof(data), - invalid_umask_format); - - return err; -} - /* --------------------------------------------------------------------- * The "unknown_file_type" error type. * --------------------------------------------------------------------- */ @@ -162,14 +104,6 @@ unknown_type_error(const char *path, int type) * Auxiliary functions. * --------------------------------------------------------------------- */ -static -bool -check_umask(const mode_t exp_mode, const mode_t min_mode) -{ - const mode_t actual_mode = (~current_umask() & exp_mode); - return (actual_mode & min_mode) == min_mode; -} - static atf_error_t copy_contents(const atf_fs_path_t *p, char **buf) @@ -189,15 +123,6 @@ copy_contents(const atf_fs_path_t *p, char **buf) return err; } -static -mode_t -current_umask(void) -{ - const mode_t current = umask(0); - (void)umask(current); - return current; -} - static atf_error_t do_mkdtemp(char *tmpl) @@ -794,11 +719,10 @@ atf_fs_mkdtemp(atf_fs_path_t *p) { atf_error_t err; char *buf; + mode_t mask; - if (!check_umask(S_IRWXU, S_IRWXU)) { - err = invalid_umask_error(p, atf_fs_stat_dir_type, current_umask()); - goto out; - } + mask = umask(0); + umask(mask & 077); err = copy_contents(p, &buf); if (atf_is_error(err)) @@ -814,6 +738,7 @@ atf_fs_mkdtemp(atf_fs_path_t *p) out_buf: free(buf); out: + umask(mask); return err; } @@ -823,11 +748,10 @@ atf_fs_mkstemp(atf_fs_path_t *p, int *fdout) atf_error_t err; char *buf; int fd; + mode_t mask; - if (!check_umask(S_IRWXU, S_IRWXU)) { - err = invalid_umask_error(p, atf_fs_stat_reg_type, current_umask()); - goto out; - } + mask = umask(0); + umask(mask & 077); err = copy_contents(p, &buf); if (atf_is_error(err)) @@ -844,6 +768,7 @@ atf_fs_mkstemp(atf_fs_path_t *p, int *fdout) out_buf: free(buf); out: + umask(mask); return err; } diff --git a/contrib/atf/atf-c/detail/fs_test.c b/contrib/atf/atf-c/detail/fs_test.c index 7812be0334b8..a9cc34a4f48b 100644 --- a/contrib/atf/atf-c/detail/fs_test.c +++ b/contrib/atf/atf-c/detail/fs_test.c @@ -896,25 +896,25 @@ ATF_TC_BODY(mkdtemp_err, tc) static void do_umask_check(atf_error_t (*const mk_func)(atf_fs_path_t *), - atf_fs_path_t *path, const mode_t test_mask, - const char *str_mask, const char *exp_name) + atf_error_t (*const rm_func)(const atf_fs_path_t *), + atf_fs_path_t *tmpl, const mode_t test_mask, + const char *exp_name) { - char buf[1024]; - int old_umask; + atf_fs_path_t path; + int pre_mask, post_mask; atf_error_t err; - printf("Creating temporary %s with umask %s\n", exp_name, str_mask); + printf("Creating temporary %s with umask %05o\n", exp_name, test_mask); - old_umask = umask(test_mask); - err = mk_func(path); - (void)umask(old_umask); + RE(atf_fs_path_copy(&path, tmpl)); - ATF_REQUIRE(atf_is_error(err)); - ATF_REQUIRE(atf_error_is(err, "invalid_umask")); - atf_error_format(err, buf, sizeof(buf)); - ATF_CHECK(strstr(buf, exp_name) != NULL); - ATF_CHECK(strstr(buf, str_mask) != NULL); - atf_error_free(err); + pre_mask = umask(test_mask); + err = mk_func(&path); + post_mask = umask(pre_mask); + + ATF_REQUIRE(!atf_is_error(err)); + ATF_CHECK_EQ(post_mask, test_mask); + RE(rm_func(&path)); } ATF_TC(mkdtemp_umask); @@ -929,11 +929,11 @@ ATF_TC_BODY(mkdtemp_umask, tc) RE(atf_fs_path_init_fmt(&p, "testdir.XXXXXX")); - do_umask_check(atf_fs_mkdtemp, &p, 00100, "00100", "directory"); - do_umask_check(atf_fs_mkdtemp, &p, 00200, "00200", "directory"); - do_umask_check(atf_fs_mkdtemp, &p, 00400, "00400", "directory"); - do_umask_check(atf_fs_mkdtemp, &p, 00500, "00500", "directory"); - do_umask_check(atf_fs_mkdtemp, &p, 00600, "00600", "directory"); + do_umask_check(atf_fs_mkdtemp, atf_fs_rmdir, &p, 00100, "directory"); + do_umask_check(atf_fs_mkdtemp, atf_fs_rmdir, &p, 00200, "directory"); + do_umask_check(atf_fs_mkdtemp, atf_fs_rmdir, &p, 00400, "directory"); + do_umask_check(atf_fs_mkdtemp, atf_fs_rmdir, &p, 00500, "directory"); + do_umask_check(atf_fs_mkdtemp, atf_fs_rmdir, &p, 00600, "directory"); atf_fs_path_fini(&p); } @@ -1039,9 +1039,9 @@ ATF_TC_BODY(mkstemp_umask, tc) RE(atf_fs_path_init_fmt(&p, "testfile.XXXXXX")); - do_umask_check(mkstemp_discard_fd, &p, 00100, "00100", "regular file"); - do_umask_check(mkstemp_discard_fd, &p, 00200, "00200", "regular file"); - do_umask_check(mkstemp_discard_fd, &p, 00400, "00400", "regular file"); + do_umask_check(mkstemp_discard_fd, atf_fs_unlink, &p, 00100, "regular file"); + do_umask_check(mkstemp_discard_fd, atf_fs_unlink, &p, 00200, "regular file"); + do_umask_check(mkstemp_discard_fd, atf_fs_unlink, &p, 00400, "regular file"); atf_fs_path_fini(&p); } diff --git a/contrib/atf/atf-sh/atf-check_test.sh b/contrib/atf/atf-sh/atf-check_test.sh index 9542dfb0bd9f..91d024a85bcd 100644 --- a/contrib/atf/atf-sh/atf-check_test.sh +++ b/contrib/atf/atf-sh/atf-check_test.sh @@ -389,21 +389,19 @@ stdin_body() atf_fail "atf-check does not seem to respect stdin" } -atf_test_case invalid_umask -invalid_umask_head() +atf_test_case unusual_umask +unusual_umask_head() { - atf_set "descr" "Tests for a correct error condition if the umask is" \ - "too restrictive" + atf_set "descr" "Tests that atf-check doesn't care about unusual umasks" } -invalid_umask_body() +unusual_umask_body() { - umask 0222 - ${Atf_Check} false 2>stderr && \ - atf_fail "atf-check returned 0 but it should have failed" - cat stderr - grep 'temporary.*current umask.*0222' stderr >/dev/null || \ - atf_fail "atf-check did not report an error related to the" \ - "current umask" + for mask in 022 027 0222 0177 0777 ; do + umask $mask + ${Atf_Check} true || \ + atf_fail "atf-check failed with umask $mask" + done + umask 022 } atf_init_test_cases() @@ -435,7 +433,7 @@ atf_init_test_cases() atf_add_test_case stdin - atf_add_test_case invalid_umask + atf_add_test_case unusual_umask } # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4