Browse Source

Fix some unchecked Windows date provider retvals

pull/1953/head
Sami Vaarala 6 years ago
parent
commit
308dc969c4
  1. 20
      src-input/duk_bi_date_windows.c

20
src-input/duk_bi_date_windows.c

@ -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
@ -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;
@ -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
@ -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 */

Loading…
Cancel
Save