changeset 9277177eccff in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=9277177eccff
description:
        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:

 src/base/time.cc      |  15 ++-------------
 src/dev/sparc/dtod.cc |  13 ++-----------
 2 files changed, 4 insertions(+), 24 deletions(-)

diffs (47 lines):

diff -r 59f9f18aae0c -r 9277177eccff src/base/time.cc
--- a/src/base/time.cc  Mon Oct 20 18:03:55 2014 -0400
+++ b/src/base/time.cc  Mon Oct 20 18:03:55 2014 -0400
@@ -150,18 +150,7 @@
 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));
 }
 
diff -r 59f9f18aae0c -r 9277177eccff src/dev/sparc/dtod.cc
--- a/src/dev/sparc/dtod.cc     Mon Oct 20 18:03:55 2014 -0400
+++ b/src/dev/sparc/dtod.cc     Mon Oct 20 18:03:55 2014 -0400
@@ -53,17 +53,8 @@
     : BasicPioDevice(p, 0x08)
 {
     struct tm tm = p->time;
-    char *tz;
-
-    tz = getenv("TZ");
-    setenv("TZ", "", 1);
-    tzset();
-    todTime = mktime(&tm);
-    if (tz)
-        setenv("TZ", tz, 1);
-    else
-        unsetenv("TZ");
-    tzset();
+    time_t local = mktime(&tm);
+    todTime = mktime(gmtime(&local));
 
     DPRINTFN("Real-time clock set to %s\n", asctime(&tm));
     DPRINTFN("Real-time clock set to %d\n", todTime);
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to