[rtems commit] score: Limit the CLOCK_REALTIME setting

Sebastian Huber sebh at rtems.org
Mon Sep 6 10:25:31 UTC 2021


Module:    rtems
Branch:    master
Commit:    6d2becb78d46c82fd3bacfb94cbfd02e440f3d67
Changeset: http://git.rtems.org/rtems/commit/?id=6d2becb78d46c82fd3bacfb94cbfd02e440f3d67

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Sep  3 15:04:49 2021 +0200

score: Limit the CLOCK_REALTIME setting

Limit the CLOCK_REALTIME setting to ensure that the CLOCK_REALTIME is defined
for a system uptime of at least 114 years.

---

 cpukit/include/rtems/score/todimpl.h |  9 +++++++++
 cpukit/score/src/coretodcheck.c      |  2 +-
 testsuites/psxtests/psxclock/init.c  | 14 ++++++++++++++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/cpukit/include/rtems/score/todimpl.h b/cpukit/include/rtems/score/todimpl.h
index ceeef2e..f85689f 100644
--- a/cpukit/include/rtems/score/todimpl.h
+++ b/cpukit/include/rtems/score/todimpl.h
@@ -116,6 +116,15 @@ extern "C" {
   (4 * TOD_SECONDS_PER_DAY))
 
 /**
+ * @brief Seconds from 1970-01-01T00:00:00Z to 2400-01-01T00:00:00Z.
+ *
+ * This is the latest time of day which should be set by _TOD_Set().  The year
+ * 2400 was chosen to guarantee a defined CLOCK_REALTIME within the range of a
+ * system uptime of about 114 years.
+ */
+#define TOD_SECONDS_1970_THROUGH_2400 13569465600
+
+/**
  *  @brief Earliest year to which an time of day can be initialized.
  *
  *  The following constant define the earliest year to which an
diff --git a/cpukit/score/src/coretodcheck.c b/cpukit/score/src/coretodcheck.c
index b42435a..8c012c5 100644
--- a/cpukit/score/src/coretodcheck.c
+++ b/cpukit/score/src/coretodcheck.c
@@ -51,7 +51,7 @@ Status_Control _TOD_Is_valid_new_time_of_day( const struct timespec *tod )
     return STATUS_INVALID_NUMBER;
   }
 
-  if ( _Watchdog_Is_far_future_timespec( tod ) ) {
+  if ( tod->tv_sec > TOD_SECONDS_1970_THROUGH_2400 ) {
     return STATUS_INVALID_NUMBER;
   }
 
diff --git a/testsuites/psxtests/psxclock/init.c b/testsuites/psxtests/psxclock/init.c
index 778637b..66d9388 100644
--- a/testsuites/psxtests/psxclock/init.c
+++ b/testsuites/psxtests/psxclock/init.c
@@ -131,6 +131,20 @@ static rtems_task Init(
   rtems_test_assert( sc == -1 );
   rtems_test_assert( errno == EINVAL );
 
+  puts( "Init: clock_settime - 2400-01-01T00:00:00.999999999Z SUCCESSFUL" );
+  tv.tv_sec = 13569465600;
+  tv.tv_nsec = 999999999;
+  sc = clock_settime( CLOCK_REALTIME, &tv );
+  rtems_test_assert( sc == 0 );
+
+  puts( "Init: clock_settime - 2400-01-01T00:00:01Z EINVAL" );
+  tv.tv_sec = 13569465601;
+  tv.tv_nsec = 0;
+  errno = 0;
+  sc = clock_settime( CLOCK_REALTIME, &tv );
+  rtems_test_assert( sc == -1 );
+  rtems_test_assert( errno == EINVAL );
+
   puts( "Init: clock_settime - far future EINVAL" );
   tv.tv_sec = 17179869184;
   tv.tv_nsec = 0;



More information about the vc mailing list