This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 2/2] linux: clock_settime: Return proper value when passing NULL pointer
- From: Alistair Francis <alistair23 at gmail dot com>
- To: Lukasz Majewski <lukma at denx dot de>
- Cc: Joseph Myers <joseph at codesourcery dot com>, Paul Eggert <eggert at cs dot ucla dot edu>, Alistair Francis <alistair dot francis at wdc dot com>, GNU C Library <libc-alpha at sourceware dot org>, Adhemerval Zanella <adhemerval dot zanella at linaro dot org>, Florian Weimer <fweimer at redhat dot com>, Florian Weimer <fw at deneb dot enyo dot de>, Zack Weinberg <zackw at panix dot com>, "Carlos O'Donell" <carlos at redhat dot com>
- Date: Fri, 8 Nov 2019 08:56:25 -0800
- Subject: Re: [PATCH 2/2] linux: clock_settime: Return proper value when passing NULL pointer
- References: <20191108153344.10949-1-lukma@denx.de> <20191108153344.10949-2-lukma@denx.de>
On Fri, Nov 8, 2019 at 7:34 AM Lukasz Majewski <lukma@denx.de> wrote:
>
> When in __clock_settime function (__TIMESIZE != 64) the const struct
> timespec's *tp pointer is NULL, the Linux kernel syscall returns
> -EFAULT.
> Without this patch the glibc crashes (when dereferencing NULL pointer)
> as the Linux kernel syscall is not reached at all.
>
> There is no need for such check in the __clock_settime64, as this
> pointer either goes directly to Linux kernel or the pointer to local
> copy is used (ts64).
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> sysdeps/unix/sysv/linux/clock_settime.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c
> index 6706dbb31f..e358a18998 100644
> --- a/sysdeps/unix/sysv/linux/clock_settime.c
> +++ b/sysdeps/unix/sysv/linux/clock_settime.c
> @@ -51,7 +51,14 @@ __clock_settime64 (clockid_t clock_id, const struct __timespec64 *tp)
> int
> __clock_settime (clockid_t clock_id, const struct timespec *tp)
> {
> - struct __timespec64 ts64 = valid_timespec_to_timespec64 (*tp);
> + struct __timespec64 ts64;
> +
> + if (tp == NULL)
> + {
> + __set_errno (EFAULT);
> + return -1;
> + }
> + ts64 = valid_timespec_to_timespec64 (*tp);
>
> return __clock_settime64 (clock_id, &ts64);
> }
> --
> 2.20.1
>