-
Notifications
You must be signed in to change notification settings - Fork 26
Fix Year 2038 Problem in Sntp_ConvertToUnixTime #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kar-rahul-aws
merged 20 commits into
FreeRTOS:main
from
kar-rahul-aws:new_fix_2038_issue
Apr 15, 2025
Merged
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
68bf4b6
Fix year 2038 problem
kar-rahul-aws 6c73e6b
Fix bound checking test and remove the case for SntpErrorTimeNotSuppo…
kar-rahul-aws 6c6d479
Fix CBMC failure
kar-rahul-aws 3b19b67
Add underflow check
kar-rahul-aws d5793ef
Fix formatting
kar-rahul-aws 953d238
Fix CI issue with python version
kar-rahul-aws 5180907
Fix CI issue with python version
kar-rahul-aws ec6f1e0
Fix coverage tests to run with respect to Ubuntu 24.04
kar-rahul-aws 0596187
Fix CI check for lcov V2.3.1
kar-rahul-aws 51fcd01
Fix CI check for lcov V2.3.1
kar-rahul-aws d3de88c
Fix CI check for lcov V2.3.1
kar-rahul-aws f684f35
Add ruby installation for coverage
kar-rahul-aws 6c66e29
Fix coverage fail
kar-rahul-aws cdccaab
Fix CI check
kar-rahul-aws a0a48b2
Fix CI check
kar-rahul-aws b61c9db
Fix lcov: ERROR
kar-rahul-aws 3ea76fa
Add comments
kar-rahul-aws 796c591
Address review comments
kar-rahul-aws d21e916
Fix doxygen build
kar-rahul-aws e82d127
Address review comments
kar-rahul-aws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -812,7 +812,7 @@ SntpStatus_t Sntp_CalculatePollInterval( uint16_t clockFreqTolerance, | |
} | ||
|
||
SntpStatus_t Sntp_ConvertToUnixTime( const SntpTimestamp_t * pSntpTime, | ||
uint32_t * pUnixTimeSecs, | ||
UnixTime_t * pUnixTimeSecs, | ||
uint32_t * pUnixTimeMicrosecs ) | ||
{ | ||
SntpStatus_t status = SntpSuccess; | ||
|
@@ -821,13 +821,6 @@ SntpStatus_t Sntp_ConvertToUnixTime( const SntpTimestamp_t * pSntpTime, | |
{ | ||
status = SntpErrorBadParameter; | ||
} | ||
/* Check if passed time does not lie in the [UNIX epoch in 1970, UNIX time overflow in 2038] time range. */ | ||
else if( ( pSntpTime->seconds > SNTP_TIME_AT_LARGEST_UNIX_TIME_SECS ) && | ||
( pSntpTime->seconds < SNTP_TIME_AT_UNIX_EPOCH_SECS ) ) | ||
{ | ||
/* The SNTP timestamp is outside the supported time range for conversion. */ | ||
status = SntpErrorTimeNotSupported; | ||
} | ||
else | ||
{ | ||
/* Handle case when timestamp represents date in SNTP era 1 | ||
|
@@ -839,12 +832,13 @@ SntpStatus_t Sntp_ConvertToUnixTime( const SntpTimestamp_t * pSntpTime, | |
* + | ||
* Sntp Time since Era 1 Epoch | ||
*/ | ||
*pUnixTimeSecs = UNIX_TIME_SECS_AT_SNTP_ERA_1_SMALLEST_TIME + pSntpTime->seconds; | ||
*pUnixTimeSecs = ( UnixTime_t ) ( UNIX_TIME_SECS_AT_SNTP_ERA_1_SMALLEST_TIME + pSntpTime->seconds ); | ||
} | ||
|
||
/* Handle case when SNTP timestamp is in SNTP era 1 time range. */ | ||
else | ||
if( pSntpTime->seconds >= SNTP_TIME_AT_UNIX_EPOCH_SECS ) | ||
{ | ||
*pUnixTimeSecs = pSntpTime->seconds - SNTP_TIME_AT_UNIX_EPOCH_SECS; | ||
*pUnixTimeSecs = ( UnixTime_t ) ( pSntpTime->seconds - SNTP_TIME_AT_UNIX_EPOCH_SECS ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to above comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated. |
||
} | ||
|
||
/* Convert SNTP fractions to microseconds for UNIX time. */ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also update the
seconds
field ofSntpTimestamp_t
or cast it toUnixTime_t
(ifseconds
withuint32_t
itself doesn't overflow) before the addition takes place in order to make this change effective? Otherwise, I believe the addition should be happening asuint32_t
and the overflow must have happened before theUnixTime_t
cast of the result.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.