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) | |||
| 98 | return n; | 98 | return n; |
| 99 | } | 99 | } |
| 100 | #undef PO10u_LIMIT | 100 | #undef PO10u_LIMIT |
| 101 | |||
| 102 | int plist_real_to_time64(double realval, Time64_T *timev) | ||
| 103 | { | ||
| 104 | if (!timev || !isfinite(realval)) { | ||
| 105 | return -1; | ||
| 106 | } | ||
| 107 | |||
| 108 | if (realval < (double)TIME64_MIN - (double)MAC_EPOCH || | ||
| 109 | realval > (double)TIME64_MAX - (double)MAC_EPOCH) { | ||
| 110 | return -1; | ||
| 111 | } | ||
| 112 | |||
| 113 | *timev = (Time64_T)realval + MAC_EPOCH; | ||
| 114 | return 0; | ||
| 115 | } | ||
