From: Marcin Cieślak Date: Wed, 24 May 2017 18:53:23 +0000 (+0200) Subject: Bug #56499: unreadable /etc/localtime should not cause an exception (#4881) X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=940944dcdefb56f7952cd35a43bcbd5f70ba78ef;p=mono.git Bug #56499: unreadable /etc/localtime should not cause an exception (#4881) * Bug #56499: unreadable /etc/localtime should not cause an exception * Fix build --- 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