Busybox syslogd -Z option broken
The patch 0015-syslogd-adjust-timezone-option.patch
should probably
set the year in the struct tm to something representable. Not sure if
this is 32 bit bug only.
Package Version: busybox 1.26.2-r7, Intel 32 bit.
To reproduce:
# service syslog stop
# syslogd -N -O - -Z
In other terminal:
$ logger -t test test
Expected output: the correct date
Actual output:
Dec 31 23:59:59 vm user.notice test: test
This happens because mktime
actually fails with EOVERFLOW
(tm_year
is initialized to 0 = the year 1900 which is not representable in 32 bit
time_t) and returns (time_t)-1
.
Simple program to reproduce below:
#include <stdio.h>
#include <time.h>
void doit(const char *ts, struct tm *nowtm) {
time_t tm;
if (!strptime(ts, "%b %e %T", nowtm)) {
fprintf(stderr, "Err strptime\n");
}
printf("Year is %d\n", nowtm->tm_year);
tm = mktime(nowtm);
if (tm == (time_t)-1) {
perror("mktime");
}
printf("Parsed as: %s\n", ctime(&tm));
}
int main() {
const char *ts = "Oct 22 02:17:13";
struct tm origtm = { .tm_isdst = 0 };
struct tm fixedtm = { .tm_isdst = 0, .tm_year=100 };
tzset();
printf("With original:\n");
doit(ts, &origtm);
printf("With fixed:\n");
doit(ts, &fixedtm);
}
(from redmine: issue id 8028, created on 2017-10-22)