[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#1057856: glibc: mktime now returns clock for UTC with isdst=1



Hello,

Thank you for the quick answer and the details provided.

You can submit the test program to the upstream bugzilla, no problem.

Best regards,
Paulo Tomé

On Mon, Dec 11, 2023 at 9:36 PM Aurelien Jarno <aurel32@debian.org> wrote:
Hi,

On 2023-12-09 18:23, Paulo Tomé wrote:
> Package: libc6
> Version: 2.36-9+deb12u3
> Severity: normal
> Tags: upstream
> X-Debbugs-Cc: paulo.tome@gmail.com
>
> Dear Maintainer,
>
> *** Reporter, please consider answering these questions, where appropriate ***
>
>    * What led up to the situation?
>    * What exactly did you do (or not do) that was effective (or
>      ineffective)?
>    * What was the outcome of this action?
>    * What outcome did you expect instead?
>
> *** End of the template - remove these template lines ***
>
> After compiling Erlang from source (erlang.org) a test case failed. The
> test case detects if local time is converted correctly to universal time
> even if isdst=1 for the UTC timezone. The following issue reports the
> details: https://github.com/erlang/otp/issues/7938
>
> I created a small test program that reproduces the behavior. The program
> calls mktime for a certain date, with isdst=1 in the tm struct.

Thanks for the details and for the reproducer, that's very helpful.

> When setting TZ=UTC in the environment, mktime returns a valid clock
> offset by one hour. In previous versions of glibc (tested 2.35 on Ubuntu
> LTS 22.04.3) the same call to mktime returns -1. The error (-1) makes
> sense, since the UTC timezone does not have DST.
>
> After downloading the Debian glibc-source for 2.36, I see a patch that
> could explain this behavior.
>
>     /usr/src/glibc/debian/patches/git-updates.diff
>
> +      /* No unusual DST offset was found nearby.  Assume one-hour DST.  */
> +      t += 60 * 60 * dst_difference;
> +      if (mktime_min <= t && t <= mktime_max && convert_time (convert, t, &tm))
> +       goto offset_found;
> +
>        __set_errno (EOVERFLOW);
>        return -1;
>      }
>
> This change was not present on the other glibc I tested (2.35 on
> Ubuntu). I checked upstream glibc 2.38 and the change is in the source.

Yes, I confirm this changes explains the behaviour you are observing. It
comes from the following upstream commit, which has been introduced in
the 2.37 release and backported in the 2.34, 2.35 and 2.36 upstream
stable trees:

https://sourceware.org/git/?p=glibc.git;a=commit;h=83859e1115269cf56d21669361d4ddbe2687831c

> I'm not sure if this is a bug, but for the UTC timezone I would expect
> an error if we asked for the time with DST.

This not clear to me if it is a bug or not. Quoting the standard (ISO C
or POSIX):

  A positive or 0 value for tm_isdst shall cause mktime() to presume
  initially that Daylight Savings Time, respectively, is or is not in
  effect for the specified time. A negative value for tm_isdst shall
  cause mktime() to attempt to determine whether Daylight Savings Time
  is in effect for the specified time.

The word "presume initially" looks like an initial guess should be
provided (for disambiguating two identical dates), but it doesn't
enforce the result.

That said, looking at the FreeBSD libc implementation, it seems the
original glibc behaviour is the correct one. The best is probably to
report the issue upstream.

> For reference, this is the test program:

Thanks. Do you mind if I submit your test program to the upstream
bugzilla? Or do you prefer to submit the bug yourself?

Regards
Aurelien

--
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                     http://aurel32.net

Reply to: