aboutsummaryrefslogtreecommitdiff
path: root/cutils.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-10-01 14:22:06 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2012-10-05 08:02:30 -0500
commitb6db4aca20e9af4f62c9c9e08b9b9672a6ed3390 (patch)
treec720251bf1c6e4aa90b391fe80f8a7fb8b280792 /cutils.c
parente0fea6b1e4df2067a51e08e67a17cb98a547287c (diff)
rtc: fix overflow in mktimegm
When setting a date in 1980, Linux is actually disregarding the century byte and setting the year to 2080. This causes a year-2038 overflow in mktimegm. Fix this by doing the days-to-seconds computation in 64-bit math. Reported-by: Lucas Meneghel Rodrigues <lookkas@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'cutils.c')
-rw-r--r--cutils.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/cutils.c b/cutils.c
index 8ef648f4b9..8edd8fa13c 100644
--- a/cutils.c
+++ b/cutils.c
@@ -115,7 +115,7 @@ time_t mktimegm(struct tm *tm)
m += 12;
y--;
}
- t = 86400 * (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 +
+ t = 86400ULL * (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 +
y / 400 - 719469);
t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
return t;