After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 511807 - g_time_val_to_iso8601() uses MT-unsafe gmtime() function
g_time_val_to_iso8601() uses MT-unsafe gmtime() function
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal major
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2008-01-24 15:06 UTC by Sebastian Dröge (slomo)
Modified: 2008-02-03 10:54 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Sebastian Dröge (slomo) 2008-01-24 15:06:48 UTC
Hi,
g_time_val_to_iso8601() currently calls gmtime() to get the time in UTC. This function is not MT safe as the result is stored in a static variable according to the glibc docs at least[0]. Better would be, to use gmtime_r() which unfortunately is POSIX.1c, or another replacement that actually is MT safe.

But maybe this doesn't matter that much because the global static variable is stored in TLS but even then it can cause weird effects:

- Call of gmtime()
- Call of g_time_val_to_iso8601()
- The old result of gmtime() is overwritten and contains something unexpected
Comment 1 Sebastian Dröge (slomo) 2008-01-24 15:08:56 UTC
glibc docs about gmtime(): http://www.gnu.org/software/libc/manual/html_node/Broken_002ddown-Time.html#index-gmtime-2641

Comment 2 Matthias Clasen 2008-01-25 05:45:59 UTC
Sounds right that we should use gmtime_r if it is available, at least.
Comment 3 Tor Lillqvist 2008-01-25 08:53:41 UTC
FYI, in the Microsoft C library gmtime_r() isn't available, but that doesn't matter much, as gmtime() is MT-safe, it uses thread-local storage.

(Of course, this doesn't help for the use case mentioned, "Call of gmtime(). Call of g_time_val_to_iso8601(). The old result of gmtime() is overwritten" but then people who call gmtime() and don't copy the result immediately afterwards probably deserve what they get anyway.)
Comment 4 Matthias Clasen 2008-01-28 06:27:36 UTC
2008-01-28  Matthias Clasen  <mclasen@redhat.com>

        * configure.in: Check for gmtime_r.
        * glib/gtimer.c: Use gmtime_r when available.  (#511807,
        Sebastian Dröge)

Comment 5 Sebastian Dröge (slomo) 2008-02-02 07:05:13 UTC
Didn't you forget to commit the configure.in change?
Comment 6 Sebastian Dröge (slomo) 2008-02-03 10:54:48 UTC
Well, I added the check now in trunk.