Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Sep 2025 12:40:08 GMT
From:      Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= <des@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: cf76bfbb2351 - main - tzcode: Test escape from TZDIR
Message-ID:  <202509291240.58TCe8gw094913@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=cf76bfbb235116702ea1689bf984f200a72d2790

commit cf76bfbb235116702ea1689bf984f200a72d2790
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2025-09-29 12:36:24 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2025-09-29 12:39:49 +0000

    tzcode: Test escape from TZDIR
    
    Test a value of TZ that temporarily escapes from TZDIR (which is not
    permitted when setugid) then reenters it.
    
    MFC after:      3 days
---
 lib/libc/tests/stdtime/detect_tz_changes_test.c | 39 ++++++++++++++++---------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/lib/libc/tests/stdtime/detect_tz_changes_test.c b/lib/libc/tests/stdtime/detect_tz_changes_test.c
index fe6b04357331..06c31c9fbc3d 100644
--- a/lib/libc/tests/stdtime/detect_tz_changes_test.c
+++ b/lib/libc/tests/stdtime/detect_tz_changes_test.c
@@ -24,10 +24,12 @@
 
 #include <atf-c.h>
 
-static const struct tzcase {
+struct tzcase {
 	const char *tzfn;
 	const char *expect;
-} tzcases[] = {
+};
+
+static const struct tzcase tzcases[] = {
 	/*
 	 * A handful of time zones and the expected result of
 	 * strftime("%z (%Z)", tm) when that time zone is active
@@ -43,7 +45,8 @@ static const struct tzcase {
 	{ "UTC",		"+0000 (UTC)"	},
 	{ 0 },
 };
-
+static const struct tzcase utc = { "UTC", "+0000 (UTC)" };
+static const struct tzcase invalid = { "invalid", "+0000 (-00)" };
 static const time_t then = 1751328000; /* 2025-07-01 00:00:00 UTC */
 
 static bool debugging;
@@ -139,7 +142,7 @@ ATF_TC_BODY(tz_invalid_file, tc)
 	ATF_REQUIRE_EQ(0, chdir("/"));
 	/* check timezone */
 	unsetenv("TZ");
-	test_tz("+0000 (-00)");
+	test_tz(invalid.expect);
 }
 
 ATF_TC(thin_jail);
@@ -366,12 +369,8 @@ test_tz_env(const char *tzval, const char *expect)
 	test_tz(expect);
 }
 
-ATF_TC(tz_env);
-ATF_TC_HEAD(tz_env, tc)
-{
-	atf_tc_set_md_var(tc, "descr", "Test TZ environment variable");
-}
-ATF_TC_BODY(tz_env, tc)
+static void
+tz_env_common(void)
 {
 	char path[MAXPATHLEN];
 	const struct tzcase *tzcase = tzcases;
@@ -394,6 +393,18 @@ ATF_TC_BODY(tz_env, tc)
 	}
 }
 
+ATF_TC(tz_env);
+ATF_TC_HEAD(tz_env, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Test TZ environment variable");
+}
+ATF_TC_BODY(tz_env, tc)
+{
+	tz_env_common();
+	/* escape from TZDIR is permitted when not setugid */
+	test_tz_env("../zoneinfo/UTC", utc.expect);
+}
+
 
 ATF_TC(tz_invalid_env);
 ATF_TC_HEAD(tz_invalid_env, tc)
@@ -403,8 +414,8 @@ ATF_TC_HEAD(tz_invalid_env, tc)
 }
 ATF_TC_BODY(tz_invalid_env, tc)
 {
-	test_tz_env("invalid", "+0000 (-00)");
-	test_tz_env(":invalid", "+0000 (-00)");
+	test_tz_env("invalid", invalid.expect);
+	test_tz_env(":invalid", invalid.expect);
 }
 
 ATF_TC(setugid);
@@ -443,7 +454,9 @@ ATF_TC_BODY(tz_env_setugid, tc)
 {
 	ATF_REQUIRE_EQ(0, seteuid(UID_NOBODY));
 	ATF_REQUIRE(issetugid());
-	ATF_TC_BODY_NAME(tz_env)(tc);
+	tz_env_common();
+	/* escape from TZDIR is not permitted when setugid */
+	test_tz_env("../zoneinfo/UTC", invalid.expect);
 }
 
 ATF_TP_ADD_TCS(tp)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202509291240.58TCe8gw094913>