From e1454560cfa22c040bfbb5896d633a6c7213deb2 Mon Sep 17 00:00:00 2001 From: cheloha Date: Wed, 8 Nov 2023 15:51:28 +0000 Subject: [PATCH] libc, librthread: _twait: fully validate absolute timeout Use timespecisvalid(3) to check both bounds for tv_nsec. Link: https://marc.info/?l=openbsd-tech&m=169913314230496&w=2 ok miod@ --- lib/libc/thread/synch.h | 4 ++-- lib/librthread/synch.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/libc/thread/synch.h b/lib/libc/thread/synch.h index 6b9fab1642d..c417822bb43 100644 --- a/lib/libc/thread/synch.h +++ b/lib/libc/thread/synch.h @@ -1,4 +1,4 @@ -/* $OpenBSD: synch.h,v 1.7 2021/06/13 21:11:54 kettenis Exp $ */ +/* $OpenBSD: synch.h,v 1.8 2023/11/08 15:51:28 cheloha Exp $ */ /* * Copyright (c) 2017 Martin Pieuchot * @@ -41,7 +41,7 @@ _twait(volatile uint32_t *p, int val, clockid_t clockid, const struct timespec * return error; } - if (abs->tv_nsec >= 1000000000 || WRAP(clock_gettime)(clockid, &rel)) + if (!timespecisvalid(abs) || WRAP(clock_gettime)(clockid, &rel)) return EINVAL; rel.tv_sec = abs->tv_sec - rel.tv_sec; diff --git a/lib/librthread/synch.h b/lib/librthread/synch.h index e6ad156778c..516a97afa64 100644 --- a/lib/librthread/synch.h +++ b/lib/librthread/synch.h @@ -1,4 +1,4 @@ -/* $OpenBSD: synch.h,v 1.8 2021/06/13 21:11:54 kettenis Exp $ */ +/* $OpenBSD: synch.h,v 1.9 2023/11/08 15:51:28 cheloha Exp $ */ /* * Copyright (c) 2017 Martin Pieuchot * @@ -41,7 +41,7 @@ _twait(volatile uint32_t *p, int val, clockid_t clockid, const struct timespec * return error; } - if (abs->tv_nsec >= 1000000000 || clock_gettime(clockid, &rel)) + if (!timespecisvalid(abs) || clock_gettime(clockid, &rel)) return EINVAL; rel.tv_sec = abs->tv_sec - rel.tv_sec; -- 2.20.1