perform minimal sanity checks on zoneinfo files loaded via TZ variable
authorRich Felker <dalias@aerifal.cx>
Wed, 23 Apr 2014 00:09:56 +0000 (20:09 -0400)
committerRich Felker <dalias@aerifal.cx>
Wed, 23 Apr 2014 00:09:56 +0000 (20:09 -0400)
previously, setting TZ to the pathname of a file which was not a valid
zoneinfo file would usually cause programs using local time zone based
operations to crash. the new code checks the file size and magic at
the beginning of the file, which seems sufficient to prevent
accidental misconfiguration from causing crashes. attempting to make
fully-robust validation would be futile unless we wanted to drop use
of mmap (shared zoneinfo) and instead read it into a local buffer,
since such validation would be subject to race conditions with
modification of the file.

src/time/__tz.c

index 93d59e8..6d7173c 100644 (file)
@@ -168,6 +168,11 @@ static void do_tzset()
                }
                if (!map) s = __gmt;
        }
+       if (map && (map_size < 44 || memcmp(map, "TZif", 4))) {
+               __munmap((void *)map, map_size);
+               map = 0;
+               s = __gmt;
+       }
 
        zi = map;
        if (map) {