]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Linux: Fix UTC offset setting in settimeofday for __TIMESIZE != 64
authorFlorian Weimer <fweimer@redhat.com>
Tue, 30 Jun 2020 19:19:43 +0000 (21:19 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Tue, 30 Jun 2020 19:20:20 +0000 (21:20 +0200)
The time argument is NULL in this case, and attempt to convert it
leads to a null pointer dereference.

This fixes commit d2e3b697da2433c08702f95c76458c51545c3df1
("y2038: linux: Provide __settimeofday64 implementation").

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
sysdeps/unix/sysv/linux/settimeofday.c

index ea45f1d7cbe0d669f87b97b6cc185db2519b6d97..2bb589f8e24e40ccd90546ea212d526d8434fb6b 100644 (file)
@@ -25,6 +25,7 @@
 int
 __settimeofday64 (const struct __timeval64 *tv, const struct timezone *tz)
 {
+  /* Backwards compatibility for setting the UTC offset.  */
   if (__glibc_unlikely (tz != 0))
     {
       if (tv != 0)
@@ -45,9 +46,13 @@ libc_hidden_def (__settimeofday64)
 int
 __settimeofday (const struct timeval *tv, const struct timezone *tz)
 {
-  struct __timeval64 tv64 = valid_timeval_to_timeval64 (*tv);
-
-  return __settimeofday64 (&tv64, tz);
+  if (__glibc_unlikely (tv == NULL))
+    return __settimeofday64 (NULL, tz);
+  else
+    {
+      struct __timeval64 tv64 = valid_timeval_to_timeval64 (*tv);
+      return __settimeofday64 (&tv64, tz);
+    }
 }
 #endif
 weak_alias (__settimeofday, settimeofday);