diff options
| author | 2026-05-22 19:20:51 +0200 | |
|---|---|---|
| committer | 2026-05-22 19:20:51 +0200 | |
| commit | ba82092e43d4769dbc6f0557d58a243f93542486 (patch) | |
| tree | 4054d7d4b701207f6a7def2799295557c5fdf68d /src/common.c | |
| parent | 9711459dbed7d60bb00c7d2c052623e8489c88e1 (diff) | |
| download | libplist-ba82092e43d4769dbc6f0557d58a243f93542486.tar.gz libplist-ba82092e43d4769dbc6f0557d58a243f93542486.tar.bz2 | |
common: validate PLIST_DATE values before Time64_T conversion
Avoid undefined behavior when serializing malformed PLIST_DATE values
containing NaN, infinity, or values outside the Time64_T range. Add a
shared helper for checked date conversion and use it across writer paths.
Diffstat (limited to 'src/common.c')
| -rw-r--r-- | src/common.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c index 0b11d57..810c2e0 100644 --- a/src/common.c +++ b/src/common.c @@ -98,3 +98,18 @@ int num_digits_u(uint64_t i) return n; } #undef PO10u_LIMIT + +int plist_real_to_time64(double realval, Time64_T *timev) +{ + if (!timev || !isfinite(realval)) { + return -1; + } + + if (realval < (double)TIME64_MIN - (double)MAC_EPOCH || + realval > (double)TIME64_MAX - (double)MAC_EPOCH) { + return -1; + } + + *timev = (Time64_T)realval + MAC_EPOCH; + return 0; +} |
