Bug #56499: unreadable /etc/localtime should not cause an exception (#4881)
authorMarcin Cieślak <saper@saper.info>
Wed, 24 May 2017 18:53:23 +0000 (20:53 +0200)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 24 May 2017 18:53:23 +0000 (20:53 +0200)
* Bug #56499: unreadable /etc/localtime should not cause an exception

* Fix build

mcs/class/corlib/System/TimeZoneInfo.cs

index 5c812b6f592288d5ac486919837ee6170de6ddde..1c5cdd3ae820dc363687a19efbfe553ca31b6b20 100644 (file)
@@ -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