]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Define in_int32_t_range to check if the 64 bit time_t syscall should be used
authorYunQiang Su <yunqiang.su@cipunited.com>
Tue, 8 Nov 2022 04:49:46 +0000 (12:49 +0800)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 17 Nov 2022 17:35:13 +0000 (14:35 -0300)
Currently glibc uses in_time_t_range to detects time_t overflow,
and if it occurs fallbacks to 64 bit syscall version.

The function name is confusing because internally time_t might be
either 32 bits or 64 bits (depending on __TIMESIZE).

This patch refactors the in_time_t_range by replacing it with
in_int32_t_range for the case to check if the 64 bit time_t syscall
should be used.

The in_time_t range is used to detect overflow of the
syscall return value.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
18 files changed:
include/time.h
nptl/futex-internal.c
sysdeps/unix/sysv/linux/clock_adjtime.c
sysdeps/unix/sysv/linux/clock_nanosleep.c
sysdeps/unix/sysv/linux/clock_settime.c
sysdeps/unix/sysv/linux/mq_timedreceive.c
sysdeps/unix/sysv/linux/mq_timedsend.c
sysdeps/unix/sysv/linux/ppoll.c
sysdeps/unix/sysv/linux/pselect.c
sysdeps/unix/sysv/linux/recvmmsg.c
sysdeps/unix/sysv/linux/select.c
sysdeps/unix/sysv/linux/semtimedop.c
sysdeps/unix/sysv/linux/setitimer.c
sysdeps/unix/sysv/linux/setsockopt.c
sysdeps/unix/sysv/linux/sigtimedwait.c
sysdeps/unix/sysv/linux/timer_settime.c
sysdeps/unix/sysv/linux/timerfd_settime.c
sysdeps/unix/sysv/linux/utimensat.c

index 20abea69d4e58d2ba43ac29fd4171e2c0f76645d..f599eeed4e2d9990c3862442037353aca397117c 100644 (file)
@@ -347,12 +347,20 @@ libc_hidden_proto (__time64)
 /* Check whether T fits in int32_t, assume all usages are for
    sizeof(time_t) == 32.  */
 static inline bool
-in_time_t_range (__time64_t t)
+in_int32_t_range (__time64_t t)
 {
   int32_t s = t;
   return s == t;
 }
 
+/* Check whether T fits in time_t.  */
+static inline bool
+in_time_t_range (__time64_t t)
+{
+  time_t s = t;
+  return s == t;
+}
+
 /* Convert a known valid struct timeval into a struct __timespec64.  */
 static inline struct __timespec64
 valid_timeval_to_timespec64 (const struct timeval tv)
index 7ec228e8fb36467c249be779f9f46d5c2536b83f..6b8ac2304db5957362ad4c382028c6af115d3289 100644 (file)
@@ -87,7 +87,7 @@ __futex_abstimed_wait_common (unsigned int* futex_word,
   err = __futex_abstimed_wait_common64 (futex_word, expected, op, abstime,
                                        private, cancel);
 #else
-  bool need_time64 = abstime != NULL && !in_time_t_range (abstime->tv_sec);
+  bool need_time64 = abstime != NULL && !in_int32_t_range (abstime->tv_sec);
   if (need_time64)
     {
       err = __futex_abstimed_wait_common64 (futex_word, expected, op, abstime,
@@ -162,7 +162,7 @@ __futex_lock_pi64 (int *futex_word, clockid_t clockid,
 # ifdef __ASSUME_TIME64_SYSCALLS
   err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op_pi, 0, abstime);
 # else
-  bool need_time64 = abstime != NULL && !in_time_t_range (abstime->tv_sec);
+  bool need_time64 = abstime != NULL && !in_int32_t_range (abstime->tv_sec);
   if (need_time64)
     err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op_pi, 0, abstime);
   else
index 5ded82f5061948d7fa9af2ae09f92ad14f39f588..63ea68c3afad05479a96d7c92596835c89e2f896 100644 (file)
@@ -35,7 +35,7 @@ __clock_adjtime64 (const clockid_t clock_id, struct __timex64 *tx64)
     return r;
 
   if (tx64->modes & ADJ_SETOFFSET
-      && ! in_time_t_range (tx64->time.tv_sec))
+      && ! in_int32_t_range (tx64->time.tv_sec))
     {
       __set_errno (EOVERFLOW);
       return -1;
index e610fd4e8dd204752ac1bba7a3f73e5452e44a68..903106048634c47cbf8620a1a5c8d7a6c4bb7223 100644 (file)
@@ -48,7 +48,7 @@ __clock_nanosleep_time64 (clockid_t clock_id, int flags,
   r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, clock_id, flags, req,
                               rem);
 #else
-  if (!in_time_t_range (req->tv_sec))
+  if (!in_int32_t_range (req->tv_sec))
     {
       r = INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, clock_id, flags,
                                   req, rem);
index 2a32e2eb137a3a060e3ff53d1a2a8ef2c0b954f8..db9698ba0d642280a2e6656450c8dd85ba76666a 100644 (file)
@@ -41,7 +41,7 @@ __clock_settime64 (clockid_t clock_id, const struct __timespec64 *tp)
   if (ret == 0 || errno != ENOSYS)
     return ret;
 
-  if (! in_time_t_range (tp->tv_sec))
+  if (! in_int32_t_range (tp->tv_sec))
     {
       __set_errno (EOVERFLOW);
       return -1;
index 5bf1e0a83bad6735b06e67956c3a475de58eab5c..6c719d4b700c675a9f987b01f4c63bdb76e0609c 100644 (file)
@@ -36,7 +36,7 @@ ___mq_timedreceive_time64 (mqd_t mqdes, char *__restrict msg_ptr, size_t msg_len
                         msg_prio, abs_timeout);
 #else
   bool need_time64 = abs_timeout != NULL
-                    && !in_time_t_range (abs_timeout->tv_sec);
+                    && !in_int32_t_range (abs_timeout->tv_sec);
   if (need_time64)
     {
       int r = SYSCALL_CANCEL (mq_timedreceive_time64, mqdes, msg_ptr, msg_len,
index 3ca50509764b20f16e4e01bca45d0577b9ab42ae..eb8353feef1662911ddd6984ae382c672b0a10bb 100644 (file)
@@ -36,7 +36,7 @@ ___mq_timedsend_time64 (mqd_t mqdes, const char *msg_ptr, size_t msg_len,
                         msg_prio, abs_timeout);
 #else
   bool need_time64 = abs_timeout != NULL
-                    && !in_time_t_range (abs_timeout->tv_sec);
+                    && !in_int32_t_range (abs_timeout->tv_sec);
   if (need_time64)
     {
       int r = SYSCALL_CANCEL (mq_timedsend_time64, mqdes, msg_ptr, msg_len,
index 2e173b931d7537b5742529fcc52c8c4fcadf2f5b..45b52d6c76d3200f6cc2017675353219d615a48b 100644 (file)
@@ -43,7 +43,7 @@ __ppoll64 (struct pollfd *fds, nfds_t nfds, const struct __timespec64 *timeout,
                         __NSIG_BYTES);
 #else
   int ret;
-  bool need_time64 = timeout != NULL && !in_time_t_range (timeout->tv_sec);
+  bool need_time64 = timeout != NULL && !in_int32_t_range (timeout->tv_sec);
   if (need_time64)
     {
       ret = SYSCALL_CANCEL (ppoll_time64, fds, nfds, timeout, sigmask,
index eba1c111f8bbbaab1c979a3d34db406ba0cff35b..23fd0dfad6184ecb49371caa1b4f29f73d719145 100644 (file)
@@ -56,7 +56,7 @@ __pselect64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
   return pselect64_syscall (nfds, readfds, writefds, exceptfds, timeout,
                            sigmask);
 #else
-  bool need_time64 = timeout != NULL && !in_time_t_range (timeout->tv_sec);
+  bool need_time64 = timeout != NULL && !in_int32_t_range (timeout->tv_sec);
   if (need_time64)
     {
       int r = pselect64_syscall (nfds, readfds, writefds, exceptfds, timeout,
index d9664d61c4cc1b66dc9fc13c63918e95b1f9483b..1ba5a4f25c6a6421d39ba36278eaf217679aa38d 100644 (file)
@@ -35,7 +35,7 @@ recvmmsg_syscall (int fd, struct mmsghdr *vmessages, unsigned int vlen,
   struct timespec ts32, *pts32 = NULL;
   if (timeout != NULL)
     {
-      if (! in_time_t_range (timeout->tv_sec))
+      if (! in_int32_t_range (timeout->tv_sec))
        {
          __set_errno (EINVAL);
          return -1;
index a3f0a2eba7471e53033f5da4196ab9abcc9edc90..fd147dfdd4a213d92faf632d367d7a20fcf6fe51 100644 (file)
@@ -72,7 +72,7 @@ __select64 (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
     TIMESPEC_TO_TIMEVAL (timeout, pts64);
   return r;
 #else
-  bool need_time64 = timeout != NULL && !in_time_t_range (timeout->tv_sec);
+  bool need_time64 = timeout != NULL && !in_int32_t_range (timeout->tv_sec);
   if (need_time64)
     {
       int r = SYSCALL_CANCEL (pselect6_time64, nfds, readfds, writefds,
index 38a401bb6fba7c68456f978f2a5f434ddc5a25a1..0cdc0fad4b54c8920c254434d85e600d78d93d0f 100644 (file)
@@ -42,7 +42,7 @@ __semtimedop64 (int semid, struct sembuf *sops, size_t nsops,
 #ifdef __ASSUME_TIME64_SYSCALLS
   return semtimedop_syscall (semid, sops, nsops, timeout);
 #else
-  bool need_time64 = timeout != NULL && !in_time_t_range (timeout->tv_sec);
+  bool need_time64 = timeout != NULL && !in_int32_t_range (timeout->tv_sec);
   if (need_time64)
     {
       int r = semtimedop_syscall (semid, sops, nsops, timeout);
index 6d5183aa632b05fff972a547d783c962e9106b03..55e6003e0f5b60dc456aa19d66bfafd07e0b28ba 100644 (file)
@@ -32,8 +32,8 @@ __setitimer64 (__itimer_which_t which,
 #else
   struct __itimerval32 new_value_32;
 
-  if (! in_time_t_range (new_value->it_interval.tv_sec)
-      || ! in_time_t_range (new_value->it_value.tv_sec))
+  if (! in_int32_t_range (new_value->it_interval.tv_sec)
+      || ! in_int32_t_range (new_value->it_value.tv_sec))
     {
       __set_errno (EOVERFLOW);
       return -1;
index 4292f411f3c50735f9261c433ebdac310885e43f..6506ca03ab2956447483cc984051a7a734e64c75 100644 (file)
@@ -54,7 +54,7 @@ setsockopt32 (int fd, int level, int optname, const void *optval,
          }
 
        struct __timeval64 *tv64 = (struct __timeval64 *) optval;
-       if (! in_time_t_range (tv64->tv_sec))
+       if (! in_int32_t_range (tv64->tv_sec))
          {
            __set_errno (EOVERFLOW);
            break;
index 069fa1d5e49afe6e91342f717d5ac8a04abf63f9..1993e3f85a1b55ce465b49add661c139f5c6f3ce 100644 (file)
@@ -31,7 +31,7 @@ __sigtimedwait64 (const sigset_t *set, siginfo_t *info,
   result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout,
                           __NSIG_BYTES);
 #else
-  bool need_time64 = timeout != NULL && !in_time_t_range (timeout->tv_sec);
+  bool need_time64 = timeout != NULL && !in_int32_t_range (timeout->tv_sec);
   if (need_time64)
     {
       result = SYSCALL_CANCEL (rt_sigtimedwait_time64, set, info, timeout,
index 518fed9c59f2235787f15e2f4d854fa7ce112115..056e0aff599cb5610c90e972b8435aa7bba11462 100644 (file)
@@ -46,8 +46,8 @@ ___timer_settime64 (timer_t timerid, int flags,
 #  endif
   struct itimerspec its32, oits32;
 
-  if (! in_time_t_range ((value->it_value).tv_sec)
-      || ! in_time_t_range ((value->it_interval).tv_sec))
+  if (! in_int32_t_range ((value->it_value).tv_sec)
+      || ! in_int32_t_range ((value->it_interval).tv_sec))
     {
       __set_errno (EOVERFLOW);
       return -1;
index 59282bf1ad936febe415f3b478c7b211043e095d..c5f3f14c3b931437463982b8a3ee0d60cf62644f 100644 (file)
@@ -33,8 +33,8 @@ __timerfd_settime64 (int fd, int flags, const struct __itimerspec64 *value,
 #ifdef __ASSUME_TIME64_SYSCALLS
   return INLINE_SYSCALL_CALL (timerfd_settime64, fd, flags, value, ovalue);
 #else
-  bool need_time64 = !in_time_t_range (value->it_value.tv_sec)
-                    || !in_time_t_range (value->it_interval.tv_sec);
+  bool need_time64 = !in_int32_t_range (value->it_value.tv_sec)
+                    || !in_int32_t_range (value->it_interval.tv_sec);
   if (need_time64)
     {
       int r = INLINE_SYSCALL_CALL (timerfd_settime64, fd, flags, value,
index 5662ecc9aa3814c75b97a165250e3394fd178969..54a5e476186a4aa06beee4316bc310f604652a29 100644 (file)
@@ -41,9 +41,9 @@ __utimensat64_helper (int fd, const char *file,
 
   bool need_time64 = tsp64 != NULL
                     && ((!TS_SPECIAL (tsp64[0])
-                         && !in_time_t_range (tsp64[0].tv_sec))
+                         && !in_int32_t_range (tsp64[0].tv_sec))
                         || (!TS_SPECIAL (tsp64[1])
-                            && !in_time_t_range (tsp64[1].tv_sec)));
+                            && !in_int32_t_range (tsp64[1].tv_sec)));
   if (need_time64)
     {
       int r = INLINE_SYSCALL_CALL (utimensat_time64, fd, file, &tsp64[0],