]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
hurd: __adjtime(): struct timeval and time_value_t are not identical.
authorMichael Kelly <mike@weatherwax.co.uk>
Wed, 15 Apr 2026 20:18:52 +0000 (22:18 +0200)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Wed, 15 Apr 2026 20:22:08 +0000 (22:22 +0200)
'struct timeval' and 'struct time_value' have different types for the
microseconds component: int and long int. Casting one to the other
leads to negative numbers not being preserved properly within the
called code.
Message-ID: <20260415180318.109742-3-mike@weatherwax.co.uk>

sysdeps/mach/hurd/adjtime.c

index 915b86da139f7456cc2190db32d2e031c2132726..9d01533b23ff25b2fc2fccc44a00e9c04d9a079f 100644 (file)
@@ -28,31 +28,36 @@ __adjtime (const struct timeval *delta, struct timeval *olddelta)
 {
   error_t err;
   mach_port_t hostpriv;
-  struct timeval dummy;
+  time_value_t rpc_delta, rpc_olddelta;
 
   err = __get_privileged_ports (&hostpriv, NULL);
   if (err)
     return __hurd_fail (EPERM);
 
-  if (olddelta == NULL)
-    olddelta = &dummy;
-
   if (delta != NULL)
     {
       if (delta->tv_usec >=  TIME_MICROS_MAX ||
           delta->tv_usec <= -TIME_MICROS_MAX)
        return EINVAL;
+
+      rpc_delta.seconds = delta->tv_sec;
+      rpc_delta.microseconds = delta->tv_usec;
     }
+  else
+    return EINVAL;
 
-  err = __host_adjust_time (hostpriv,
-                           /* `time_value_t' and `struct timeval' are in
-                               fact identical with the names changed.  */
-                           *(time_value_t *) delta,
-                           (time_value_t *) olddelta);
+  err = __host_adjust_time (hostpriv, rpc_delta, &rpc_olddelta);
   __mach_port_deallocate (__mach_task_self (), hostpriv);
 
   if (err)
     return __hurd_fail (err);
+
+  if (olddelta != NULL)
+    {
+      olddelta->tv_sec = rpc_olddelta.seconds;
+      olddelta->tv_usec = rpc_olddelta.microseconds;
+    }
+
   return 0;
 }