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

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