From f7fc11ee8f95e6a41cb989330c215ba6d981667a Mon Sep 17 00:00:00 2001 From: Tomoya Tanjo Date: Tue, 26 Aug 2014 16:14:02 +0900 Subject: [PATCH] Make std.file.timeLastModified with two arguments safe --- std/file.d | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/std/file.d b/std/file.d index b82466bd194..234c98f2781 100644 --- a/std/file.d +++ b/std/file.d @@ -905,15 +905,15 @@ else } -------------------- +/ -SysTime timeLastModified(in char[] name, SysTime returnIfMissing) +SysTime timeLastModified(in char[] name, SysTime returnIfMissing) @safe { version(Windows) { if(!exists(name)) return returnIfMissing; - SysTime dummy = void; - SysTime ftm = void; + SysTime dummy; + SysTime ftm; getTimesWin(name, dummy, dummy, ftm); @@ -921,9 +921,13 @@ SysTime timeLastModified(in char[] name, SysTime returnIfMissing) } else version(Posix) { + static auto trustedStat(in char[] path, ref stat_t buf) @trusted + { + return stat(path.tempCString(), &buf); + } stat_t statbuf = void; - return stat(name.tempCString(), &statbuf) != 0 ? + return trustedStat(name, statbuf) != 0 ? returnIfMissing : SysTime(unixTimeToStdTime(statbuf.st_mtime)); }