Fix Year 2038 Problem in Sntp_ConvertToUnixTime#104
Merged
kar-rahul-aws merged 20 commits intoFreeRTOS:mainfrom Apr 15, 2025
Merged
Fix Year 2038 Problem in Sntp_ConvertToUnixTime#104kar-rahul-aws merged 20 commits intoFreeRTOS:mainfrom
kar-rahul-aws merged 20 commits intoFreeRTOS:mainfrom
Conversation
Member
|
Shouldn't we update the |
Contributor
Author
|
The coreSNTP Windows Simulator demo will need to be changed here , will do that once these changes get approved. |
cookpate
previously approved these changes
Apr 11, 2025
source/core_sntp_serializer.c
Outdated
| * 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 ); |
Member
There was a problem hiding this comment.
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.
source/core_sntp_serializer.c
Outdated
| 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 ); |
Member
There was a problem hiding this comment.
Similar to above comment.
tony-josi-aws
approved these changes
Apr 14, 2025
cookpate
approved these changes
Apr 14, 2025
2 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.