Menu

#99 Use of thread-unsafe gmtime() in httpreadwrite.c

closed-fixed
nobody
None
5
2012-04-27
2012-03-18
zephyrus
No

In upnp/src/genlib/net/http/httpreadwrite.c, a function called gmtime() is used
to obtain a date string.
However, it is not thread-safe..
.
Found by running the code using valgrind.

Patch attached.

(Sorry, I am still new to git and I could not fix
the commit message that contained incorrect function name, and
so hand-editied it. I have no idea if there is any ill-effect to the resulting patch
although I don't see any proble with it ;-)

Discussion

  • Yoichi NAKAYAMA

    Yoichi NAKAYAMA - 2012-03-24

    Windows version of gmtime uses thread local variable:
    http://msdn.microsoft.com/en-us/library/0z9czt0w\(v=vs.80).aspx
    > Both the 32-bit and 64-bit versions of gmtime, mktime, mkgmtime, and localtime
    > all use a single tm structure per thread for the conversion. Each call to one of
    > these functions destroys the result of any previous call.

    Therefore, keep original code in #ifdef WIN32.

     
  • zephyrus

    zephyrus - 2012-03-25

    Updated diff to taake care of WIN32 issue.

     
  • zephyrus

    zephyrus - 2012-03-25

    I uploaded a patch that takes of WIN32 issue.

     
  • Yoichi NAKAYAMA

    Yoichi NAKAYAMA - 2012-04-05

    zephyrus,
    I found gmtime is used in webserver.c too.
    I'll commit a change for both.
    Regards,

     
  • Yoichi NAKAYAMA

    Yoichi NAKAYAMA - 2012-04-05

    zephyrus,
    I've pushed Commit:34a77cc095a6be89a7cb2d71202364c3cc7e8d26
    in branch-1.6.x. Close this issue if it is OK.
    Regards,

     
  • Yoichi NAKAYAMA

    Yoichi NAKAYAMA - 2012-04-05
    • status: open --> pending-fixed
     
  • zephyrus

    zephyrus - 2012-04-11
    • status: pending-fixed --> open-fixed
     
  • zephyrus

    zephyrus - 2012-04-11

    Thanks!
    (Sorry I was tied up with day job and could not follow up on this quickly.)

     
  • zephyrus

    zephyrus - 2012-04-27

    Sorry I was not sure how to close this, but now I closed it!

     
  • Yoichi NAKAYAMA

    Yoichi NAKAYAMA - 2012-04-27
    • status: open-fixed --> closed-fixed
     
MongoDB Logo MongoDB