]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3626] (SNTP) UTC offset calculation needs dst flag
authorJuergen Perlinger <perlinger@ntp.org>
Wed, 24 Jun 2020 17:39:47 +0000 (19:39 +0200)
committerJuergen Perlinger <perlinger@ntp.org>
Wed, 24 Jun 2020 17:39:47 +0000 (19:39 +0200)
bk: 5ef38fe3rBM3XfizSkrIDTTXNGJI7g

ChangeLog
sntp/utilities.c

index eeceaa9f10cb57b56caf561eaab50a81ec861f63..fcff81bc45c93031c54258a1cac00b245907f9b0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+---
+* [Bug 3626] (SNTP) UTC offset calculation needs dst flag <perlinger@ntp.org>
+  - applied patch by Gerry Garvey
+
 ---
 (4.2.8p15) 2020/06/23 Released by Harlan Stenn <stenn@ntp.org>
 
index 43cd786b9939fd8ddd0ad0734aaa8aff473edad4..2069bc9b3da26721f3d148ff696c7747a64e48d7 100644 (file)
@@ -140,17 +140,22 @@ tv_to_str(
        const size_t bufsize = 48;
        char *buf;
        time_t gmt_time, local_time;
-       struct tm *p_tm_local;
-       int hh, mm, lto;
+       struct tm *ptm, tm_local;
+       int hh, mm, lto, isdst;
 
        /*
         * convert to struct tm in UTC, then intentionally feed
         * that tm to mktime() which expects local time input, to
         * derive the offset from UTC to local time.
+        * Need to retrieve dst flag from localtime first for mktime.
         */
        gmt_time = tv->tv_sec;
-       local_time = mktime(gmtime(&gmt_time));
-       p_tm_local = localtime(&gmt_time);
+       ptm = localtime(&gmt_time);
+       memcpy (&tm_local, ptm, sizeof(tm_local));
+       isdst = ptm->tm_isdst;
+       ptm = gmtime(&gmt_time);
+       ptm->tm_isdst = isdst;
+       local_time = mktime(ptm);
 
        /* Local timezone offsets should never cause an overflow.  Yeah. */
        lto = difftime(local_time, gmt_time);
@@ -161,12 +166,12 @@ tv_to_str(
        buf = emalloc(bufsize);
        snprintf(buf, bufsize,
                 "%d-%.2d-%.2d %.2d:%.2d:%.2d.%.6d (%+03d%02d)",
-                p_tm_local->tm_year + 1900,
-                p_tm_local->tm_mon + 1,
-                p_tm_local->tm_mday,
-                p_tm_local->tm_hour,
-                p_tm_local->tm_min,
-                p_tm_local->tm_sec,
+                tm_local.tm_year + 1900,
+                tm_local.tm_mon + 1,
+                tm_local.tm_mday,
+                tm_local.tm_hour,
+                tm_local.tm_min,
+                tm_local.tm_sec,
                 (int)tv->tv_usec,
                 hh,
                 mm);