-
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
Fix Year 2038 Problem in Sntp_ConvertToUnixTime #104
Conversation
Shouldn't we update the |
The coreSNTP Windows Simulator demo will need to be changed here , will do that once these changes get approved. |
source/core_sntp_serializer.c
Outdated
@@ -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 ); |
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 of SntpTimestamp_t
or cast it to UnixTime_t
(if seconds
with uint32_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 as uint32_t
and the overflow must have happened before the UnixTime_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.
source/core_sntp_serializer.c
Outdated
{ | ||
*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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
Description
This SNTP function assumes 32-bit signed UNIX timestamps, but devices going into production now should probably be using unsigned 32-bit UNIX timestamps or wider signed 64-bit timestamps.
This PR updates the SNTP to Unix time conversion logic to support 64-bit Unix time (Y2038 compliance) while maintaining backward compatibility with legacy 32-bit systems.
Test Steps
Checklist:
Related Issue
https://t.corp.amazon.com/P204919465
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.