Mail archive
alpine-aports

[alpine-aports] [PATCH v2] main/busybox: fix timezone adjustment in syslogd

From: Oleg Omelyusik <oleg.omelyusik_at_gmail.com>
Date: Tue, 22 Aug 2017 14:58:22 +0300

---
Changes v1 -> v2:
  - rebased to the master branch
 ...gd-fix-timezone-adjustment-implementation.patch | 47 ++++++++++++++++++++++
 main/busybox/APKBUILD                              |  2 +
 2 files changed, 49 insertions(+)
 create mode 100644 main/busybox/0013-syslogd-fix-timezone-adjustment-implementation.patch
diff --git a/main/busybox/0013-syslogd-fix-timezone-adjustment-implementation.patch b/main/busybox/0013-syslogd-fix-timezone-adjustment-implementation.patch
new file mode 100644
index 0000000000..f276bc3e57
--- /dev/null
+++ b/main/busybox/0013-syslogd-fix-timezone-adjustment-implementation.patch
_at_@ -0,0 +1,47 @@
+From b09a292755943b3881aa3525c906989929c19fc8 Mon Sep 17 00:00:00 2001
+From: Oleg Omelyusik <oleg.omelyusik_at_gmail.com>
+Date: Fri, 21 Jul 2017 16:29:55 +0300
+Subject: [PATCH] syslogd: fix timezone adjustment implementation
+
+strptime() does not set year value which is needed for mktime().
+Also need to take into account year value when operating with timestamps
+to prevent invalid convertions for leap years (e.g. Feb 28 23:00:00 UTC to GMT+2).
+---
+ sysklogd/syslogd.c | 14 +++++++++++---
+ 1 file changed, 11 insertions(+), 3 deletions(-)
+
+diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
+index 1c67d1379..5ad50acd0 100644
+--- a/sysklogd/syslogd.c
++++ b/sysklogd/syslogd.c
+_at_@ -820,7 +820,8 @@ static void timestamp_and_log(int pri, char *msg, int len)
+ {
+ 	char *timestamp;
+ 	time_t now;
+-	struct tm nowtm = { .tm_isdst = 0 };
++	struct tm msgtm = { .tm_isdst = 0 };
++	struct tm nowtm = { 0 };
+ 
+ 	/* Jan 18 00:11:22 msg... */
+ 	/* 01234567890123456 */
+_at_@ -830,8 +831,15 @@ static void timestamp_and_log(int pri, char *msg, int len)
+ 		now = time(NULL);
+ 		timestamp = ctime(&now) + 4; /* skip day of week */
+ 	} else {
+-		if (G.adjustTimezone && strptime(msg, "%b %e %T", &nowtm)) {
+-			now = mktime(&nowtm) - timezone;
++		if (G.adjustTimezone && strptime(msg, "%b %e %T", &msgtm)) {
++			/* set message year as current or previous year */
++			now = time(NULL);
++			gmtime_r(&now, &nowtm);
++			msgtm.tm_year = nowtm.tm_year;
++			if (nowtm.tm_mon < msgtm.tm_mon)
++				--msgtm.tm_year;
++			/* adjust message timestamp */
++			now = mktime(&msgtm) - timezone;
+ 			timestamp = ctime(&now) + 4; /* skip day of week */
+ 		} else {
+ 			now = 0;
+-- 
+2.13.0
+
diff --git a/main/busybox/APKBUILD b/main/busybox/APKBUILD
index 63fc3369c6..97c5491b0c 100644
--- a/main/busybox/APKBUILD
+++ b/main/busybox/APKBUILD
_at_@ -32,6 +32,7 @@ source="http://busybox.net/downloads/$pkgname-$pkgver.tar.bz2
 	0011-testsuite-fix-cpio-tests.patch
 	0001-unzip-fix-regression-on-big-endian-machines.patch
 	0012-microcom-segfault.patch
+	0013-syslogd-fix-timezone-adjustment-implementation.patch
 
 	top-buffer-overflow.patch
 
_at_@ -184,6 +185,7 @@ d1c375184f806f7550bac5c82ab5471bdb8085d845172c973724b22af05ab3759b3ce982e088b4c4
 f4e00eb13fda752df13f300a7ed9b1320ca9f573c4309247f292c8710464d7be8740148f42e4aff16312335eadabce5a629dce4af58334b9199faf2fd658e4f9  0011-testsuite-fix-cpio-tests.patch
 daa6732a95a52a194d2031f2d5af5f658b9da3e8669fc2206000faaab7da56966a62646eed615fd1cbc5f07d42c03bf19ff183ef6f933b7daaeef1d388e21874  0001-unzip-fix-regression-on-big-endian-machines.patch
 a09a64b3bce8048c58a68dcd2dd9e63c911009c06195d6bb4e5aecfb5700e479c25b34635c60899127975fae32275ad51846ee75f840d612e00668ce9aba8322  0012-microcom-segfault.patch
+e6774045441a88bf6b1edb83865cac33ee1a51c2da510b190cf6d790f1d2e6f13dc386c992ef414810dad7b80686f772b28adc5c25171bdc14cddc256344cdff  0013-syslogd-fix-timezone-adjustment-implementation.patch
 524e858b52cb31fb8d24e8c7f18606fff349aeab6a14da9cca3902641f6127980daed73c53586c6e8b41eecda06cdb29c40ff1dde2dc82a318c2649680458921  top-buffer-overflow.patch
 a9b1403c844c51934637215307dd9e2adb9458921047acff0d86dcf229b6e0027f4b2c6cdaa25a58407aad9d098fb5685d58eb5ff8d2aa3de4912cdea21fe54c  acpid.logrotate
 857dece10267a065e0e8c16dd6190656f890a5aff774e96321715673dda23e75a8e61148e81d6286b7bdfe737a0b99104f9b04deeb4f392c72b63d8e3d00e556  busyboxconfig
-- 
2.13.5
---
Unsubscribe:  alpine-aports+unsubscribe_at_lists.alpinelinux.org
Help:         alpine-aports+help_at_lists.alpinelinux.org
---
Received on Tue Aug 22 2017 - 14:58:22 UTC