[PATCH] Linux: Fix UTC offset setting in settimeofday for __TIMESIZE != 64
Florian Weimer
fweimer@redhat.com
Tue Jun 30 14:06:25 GMT 2020
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").
---
Tested on i686-linux-gnu, but only with the glibc test suite.
sysdeps/unix/sysv/linux/settimeofday.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/sysdeps/unix/sysv/linux/settimeofday.c b/sysdeps/unix/sysv/linux/settimeofday.c
index ea45f1d7cb..40529cdeec 100644
--- a/sysdeps/unix/sysv/linux/settimeofday.c
+++ b/sysdeps/unix/sysv/linux/settimeofday.c
@@ -25,14 +25,14 @@
int
__settimeofday64 (const struct __timeval64 *tv, const struct timezone *tz)
{
+ /* The 64-bit interface does support setting the UTC offset. */
if (__glibc_unlikely (tz != 0))
{
if (tv != 0)
- {
- __set_errno (EINVAL);
- return -1;
- }
- return __settimezone (tz);
+ __set_errno (EINVAL);
+ else
+ __set_errno (ENOSYS);
+ return -1;
}
struct __timespec64 ts = timeval64_to_timespec64 (*tv);
@@ -45,8 +45,18 @@ libc_hidden_def (__settimeofday64)
int
__settimeofday (const struct timeval *tv, const struct timezone *tz)
{
+ /* Backwards compatibility for setting the UTC offset. */
+ if (__glibc_unlikely (tz != 0))
+ {
+ if (tv != 0)
+ {
+ __set_errno (EINVAL);
+ return -1;
+ }
+ return __settimezone (tz);
+ }
+
struct __timeval64 tv64 = valid_timeval_to_timeval64 (*tv);
-
return __settimeofday64 (&tv64, tz);
}
#endif
More information about the Libc-alpha
mailing list