Skip to content

Commit

Permalink
Fixing a hang that would occur when there is incorrectly set time zon…
Browse files Browse the repository at this point in the history
…e data in the windows registry. (case 1256569)
  • Loading branch information
UnityAlex committed Jun 30, 2020
1 parent 18d0e5f commit 6690ed6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions mcs/class/corlib/System/TimeZoneInfo.WinRT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ internal struct DYNAMIC_TIME_ZONE_INFORMATION

internal const uint TIME_ZONE_ID_INVALID = 0xffffffff;
internal const uint ERROR_NO_MORE_ITEMS = 259;
internal const uint ERROR_SUCCESS = 0;

[DllImport ("api-ms-win-core-timezone-l1-1-0.dll")]
internal extern static uint EnumDynamicTimeZoneInformation (uint dwIndex, out DYNAMIC_TIME_ZONE_INFORMATION lpTimeZoneInformation);
Expand Down Expand Up @@ -349,7 +350,7 @@ internal static List<TimeZoneInfo> GetSystemTimeZonesWinRTFallback ()
try {
uint index = 0;
DYNAMIC_TIME_ZONE_INFORMATION dtzi;
while (EnumDynamicTimeZoneInformation (index++, out dtzi) != ERROR_NO_MORE_ITEMS) {
while (EnumDynamicTimeZoneInformation (index++, out dtzi) == ERROR_SUCCESS) {
var timeZoneInfo = TryCreateTimeZone (dtzi);
if (timeZoneInfo != null)
result.Add (timeZoneInfo);
Expand All @@ -358,8 +359,6 @@ internal static List<TimeZoneInfo> GetSystemTimeZonesWinRTFallback ()
// EnumDynamicTimeZoneInformation() might not be available.
}

if (result.Count == 0)
result.Add (Local);
return result;
}
}
Expand Down
4 changes: 4 additions & 0 deletions mcs/class/corlib/System/TimeZoneInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,10 @@ public static ReadOnlyCollection<TimeZoneInfo> GetSystemTimeZones ()
if (systemTimeZones == null) {
var tz = new List<TimeZoneInfo> ();
GetSystemTimeZonesCore (tz);
// Don't want to return an empty list if we can help it
// but we don't want to stack overflow via a CreateLocal loop
if (tz.Count == 0 && local != null)
tz.Add(Local);
Interlocked.CompareExchange (ref systemTimeZones, new ReadOnlyCollection<TimeZoneInfo> (tz), null);
}

Expand Down

0 comments on commit 6690ed6

Please sign in to comment.