Skip to content

Commit

Permalink
Y2038: improve printing of time settings (#1493)
Browse files Browse the repository at this point in the history
Avoid truncation errors when printing time_t-based squid.conf directives
on platforms with 32-bit int and 64-bit time_t. Also avoid similar
errors when printing time_msec-based directives on platforms with 32-bit
int.

Detected by Coverity. CID 1529622: Use of 32-bit time_t (Y2K38_SAFETY).
  • Loading branch information
kinkie authored and squid-anubis committed Oct 3, 2023
1 parent c375465 commit 608c50d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/cache_cf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2950,7 +2950,8 @@ parse_TokenOrQuotedString(char **var)
static void
dump_time_t(StoreEntry * entry, const char *name, time_t var)
{
storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var);
PackableStream os(*entry);
os << name << ' ' << var << " seconds\n";
}

void
Expand All @@ -2972,10 +2973,11 @@ free_time_t(time_t * var)
static void
dump_time_msec(StoreEntry * entry, const char *name, time_msec_t var)
{
PackableStream os(*entry);
if (var % 1000)
storeAppendPrintf(entry, "%s %" PRId64 " milliseconds\n", name, var);
os << name << ' ' << var << " milliseconds\n";
else
storeAppendPrintf(entry, "%s %d seconds\n", name, (int)(var/1000) );
os << name << ' ' << (var/1000) << " seconds\n";
}

static void
Expand Down

0 comments on commit 608c50d

Please sign in to comment.