[Rpm-maint] [rpm-software-management/rpm] RPM does not properly restore the timezone after parsing a changelog date (Issue #1821)

Miro Hrončok notifications at github.com
Fri Nov 5 13:19:32 UTC 2021


This is a copy of https://bugzilla.redhat.com/show_bug.cgi?id=1881917

We can reproduce this with Python, but I think that any program that uses RPM as a library and does timezone stuff would be impacted.

 1. Upon interpreter or datetime initialization, Python calls `tzset()`
 2. When parsing the changelog, RPM sets the TZ environment variable to UTC and calls `mktime()` (which internally calls `tzset()`)
 3. RPM resets the TZ environment variable to original, but does **not call `tzset()`**
 4. Python assumes the timezone is UTC until and unless `tzset()` is called (e.g. via `mktime()`)

I believe that rpm should call `tzset()` after resetting the TZ environment variable after this code:

https://github.com/rpm-software-management/rpm/blob/4a82a683410918f17c14bb979e75330779664099/build/parseChangelog.c#L173-L178


Reproducer in Python. Have a valid/parseable spec file with changelog ready.

Set the TZ variable to a timezone that you can easily distinguish from UTC, e.g. `Pacific/Honolulu`:

```shell
$ TZ=Pacific/Honolulu python3
```

```pycon
>>> import rpm, time, datetime

>>> datetime.datetime.now()  # this returns time in Honolulu
datetime.datetime(2021, 11, 5, 3, 18, 6, 241575)

>>> spec = rpm.spec("foo.spec")  # parse a specfile

>>> datetime.datetime.now()  # this returns time in UTC
datetime.datetime(2021, 11, 5, 13, 18, 23, 105545)

>>> time.mktime(datetime.datetime.now().timetuple())  # calls tzset() interanlly
1636154321.0
>>> datetime.datetime.now()  # this returns time in Honolulu
datetime.datetime(2021, 11, 5, 3, 18, 44, 193766)
```


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1821
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20211105/b6cb2e48/attachment.html>


More information about the Rpm-maint mailing list