Skip to content

Commit

Permalink
win32.c: Add mutexes around some calls
Browse files Browse the repository at this point in the history
These could have races.
  • Loading branch information
khwilliamson committed May 5, 2021
1 parent 24a9fd1 commit 24950bc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion win32/win32.c
Expand Up @@ -1482,6 +1482,8 @@ time_t
translate_ft_to_time_t(FILETIME ft) {
SYSTEMTIME st, local_st;
struct tm pt;
time_t retval;
dTHX;

if (!FileTimeToSystemTime(&ft, &st) ||
!SystemTimeToTzSpecificLocalTime(NULL, &st, &local_st)) {
Expand All @@ -1497,7 +1499,11 @@ translate_ft_to_time_t(FILETIME ft) {
pt.tm_sec = local_st.wSecond;
pt.tm_isdst = -1;

return mktime(&pt);
MKTIME_LOCK;
retval = mktime(&pt);
MKTIME_UNLOCK;

return retval;
}

typedef DWORD (__stdcall *pGetFinalPathNameByHandleA_t)(HANDLE, LPSTR, DWORD, DWORD);
Expand Down Expand Up @@ -2231,9 +2237,12 @@ filetime_from_time(PFILETIME pFileTime, time_t Time)
{
struct tm *pt;
SYSTEMTIME st;
dTHX;

GMTIME_LOCK;
pt = gmtime(&Time);
if (!pt) {
GMTIME_UNLOCK;
pFileTime->dwLowDateTime = 0;
pFileTime->dwHighDateTime = 0;
fprintf(stderr, "fail bad gmtime\n");
Expand All @@ -2248,6 +2257,8 @@ filetime_from_time(PFILETIME pFileTime, time_t Time)
st.wSecond = pt->tm_sec;
st.wMilliseconds = 0;

GMTIME_UNLOCK;

if (!SystemTimeToFileTime(&st, pFileTime)) {
pFileTime->dwLowDateTime = 0;
pFileTime->dwHighDateTime = 0;
Expand Down

0 comments on commit 24950bc

Please sign in to comment.