Skip to content

[Review]Fix the potential 2038 issues#7466

Closed
wenshan1 wants to merge 1 commit intocurl:masterfrom
wenshan1:blan-2038-issues
Closed

[Review]Fix the potential 2038 issues#7466
wenshan1 wants to merge 1 commit intocurl:masterfrom
wenshan1:blan-2038-issues

Conversation

@wenshan1
Copy link
Contributor

@wenshan1 wenshan1 commented Jul 21, 2021

  1. The length of long in a 32-bit system is 32 bits, which cannot be used to save timestamps after 2038.
    Most operating systems have extended time_t to 64 bits.
  2. The return type of time() is time_t, the tv_sec type in struct timeval is time_t except windows.
    Possible loss of data caused by the following code:
    The code now.tv_sec = (long)time(NULL);
  3. This pull request don't solve the 2038 issues in windows.

This changes is to remove the operation of casting to long.

@bagder
Copy link
Member

bagder commented Jul 21, 2021

There are also the reverse situation platforms with 64 bit long and 32 bit time_t...

@bagder
Copy link
Member

bagder commented Jul 21, 2021

Did you verify this patch on a system with 32 bit long and 64 bit time_t to see that it handles dates after 2038?

@wenshan1 wenshan1 changed the title Fix the potential 2038 issues [WIP]Fix the potential 2038 issues Jul 22, 2021
@wenshan1
Copy link
Contributor Author

There are also the reverse situation platforms with 64 bit long and 32 bit time_t...

The win 64-bit use an abstract data model called LLP64 (or P64).
https://docs.microsoft.com/en-us/windows/win32/winprog64/abstract-data-models

@wenshan1 wenshan1 closed this Jul 22, 2021
@wenshan1 wenshan1 reopened this Jul 22, 2021
@bagder
Copy link
Member

bagder commented Jul 22, 2021

There are also the reverse situation platforms with 64 bit long and 32 bit time_t...

The win 64-bit use an abstract data model called LLP64 (or P64).
https://docs.microsoft.com/en-us/windows/win32/winprog64/abstract-data-models

I was not referring to Windows. I'm pretty sure (early?) AIX versions work like I explained.

The length of long in a 32-bit system is 32 bits, which cannot be used to
save timestamps after 2038.
Most operating systems have extended time_t to 64 bits.

This changes is to replace the operation of casting to long with
casting to time_t.
@wenshan1 wenshan1 changed the title [WIP]Fix the potential 2038 issues [Review]Fix the potential 2038 issues Jul 23, 2021
@wenshan1
Copy link
Contributor Author

There are also the reverse situation platforms with 64 bit long and 32 bit time_t...

The win 64-bit use an abstract data model called LLP64 (or P64).
https://docs.microsoft.com/en-us/windows/win32/winprog64/abstract-data-models

I was not referring to Windows. I'm pretty sure (early?) AIX versions work like I explained.

AIX

If AIX is posix compatible system, I think my PR don't introduce a new issue even if the platform is 64-bit long and 32-bit time_t.

@bagder
Copy link
Member

bagder commented Jul 30, 2021

Thanks!

@bagder bagder closed this in 5b9fedb Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants