summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-09-25 18:20:44 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2017-09-25 18:28:31 -0700
commit8f87a5918ef7fac9181d34f29233f482000b4396 (patch)
tree941d0a37d70287d68ca87d1e92400d16b75df064
parenta42187c950f47738d2ec7154bd5fb13927fa4d27 (diff)
downloadgnulib-8f87a5918ef7fac9181d34f29233f482000b4396.tar.gz
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.
-rw-r--r--ChangeLog10
-rw-r--r--modules/chown-tests1
-rw-r--r--modules/fchownat-tests1
-rw-r--r--modules/fdutimensat-tests1
-rw-r--r--modules/futimens-tests1
-rw-r--r--modules/lchown-tests1
-rw-r--r--modules/stat-time-tests1
-rw-r--r--modules/utime-tests1
-rw-r--r--modules/utimens-tests1
-rw-r--r--modules/utimensat-tests1
-rw-r--r--tests/nap.h21
11 files changed, 32 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 0995e5d539..9935941df2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2017-09-25 Paul Eggert <eggert@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 58b9656821..13138f438b 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 4e289bda5d..81adf7fe83 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 a77ada4f06..37f70c6528 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 c7e9db2f01..5191413007 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 d7288fea6c..c5bba89d50 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 18843de5a6..c512eca76c 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 1d3da120e9..a64d0a0069 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 d5e3085d27..2a95346a0d 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 09e5cb15bf..15c79407e8 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 c16ee904e6..24043c6121 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.