From 118a2aee07f64d605b6668cbe195c1f44eac6be6 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Wed, 27 Apr 2022 13:40:30 -0300 Subject: linux: Fix fchmodat with AT_SYMLINK_NOFOLLOW for 64 bit time_t (BZ#29097) The AT_SYMLINK_NOFOLLOW emulation ues the default 32 bit stat internal calls, which fails with EOVERFLOW if the file constains timestamps beyond 2038. Checked on i686-linux-gnu. --- io/tst-lchmod.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'io/tst-lchmod.c') diff --git a/io/tst-lchmod.c b/io/tst-lchmod.c index c644f565f6..c1c41bda88 100644 --- a/io/tst-lchmod.c +++ b/io/tst-lchmod.c @@ -66,10 +66,27 @@ select_path (bool do_relative_path, const char *full_path, const char *relative_ return full_path; } +static void +update_file_time_to_y2038 (const char *fname, int flags) +{ +#ifdef CHECK_TIME64 + /* Y2038 threshold plus 1 second. */ + const struct timespec ts[] = { { 0x80000001LL, 0}, { 0x80000001LL } }; + TEST_VERIFY_EXIT (utimensat (AT_FDCWD, fname, ts, flags) == 0); +#endif +} + static void test_1 (bool do_relative_path, int (*chmod_func) (int fd, const char *, mode_t, int)) { char *tempdir = support_create_temp_directory ("tst-lchmod-"); +#ifdef CHECK_TIME64 + if (!support_path_support_time64 (tempdir)) + { + puts ("info: test skipped, filesystem does not support 64 bit time_t"); + return; + } +#endif char *path_dangling = xasprintf ("%s/dangling", tempdir); char *path_file = xasprintf ("%s/file", tempdir); @@ -93,9 +110,12 @@ test_1 (bool do_relative_path, int (*chmod_func) (int fd, const char *, mode_t, xsymlink ("loop", path_loop); xsymlink ("target-does-not-exist", path_dangling); + update_file_time_to_y2038 (path_file, 0); + update_file_time_to_y2038 (path_to_file, AT_SYMLINK_NOFOLLOW); + /* Check that the modes do not collide with what we will use in the test. */ - struct stat64 st; + struct stat st; xstat (path_file, &st); TEST_VERIFY ((st.st_mode & 0777) != 1); xlstat (path_to_file, &st); -- cgit 1.4.1