Blame SOURCES/Initialize-interposed-mech-list-without-allocation.patch

aa181f
From 70f30d61e7f5da178e47dcfc8feb083a17be74ff Mon Sep 17 00:00:00 2001
aa181f
From: Simo Sorce <simo@redhat.com>
aa181f
Date: Thu, 27 Aug 2020 12:32:06 -0400
aa181f
Subject: [PATCH] Initialize interposed mech list without allocation
aa181f
aa181f
While we had already fixed the leak here in main, the code performed
aa181f
unnecessary extra work, so just replacethe whole lot with a function
aa181f
that does not do any extra allocation or copy.
aa181f
aa181f
Signed-off-by: Simo Sorce <simo@redhat.com>
aa181f
[rharwood@redhat.com: commit message]
aa181f
Reviewed-by: Robbie Harwood <rharwood@redhat.com>
aa181f
(cherry picked from commit 447d5352c2a81e219ccf04348a87b2ff25b7de15)
aa181f
(cherry picked from commit 4abda7e47551f39adfc074fc017f6006a4b91a19)
aa181f
---
aa181f
 src/mechglue/gss_plugin.c | 31 ++++++++++++++++++++++++++-----
aa181f
 1 file changed, 26 insertions(+), 5 deletions(-)
aa181f
aa181f
diff --git a/src/mechglue/gss_plugin.c b/src/mechglue/gss_plugin.c
aa181f
index b9813dc..79e04d0 100644
aa181f
--- a/src/mechglue/gss_plugin.c
aa181f
+++ b/src/mechglue/gss_plugin.c
aa181f
@@ -65,6 +65,8 @@ enum gpp_behavior gpp_get_behavior(void)
aa181f
     return behavior;
aa181f
 }
aa181f
 
aa181f
+static void gpp_init_special_available_mechs(const gss_OID_set mechs);
aa181f
+
aa181f
 /* 2.16.840.1.113730.3.8.15.1 */
aa181f
 const gss_OID_desc gssproxy_mech_interposer = {
aa181f
     .length = 11,
aa181f
@@ -76,7 +78,6 @@ gss_OID_set gss_mech_interposer(gss_OID mech_type)
aa181f
     gss_OID_set interposed_mechs;
aa181f
     OM_uint32 maj, min;
aa181f
     char *envval;
aa181f
-    gss_OID_set special_mechs;
aa181f
 
aa181f
     /* avoid looping in the gssproxy daemon by avoiding to interpose
aa181f
      * any mechanism */
aa181f
@@ -119,8 +120,7 @@ gss_OID_set gss_mech_interposer(gss_OID mech_type)
aa181f
     }
aa181f
 
aa181f
     /* while there also initiaize special_mechs */
aa181f
-    special_mechs = gpp_special_available_mechs(interposed_mechs);
aa181f
-    (void)gss_release_oid_set(&min, &special_mechs);
aa181f
+    gpp_init_special_available_mechs(interposed_mechs);
aa181f
 
aa181f
 done:
aa181f
     if (maj != 0) {
aa181f
@@ -307,13 +307,13 @@ gss_OID_set gpp_special_available_mechs(const gss_OID_set mechs)
aa181f
     gss_OID n;
aa181f
     uint32_t maj, min;
aa181f
 
aa181f
-    item = gpp_get_special_oids();
aa181f
-
aa181f
     maj = gss_create_empty_oid_set(&min, &amechs);
aa181f
     if (maj) {
aa181f
         return GSS_C_NO_OID_SET;
aa181f
     }
aa181f
     for (size_t i = 0; i < mechs->count; i++) {
aa181f
+        item = gpp_get_special_oids();
aa181f
+
aa181f
         while (item) {
aa181f
             if (gpp_is_special_oid(&mechs->elements[i])) {
aa181f
                 maj = gss_add_oid_set_member(&min,
aa181f
@@ -354,6 +354,27 @@ done:
aa181f
     return amechs;
aa181f
 }
aa181f
 
aa181f
+static void gpp_init_special_available_mechs(const gss_OID_set mechs)
aa181f
+{
aa181f
+    struct gpp_special_oid_list *item;
aa181f
+
aa181f
+    for (size_t i = 0; i < mechs->count; i++) {
aa181f
+        item = gpp_get_special_oids();
aa181f
+
aa181f
+        while (item) {
aa181f
+            if (gpp_is_special_oid(&mechs->elements[i]) ||
aa181f
+                gpp_special_equal(&item->special_oid, &mechs->elements[i])) {
aa181f
+                break;
aa181f
+            }
aa181f
+            item = gpp_next_special_oids(item);
aa181f
+        }
aa181f
+        if (item == NULL) {
aa181f
+            /* not found, add to static list */
aa181f
+            (void)gpp_new_special_mech(&mechs->elements[i]);
aa181f
+        }
aa181f
+    }
aa181f
+}
aa181f
+
aa181f
 OM_uint32 gssi_internal_release_oid(OM_uint32 *minor_status, gss_OID *oid)
aa181f
 {
aa181f
     struct gpp_special_oid_list *item = NULL;