Add support for localtime_r() on Windows
localtime() returns pointer to a static buffer and can hence lead to race conditions if multiple threads try access it at the same time. In cases where thread safety matters, localtime_r() should used instead.
But localtime_r() isn't available on Windows. This MR adds support for localtime_r() so that it can be used on Windows systems just like we can on POSIX systems.
Currently localtime is only used in logging to log the current time, hence even if a race condition occurs it shouldn't be much of a problem.
But the usage of localtime() in the OpenSSH certificate MR (!493 (ed0b86e8)) could be done for any arbitrary time in which case the race condition could be dangerous (Examle: A thread could overwrite another thread's time in localtime()'s static storage and the other thread could end up using the overwritten time)
Checklist
-
Commits have Signed-off-by:with name/author being identical to the commit author -
Code modified for feature -
Test suite updated with functionality tests -
Test suite updated with negative tests -
Documentation updated
Reviewer's checklist:
-
Any issues marked for closing are addressed -
There is a test suite reasonably covering new functionality or modifications -
Function naming, parameters, return values, types, etc., are consistent and according to CONTRIBUTING.md -
This feature/change has adequate documentation added -
No obvious mistakes in the code