From ebaa53c5f1253974c6f23bb1500d8de198e84ab8 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 2 Jan 2021 19:31:45 +0100 Subject: [PATCH] utimensat: Fix test failures on macOS 10.13. * lib/utimensat.c: Include , . (rpl_utimensat): Check against invalid tv_nsec values. Before calling utimensat, recognize a filename ending in a slash that does not point to a directory. --- ChangeLog | 8 ++++++++ lib/utimensat.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/ChangeLog b/ChangeLog index fb6a8c2d9d..183e877033 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2021-01-02 Bruno Haible + utimensat: Fix test failures on macOS 10.13. + * lib/utimensat.c: Include , . + (rpl_utimensat): Check against invalid tv_nsec values. Before calling + utimensat, recognize a filename ending in a slash that does not point + to a directory. + +2021-01-02 Bruno Haible + utimens: Fix test failure on macOS 10.13. * lib/utimens.c: Include . diff --git a/lib/utimensat.c b/lib/utimensat.c index 2cea64f698..1daff88e6e 100644 --- a/lib/utimensat.c +++ b/lib/utimensat.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include "stat-time.h" #include "timespec.h" @@ -106,6 +108,34 @@ rpl_utimensat (int fd, char const *file, struct timespec const times[2], } # endif # endif +# if defined __APPLE__ && defined __MACH__ + /* macOS 10.13 does not reject invalid tv_nsec values either. */ + if (times + && ((times[0].tv_nsec != UTIME_OMIT + && times[0].tv_nsec != UTIME_NOW + && ! (0 <= times[0].tv_nsec + && times[0].tv_nsec < TIMESPEC_HZ)) + || (times[1].tv_nsec != UTIME_OMIT + && times[1].tv_nsec != UTIME_NOW + && ! (0 <= times[1].tv_nsec + && times[1].tv_nsec < TIMESPEC_HZ)))) + { + errno = EINVAL; + return -1; + } + size_t len = strlen (file); + if (len > 0 && file[len - 1] == '/') + { + struct stat statbuf; + if (fstatat (fd, file, &statbuf, 0) < 0) + return -1; + if (!S_ISDIR (statbuf.st_mode)) + { + errno = ENOTDIR; + return -1; + } + } +# endif result = utimensat (fd, file, times, flag); /* Linux kernel 2.6.25 has a bug where it returns EINVAL for UTIME_NOW or UTIME_OMIT with non-zero tv_sec, which -- 2.11.4.GIT