From 940944dcdefb56f7952cd35a43bcbd5f70ba78ef Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marcin=20Cie=C5=9Blak?= Date: Wed, 24 May 2017 20:53:23 +0200 Subject: [PATCH] Bug #56499: unreadable /etc/localtime should not cause an exception (#4881) * Bug #56499: unreadable /etc/localtime should not cause an exception * Fix build --- mcs/class/corlib/System/TimeZoneInfo.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mcs/class/corlib/System/TimeZoneInfo.cs b/mcs/class/corlib/System/TimeZoneInfo.cs index 5c812b6f592..1c5cdd3ae82 100644 --- a/mcs/class/corlib/System/TimeZoneInfo.cs +++ b/mcs/class/corlib/System/TimeZoneInfo.cs @@ -574,11 +574,17 @@ namespace System #if LIBC private static TimeZoneInfo FindSystemTimeZoneByFileName (string id, string filepath) { - if (!File.Exists (filepath)) - throw new TimeZoneNotFoundException (); - - using (FileStream stream = File.OpenRead (filepath)) { + FileStream stream = null; + try { + stream = File.OpenRead (filepath); + } catch (Exception ex) { + throw new TimeZoneNotFoundException ("Couldn't read time zone file " + filepath, ex); + } + try { return BuildFromStream (id, stream); + } finally { + if (stream != null) + stream.Dispose(); } } #endif -- 2.11.4.GIT