bji / libs3

Other
157 stars 151 forks source link

Fix corrupted request time headers due to thread-unsafe gmtime #22

Closed earlephilhower closed 8 years ago

earlephilhower commented 8 years ago

Howdy,

I use libs3 w/pthreads in my app, and was seeing frequent requests whose time was Jan 1, 1970. After some digging I found that it's using a stdlib routine which is not thread safe to grab the time. Replacing w/a thread-safe version fixes the multithreaded case and works fine for single-threaded as well. The commit message is below.

Thanks, -Earle F. Philhower, III

gmtime() is used to convert the system time to GMT so that the S3 request time can be appended to the headers. It returns a pointer to a library static struct tm. This works fine in the single- threaded case, but can cause request times to be corrupted should libs3 be called in a multithreaded use case.

Replaces the gmtime() with a gmtime_r() call which takes a pointer to a thread-local struct tm, fixing the issue.

earlephilhower commented 8 years ago

Just a ping on this, since it came out during the holidays it may have been overlooked. Thanks.

bjitivo commented 8 years ago

Yes, it was missed for that reason. Thank you for the fix!

bji commented 8 years ago

Whoops wrong account!