From patchwork Fri Nov 8 15:33:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 35748 Received: (qmail 63641 invoked by alias); 8 Nov 2019 15:34:07 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 63623 invoked by uid 89); 8 Nov 2019 15:34:07 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: mail-out.m-online.net From: Lukasz Majewski To: Joseph Myers , Paul Eggert Cc: Alistair Francis , Alistair Francis , GNU C Library , Adhemerval Zanella , Florian Weimer , Florian Weimer , Zack Weinberg , Carlos O'Donell , Lukasz Majewski Subject: [PATCH 2/2] linux: clock_settime: Return proper value when passing NULL pointer Date: Fri, 8 Nov 2019 16:33:44 +0100 Message-Id: <20191108153344.10949-2-lukma@denx.de> In-Reply-To: <20191108153344.10949-1-lukma@denx.de> References: <20191108153344.10949-1-lukma@denx.de> MIME-Version: 1.0 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 --- 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); }