Refactor IdCTypes unit for improved compatibility#18
Open
xjikka wants to merge 2 commits intomezen:masterfrom
Open
Refactor IdCTypes unit for improved compatibility#18xjikka wants to merge 2 commits intomezen:masterfrom
xjikka wants to merge 2 commits intomezen:masterfrom
Conversation
Fix ABI mismatch for struct tm on Linux (glibc)
On Linux/glibc (e.g. Raspberry Pi armhf), struct tm contains additional fields:
tm_gmtoff (long)
tm_zone (char*)
This makes sizeof(struct tm) 44 bytes, while current TIdC_TM is only 36 bytes (POSIX fields only).
Functions like ASN1_TIME_to_tm() write a full glibc struct tm.
With the smaller Pascal record this causes stack corruption (observed as random overwrites of local variables, invalid TDateTime values such as 1899, etc.).
This PR extends TIdC_TM under {$IFDEF LINUX} to match the actual glibc layout and prevent memory corruption.
No behavior change on non-Linux platforms.
Reproducible on:
Linux armhf (Raspberry Pi OS / Debian)
OpenSSL 1.1.1
Cross-compiled FPC binaries
Author
|
Example of the issue (FPC cross-compiled Win to Linux/ARM, Raspberry Pi) Example code (FPC cross-compile to Raspberry Pi 3B, armhf): Output: nb is unexpectedly overwritten after calling ValidFromInGMT, even though it is not modified by user code. This demonstrates stack corruption caused by ASN1_TIME_to_tm() writing a full glibc struct tm into a smaller Pascal record. |
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.
Fix ABI mismatch for struct tm on Linux (glibc)
On Linux/glibc (e.g. Raspberry Pi armhf), struct tm contains additional fields:
tm_gmtoff (long)
tm_zone (char*)
This makes sizeof(struct tm) 44 bytes, while current TIdC_TM is only 36 bytes (POSIX fields only).
Functions like ASN1_TIME_to_tm() write a full glibc struct tm. With the smaller Pascal record this causes stack corruption (observed as random overwrites of local variables, invalid TDateTime values such as 1899, etc.).
This PR extends TIdC_TM under {$IFDEF LINUX} to match the actual glibc layout and prevent memory corruption. No behavior change on non-Linux platforms.
Reproducible on:
Linux armhf (Raspberry Pi OS / Debian)
OpenSSL 1.1.1
Cross-compiled FPC binaries