Skip to content

Commit 6690ed6

Browse files
committed
Fixing a hang that would occur when there is incorrectly set time zone data in the windows registry. (case 1256569)
1 parent 18d0e5f commit 6690ed6

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

mcs/class/corlib/System/TimeZoneInfo.WinRT.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ internal struct DYNAMIC_TIME_ZONE_INFORMATION
6161

6262
internal const uint TIME_ZONE_ID_INVALID = 0xffffffff;
6363
internal const uint ERROR_NO_MORE_ITEMS = 259;
64+
internal const uint ERROR_SUCCESS = 0;
6465

6566
[DllImport ("api-ms-win-core-timezone-l1-1-0.dll")]
6667
internal extern static uint EnumDynamicTimeZoneInformation (uint dwIndex, out DYNAMIC_TIME_ZONE_INFORMATION lpTimeZoneInformation);
@@ -349,7 +350,7 @@ internal static List<TimeZoneInfo> GetSystemTimeZonesWinRTFallback ()
349350
try {
350351
uint index = 0;
351352
DYNAMIC_TIME_ZONE_INFORMATION dtzi;
352-
while (EnumDynamicTimeZoneInformation (index++, out dtzi) != ERROR_NO_MORE_ITEMS) {
353+
while (EnumDynamicTimeZoneInformation (index++, out dtzi) == ERROR_SUCCESS) {
353354
var timeZoneInfo = TryCreateTimeZone (dtzi);
354355
if (timeZoneInfo != null)
355356
result.Add (timeZoneInfo);
@@ -358,8 +359,6 @@ internal static List<TimeZoneInfo> GetSystemTimeZonesWinRTFallback ()
358359
// EnumDynamicTimeZoneInformation() might not be available.
359360
}
360361

361-
if (result.Count == 0)
362-
result.Add (Local);
363362
return result;
364363
}
365364
}

mcs/class/corlib/System/TimeZoneInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,10 @@ public static ReadOnlyCollection<TimeZoneInfo> GetSystemTimeZones ()
787787
if (systemTimeZones == null) {
788788
var tz = new List<TimeZoneInfo> ();
789789
GetSystemTimeZonesCore (tz);
790+
// Don't want to return an empty list if we can help it
791+
// but we don't want to stack overflow via a CreateLocal loop
792+
if (tz.Count == 0 && local != null)
793+
tz.Add(Local);
790794
Interlocked.CompareExchange (ref systemTimeZones, new ReadOnlyCollection<TimeZoneInfo> (tz), null);
791795
}
792796

0 commit comments

Comments
 (0)