krb5 commit [krb5-1.16]: Don't include all MEMORY ccaches in collection

Greg Hudson <[email protected]>
Newsgroups gmane.comp.encryption.kerberos.cvs
Message-ID <[email protected]>
https://github.com/krb5/krb5/commit/4fb4a9c23cc33939deab2855449019bcca1003ab
commit 4fb4a9c23cc33939deab2855449019bcca1003ab
Author: Greg Hudson <[email protected]>
Date:   Wed Aug 1 15:53:12 2018 -0400

    Don't include all MEMORY ccaches in collection
    
    In the MEMORY ccache implementation, only yield a cache in the
    per-type cursor if it is the context default cache, matching the
    behavior of FILE after commit 45360c9688ca963f75a2480f2cf818424fc3dc7b
    (ticket 6955).
    
    (cherry picked from commit 49bb627fed70c5258c151c5135ac3d95ed1ee55d)
    
    ticket: 8720
    version_fixed: 1.16.3

 src/lib/krb5/ccache/cc_memory.c |   23 +++++++++--------------
 src/lib/krb5/ccache/t_cccol.py  |    7 ++++---
 2 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/src/lib/krb5/ccache/cc_memory.c b/src/lib/krb5/ccache/cc_memory.c
index 8cdaff7..cfd5c63 100644
--- a/src/lib/krb5/ccache/cc_memory.c
+++ b/src/lib/krb5/ccache/cc_memory.c
@@ -132,7 +132,7 @@ struct mcc_cursor {
 
 /* Iterator over memory caches.  */
 struct krb5_mcc_ptcursor_data {
-    struct krb5_mcc_list_node *cur;
+    krb5_boolean first;
 };
 
 k5_cc_mutex krb5int_mcc_mutex = K5_CC_MUTEX_PARTIAL_INITIALIZER;
@@ -693,9 +693,7 @@ krb5_mcc_ptcursor_new(
         return ENOMEM;
     }
     n->data = cdata;
-    k5_cc_mutex_lock(context, &krb5int_mcc_mutex);
-    cdata->cur = mcc_head;
-    k5_cc_mutex_unlock(context, &krb5int_mcc_mutex);
+    cdata->first = TRUE;
     *cursor = n;
     return 0;
 }
@@ -707,22 +705,19 @@ krb5_mcc_ptcursor_next(
     krb5_ccache *ccache)
 {
     struct krb5_mcc_ptcursor_data *cdata = NULL;
+    const char *defname;
 
     *ccache = NULL;
     cdata = cursor->data;
-    if (cdata->cur == NULL)
+    if (!cdata->first)
         return 0;
+    cdata->first = FALSE;
 
-    *ccache = malloc(sizeof(**ccache));
-    if (*ccache == NULL)
-        return ENOMEM;
+    defname = krb5_cc_default_name(context);
+    if (defname == NULL || strncmp(defname, "MEMORY:", 7) != 0)
+        return 0;
 
-    (*ccache)->ops = &krb5_mcc_ops;
-    (*ccache)->data = cdata->cur->cache;
-    k5_cc_mutex_lock(context, &krb5int_mcc_mutex);
-    cdata->cur = cdata->cur->next;
-    k5_cc_mutex_unlock(context, &krb5int_mcc_mutex);
-    return 0;
+    return krb5_cc_resolve(context, defname, ccache);
 }
 
 static krb5_error_code KRB5_CALLCONV
diff --git a/src/lib/krb5/ccache/t_cccol.py b/src/lib/krb5/ccache/t_cccol.py
index f7f1785..c6d5f51 100755
--- a/src/lib/krb5/ccache/t_cccol.py
+++ b/src/lib/krb5/ccache/t_cccol.py
@@ -97,10 +97,11 @@ if test_keyring:
 
 mfoo = 'MEMORY:foo'
 mbar = 'MEMORY:bar'
-cursor_test('filemem', [fccname, mfoo, mbar], [fccname, mfoo, mbar])
-cursor_test('dirmem', [dccname, mfoo], [duser, dalice, dbob, mfoo])
+cursor_test('filemem', [fccname, mfoo], [fccname])
+cursor_test('dirmem', [dccname, mfoo], [duser, dalice, dbob])
+cursor_test('mem', [mfoo, mbar], [mfoo])
 if test_keyring:
-    cursor_test('keyringmem', [krccname, mfoo], [kruser, kralice, krbob, mfoo])
+    cursor_test('keyringmem', [krccname, mfoo], [kruser, kralice, krbob])
 
 # Test krb5_cccol_have_content.
 realm.run(['./t_cccursor', dccname, 'CONTENT'])
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.