[PATCH rtems-libbsd 1/7] rtemsbsd: Catch timeout overflows
chrisj at rtems.org
chrisj at rtems.org
Tue Jul 27 08:58:45 UTC 2021
From: Chris Johns <chrisj at rtems.org>
Update #4475
---
rtemsbsd/rtems/rtems-kernel-timesupport.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/rtemsbsd/rtems/rtems-kernel-timesupport.c b/rtemsbsd/rtems/rtems-kernel-timesupport.c
index ef14d1fa..5d290d66 100644
--- a/rtemsbsd/rtems/rtems-kernel-timesupport.c
+++ b/rtemsbsd/rtems/rtems-kernel-timesupport.c
@@ -35,6 +35,7 @@
#include <machine/rtems-bsd-kernel-space.h>
+#include <limits.h>
#include <sys/time.h>
#include <rtems/score/timespec.h>
@@ -46,9 +47,14 @@ int
tvtohz(struct timeval *tv)
{
struct timespec ts;
+ uint32_t ticks;
ts.tv_sec = tv->tv_sec;
ts.tv_nsec = tv->tv_usec * 1000;
- return (int) _Timespec_To_ticks( &ts );
+ ticks = _Timespec_To_ticks( &ts );
+ if (ticks > INT_MAX)
+ ticks = INT_MAX;
+
+ return ticks;
}
--
2.24.1
More information about the devel
mailing list