From: Bruno Haible Date: Sat, 2 Jan 2021 18:31:45 +0000 (+0100) Subject: utimensat: Fix test failures on macOS 10.13. X-Git-Tag: v1.0~3230 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=ebaa53c5f1253974c6f23bb1500d8de198e84ab8;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index fb6a8c2d9d..183e877033 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +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. 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" @@ -105,6 +107,34 @@ rpl_utimensat (int fd, char const *file, struct timespec const times[2], return -1; } # 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