epan: Fix ENC_TIME_ZBEE_ZCL calculation

The Zigbee ZCL Epoch is *after* the UN*X epoch, which means, given
that all the epoch delta #defines in wsutil/epochs.h are unsigned,
that the delta needs to be *added* to a time in seconds since the
Zigbee ZCL Epoch to give a time in seconds since the UN*X epoch.
This is the opposite operation for all the other epoch deltas in
epochs.h, which refer to epoch absolute times *before* the UN*X epoch.

Note the correct operation is done in the various Zigbee dissectors
already; the problem is only in epan/proto.c

Verified with the sample capture in #14138

Fixup 00e069e6cd9d72e79f207bbb5ddc6901c6e14420
This commit is contained in:
John Thacker 2025-04-19 20:44:37 -04:00 committed by Guy Harris
parent f802e5ee6e
commit 9fa0d9a8f7
2 changed files with 14 additions and 5 deletions

View File

@ -2600,11 +2600,11 @@ get_time_value(proto_tree *tree, tvbuff_t *tvb, const int start,
if (length == 8) {
tmp64secs = tvb_get_ntoh64(tvb, start);
time_stamp->secs = (time_t)(int64_t)(tmp64secs - EPOCH_DELTA_2000_01_01_00_00_00_UTC);
time_stamp->secs = (time_t)(int64_t)(tmp64secs + EPOCH_DELTA_2000_01_01_00_00_00_UTC);
time_stamp->nsecs = 0;
} else if (length == 4) {
tmpsecs = tvb_get_ntohl(tvb, start);
time_stamp->secs = (time_t)(int32_t)(tmpsecs - EPOCH_DELTA_2000_01_01_00_00_00_UTC);
time_stamp->secs = (time_t)(tmpsecs + EPOCH_DELTA_2000_01_01_00_00_00_UTC);
time_stamp->nsecs = 0;
} else {
time_stamp->secs = 0;
@ -2622,11 +2622,11 @@ get_time_value(proto_tree *tree, tvbuff_t *tvb, const int start,
if (length == 8) {
tmp64secs = tvb_get_letoh64(tvb, start);
time_stamp->secs = (time_t)(int64_t)(tmp64secs - EPOCH_DELTA_2000_01_01_00_00_00_UTC);
time_stamp->secs = (time_t)(int64_t)(tmp64secs + EPOCH_DELTA_2000_01_01_00_00_00_UTC);
time_stamp->nsecs = 0;
} else if (length == 4) {
tmpsecs = tvb_get_letohl(tvb, start);
time_stamp->secs = (time_t)(int32_t)(tmpsecs - EPOCH_DELTA_2000_01_01_00_00_00_UTC);
time_stamp->secs = (time_t)(tmpsecs + EPOCH_DELTA_2000_01_01_00_00_00_UTC);
time_stamp->nsecs = 0;
} else {
time_stamp->secs = 0;

View File

@ -18,6 +18,12 @@
* Deltas between the epochs for various non-UN*X time stamp formats and
* the January 1, 1970, 00:00:00 (proleptic?) UTC epoch for the UN*X time
* stamp format.
*
* XXX - All of these are unsigned, but note that most of these epochs are
* before the UN*X epoch but one is afterwards, which changes whether the
* delta should be subtracted or added to a time in the other epoch to
* produce a time_t in the UN*X epoch. Perhaps they should be signed,
* or there should macros that do the arithmetic and return a time_t?
*/
/*
@ -67,7 +73,10 @@
/*
* 2000-01-01 00:00:00 UTC.
* Used by the Zigbee Zigbee Cluster Library protocol.
*
* This is *after* the UN*X epoch, so to convert from a time in seconds from
* this epoch this delta needs to be *added*, unlike the other values.
*/
#define EPOCH_DELTA_2000_01_01_00_00_00_UTC ((unsigned)(((3*365 + 366)*7 + 2*365)*24*3600))
#define EPOCH_DELTA_2000_01_01_00_00_00_UTC UINT64_C(((3*365 + 366)*7 + 2*365)*24*3600)
#endif /* __EPOCHS_H__ */