tm_isdst=1 with mktime on 20.04 produces unexpected output

Bug #1954963 reported by Daniel
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
glibc (Ubuntu)
New
Undecided
Unassigned

Bug Description

Package: glibc
Version: 2.31

Use of mktime with tm_isdst=1 results in -1 indicating an error. This appears unexpected, and cannot be replicated on OS X 11.6.1, Centos 7.9, Fedora 35, Alpine or RHEL 8.

The issue was first observed on Github Actions ubuntu-latest (20.04).

This issue was originally opened on the CPython bug tracker. They advised opening a bug report with both Ubuntu and Debian. The bug opened with Debian can be found here:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1001774

The original report with CPython can be found here:

https://bugs.python.org/issue44413

An example C program follows at the end of the bug report, and can be compiled with “gcc bug.c -o bug”.

An example of execution of the bug, and failure, within a glibc 2.31 environment can be found here:

https://github.com/wasade/cpython/runs/4541212472?check_suite_focus=true#step:17:57

Thank you for your time. Please let me know if additional information would be helpful. This is my first bug report to Ubuntu. Though I reviewed the guidance docs, I apologize in advance if I overlooked something.
-Daniel

#include <time.h>
#include <stdio.h>

void do_test() {
  struct tm tm_works = { .tm_year=117,
                         .tm_mon=4,
                         .tm_mday=26,
                         .tm_hour=15,
                         .tm_min=30,
                         .tm_sec=16,
                         .tm_wday=4,
                         .tm_yday=145,
                         .tm_isdst=-1 };

  struct tm tm_fails = { .tm_year=117,
                         .tm_mon=4,
                         .tm_mday=26,
                         .tm_hour=15,
                         .tm_min=30,
                         .tm_sec=16,
                         .tm_wday=4,
                         .tm_yday=145,
                         .tm_isdst=1 };

  time_t works = mktime(&tm_works);
  time_t fails = mktime(&tm_fails);

  if(works == -1) {
      printf("Unexpected failure\n");
  } else {
      if(works == fails) {
          printf("Test passed\n");
      } else {
          printf("Test failed: works=%d; fails=%d\n", (int)works, (int)fails);
      }
  }
}

int main(int argc, char **argv) {
    do_test();
}

Revision history for this message
Daniel (wasade) wrote :

A resolution on this issue was identified with Debian:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1001774

The behavior noted here is expected and correct.

This is related to a bug/change in glibc 2.29. The failure can arise if timezone is not set (e.g., "Etc/UTC"), and possibly other scenarios that would result in tm_isdst < 0.

The behavior of mktime differs on ubuntu 20.04 and 18.04 as they use different glibc versions. Aurelien with Debian notes this may be a bug for 18.04. Please see the thread with Debian for further detail.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.