From d61eab22f397c20b68abe8f051973604e6b71a81 Mon Sep 17 00:00:00 2001 From: XJ <38142124+xjikka@users.noreply.github.com> Date: Tue, 13 Jan 2026 01:06:05 +0100 Subject: [PATCH 1/2] Refactor IdCTypes unit for improved compatibility 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 --- Lib/System/IdCTypes.pas | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Lib/System/IdCTypes.pas b/Lib/System/IdCTypes.pas index 5d8623c9d..9095b328b 100644 --- a/Lib/System/IdCTypes.pas +++ b/Lib/System/IdCTypes.pas @@ -296,6 +296,16 @@ TIdC_TM = record tm_wday: TIdC_INT; (* day of the week, range 0 to 6 *) tm_yday: TIdC_INT; (* day in the year, range 0 to 365 *) tm_isdst: TIdC_INT; (* daylight saving time *) + {$IFDEF LINUX} + // glibc struct tm extension: + // ASN1_TIME_to_tm() writes a full glibc struct tm (tm_gmtoff, tm_zone). + // Without these fields TIdC_TM is too small, causing stack corruption + // (e.g. invalid X509 ValidFrom/ValidTo values) on Linux targets. + // This is especially visible with FPC cross-compilation to Linux/ARM + // (e.g. Raspberry Pi), where X509 ValidFrom/ValidTo values become invalid. + tm_gmtoff: TIdC_LONG; // seconds east of UTC + tm_zone: PAnsiChar; // timezone abbreviation + {$ENDIF} end; PIdC_TM = ^TIdC_TM; PPIdC_TM = ^PIdC_TM; @@ -303,3 +313,4 @@ TIdC_TM = record implementation end. + From 28a59689f668463643b66397348aa9ac05273f4f Mon Sep 17 00:00:00 2001 From: XJ <38142124+xjikka@users.noreply.github.com> Date: Tue, 13 Jan 2026 12:28:26 +0100 Subject: [PATCH 2/2] date --- Lib/System/IdCTypes.pas | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/System/IdCTypes.pas b/Lib/System/IdCTypes.pas index 9095b328b..906df7d07 100644 --- a/Lib/System/IdCTypes.pas +++ b/Lib/System/IdCTypes.pas @@ -297,7 +297,7 @@ TIdC_TM = record tm_yday: TIdC_INT; (* day in the year, range 0 to 365 *) tm_isdst: TIdC_INT; (* daylight saving time *) {$IFDEF LINUX} - // glibc struct tm extension: + // xjikka 20260112 glibc struct tm extension: // ASN1_TIME_to_tm() writes a full glibc struct tm (tm_gmtoff, tm_zone). // Without these fields TIdC_TM is too small, causing stack corruption // (e.g. invalid X509 ValidFrom/ValidTo values) on Linux targets. @@ -314,3 +314,4 @@ implementation end. +