]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-var-expand: test-var-expand - Initialize tm before strptime()
authorAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 27 Jan 2025 09:33:07 +0000 (11:33 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:16 +0000 (12:34 +0200)
strptime() only sets what it parses, this test will fail if
localtime_r() and strptime() disagree on the local timezone, so
use localtime_r() to initialize tm with current tz to ensure they
will.

src/lib-var-expand/test-var-expand.c

index c31696fe6897cae20984c388d9b29ef628d0f070..a87815678fbcc1beedc1d80860406cb1b23604d7 100644 (file)
@@ -456,6 +456,10 @@ static void test_var_expand_providers(void) {
                /* try to parse result */
                struct tm tm;
                i_zero(&tm);
+               /* get localtime to ensure we are in same timezone */
+               time_t t = time(NULL);
+               if (localtime_r(&t, &tm) == NULL)
+                       i_panic("localtime_r() failed: %m");
                if (strptime(datetime, "%Y%m%dT%H%M%S", &tm) == NULL) {
                        test_failed(t_strdup_printf("strptime() failed: %m"));
                } else {