Blame SOURCES/Fix-more-time-manipulations-for-y2038.patch

963210
From 006c68f6ed266d5ea7a24512349a931f45160cc6 Mon Sep 17 00:00:00 2001
963210
From: Greg Hudson <ghudson@mit.edu>
963210
Date: Wed, 17 May 2017 14:52:09 -0400
963210
Subject: [PATCH] Fix more time manipulations for y2038
963210
963210
Use timestamp helper functions to ensure that more operations are safe
963210
after y2038, and display the current timestamp as unsigned in
963210
krb5int_trace().
963210
963210
ticket: 8352
963210
(cherry picked from commit a60db180211a383bd382afe729e9309acb8dcf53)
963210
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
963210
---
963210
 src/kadmin/server/misc.c   | 2 +-
963210
 src/kdc/dispatch.c         | 2 +-
963210
 src/lib/krb5/os/c_ustime.c | 8 ++++----
963210
 src/lib/krb5/os/trace.c    | 2 +-
963210
 4 files changed, 7 insertions(+), 7 deletions(-)
963210
963210
diff --git a/src/kadmin/server/misc.c b/src/kadmin/server/misc.c
963210
index 27a6376af..a75b65a26 100644
963210
--- a/src/kadmin/server/misc.c
963210
+++ b/src/kadmin/server/misc.c
963210
@@ -184,7 +184,7 @@ check_min_life(void *server_handle, krb5_principal principal,
963210
             (void) kadm5_free_principal_ent(handle->lhandle, &princ);
963210
             return (ret == KADM5_UNK_POLICY) ? 0 : ret;
963210
         }
963210
-        if((now - princ.last_pwd_change) < pol.pw_min_life &&
963210
+        if(ts_delta(now, princ.last_pwd_change) < pol.pw_min_life &&
963210
            !(princ.attributes & KRB5_KDB_REQUIRES_PWCHANGE)) {
963210
             if (msg_ret != NULL) {
963210
                 time_t until;
963210
diff --git a/src/kdc/dispatch.c b/src/kdc/dispatch.c
963210
index 3a169ebc7..16a35d2be 100644
963210
--- a/src/kdc/dispatch.c
963210
+++ b/src/kdc/dispatch.c
963210
@@ -104,7 +104,7 @@ reseed_random(krb5_context kdc_err_context)
963210
         if (last_os_random == 0)
963210
             last_os_random = now;
963210
         /* Grab random data from OS every hour*/
963210
-        if (now-last_os_random >= 60 * 60) {
963210
+        if (ts_delta(now, last_os_random) >= 60 * 60) {
963210
             krb5_c_random_os_entropy(kdc_err_context, 0, NULL);
963210
             last_os_random = now;
963210
         }
963210
diff --git a/src/lib/krb5/os/c_ustime.c b/src/lib/krb5/os/c_ustime.c
963210
index 871d72183..68fb381f4 100644
963210
--- a/src/lib/krb5/os/c_ustime.c
963210
+++ b/src/lib/krb5/os/c_ustime.c
963210
@@ -102,17 +102,17 @@ krb5_crypto_us_timeofday(krb5_int32 *seconds, krb5_int32 *microseconds)
963210
        putting now.sec in the past.  But don't just use '<' because we
963210
        need to properly handle the case where the administrator intentionally
963210
        adjusted time backwards. */
963210
-    if ((now.sec == last_time.sec-1) ||
963210
-        ((now.sec == last_time.sec) && (now.usec <= last_time.usec))) {
963210
+    if (now.sec == ts_incr(last_time.sec, -1) ||
963210
+        (now.sec == last_time.sec && !ts_after(last_time.usec, now.usec))) {
963210
         /* Correct 'now' to be exactly one microsecond later than 'last_time'.
963210
            Note that _because_ we perform this hack, 'now' may be _earlier_
963210
            than 'last_time', even though the system time is monotonically
963210
            increasing. */
963210
 
963210
         now.sec = last_time.sec;
963210
-        now.usec = ++last_time.usec;
963210
+        now.usec = ts_incr(last_time.usec, 1);
963210
         if (now.usec >= 1000000) {
963210
-            ++now.sec;
963210
+            now.sec = ts_incr(now.sec, 1);
963210
             now.usec = 0;
963210
         }
963210
     }
963210
diff --git a/src/lib/krb5/os/trace.c b/src/lib/krb5/os/trace.c
963210
index a19246128..74c315c90 100644
963210
--- a/src/lib/krb5/os/trace.c
963210
+++ b/src/lib/krb5/os/trace.c
963210
@@ -350,7 +350,7 @@ krb5int_trace(krb5_context context, const char *fmt, ...)
963210
         goto cleanup;
963210
     if (krb5_crypto_us_timeofday(&sec, &usec) != 0)
963210
         goto cleanup;
963210
-    if (asprintf(&msg, "[%d] %d.%d: %s\n", (int) getpid(), (int) sec,
963210
+    if (asprintf(&msg, "[%d] %u.%d: %s\n", (int) getpid(), (unsigned int) sec,
963210
                  (int) usec, str) < 0)
963210
         goto cleanup;
963210
     info.message = msg;