Skip to content

Commit 7353726

Browse files
Fix a Y2038 bug by replacing Int32x32To64 with regular multiplication (#12027)
Int32x32To64 macro internally truncates the arguments to int32, while time_t is 64-bit on most/all modern platforms. Therefore, usage of this macro creates a Year 2038 bug.
1 parent 4670d13 commit 7353726

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

src/common/utility_win.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,20 @@ bool Utility::hasDarkSystray()
8989

9090
void Utility::UnixTimeToFiletime(time_t t, FILETIME *filetime)
9191
{
92-
LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000;
92+
LONGLONG ll = (t * 10000000LL) + 116444736000000000LL;
9393
filetime->dwLowDateTime = (DWORD) ll;
9494
filetime->dwHighDateTime = ll >>32;
9595
}
9696

97-
void Utility::FiletimeToLargeIntegerFiletime(FILETIME *filetime, LARGE_INTEGER *hundredNSecs)
97+
void Utility::FiletimeToLargeIntegerFiletime(const FILETIME *filetime, LARGE_INTEGER *hundredNSecs)
9898
{
9999
hundredNSecs->LowPart = filetime->dwLowDateTime;
100100
hundredNSecs->HighPart = filetime->dwHighDateTime;
101101
}
102102

103103
void Utility::UnixTimeToLargeIntegerFiletime(time_t t, LARGE_INTEGER *hundredNSecs)
104104
{
105-
LONGLONG ll = Int32x32To64(t, 10000000) + 116444736000000000;
106-
hundredNSecs->LowPart = (DWORD) ll;
107-
hundredNSecs->HighPart = ll >>32;
105+
hundredNSecs->QuadPart = (t * 10000000LL) + 116444736000000000LL;
108106
}
109107

110108

src/common/utility_win.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ namespace Utility {
6868

6969
// Possibly refactor to share code with UnixTimevalToFileTime in c_time.c
7070
OCSYNC_EXPORT void UnixTimeToFiletime(time_t t, FILETIME *filetime);
71-
OCSYNC_EXPORT void FiletimeToLargeIntegerFiletime(FILETIME *filetime, LARGE_INTEGER *hundredNSecs);
71+
OCSYNC_EXPORT void FiletimeToLargeIntegerFiletime(const FILETIME *filetime, LARGE_INTEGER *hundredNSecs);
7272
OCSYNC_EXPORT void UnixTimeToLargeIntegerFiletime(time_t t, LARGE_INTEGER *hundredNSecs);
7373

7474
OCSYNC_EXPORT QString formatWinError(long error);

src/csync/std/c_time.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ Q_LOGGING_CATEGORY(lcCSyncCtime, "sync.csync.c_time", QtInfoMsg)
4848
//after Microsoft KB167296
4949
static void UnixTimevalToFileTime(struct timeval t, LPFILETIME pft)
5050
{
51-
LONGLONG ll;
52-
ll = Int32x32To64(t.tv_sec, CSYNC_USEC_IN_SEC*10) + t.tv_usec*10 + CSYNC_SECONDS_SINCE_1601*CSYNC_USEC_IN_SEC*10;
51+
LONGLONG ll = t.tv_sec * CSYNC_USEC_IN_SEC*10 + t.tv_usec*10 + CSYNC_SECONDS_SINCE_1601*CSYNC_USEC_IN_SEC*10;
5352
pft->dwLowDateTime = (DWORD)ll;
5453
pft->dwHighDateTime = ll >> 32;
5554
}

0 commit comments

Comments
 (0)