Changeset 7bbbe42 in rtems


Ignore:
Timestamp:
Apr 8, 2021, 1:41:15 PM (5 weeks ago)
Author:
Frank Kühndel <frank.kuehndel@…>
Branches:
master
Children:
97ba94b
Parents:
2a24f99d
git-author:
Frank Kühndel <frank.kuehndel@…> (04/08/21 13:41:15)
git-committer:
Sebastian Huber <sebastian.huber@…> (04/21/21 05:13:31)
Message:

clock:_TOD_To_seconds(): Fix year 2514 overflow

This patch fixes issue #4338 by changing _TOD_Validate()
to only accept years till 2105. This requires another patch
to change the documentation of rtems_clock_set() and other
affected API functions (indicating the end date is 2105 not 2514).

I tried to support till year 2514 but it turned out that
this needs changing the Timer Manager too. That in turn
would mean to change _TOD_Seconds_since_epoch( void )
from 32 to 64 bit. Sebastian pointed out that a naive extension
leads to trouble with 32 bit processors. He deemed a safe
re-implementation too costly performance wise considering
that year 2106 is far away and current binaries using RTEMS
Classic API are unlikely to be in use by 2106.

The constant TOD_SECONDS_AT_2100_03_01_00_00 in
cpukit/rtems/src/clocktodtoseconds.c happens to be wrong by
1 hour. When setting the date 2100-Feb-28 23:59:59 and then
reading the date again you will find yourself in 2100-Feb-27.

Update #4338

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/score/todimpl.h

    r2a24f99d r7bbbe42  
    123123 */
    124124#define TOD_BASE_YEAR 1988
     125
     126/**
     127 *  @brief Latest year to which a time of day can be initialized.
     128 *
     129 *  The following constant defines the latest year to which an
     130 *  RTEMS time of day can be set using rtems_clock_set().
     131 *
     132 *  32 bits can accept as latest point in time 2106-Feb-7 6:28:15
     133 *  but to simplify the implementation, is was decided to only
     134 *  check that the year is not greater than the year of this constant.
     135 *
     136 *  The internal realtime clock can run centuries longer but in
     137 *  contrast to the POSIX API, the RTEMS Classic API does not
     138 *  support this for efficiency reasons.
     139 */
     140#define TOD_LATEST_YEAR 2105
    125141
    126142/**
  • cpukit/rtems/src/clocktodtoseconds.c

    r2a24f99d r7bbbe42  
    2424#include <rtems/score/todimpl.h>
    2525
    26 #define TOD_SECONDS_AT_2100_03_01_00_00 4107538800UL
     26#define TOD_SECONDS_AT_2100_03_01_00_00 4107542400UL
    2727
    2828/*
  • cpukit/rtems/src/clocktodvalidate.c

    r2a24f99d r7bbbe42  
    5353      (the_tod->month  >  TOD_MONTHS_PER_YEAR)    ||
    5454      (the_tod->year   <  TOD_BASE_YEAR)          ||
     55      (the_tod->year   >  TOD_LATEST_YEAR)        ||
    5556      (the_tod->day    == 0) )
    5657     return false;
  • testsuites/sptests/sp2038/init.c

    r2a24f99d r7bbbe42  
    150150  4200272895UL,
    151151  4231808895UL,
    152   4263431295UL,
    153   4294967295UL
     152  4263431295UL
    154153};
    155154
     
    172171};
    173172
    174 static const rtems_time_of_day nearly_problem_2106 = {
    175   .year = 2106,
     173static const rtems_time_of_day tod_to_seconds_base = {
     174  .year = 0,
    176175  .month = 2,
    177176  .day = 7,
     
    181180};
    182181
     182static const rtems_time_of_day nearly_problem_2106 = {
     183  .year = 2105,
     184  .month = 12,
     185  .day = 31,
     186  .hour = 23,
     187  .minute = 59,
     188  .second = 59
     189};
     190
    183191static const rtems_time_of_day problem_2106 = {
    184192  .year = 2106,
    185   .month = 2,
    186   .day = 7,
    187   .hour = 6,
    188   .minute = 28,
    189   .second = 16
     193  .month = 1,
     194  .day = 1,
     195  .hour = 0,
     196  .minute = 0,
     197  .second = 0
    190198};
    191199
     
    215223
    216224  for (i = 0; i < n; ++i) {
    217     rtems_time_of_day tod = nearly_problem_2106;
     225    rtems_time_of_day tod = tod_to_seconds_base;
    218226    uint32_t seconds = 0;
    219227    rtems_interval seconds_as_interval = 0;
Note: See TracChangeset for help on using the changeset viewer.