[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[win-pv-devel] [PATCH] Limit timeoffset to valid values


  • To: <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Owen Smith <owen.smith@xxxxxxxxxx>
  • Date: Fri, 23 Aug 2019 14:21:54 +0100
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=owen.smith@xxxxxxxxxx; spf=Pass smtp.mailfrom=owen.smith@xxxxxxxxxx; spf=None smtp.helo=postmaster@xxxxxxxxxxxxxxx
  • Cc: Owen Smith <owen.smith@xxxxxxxxxx>
  • Delivery-date: Fri, 23 Aug 2019 13:22:40 +0000
  • Ironport-sdr: 1Fliwif4muzXqSYBJpusUNrhdlzTI3oHof8TX5Bh37ihsqaeavuFt+nnB8V5Sw47JUrMdxxFnx 3cUPV6mPP9TVGRvpMSgiTqo4JpQN+gx89f77pnbKA4mfXXvkEug4DY3UhNDbseQ5dQcb4W4fmn Ps/y1hzCvEDa9a0clSWEPgNHxQ57clSIxSXwBDtTLgn7Vk/OQ7vfN1+/SwvuOROxj6l3Li7Ltp LS1Swt/tgIl+HpPt+aPMBq0eFmlDYS/DhVxjaMtt5TLvztzDt2WxY7OPN6SFrOkrD4AMYcDHgr X+I=
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

timeoffset is expressed in +/- seconds from UTC. This translates to
43200. Log out of range values and ignore the timeoffset.

Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
---
 src/xenagent/service.cpp | 30 ++++++++++++++++++++++--------
 src/xenagent/service.h   |  2 +-
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/src/xenagent/service.cpp b/src/xenagent/service.cpp
index a77ff23..2c034b8 100644
--- a/src/xenagent/service.cpp
+++ b/src/xenagent/service.cpp
@@ -40,6 +40,9 @@
 #include "service.h"
 #include "messages.h"
 
+// 12 hours in seconds
+#define MAX_TIME_OFFSET (12 * 60 * 60)
+
 class CCritSec
 {
 public:
@@ -404,17 +407,23 @@ bool CXenIfaceCreator::IsRTCInUTC()
     return val;
 }
 
-void CXenIfaceCreator::AdjustXenTimeToUTC(FILETIME* now)
+long CXenIfaceCreator::AdjustXenTimeToUTC(FILETIME* now)
 {
     std::string vm;
     if (!m_device->StoreRead("vm", vm))
-        return;
+        return 0;
 
     std::string offs;
     if (!m_device->StoreRead(vm + "/rtc/timeoffset", offs))
-        return;
+        return 0;
 
     long offset = (long)atoi(offs.c_str());
+    if (offset > MAX_TIME_OFFSET || offset < -MAX_TIME_OFFSET) {
+        CXenAgent::Log("Invalid offset \"%s\" (%+d), using 0 offset\n",
+                       offs.c_str(),
+                       offset);
+        return 0;
+    }
 
     ULARGE_INTEGER lnow;
     lnow.LowPart  = now->dwLowDateTime;
@@ -424,11 +433,14 @@ void CXenIfaceCreator::AdjustXenTimeToUTC(FILETIME* now)
 
     now->dwLowDateTime  = lnow.LowPart;
     now->dwHighDateTime = lnow.HighPart;
+
+    return offset;
 }
 
 void CXenIfaceCreator::SetXenTime()
 {
     bool IsUTC = IsRTCInUTC();
+    long offset = 0;
 
     SYSTEMTIME cur = { 0 };
     if (IsUTC)
@@ -441,7 +453,7 @@ void CXenIfaceCreator::SetXenTime()
         return;
 
     if (IsUTC)
-        AdjustXenTimeToUTC(&now);
+        offset = AdjustXenTimeToUTC(&now);
 
     SYSTEMTIME sys = { 0 };
     if (!FileTimeToSystemTime(&now, &sys))
@@ -451,12 +463,14 @@ void CXenIfaceCreator::SetXenTime()
         return;
 
     CXenAgent::Log("RTC is in %s\n", IsUTC ? "UTC" : "local time");
-    CXenAgent::Log("Time Now = %d/%d/%d %d:%02d:%02d.%d\n",
+    CXenAgent::Log("Time Now = %d/%d/%d %d:%02d:%02d.%d (%+d)\n",
                    cur.wYear, cur.wMonth, cur.wDay,
-                   cur.wHour, cur.wMinute, cur.wSecond, cur.wMilliseconds);
-    CXenAgent::Log("New Time = %d/%d/%d %d:%02d:%02d.%d\n",
+                   cur.wHour, cur.wMinute, cur.wSecond, cur.wMilliseconds,
+                   offset);
+    CXenAgent::Log("New Time = %d/%d/%d %d:%02d:%02d.%d (%+d)\n",
                    sys.wYear, sys.wMonth, sys.wDay,
-                   sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds);
+                   sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds,
+                   offset);
 
     if (IsUTC)
         SetSystemTime(&sys);
diff --git a/src/xenagent/service.h b/src/xenagent/service.h
index 9547177..e8d2ef5 100644
--- a/src/xenagent/service.h
+++ b/src/xenagent/service.h
@@ -86,7 +86,7 @@ private:
     void StopSlateModeWatch();
     void AcquireShutdownPrivilege();
     bool IsRTCInUTC();
-    void AdjustXenTimeToUTC(FILETIME* time);
+    long AdjustXenTimeToUTC(FILETIME* time);
     void SetXenTime();
 
 private:
-- 
2.16.2.windows.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/win-pv-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.