ldap/servers/slapd/dn.c | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
New commits:
commit 0c44a46448595fdb1e079b5f4c91d4d8bfa2e0f2
Author: Noriko Hosoi <nhosoi(a)totoro.usersys.redhat.com>
Date: Mon Jan 7 17:07:52 2013 -0800
Ticket #547 - Incorrect assumption in ndn cache
Bug Description: In ndn_cache_lookup, to determine the given dn
is already normalized or not, the length is compared with the
normalized dn length. If they match, it considers the given dn
is already normalized. But there are cases even if the lengths
are equal, the given dn may not be normalized yet.
(e.g., 'cn="o=ABC",o=XYZ' vs. 'cn=o\3DABC,o=XYZ')
Fix Description: This patch adds another check: if the dn and
normalized dn length match, call memcmp to compare the 2 dn's.
When memcmp returns 0, ndn_cache_lookup returns the passed dn.
https://fedorahosted.org/389/ticket/547
Reviewed by mreynolds (Thanks, Mark!).
diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c
index d643d33..6081119 100644
--- a/ldap/servers/slapd/dn.c
+++ b/ldap/servers/slapd/dn.c
@@ -2706,26 +2706,29 @@ ndn_cache_lookup(char *dn, size_t dn_len, char **result, char
**udn, int *rc)
slapi_rwlock_rdlock(ndn_cache_lock);
ndn_ht_val = (struct ndn_hash_val *)PL_HashTableLookupConst(ndn_cache_hashtable,
dn);
if(ndn_ht_val){
- ndn_cache_update_lru(&ndn_ht_val->lru_node);
- slapi_counter_increment(ndn_cache->cache_hits);
- if(ndn_ht_val->len == dn_len ){
- /* the dn was already normalized, just return the dn as the result */
- *result = dn;
- *rc = 0;
- } else {
- *rc = 1; /* free result */
+ ndn_cache_update_lru(&ndn_ht_val->lru_node);
+ slapi_counter_increment(ndn_cache->cache_hits);
+ if ((ndn_ht_val->len != dn_len) ||
+ /* even if the lengths match, dn may not be normalized yet.
+ * (e.g., 'cn="o=ABC",o=XYZ' vs.
'cn=o\3DABC,o=XYZ') */
+ (memcmp(dn, ndn_ht_val->ndn, dn_len))){
+ *rc = 1; /* free result */
ndn = slapi_ch_malloc(ndn_ht_val->len + 1);
memcpy(ndn, ndn_ht_val->ndn, ndn_ht_val->len);
ndn[ndn_ht_val->len] = '\0';
*result = ndn;
+ } else {
+ /* the dn was already normalized, just return the dn as the result */
+ *result = dn;
+ *rc = 0;
}
rv = 1;
} else {
- /* copy/preserve the udn, so we can use it as the key when we add dn's to the
hashtable */
- key = slapi_ch_malloc(dn_len + 1);
- memcpy(key, dn, dn_len);
- key[dn_len] = '\0';
- *udn = key;
+ /* copy/preserve the udn, so we can use it as the key when we add dn's to the
hashtable */
+ key = slapi_ch_malloc(dn_len + 1);
+ memcpy(key, dn, dn_len);
+ key[dn_len] = '\0';
+ *udn = key;
}
slapi_rwlock_unlock(ndn_cache_lock);