Blame SOURCES/0044-Ticket-47577-crash-when-removing-entries-from-cache.patch

ba46c7
From 583eda60ede7224cea8aed5bae1bc819fab77b45 Mon Sep 17 00:00:00 2001
ba46c7
From: Ludwig Krispenz <lkrispen@redhat.com>
ba46c7
Date: Tue, 5 Nov 2013 16:58:44 +0100
ba46c7
Subject: [PATCH 44/44] Ticket 47577 - crash when removing entries from cache
ba46c7
ba46c7
Bug Description:  when the dn of an entry in the cache was adjusted to the parent dn, for soenm time
ba46c7
	teh dn was not defined, anothe thread accessing the dn of teh chached entry could crash
ba46c7
ba46c7
Fix Description:   hold the cache mutex when modifyingthe dn of an entry in the cache
ba46c7
ba46c7
https://fedorahosted.org/389/ticket/47577
ba46c7
ba46c7
Reviewed by: rmeggins
ba46c7
(cherry picked from commit 7272dbda7f43974eed003cbcfc0ddd57fe433687)
ba46c7
(cherry picked from commit 1056a6282f246a9c396b8052d726005fe8189512)
ba46c7
(cherry picked from commit 00b19f3b4af662341c72fa6cfd60b5e136f1428f)
ba46c7
(cherry picked from commit ecc210f3ca25528f5f718680409ded0021d5604c)
ba46c7
---
ba46c7
 ldap/servers/slapd/back-ldbm/back-ldbm.h       | 2 ++
ba46c7
 ldap/servers/slapd/back-ldbm/cache.c           | 8 ++++++++
ba46c7
 ldap/servers/slapd/back-ldbm/id2entry.c        | 2 ++
ba46c7
 ldap/servers/slapd/back-ldbm/proto-back-ldbm.h | 2 ++
ba46c7
 4 files changed, 14 insertions(+)
ba46c7
ba46c7
diff --git a/ldap/servers/slapd/back-ldbm/back-ldbm.h b/ldap/servers/slapd/back-ldbm/back-ldbm.h
ba46c7
index 970f3c2..5f8a05a 100644
ba46c7
--- a/ldap/servers/slapd/back-ldbm/back-ldbm.h
ba46c7
+++ b/ldap/servers/slapd/back-ldbm/back-ldbm.h
ba46c7
@@ -409,6 +409,8 @@ struct cache {
ba46c7
 #define CACHE_ADD(cache, p, a) cache_add((cache), (void *)(p), (void **)(a))
ba46c7
 #define CACHE_RETURN(cache, p) cache_return((cache), (void **)(p))
ba46c7
 #define CACHE_REMOVE(cache, p) cache_remove((cache),  (void *)(p))
ba46c7
+#define CACHE_LOCK(cache) cache_lock((cache))
ba46c7
+#define CACHE_UNLOCK(cache) cache_unlock((cache))
ba46c7
 
ba46c7
 /* various modules keep private data inside the attrinfo structure */
ba46c7
 typedef struct dblayer_private dblayer_private;
ba46c7
diff --git a/ldap/servers/slapd/back-ldbm/cache.c b/ldap/servers/slapd/back-ldbm/cache.c
ba46c7
index 5fa06fb..a73ae6a 100644
ba46c7
--- a/ldap/servers/slapd/back-ldbm/cache.c
ba46c7
+++ b/ldap/servers/slapd/back-ldbm/cache.c
ba46c7
@@ -1472,6 +1472,14 @@ int cache_add_tentative(struct cache *cache, struct backentry *e,
ba46c7
 {
ba46c7
     return entrycache_add_int(cache, e, ENTRY_STATE_CREATING, alt);
ba46c7
 }
ba46c7
+void cache_lock(struct cache *cache)
ba46c7
+{
ba46c7
+    PR_Lock(cache->c_mutex);
ba46c7
+}
ba46c7
+void cache_unlock(struct cache *cache)
ba46c7
+{
ba46c7
+    PR_Unlock(cache->c_mutex);
ba46c7
+}
ba46c7
 
ba46c7
 /* locks an entry so that it can be modified (you should have gotten the
ba46c7
  * entry via cache_find_*).
ba46c7
diff --git a/ldap/servers/slapd/back-ldbm/id2entry.c b/ldap/servers/slapd/back-ldbm/id2entry.c
ba46c7
index dae558c..7a3b19e 100644
ba46c7
--- a/ldap/servers/slapd/back-ldbm/id2entry.c
ba46c7
+++ b/ldap/servers/slapd/back-ldbm/id2entry.c
ba46c7
@@ -167,10 +167,12 @@ id2entry_add_ext(backend *be, struct backentry *e, back_txn *txn,
ba46c7
                         if (myparentdn && PL_strcmp(parentdn, myparentdn)) {
ba46c7
                             Slapi_DN *sdn = slapi_entry_get_sdn(e->ep_entry);
ba46c7
                             char *newdn = NULL;
ba46c7
+                            CACHE_LOCK(&inst->inst_cache);
ba46c7
                             slapi_sdn_done(sdn);
ba46c7
                             newdn = slapi_ch_smprintf("%s,%s", myrdn, parentdn);
ba46c7
                             slapi_sdn_init_dn_passin(sdn, newdn);
ba46c7
                             slapi_sdn_get_ndn(sdn); /* to set ndn */
ba46c7
+                            CACHE_UNLOCK(&inst->inst_cache);
ba46c7
                         }
ba46c7
                         slapi_ch_free_string(&myparentdn);
ba46c7
                     }
ba46c7
diff --git a/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h b/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h
ba46c7
index 3b2e586..d168714 100644
ba46c7
--- a/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h
ba46c7
+++ b/ldap/servers/slapd/back-ldbm/proto-back-ldbm.h
ba46c7
@@ -76,6 +76,8 @@ void cache_get_stats(struct cache *cache, PRUint64 *hits, PRUint64 *tries,
ba46c7
 void cache_debug_hash(struct cache *cache, char **out);
ba46c7
 int cache_remove(struct cache *cache,  void *e);
ba46c7
 void cache_return(struct cache *cache, void **bep);
ba46c7
+void cache_lock(struct cache *cache);
ba46c7
+void cache_unlock(struct cache *cache);
ba46c7
 struct backentry *cache_find_dn(struct cache *cache, const char *dn, unsigned long ndnlen);
ba46c7
 struct backentry *cache_find_id(struct cache *cache, ID id);
ba46c7
 struct backentry *cache_find_uuid(struct cache *cache, const char *uuid);
ba46c7
-- 
ba46c7
1.8.1.4
ba46c7