InterNetNews / inn

INN (InterNetNews) Usenet server
https://www.isc.org/othersoftware/#INN
Other
68 stars 12 forks source link

Treat time_t as unsigned long (Y2038 issue on 32-bit archs) #291

Closed Julien-Elie closed 2 months ago

Julien-Elie commented 7 months ago

On 32-bit architectures (i386) with support for 64-bit _timet, reading and converting _timet to signed long will fail in 2038. Let's audit the INN source code for such uses and switch to unsigned long, which will work until 2106. Hopefully 32-bit archs will be long time gone by that time!

A proper fix would be to switch everything to signed long long (8 bytes on 32-bit archs) but that's more complex and a lot of work to do, and very probably useless as it would only be needed in year 2106 for 32-bit archs...

As for the changes to do, a first glance at some parts of the code shows the following patterns to change:

    time_t date;
-   warn("can't format %ld", (long) date);
+   warn("can't format %lu", (unsigned long) date);
    time_t arrived, expires;
-   arrived = (time_t) atol(p);
+   arrived = (time_t) atoll(p);
    time_t expireIncTime;
-   expireIncTime = strtol(buf + 4, NULL, 0);
+   expireIncTime = strtoul(buf + 4, NULL, 0);

(unsigned long fits in _timet in both 32 and 64-bit platforms, so adding an explicit cast to _timet is not necessary)