Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Luke-Jr on April 09, 2011, 02:39:58 AM



Title: [PULL] Bugfix for rfc1123Time
Post by: Luke-Jr on April 09, 2011, 02:39:58 AM
Someone in #bitcoin-discussion was having problems with JSON-RPC and it turned out to be related to their timezone overflowing the rfc1123Time function's buffer. My 'rfc1123Time_localefix' branch addresses the problem by forcing the locale and timezone to POSIX and UTC for its purposes (and resetting it back later).

git fetch git://gitorious.org/~Luke-Jr/bitcoin/luke-jr-bitcoin.git rfc1123Time_localefix && git diff 454bc8..FETCH_HEAD && git merge FETCH_HEAD

I suspect the JSON-RPC has other locale problems as well, in case someone wants to look into it further.


Title: Re: [PULL] Bugfix for rfc1123Time
Post by: Luke-Jr on April 09, 2011, 03:08:00 AM
Correction to my above summary: bitcoind does use gmtime to get the correct UTC time, but the problem was that Windows still tries to put the local timezone for %Z rather than UTC as is being encoded.

Actually, according to the RFC, numeric timezones should be used (not names). So rather than force TZ to UTC, the buffer should be extended and %z used instead of %Z. I do not have any idea if Windows complies with %z better than %Z, so I am leaving the temporarily-set-TZ hack in. Otherwise, my branch now uses %z.

Please note that the timezone is not the only issue here. The locale must also be forced to POSIX to get the usual weekday (Sun-Sat) and month (Jan-Dec) abbreviations, rather than some local variant.


Title: Re: [PULL] Bugfix for rfc1123Time
Post by: Gavin Andresen on April 09, 2011, 04:25:16 PM
GMT is always +0:00, so why not hardcode that instead of using %z or %Z?

RE: changing locale:  good idea.


Title: Re: [PULL] Bugfix for rfc1123Time
Post by: jgarzik on April 09, 2011, 05:11:34 PM
GMT is always +0:00, so why not hardcode that instead of using %z or %Z?

Yep, that should work just fine.



Title: Re: [PULL] Bugfix for rfc1123Time
Post by: Luke-Jr on April 09, 2011, 05:39:54 PM
Ok, rewrote my branch to only set locale and hard-code "+0000"; good idea.