Skip to content

Commit

Permalink
Merge pull request #1953 from svaarala/windows-date-return-value-check
Browse files Browse the repository at this point in the history
Fix some unchecked Windows date provider retvals
  • Loading branch information
svaarala authored Aug 3, 2018
2 parents 1c98bdb + 5af0c44 commit 2aecfba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions RELEASES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3364,6 +3364,9 @@ Planned

* Fix 'defined but not used' warning for Windows (GH-1775)

* Fix potential uninitialized data use when Windows Date provider
FileTimeToSystemTime() or FileTimeToLocalFileTime() failed (GH-1953)

* Fix some Clang warnings by avoiding undefined behavior by default, define
DUK_USE_ALLOW_UNDEFINED_BEHAVIOR to reduce the explicit undefined behavior
checks for better footprint/performance (GH-1777, GH-1795, GH-1796, GH-1797,
Expand Down
20 changes: 17 additions & 3 deletions src-input/duk_bi_date_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ DUK_INTERNAL duk_int_t duk_bi_date_get_local_tzoffset_windows(duk_double_t d) {
ULARGE_INTEGER tmp2;
ULARGE_INTEGER tmp3;
FILETIME ft1;
BOOL ret;

/* XXX: handling of timestamps outside Windows supported range.
* How does Windows deal with dates before 1600? Does windows
Expand All @@ -115,7 +116,11 @@ DUK_INTERNAL duk_int_t duk_bi_date_get_local_tzoffset_windows(duk_double_t d) {

ft1.dwLowDateTime = tmp2.LowPart;
ft1.dwHighDateTime = tmp2.HighPart;
FileTimeToSystemTime((const FILETIME *) &ft1, &st2);
ret = FileTimeToSystemTime((const FILETIME *) &ft1, &st2);
if (!ret) {
DUK_D(DUK_DPRINT("FileTimeToSystemTime() failed, return tzoffset 0"));
return 0;
}
if (SystemTimeToTzSpecificLocalTime((LPTIME_ZONE_INFORMATION) NULL, &st2, &st3) == 0) {
DUK_D(DUK_DPRINT("SystemTimeToTzSpecificLocalTime() failed, return tzoffset 0"));
return 0;
Expand All @@ -135,6 +140,7 @@ DUK_INTERNAL duk_int_t duk_bi_date_get_local_tzoffset_windows_no_dst(duk_double_
FILETIME ft2;
ULARGE_INTEGER tmp1;
ULARGE_INTEGER tmp2;
BOOL ret;

/* Do a similar computation to duk_bi_date_get_local_tzoffset_windows
* but without accounting for daylight savings time. Use this on
Expand All @@ -150,9 +156,17 @@ DUK_INTERNAL duk_int_t duk_bi_date_get_local_tzoffset_windows_no_dst(duk_double_

ft1.dwLowDateTime = tmp1.LowPart;
ft1.dwHighDateTime = tmp1.HighPart;
FileTimeToLocalFileTime((const FILETIME *) &ft1, &ft2);
ret = FileTimeToLocalFileTime((const FILETIME *) &ft1, &ft2);
if (!ret) {
DUK_D(DUK_DPRINT("FileTimeToLocalFileTime() failed, return tzoffset 0"));
return 0;
}

FileTimeToSystemTime((const FILETIME *) &ft2, &st2);
ret = FileTimeToSystemTime((const FILETIME *) &ft2, &st2);
if (!ret) {
DUK_D(DUK_DPRINT("FileTimeToSystemTime() failed, return tzoffset 0"));
return 0;
}
duk__convert_systime_to_ularge((const SYSTEMTIME *) &st2, &tmp2);

return (duk_int_t) (((LONGLONG) tmp2.QuadPart - (LONGLONG) tmp1.QuadPart) / DUK_I64_CONSTANT(10000000)); /* seconds */
Expand Down

0 comments on commit 2aecfba

Please sign in to comment.