From 91e041dbfcccbe5dd6fb96e01826d55d408dad4d Mon Sep 17 00:00:00 2001 From: Thomas Ries Date: Mon, 25 Oct 2021 11:50:23 +0200 Subject: [PATCH] fixed some Y2038 issues related to 64bit time support for 32bit plattforms --- ChangeLog | 2 ++ src/register.c | 8 ++++---- src/siproxd.h | 18 +++++++++++++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index af1ca8c..6cfa511 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 0.8.4dev ======== + 25-Oct-2021: - fixed some Y2038 issues related to 64bit time + support for 32bit plattforms 29-Jun-2021: - fix: silence_log handling - was always logging everything to syslog,even if set to >0 27-Dec-2020: - plugin_stripheaders: deal with mode header field diff --git a/src/register.c b/src/register.c index 70dc159..428790b 100644 --- a/src/register.c +++ b/src/register.c @@ -74,7 +74,7 @@ void register_init(void) { for (i=0;i < URLMAP_SIZE; i++) { t=fgets(buff, sizeof(buff), stream); if (t==NULL) { break;} - sts=sscanf(buff, "****:%i:%i", &urlmap[i].active, &urlmap[i].expires); + sts=sscanf(buff, "****:%i:%"TIME_T_INT_FMT , &urlmap[i].active, &urlmap[i].expires); if (sts == 0) break; /* format error */ if (urlmap[i].active) { #define R(X) {\ @@ -146,7 +146,7 @@ void register_save(void) { } for (i=0;i < URLMAP_SIZE; i++) { - fprintf(stream, "****:%i:%i\n", urlmap[i].active, urlmap[i].expires); + fprintf(stream, "****:%i:%"TIME_T_INT_FMT "\n", urlmap[i].active, urlmap[i].expires); if (urlmap[i].active) { #define W(X) { \ char *tmp=NULL; \ @@ -336,12 +336,12 @@ int register_client(sip_ticket_t *ticket, int force_lcl_masq) { /* check address-of-record ("public address" of user) */ if (compare_url(url1_to, url2_to)==STS_SUCCESS) { DEBUGC(DBCLASS_REG, "found entry for %s@%s <-> %s@%s at " - "slot=%i, exp=%li", + "slot=%i, exp=%"TIME_T_INT_FMT, (url1_contact->username) ? url1_contact->username : "*NULL*", (url1_contact->host) ? url1_contact->host : "*NULL*", (url2_to->username) ? url2_to->username : "*NULL*", (url2_to->host) ? url2_to->host : "*NULL*", - i, (long)urlmap[i].expires-time_now); + i, urlmap[i].expires-time_now); break; } } diff --git a/src/siproxd.h b/src/siproxd.h index 5fdf601..1205405 100644 --- a/src/siproxd.h +++ b/src/siproxd.h @@ -30,7 +30,7 @@ */ struct urlmap_s { int active; - int expires; + time_t expires; osip_uri_t *true_url; // true URL of UA (inbound URL) osip_uri_t *masq_url; // masqueraded URL (outbound URL) osip_uri_t *reg_url; // registered URL (masq URL as wished by UA) @@ -352,6 +352,22 @@ int unload_plugins(void); #define satoi atoi /* used in libosips MSG_TEST_CODE macro ... */ #endif +/* + * Y2038 stuff (64bit time_t in 32bit C libs) + * reason: + * libc64: long int ("ld") -> 64bit + * libc32: long int ("ld") -> 32bit + * also see: https://sourceware.org/glibc/wiki/Y2038ProofnessDesign + * + * TIME_T_INT_FMT: time_t format string to use in printf/scanf + */ +#ifndef TIME_T_INT_FMT +#ifdef __USE_TIME_BITS64 +#define TIME_T_INT_FMT PRId64 +#else +#define TIME_T_INT_FMT "ld" +#endif +#endif /* * Macro that limits the frequency of this particular code