Blame SOURCES/0008-Issue-51095-abort-operation-if-CSN-can-not-be-genera.patch

a26cad
From 8d14ff153e9335b09739438344f9c3c78a496548 Mon Sep 17 00:00:00 2001
a26cad
From: Mark Reynolds <mreynolds@redhat.com>
a26cad
Date: Fri, 22 May 2020 10:42:11 -0400
a26cad
Subject: [PATCH 08/12] Issue 51095 - abort operation if CSN can not be
a26cad
 generated
a26cad
a26cad
Bug Description:  If we fail to get the system time then we were using an
a26cad
                  uninitialized timespec struct which could lead to bizarre
a26cad
                  times in CSN's.
a26cad
a26cad
Fix description:  Check if the system time function fails, and if it does
a26cad
                  then abort the update operation.
a26cad
a26cad
relates: https://pagure.io/389-ds-base/issue/51095
a26cad
a26cad
Reviewed by: firstyear & tbordaz(Thanks!!)
a26cad
---
a26cad
 ldap/servers/plugins/replication/repl5.h      |  2 +-
a26cad
 .../plugins/replication/repl5_replica.c       | 33 ++++++++------
a26cad
 ldap/servers/slapd/back-ldbm/ldbm_add.c       |  8 +++-
a26cad
 ldap/servers/slapd/back-ldbm/ldbm_delete.c    |  9 +++-
a26cad
 ldap/servers/slapd/back-ldbm/ldbm_modify.c    | 10 ++++-
a26cad
 ldap/servers/slapd/back-ldbm/ldbm_modrdn.c    |  8 +++-
a26cad
 ldap/servers/slapd/csngen.c                   | 18 +++++++-
a26cad
 ldap/servers/slapd/entrywsi.c                 | 15 ++++---
a26cad
 ldap/servers/slapd/slap.h                     |  2 +-
a26cad
 ldap/servers/slapd/slapi-plugin.h             |  8 ++++
a26cad
 ldap/servers/slapd/slapi-private.h            |  5 ++-
a26cad
 ldap/servers/slapd/time.c                     | 43 +++++++++++++------
a26cad
 12 files changed, 118 insertions(+), 43 deletions(-)
a26cad
a26cad
diff --git a/ldap/servers/plugins/replication/repl5.h b/ldap/servers/plugins/replication/repl5.h
a26cad
index 72b7089e3..638471744 100644
a26cad
--- a/ldap/servers/plugins/replication/repl5.h
a26cad
+++ b/ldap/servers/plugins/replication/repl5.h
a26cad
@@ -776,7 +776,7 @@ void replica_disable_replication(Replica *r);
a26cad
 int replica_start_agreement(Replica *r, Repl_Agmt *ra);
a26cad
 int windows_replica_start_agreement(Replica *r, Repl_Agmt *ra);
a26cad
 
a26cad
-CSN *replica_generate_next_csn(Slapi_PBlock *pb, const CSN *basecsn);
a26cad
+int32_t replica_generate_next_csn(Slapi_PBlock *pb, const CSN *basecsn, CSN **opcsn);
a26cad
 int replica_get_attr(Slapi_PBlock *pb, const char *type, void *value);
a26cad
 
a26cad
 /* mapping tree extensions manipulation */
a26cad
diff --git a/ldap/servers/plugins/replication/repl5_replica.c b/ldap/servers/plugins/replication/repl5_replica.c
a26cad
index 02caa88d9..f01782330 100644
a26cad
--- a/ldap/servers/plugins/replication/repl5_replica.c
a26cad
+++ b/ldap/servers/plugins/replication/repl5_replica.c
a26cad
@@ -3931,11 +3931,9 @@ windows_replica_start_agreement(Replica *r, Repl_Agmt *ra)
a26cad
  * A callback function registered as op->o_csngen_handler and
a26cad
  * called by backend ops to generate opcsn.
a26cad
  */
a26cad
-CSN *
a26cad
-replica_generate_next_csn(Slapi_PBlock *pb, const CSN *basecsn)
a26cad
+int32_t
a26cad
+replica_generate_next_csn(Slapi_PBlock *pb, const CSN *basecsn, CSN **opcsn)
a26cad
 {
a26cad
-    CSN *opcsn = NULL;
a26cad
-
a26cad
     Replica *replica = replica_get_replica_for_op(pb);
a26cad
     if (NULL != replica) {
a26cad
         Slapi_Operation *op;
a26cad
@@ -3946,17 +3944,26 @@ replica_generate_next_csn(Slapi_PBlock *pb, const CSN *basecsn)
a26cad
                 CSNGen *gen = (CSNGen *)object_get_data(gen_obj);
a26cad
                 if (NULL != gen) {
a26cad
                     /* The new CSN should be greater than the base CSN */
a26cad
-                    csngen_new_csn(gen, &opcsn, PR_FALSE /* don't notify */);
a26cad
-                    if (csn_compare(opcsn, basecsn) <= 0) {
a26cad
-                        char opcsnstr[CSN_STRSIZE], basecsnstr[CSN_STRSIZE];
a26cad
+                    if (csngen_new_csn(gen, opcsn, PR_FALSE /* don't notify */) != CSN_SUCCESS) {
a26cad
+                        /* Failed to generate CSN we must abort */
a26cad
+                        object_release(gen_obj);
a26cad
+                        return -1;
a26cad
+                    }
a26cad
+                    if (csn_compare(*opcsn, basecsn) <= 0) {
a26cad
+                        char opcsnstr[CSN_STRSIZE];
a26cad
+                        char basecsnstr[CSN_STRSIZE];
a26cad
                         char opcsn2str[CSN_STRSIZE];
a26cad
 
a26cad
-                        csn_as_string(opcsn, PR_FALSE, opcsnstr);
a26cad
+                        csn_as_string(*opcsn, PR_FALSE, opcsnstr);
a26cad
                         csn_as_string(basecsn, PR_FALSE, basecsnstr);
a26cad
-                        csn_free(&opcsn);
a26cad
+                        csn_free(opcsn);
a26cad
                         csngen_adjust_time(gen, basecsn);
a26cad
-                        csngen_new_csn(gen, &opcsn, PR_FALSE /* don't notify */);
a26cad
-                        csn_as_string(opcsn, PR_FALSE, opcsn2str);
a26cad
+                        if (csngen_new_csn(gen, opcsn, PR_FALSE) != CSN_SUCCESS) {
a26cad
+                            /* Failed to generate CSN we must abort */
a26cad
+                            object_release(gen_obj);
a26cad
+                            return -1;
a26cad
+                        }
a26cad
+                        csn_as_string(*opcsn, PR_FALSE, opcsn2str);
a26cad
                         slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name,
a26cad
                                       "replica_generate_next_csn - "
a26cad
                                       "opcsn=%s <= basecsn=%s, adjusted opcsn=%s\n",
a26cad
@@ -3966,14 +3973,14 @@ replica_generate_next_csn(Slapi_PBlock *pb, const CSN *basecsn)
a26cad
                      * Insert opcsn into the csn pending list.
a26cad
                      * This is the notify effect in csngen_new_csn().
a26cad
                      */
a26cad
-                    assign_csn_callback(opcsn, (void *)replica);
a26cad
+                    assign_csn_callback(*opcsn, (void *)replica);
a26cad
                 }
a26cad
                 object_release(gen_obj);
a26cad
             }
a26cad
         }
a26cad
     }
a26cad
 
a26cad
-    return opcsn;
a26cad
+    return 0;
a26cad
 }
a26cad
 
a26cad
 /*
a26cad
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_add.c b/ldap/servers/slapd/back-ldbm/ldbm_add.c
a26cad
index d0d88bf16..ee366c74c 100644
a26cad
--- a/ldap/servers/slapd/back-ldbm/ldbm_add.c
a26cad
+++ b/ldap/servers/slapd/back-ldbm/ldbm_add.c
a26cad
@@ -645,7 +645,13 @@ ldbm_back_add(Slapi_PBlock *pb)
a26cad
                          * Current op is a user request. Opcsn will be assigned
a26cad
                          * if the dn is in an updatable replica.
a26cad
                          */
a26cad
-                        opcsn = entry_assign_operation_csn(pb, e, parententry ? parententry->ep_entry : NULL);
a26cad
+                        if (entry_assign_operation_csn(pb, e, parententry ? parententry->ep_entry : NULL, &opcsn) != 0) {
a26cad
+                            slapi_log_err(SLAPI_LOG_ERR, "ldbm_back_add",
a26cad
+                                    "failed to generate add CSN for entry (%s), aborting operation\n",
a26cad
+                                    slapi_entry_get_dn(e));
a26cad
+                            ldap_result_code = LDAP_OPERATIONS_ERROR;
a26cad
+                            goto error_return;
a26cad
+                        }
a26cad
                     }
a26cad
                     if (opcsn != NULL) {
a26cad
                         entry_set_csn(e, opcsn);
a26cad
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_delete.c b/ldap/servers/slapd/back-ldbm/ldbm_delete.c
a26cad
index 873b5b00e..fbcb57310 100644
a26cad
--- a/ldap/servers/slapd/back-ldbm/ldbm_delete.c
a26cad
+++ b/ldap/servers/slapd/back-ldbm/ldbm_delete.c
a26cad
@@ -464,7 +464,14 @@ replace_entry:
a26cad
                      * by entry_assign_operation_csn() if the dn is in an
a26cad
                      * updatable replica.
a26cad
                      */
a26cad
-                    opcsn = entry_assign_operation_csn ( pb, e->ep_entry, NULL );
a26cad
+                    if (entry_assign_operation_csn(pb, e->ep_entry, NULL, &opcsn) != 0) {
a26cad
+                        slapi_log_err(SLAPI_LOG_ERR, "ldbm_back_delete",
a26cad
+                                "failed to generate delete CSN for entry (%s), aborting operation\n",
a26cad
+                                slapi_entry_get_dn(e->ep_entry));
a26cad
+                        retval = -1;
a26cad
+                        ldap_result_code = LDAP_OPERATIONS_ERROR;
a26cad
+                        goto error_return;
a26cad
+                    }
a26cad
                 }
a26cad
                 if (opcsn != NULL) {
a26cad
                     if (!is_fixup_operation) {
a26cad
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_modify.c b/ldap/servers/slapd/back-ldbm/ldbm_modify.c
a26cad
index b0c477e3f..e9d7e87e3 100644
a26cad
--- a/ldap/servers/slapd/back-ldbm/ldbm_modify.c
a26cad
+++ b/ldap/servers/slapd/back-ldbm/ldbm_modify.c
a26cad
@@ -598,12 +598,18 @@ ldbm_back_modify(Slapi_PBlock *pb)
a26cad
                     goto error_return;
a26cad
                 }
a26cad
                 opcsn = operation_get_csn(operation);
a26cad
-                if (NULL == opcsn && operation->o_csngen_handler) {
a26cad
+                if (opcsn == NULL && operation->o_csngen_handler) {
a26cad
                     /*
a26cad
                      * Current op is a user request. Opcsn will be assigned
a26cad
                      * if the dn is in an updatable replica.
a26cad
                      */
a26cad
-                    opcsn = entry_assign_operation_csn(pb, e->ep_entry, NULL);
a26cad
+                    if (entry_assign_operation_csn(pb, e->ep_entry, NULL, &opcsn) != 0) {
a26cad
+                        slapi_log_err(SLAPI_LOG_ERR, "ldbm_back_modify",
a26cad
+                                "failed to generate modify CSN for entry (%s), aborting operation\n",
a26cad
+                                slapi_entry_get_dn(e->ep_entry));
a26cad
+                        ldap_result_code = LDAP_OPERATIONS_ERROR;
a26cad
+                        goto error_return;
a26cad
+                    }
a26cad
                 }
a26cad
                 if (opcsn) {
a26cad
                     entry_set_maxcsn(e->ep_entry, opcsn);
a26cad
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c b/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
a26cad
index 26698012a..fde83c99f 100644
a26cad
--- a/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
a26cad
+++ b/ldap/servers/slapd/back-ldbm/ldbm_modrdn.c
a26cad
@@ -543,7 +543,13 @@ ldbm_back_modrdn(Slapi_PBlock *pb)
a26cad
                      * Current op is a user request. Opcsn will be assigned
a26cad
                      * if the dn is in an updatable replica.
a26cad
                      */
a26cad
-                    opcsn = entry_assign_operation_csn(pb, e->ep_entry, parententry ? parententry->ep_entry : NULL);
a26cad
+                    if (entry_assign_operation_csn(pb, e->ep_entry, parententry ? parententry->ep_entry : NULL, &opcsn) != 0) {
a26cad
+                        slapi_log_err(SLAPI_LOG_ERR, "ldbm_back_modrdn",
a26cad
+                                "failed to generate modrdn CSN for entry (%s), aborting operation\n",
a26cad
+                                slapi_entry_get_dn(e->ep_entry));
a26cad
+                        ldap_result_code = LDAP_OPERATIONS_ERROR;
a26cad
+                        goto error_return;
a26cad
+                    }
a26cad
                 }
a26cad
                 if (opcsn != NULL) {
a26cad
                     entry_set_maxcsn(e->ep_entry, opcsn);
a26cad
diff --git a/ldap/servers/slapd/csngen.c b/ldap/servers/slapd/csngen.c
a26cad
index 68dbbda8e..b08d8b25c 100644
a26cad
--- a/ldap/servers/slapd/csngen.c
a26cad
+++ b/ldap/servers/slapd/csngen.c
a26cad
@@ -164,6 +164,7 @@ csngen_free(CSNGen **gen)
a26cad
 int
a26cad
 csngen_new_csn(CSNGen *gen, CSN **csn, PRBool notify)
a26cad
 {
a26cad
+    struct timespec now = {0};
a26cad
     int rc = CSN_SUCCESS;
a26cad
     time_t cur_time;
a26cad
     int delta;
a26cad
@@ -179,12 +180,25 @@ csngen_new_csn(CSNGen *gen, CSN **csn, PRBool notify)
a26cad
         return CSN_MEMORY_ERROR;
a26cad
     }
a26cad
 
a26cad
-    slapi_rwlock_wrlock(gen->lock);
a26cad
+    if ((rc = slapi_clock_gettime(&now)) != 0) {
a26cad
+        /* Failed to get system time, we must abort */
a26cad
+        slapi_log_err(SLAPI_LOG_ERR, "csngen_new_csn",
a26cad
+                "Failed to get system time (%s)\n",
a26cad
+                slapd_system_strerror(rc));
a26cad
+        return CSN_TIME_ERROR;
a26cad
+    }
a26cad
+    cur_time = now.tv_sec;
a26cad
 
a26cad
-    cur_time = slapi_current_utc_time();
a26cad
+    slapi_rwlock_wrlock(gen->lock);
a26cad
 
a26cad
     /* check if the time should be adjusted */
a26cad
     delta = cur_time - gen->state.sampled_time;
a26cad
+    if (delta > _SEC_PER_DAY || delta < (-1 * _SEC_PER_DAY)) {
a26cad
+        /* We had a jump larger than a day */
a26cad
+        slapi_log_err(SLAPI_LOG_INFO, "csngen_new_csn",
a26cad
+                "Detected large jump in CSN time.  Delta: %d (current time: %ld  vs  previous time: %ld)\n",
a26cad
+                delta, cur_time, gen->state.sampled_time);
a26cad
+    }
a26cad
     if (delta > 0) {
a26cad
         rc = _csngen_adjust_local_time(gen, cur_time);
a26cad
         if (rc != CSN_SUCCESS) {
a26cad
diff --git a/ldap/servers/slapd/entrywsi.c b/ldap/servers/slapd/entrywsi.c
a26cad
index 5d1d7238a..31bf65d8e 100644
a26cad
--- a/ldap/servers/slapd/entrywsi.c
a26cad
+++ b/ldap/servers/slapd/entrywsi.c
a26cad
@@ -224,13 +224,12 @@ entry_add_rdn_csn(Slapi_Entry *e, const CSN *csn)
a26cad
     slapi_rdn_free(&rdn;;
a26cad
 }
a26cad
 
a26cad
-CSN *
a26cad
-entry_assign_operation_csn(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *parententry)
a26cad
+int32_t
a26cad
+entry_assign_operation_csn(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *parententry, CSN **opcsn)
a26cad
 {
a26cad
     Slapi_Operation *op;
a26cad
     const CSN *basecsn = NULL;
a26cad
     const CSN *parententry_dncsn = NULL;
a26cad
-    CSN *opcsn = NULL;
a26cad
 
a26cad
     slapi_pblock_get(pb, SLAPI_OPERATION, &op);
a26cad
 
a26cad
@@ -252,14 +251,16 @@ entry_assign_operation_csn(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *parent
a26cad
                 basecsn = parententry_dncsn;
a26cad
             }
a26cad
         }
a26cad
-        opcsn = op->o_csngen_handler(pb, basecsn);
a26cad
+        if(op->o_csngen_handler(pb, basecsn, opcsn) != 0) {
a26cad
+            return -1;
a26cad
+        }
a26cad
 
a26cad
-        if (NULL != opcsn) {
a26cad
-            operation_set_csn(op, opcsn);
a26cad
+        if (*opcsn) {
a26cad
+            operation_set_csn(op, *opcsn);
a26cad
         }
a26cad
     }
a26cad
 
a26cad
-    return opcsn;
a26cad
+    return 0;
a26cad
 }
a26cad
 
a26cad
 /*
a26cad
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
a26cad
index a4cae784a..cef8c789c 100644
a26cad
--- a/ldap/servers/slapd/slap.h
a26cad
+++ b/ldap/servers/slapd/slap.h
a26cad
@@ -1480,7 +1480,7 @@ struct op;
a26cad
 typedef void (*result_handler)(struct conn *, struct op *, int, char *, char *, int, struct berval **);
a26cad
 typedef int (*search_entry_handler)(Slapi_Backend *, struct conn *, struct op *, struct slapi_entry *);
a26cad
 typedef int (*search_referral_handler)(Slapi_Backend *, struct conn *, struct op *, struct berval **);
a26cad
-typedef CSN *(*csngen_handler)(Slapi_PBlock *pb, const CSN *basecsn);
a26cad
+typedef int32_t *(*csngen_handler)(Slapi_PBlock *pb, const CSN *basecsn, CSN **opcsn);
a26cad
 typedef int (*replica_attr_handler)(Slapi_PBlock *pb, const char *type, void **value);
a26cad
 
a26cad
 /*
a26cad
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
a26cad
index be1e52e4d..834a98742 100644
a26cad
--- a/ldap/servers/slapd/slapi-plugin.h
a26cad
+++ b/ldap/servers/slapd/slapi-plugin.h
a26cad
@@ -6743,6 +6743,14 @@ int slapi_reslimit_get_integer_limit(Slapi_Connection *conn, int handle, int *li
a26cad
  */
a26cad
 time_t slapi_current_time(void) __attribute__((deprecated));
a26cad
 
a26cad
+/**
a26cad
+ * Get the system time and check for errors.  Return
a26cad
+ *
a26cad
+ * \param tp - a timespec struct where the system time is set
a26cad
+ * \return result code, upon success tp is set to the system time
a26cad
+ */
a26cad
+int32_t slapi_clock_gettime(struct timespec *tp);
a26cad
+
a26cad
 /**
a26cad
  * Returns the current system time as a hr clock relative to uptime
a26cad
  * This means the clock is not affected by timezones
a26cad
diff --git a/ldap/servers/slapd/slapi-private.h b/ldap/servers/slapd/slapi-private.h
a26cad
index d85ee43e5..c98c1947c 100644
a26cad
--- a/ldap/servers/slapd/slapi-private.h
a26cad
+++ b/ldap/servers/slapd/slapi-private.h
a26cad
@@ -233,7 +233,8 @@ enum
a26cad
     CSN_INVALID_PARAMETER, /* invalid function argument */
a26cad
     CSN_INVALID_FORMAT,    /* invalid state format */
a26cad
     CSN_LDAP_ERROR,        /* LDAP operation failed */
a26cad
-    CSN_NSPR_ERROR         /* NSPR API failure */
a26cad
+    CSN_NSPR_ERROR,        /* NSPR API failure */
a26cad
+    CSN_TIME_ERROR         /* Error generating new CSN due to clock failure */
a26cad
 };
a26cad
 
a26cad
 typedef struct csngen CSNGen;
a26cad
@@ -326,7 +327,7 @@ int slapi_entries_diff(Slapi_Entry **old_entries, Slapi_Entry **new_entries, int
a26cad
 void set_attr_to_protected_list(char *attr, int flag);
a26cad
 
a26cad
 /* entrywsi.c */
a26cad
-CSN *entry_assign_operation_csn(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *parententry);
a26cad
+int32_t entry_assign_operation_csn(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *parententry, CSN **opcsn);
a26cad
 const CSN *entry_get_maxcsn(const Slapi_Entry *entry);
a26cad
 void entry_set_maxcsn(Slapi_Entry *entry, const CSN *csn);
a26cad
 const CSN *entry_get_dncsn(const Slapi_Entry *entry);
a26cad
diff --git a/ldap/servers/slapd/time.c b/ldap/servers/slapd/time.c
a26cad
index 8048a3359..545538404 100644
a26cad
--- a/ldap/servers/slapd/time.c
a26cad
+++ b/ldap/servers/slapd/time.c
a26cad
@@ -61,6 +61,25 @@ poll_current_time()
a26cad
     return 0;
a26cad
 }
a26cad
 
a26cad
+/*
a26cad
+ * Check if the time function returns an error.  If so return the errno
a26cad
+ */
a26cad
+int32_t
a26cad
+slapi_clock_gettime(struct timespec *tp)
a26cad
+{
a26cad
+    int32_t rc = 0;
a26cad
+
a26cad
+    PR_ASSERT(tp && tp->tv_nsec == 0 && tp->tv_sec == 0);
a26cad
+
a26cad
+    if (clock_gettime(CLOCK_REALTIME, tp) != 0) {
a26cad
+        rc = errno;
a26cad
+    }
a26cad
+
a26cad
+    PR_ASSERT(rc == 0);
a26cad
+
a26cad
+    return rc;
a26cad
+}
a26cad
+
a26cad
 time_t
a26cad
 current_time(void)
a26cad
 {
a26cad
@@ -69,7 +88,7 @@ current_time(void)
a26cad
      * but this should be removed in favour of the
a26cad
      * more accurately named slapi_current_utc_time
a26cad
      */
a26cad
-    struct timespec now;
a26cad
+    struct timespec now = {0};
a26cad
     clock_gettime(CLOCK_REALTIME, &now;;
a26cad
     return now.tv_sec;
a26cad
 }
a26cad
@@ -83,7 +102,7 @@ slapi_current_time(void)
a26cad
 struct timespec
a26cad
 slapi_current_rel_time_hr(void)
a26cad
 {
a26cad
-    struct timespec now;
a26cad
+    struct timespec now = {0};
a26cad
     clock_gettime(CLOCK_MONOTONIC, &now;;
a26cad
     return now;
a26cad
 }
a26cad
@@ -91,7 +110,7 @@ slapi_current_rel_time_hr(void)
a26cad
 struct timespec
a26cad
 slapi_current_utc_time_hr(void)
a26cad
 {
a26cad
-    struct timespec ltnow;
a26cad
+    struct timespec ltnow = {0};
a26cad
     clock_gettime(CLOCK_REALTIME, &ltnow);
a26cad
     return ltnow;
a26cad
 }
a26cad
@@ -99,7 +118,7 @@ slapi_current_utc_time_hr(void)
a26cad
 time_t
a26cad
 slapi_current_utc_time(void)
a26cad
 {
a26cad
-    struct timespec ltnow;
a26cad
+    struct timespec ltnow = {0};
a26cad
     clock_gettime(CLOCK_REALTIME, &ltnow);
a26cad
     return ltnow.tv_sec;
a26cad
 }
a26cad
@@ -108,8 +127,8 @@ void
a26cad
 slapi_timestamp_utc_hr(char *buf, size_t bufsize)
a26cad
 {
a26cad
     PR_ASSERT(bufsize >= SLAPI_TIMESTAMP_BUFSIZE);
a26cad
-    struct timespec ltnow;
a26cad
-    struct tm utctm;
a26cad
+    struct timespec ltnow = {0};
a26cad
+    struct tm utctm = {0};
a26cad
     clock_gettime(CLOCK_REALTIME, &ltnow);
a26cad
     gmtime_r(&(ltnow.tv_sec), &utctm);
a26cad
     strftime(buf, bufsize, "%Y%m%d%H%M%SZ", &utctm);
a26cad
@@ -140,7 +159,7 @@ format_localTime_log(time_t t, int initsize __attribute__((unused)), char *buf,
a26cad
 {
a26cad
 
a26cad
     long tz;
a26cad
-    struct tm *tmsp, tms;
a26cad
+    struct tm *tmsp, tms = {0};
a26cad
     char tbuf[*bufsize];
a26cad
     char sign;
a26cad
     /* make sure our buffer will be big enough. Need at least 29 */
a26cad
@@ -191,7 +210,7 @@ format_localTime_hr_log(time_t t, long nsec, int initsize __attribute__((unused)
a26cad
 {
a26cad
 
a26cad
     long tz;
a26cad
-    struct tm *tmsp, tms;
a26cad
+    struct tm *tmsp, tms = {0};
a26cad
     char tbuf[*bufsize];
a26cad
     char sign;
a26cad
     /* make sure our buffer will be big enough. Need at least 39 */
a26cad
@@ -278,7 +297,7 @@ slapi_timespec_expire_check(struct timespec *expire)
a26cad
     if (expire->tv_sec == 0 && expire->tv_nsec == 0) {
a26cad
         return TIMER_CONTINUE;
a26cad
     }
a26cad
-    struct timespec now;
a26cad
+    struct timespec now = {0};
a26cad
     clock_gettime(CLOCK_MONOTONIC, &now;;
a26cad
     if (now.tv_sec > expire->tv_sec ||
a26cad
         (expire->tv_sec == now.tv_sec && now.tv_sec > expire->tv_nsec)) {
a26cad
@@ -293,7 +312,7 @@ format_localTime(time_t from)
a26cad
        in the syntax of a generalizedTime, except without the time zone. */
a26cad
 {
a26cad
     char *into;
a26cad
-    struct tm t;
a26cad
+    struct tm t = {0};
a26cad
 
a26cad
     localtime_r(&from, &t);
a26cad
 
a26cad
@@ -362,7 +381,7 @@ format_genTime(time_t from)
a26cad
        in the syntax of a generalizedTime. */
a26cad
 {
a26cad
     char *into;
a26cad
-    struct tm t;
a26cad
+    struct tm t = {0};
a26cad
 
a26cad
     gmtime_r(&from, &t);
a26cad
     into = slapi_ch_malloc(SLAPI_TIMESTAMP_BUFSIZE);
a26cad
@@ -382,7 +401,7 @@ time_t
a26cad
 read_genTime(struct berval *from)
a26cad
 {
a26cad
     struct tm t = {0};
a26cad
-    time_t retTime;
a26cad
+    time_t retTime = {0};
a26cad
     time_t diffsec = 0;
a26cad
     int i, gflag = 0, havesec = 0;
a26cad
 
a26cad
-- 
a26cad
2.26.2
a26cad