Blame SOURCES/Address-some-optimized-out-memset-calls.patch

749169
From 05dc6552ea0e8f0002d21ca36d7ff47d4c088bd7 Mon Sep 17 00:00:00 2001
749169
From: Greg Hudson <ghudson@mit.edu>
749169
Date: Sun, 30 Dec 2018 16:40:28 -0500
749169
Subject: [PATCH] Address some optimized-out memset() calls
749169
749169
Ilja Van Sprundel reported a list of memset() calls which gcc
749169
optimizes out.  In krb_auth_su.c, use zap() to clear the password, and
749169
remove two memset() calls when there is no password to clear.  In
749169
iakerb.c, remove an unnecessary memset() before setting the only two
749169
fields of the IAKERB header structure.  In svr_principal.c, use
749169
krb5_free_key_keyblock_contents() instead of hand-freeing key data.
749169
In asn1_k_encode.c, remove an unnecessary memset() of the kdc_req_hack
749169
shell before returning.
749169
749169
(cherry picked from commit 1057b0befec1f1c0e9d4da5521a58496e2dc0997)
749169
(cherry picked from commit 1dfff7202448a950c9133cdfe43d650092d930fd)
749169
(cherry picked from commit 54348bbfaec50bb72d1625c015f8e5c4cfa59e0d)
749169
---
749169
 src/clients/ksu/krb_auth_su.c      |  4 +---
749169
 src/lib/gssapi/krb5/iakerb.c       |  1 -
749169
 src/lib/kadm5/srv/svr_principal.c  | 10 ++--------
749169
 src/lib/krb5/asn.1/asn1_k_encode.c |  1 -
749169
 4 files changed, 3 insertions(+), 13 deletions(-)
749169
749169
diff --git a/src/clients/ksu/krb_auth_su.c b/src/clients/ksu/krb_auth_su.c
749169
index 7af48195c..e39685fff 100644
749169
--- a/src/clients/ksu/krb_auth_su.c
749169
+++ b/src/clients/ksu/krb_auth_su.c
749169
@@ -183,21 +183,19 @@ krb5_boolean ksu_get_tgt_via_passwd(context, client, options, zero_password,
749169
     if (code ) {
749169
         com_err(prog_name, code, _("while reading password for '%s'\n"),
749169
                 client_name);
749169
-        memset(password, 0, sizeof(password));
749169
         return (FALSE);
749169
     }
749169
 
749169
     if ( pwsize == 0) {
749169
         fprintf(stderr, _("No password given\n"));
749169
         *zero_password = TRUE;
749169
-        memset(password, 0, sizeof(password));
749169
         return (FALSE);
749169
     }
749169
 
749169
     code = krb5_get_init_creds_password(context, &creds, client, password,
749169
                                         krb5_prompter_posix, NULL, 0, NULL,
749169
                                         options);
749169
-    memset(password, 0, sizeof(password));
749169
+    zap(password, sizeof(password));
749169
 
749169
 
749169
     if (code) {
749169
diff --git a/src/lib/gssapi/krb5/iakerb.c b/src/lib/gssapi/krb5/iakerb.c
749169
index bb1072fe4..47c161ec9 100644
749169
--- a/src/lib/gssapi/krb5/iakerb.c
749169
+++ b/src/lib/gssapi/krb5/iakerb.c
749169
@@ -262,7 +262,6 @@ iakerb_make_token(iakerb_ctx_id_t ctx,
749169
     /*
749169
      * Assemble the IAKERB-HEADER from the realm and cookie
749169
      */
749169
-    memset(&iah, 0, sizeof(iah));
749169
     iah.target_realm = *realm;
749169
     iah.cookie = cookie;
749169
 
749169
diff --git a/src/lib/kadm5/srv/svr_principal.c b/src/lib/kadm5/srv/svr_principal.c
749169
index 64a4a2e97..73733d371 100644
749169
--- a/src/lib/kadm5/srv/svr_principal.c
749169
+++ b/src/lib/kadm5/srv/svr_principal.c
749169
@@ -2141,14 +2141,8 @@ static int decrypt_key_data(krb5_context context,
749169
         ret = krb5_dbe_decrypt_key_data(context, NULL, &key_data[i], &keys[i],
749169
                                         NULL);
749169
         if (ret) {
749169
-            for (; i >= 0; i--) {
749169
-                if (keys[i].contents) {
749169
-                    memset (keys[i].contents, 0, keys[i].length);
749169
-                    free( keys[i].contents );
749169
-                }
749169
-            }
749169
-
749169
-            memset(keys, 0, n_key_data*sizeof(krb5_keyblock));
749169
+            for (; i >= 0; i--)
749169
+                krb5_free_keyblock_contents(context, &keys[i]);
749169
             free(keys);
749169
             return ret;
749169
         }
749169
diff --git a/src/lib/krb5/asn.1/asn1_k_encode.c b/src/lib/krb5/asn.1/asn1_k_encode.c
749169
index 889460989..c4f9aacdf 100644
749169
--- a/src/lib/krb5/asn.1/asn1_k_encode.c
749169
+++ b/src/lib/krb5/asn.1/asn1_k_encode.c
749169
@@ -532,7 +532,6 @@ decode_kdc_req_body(const taginfo *t, const unsigned char *asn1, size_t len,
749169
         if (ret) {
749169
             free_kdc_req_body(b);
749169
             free(h.server_realm.data);
749169
-            memset(&h, 0, sizeof(h));
749169
             return ret;
749169
         }
749169
         b->server->realm = h.server_realm;