summaryrefslogtreecommitdiff
path: root/src/base/time.cc
diff options
context:
space:
mode:
authorAndreas Hansson <andreas.hansson@arm.com>2014-10-20 18:03:55 -0400
committerAndreas Hansson <andreas.hansson@arm.com>2014-10-20 18:03:55 -0400
commit6290f981940394a4768b566a6d55aa5e5ca5e839 (patch)
tree337cf915a15a7f18d80dacb44af3fb1778a2b73f /src/base/time.cc
parenta4a8568bd2e3300b5dc9d3deee5181a7db2a76c7 (diff)
downloadgem5-6290f981940394a4768b566a6d55aa5e5ca5e839.tar.xz
misc: Use gmtime for conversion to UTC to avoid getenv/setenv
This patch changes how we turn time into UTC. Previously we manipulated the TZ environment variable, but this has issues as the strings that are manipulated could be tainted (see e.g. CERT ENV34-C). Now we simply rely on the built-in gmtime function and avoid touching getenv/setenv all together.
Diffstat (limited to 'src/base/time.cc')
-rw-r--r--src/base/time.cc15
1 files changed, 2 insertions, 13 deletions
diff --git a/src/base/time.cc b/src/base/time.cc
index dd9e72a09..c265c1c47 100644
--- a/src/base/time.cc
+++ b/src/base/time.cc
@@ -150,18 +150,7 @@ sleep(const Time &time)
time_t
mkutctime(struct tm *time)
{
- time_t ret;
- char *tz;
-
- tz = getenv("TZ");
- setenv("TZ", "", 1);
- tzset();
- ret = mktime(time);
- if (tz)
- setenv("TZ", tz, 1);
- else
- unsetenv("TZ");
- tzset();
- return ret;
+ time_t local = mktime(time);
+ return mktime(gmtime(&local));
}