From 6290f981940394a4768b566a6d55aa5e5ca5e839 Mon Sep 17 00:00:00 2001 From: Andreas Hansson Date: Mon, 20 Oct 2014 18:03:55 -0400 Subject: 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. --- src/dev/sparc/dtod.cc | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'src/dev/sparc') diff --git a/src/dev/sparc/dtod.cc b/src/dev/sparc/dtod.cc index abbab2dee..0d57b1f83 100644 --- a/src/dev/sparc/dtod.cc +++ b/src/dev/sparc/dtod.cc @@ -53,17 +53,8 @@ DumbTOD::DumbTOD(const Params *p) : 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); -- cgit v1.2.3