* modules/chown-tests: * modules/fchownat-tests, modules/fdutimensat-tests: * modules/futimens-tests, modules/lchown-tests: * modules/stat-time-tests, modules/utime-tests: * modules/utimens-tests, modules/utimensat-tests: Depend on intprops. * tests/nap.h: Include intprops.h. (diff_timespec): Handle overflow properly. --- ChangeLog | 10 ++++++++++ modules/chown-tests | 1 + modules/fchownat-tests | 1 + modules/fdutimensat-tests | 1 + modules/futimens-tests | 1 + modules/lchown-tests | 1 + modules/stat-time-tests | 1 + modules/utime-tests | 1 + modules/utimens-tests | 1 + modules/utimensat-tests | 1 + tests/nap.h | 21 +++++++++++++-------- 11 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/ChangeLog b/ChangeLog index 0995e5d53..9935941df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2017-09-25 Paul Eggert <egg...@cs.ucla.edu> + maint: fix overflow checking in nap.h + * modules/chown-tests: + * modules/fchownat-tests, modules/fdutimensat-tests: + * modules/futimens-tests, modules/lchown-tests: + * modules/stat-time-tests, modules/utime-tests: + * modules/utimens-tests, modules/utimensat-tests: + Depend on intprops. + * tests/nap.h: Include intprops.h. + (diff_timespec): Handle overflow properly. + sys_types: update URL * m4/sys_types_h.m4: Use https: URL. diff --git a/modules/chown-tests b/modules/chown-tests index 58b965682..13138f438 100644 --- a/modules/chown-tests +++ b/modules/chown-tests @@ -7,6 +7,7 @@ tests/macros.h Depends-on: ignore-value +intprops lstat mgetgroups nanosleep diff --git a/modules/fchownat-tests b/modules/fchownat-tests index 4e289bda5..81adf7fe8 100644 --- a/modules/fchownat-tests +++ b/modules/fchownat-tests @@ -8,6 +8,7 @@ tests/macros.h Depends-on: ignore-value +intprops mgetgroups nanosleep openat-h diff --git a/modules/fdutimensat-tests b/modules/fdutimensat-tests index a77ada4f0..37f70c652 100644 --- a/modules/fdutimensat-tests +++ b/modules/fdutimensat-tests @@ -10,6 +10,7 @@ tests/macros.h Depends-on: fcntl-h ignore-value +intprops nanosleep openat timespec diff --git a/modules/futimens-tests b/modules/futimens-tests index c7e9db2f0..519141300 100644 --- a/modules/futimens-tests +++ b/modules/futimens-tests @@ -10,6 +10,7 @@ Depends-on: gettext-h fcntl-h ignore-value +intprops nanosleep timespec dup diff --git a/modules/lchown-tests b/modules/lchown-tests index d7288fea6..c5bba89d5 100644 --- a/modules/lchown-tests +++ b/modules/lchown-tests @@ -7,6 +7,7 @@ tests/macros.h Depends-on: ignore-value +intprops mgetgroups nanosleep stat-time diff --git a/modules/stat-time-tests b/modules/stat-time-tests index 18843de5a..c512eca76 100644 --- a/modules/stat-time-tests +++ b/modules/stat-time-tests @@ -4,6 +4,7 @@ tests/macros.h tests/nap.h Depends-on: +intprops nanosleep time diff --git a/modules/utime-tests b/modules/utime-tests index 1d3da120e..a64d0a006 100644 --- a/modules/utime-tests +++ b/modules/utime-tests @@ -8,6 +8,7 @@ Depends-on: dup gettext-h ignore-value +intprops nanosleep symlink timespec diff --git a/modules/utimens-tests b/modules/utimens-tests index d5e3085d2..2a95346a0 100644 --- a/modules/utimens-tests +++ b/modules/utimens-tests @@ -11,6 +11,7 @@ Depends-on: dup gettext-h ignore-value +intprops nanosleep symlink timespec diff --git a/modules/utimensat-tests b/modules/utimensat-tests index 09e5cb15b..15c79407e 100644 --- a/modules/utimensat-tests +++ b/modules/utimensat-tests @@ -9,6 +9,7 @@ tests/macros.h Depends-on: ignore-value +intprops nanosleep timespec utimecmp diff --git a/tests/nap.h b/tests/nap.h index c16ee904e..24043c612 100644 --- a/tests/nap.h +++ b/tests/nap.h @@ -22,6 +22,8 @@ # include <limits.h> # include <stdbool.h> +# include <intprops.h> + /* Name of the witness file. */ #define TEMPFILE BASE "nap.tmp" @@ -38,17 +40,20 @@ diff_timespec (struct timespec a, struct timespec b) time_t bs = b.tv_sec; int ans = a.tv_nsec; int bns = b.tv_nsec; + int sdiff; + + ASSERT (0 <= ans && ans < 2000000000); + ASSERT (0 <= bns && bns < 2000000000); if (! (bs < as || (bs == as && bns < ans))) return 0; - if (as - bs <= INT_MAX / 1000000000) - { - int sdiff = (as - bs) * 1000000000; - int usdiff = ans - bns; - if (usdiff < INT_MAX - sdiff) - return sdiff + usdiff; - } - return INT_MAX; + + if (INT_SUBTRACT_WRAPV (as, bs, &sdiff) + || INT_MULTIPLY_WRAPV (sdiff, 1000000000, &sdiff) + || INT_ADD_WRAPV (sdiff, ans - bns, &sdiff)) + return INT_MAX; + + return sdiff; } /* If DO_WRITE, bump the modification time of the file designated by NAP_FD. -- 2.13.5