cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-tracker mailing list Archives

[ curl-Bugs-1230118 ] curl_getdate(), DST, and cookie expiration

From: SourceForge.net <noreply_at_sourceforge.net>
Date: Tue, 14 Mar 2006 11:31:57 -0800

Bugs item #1230118, was opened at 2005-06-30 03:27
Message generated for change (Comment added) made by russ777
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=1230118&group_id=976

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: libcurl
Group: wrong behaviour
Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Daniel Stenberg (bagder)
Summary: curl_getdate(), DST, and cookie expiration

Initial Comment:
Platform: Windows XP
libcurl: 7.14

With the system clock properly configured to
automatically adjust for Daylight Saving Time,
curl_getdate() appears to return a time_t value which
is 1 hour ahead of the correct value. This prevents
cookies from expiring at the proper time.

The following demonstrates the problem:

#include <stdio.h>
#include "curl/curl.h"

int main()
{
        time_t tNow = ::time(NULL);
        tm tmGMT;
        char szGMT[128];

        ::memcpy(&tmGMT, ::gmtime(&tNow), sizeof(tm));
        ::strftime( szGMT, 128, "%a, %d-%b-%Y %H:%M:%S GMT",
&tmGMT );

        time_t tCURL = ::curl_getdate(szGMT, NULL);
        time_t tDiff = tCURL - tNow;

        printf("Current time: %s\n", szGMT);
        printf("Sytem time_t: %i\n", tNow);
        printf("libcurl time_t: %i\n", tCURL);
        printf("Difference: %i seconds\n", tCURL - tNow);

        return 0;
}

-----------------------------------------------------------
Example run with properly configured system clock
(during DST):

Current time: Thu, 30-Jun-2005 03:02:14 GMT
Sytem time_t: 1120100534
libcurl time_t: 1120104134
Difference: 3600 seconds

-----------------------------------------------------------
Example run with automatic DST adjustment disabled:

Current time: Thu, 30-Jun-2005 03:02:28 GMT
Sytem time_t: 1120100548
libcurl time_t: 1120100548
Difference: 0 seconds

----------------------------------------------------------------------

Comment By: Rouslan Grabar (russ777)
Date: 2006-03-14 19:31

Message:
Logged In: YES
user_id=866512

  const char *env = getenv("TZ");
  if(!env)
    _putenv("TZ=GMT");

Note the underscore in _putenv. This version of putenv does
not leak memory (7 bytes "TZ=GMT\0") when libcurl used as a
static lib. Tested under MSVC 7.1

:)

----------------------------------------------------------------------

Comment By: Daniel Stenberg (bagder)
Date: 2005-07-05 14:58

Message:
Logged In: YES
user_id=1110

Great!

I've just committed this fix. Closing this, considered fixed.

----------------------------------------------------------------------

Comment By: Gisle Vanem (giva)
Date: 2005-07-05 14:47

Message:
Logged In: YES
user_id=47168

Something like:
  const char *env = getenv("TZ");
  if (!env)
     putenv("TZ=GMT");

before time() makes the difference 0.

AFAIK, $TZ is only used by libc (msvcrt.dll). The official info
is returned by GetTimeZoneInformation().

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/sysinfo/base/gettimezoneinformation.asp

We should be able to use that (bias) in case $TZ isn't defined.

----------------------------------------------------------------------

Comment By: Daniel Stenberg (bagder)
Date: 2005-07-05 13:54

Message:
Logged In: YES
user_id=1110

Ok. Now we're getting somewhere!

Is there any (Windows-) way we can figure out what timezone
we're in and set the TZ variable before these time functions
are used, if we find out it isn't already set?

Thanks Gisle!

----------------------------------------------------------------------

Comment By: Gisle Vanem (giva)
Date: 2005-07-05 11:48

Message:
Logged In: YES
user_id=47168

Without an environment variable "TZ=GMT+1" I'm getting the
same result. With TZ set, there is no problem and difference
regarding system DST is set or not.

----------------------------------------------------------------------

Comment By: Daniel Stenberg (bagder)
Date: 2005-07-04 21:03

Message:
Logged In: YES
user_id=1110

I don't have/use windows myself. Without assistance I can't
solve this problem.

----------------------------------------------------------------------

Comment By: Daniel Stenberg (bagder)
Date: 2005-06-30 14:31

Message:
Logged In: YES
user_id=1110

Can you check what mktime() returns for this setup with and
without auto-DST set?

I can't but suspect that this is yet another chapter in the
windows-DST-mess:

http://www.codeproject.com/datetime/dstbugs.asp

----------------------------------------------------------------------

Comment By: Daniel Stenberg (bagder)
Date: 2005-06-30 06:12

Message:
Logged In: YES
user_id=1110

I'm puzzled.

Why is "automatic DST adjustment" ? Isn't that the thing
that automatically changes to DST at one date and then at
another later date it again switches off DST?

If so, how on earth can that affect the date functions like
this?

libcurl is simply using mktime() and gmtime(). I don't see
how that can be wrong. To me, it looks like Windows or the c
library you're using, is doing it wrong.

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=1230118&group_id=976
Received on 2006-03-14

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET