andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone

Blame 0289-Ticket-547-Incorrect-assumption-in-ndn-cache.patch

dc8c34
From 55c0904b0b844be3e4b82b4b07fda679ad437298 Mon Sep 17 00:00:00 2001
dc8c34
From: Noriko Hosoi <nhosoi@totoro.usersys.redhat.com>
dc8c34
Date: Mon, 7 Jan 2013 17:07:52 -0800
dc8c34
Subject: [PATCH 289/305] Ticket #547 - Incorrect assumption in ndn cache
dc8c34
dc8c34
Bug Description: In ndn_cache_lookup, to determine the given dn
dc8c34
is already normalized or not, the length is compared with the
dc8c34
normalized dn length.  If they match, it considers the given dn
dc8c34
is already normalized.  But there are cases even if the lengths
dc8c34
are equal, the given dn may not be normalized yet.
dc8c34
(e.g., 'cn="o=ABC",o=XYZ' vs. 'cn=o\3DABC,o=XYZ')
dc8c34
dc8c34
Fix Description: This patch adds another check: if the dn and
dc8c34
normalized dn length match, call memcmp to compare the 2 dn's.
dc8c34
When memcmp returns 0, ndn_cache_lookup returns the passed dn.
dc8c34
dc8c34
https://fedorahosted.org/389/ticket/547
dc8c34
dc8c34
Reviewed by mreynolds (Thanks, Mark!).
dc8c34
dc8c34
(cherry picked from commit 0c44a46448595fdb1e079b5f4c91d4d8bfa2e0f2)
dc8c34
dc8c34
Conflicts:
dc8c34
	ldap/servers/slapd/dn.c
dc8c34
dc8c34
(cherry picked from commit 10ddfbc793a77f5c1a19302034239a53c07e3ab2)
dc8c34
---
dc8c34
 ldap/servers/slapd/dn.c | 13 ++++++++-----
dc8c34
 1 file changed, 8 insertions(+), 5 deletions(-)
dc8c34
dc8c34
diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c
dc8c34
index 283f265..53c378a 100644
dc8c34
--- a/ldap/servers/slapd/dn.c
dc8c34
+++ b/ldap/servers/slapd/dn.c
dc8c34
@@ -2788,16 +2788,19 @@ ndn_cache_lookup(char *dn, size_t dn_len, char **result, char **udn, int *rc)
dc8c34
     if(ndn_ht_val){
dc8c34
         ndn_cache_update_lru(&ndn_ht_val->lru_node);
dc8c34
         slapi_counter_increment(ndn_cache->cache_hits);
dc8c34
-        if(ndn_ht_val->len == dn_len ){
dc8c34
-            /* the dn was already normalized, just return the dn as the result */
dc8c34
-            *result = dn;
dc8c34
-            *rc = 0;
dc8c34
-        } else {
dc8c34
+        if ((ndn_ht_val->len != dn_len) || 
dc8c34
+            /* even if the lengths match, dn may not be normalized yet.
dc8c34
+             * (e.g., 'cn="o=ABC",o=XYZ' vs. 'cn=o\3DABC,o=XYZ') */
dc8c34
+            (memcmp(dn, ndn_ht_val->ndn, dn_len))){
dc8c34
             *rc = 1; /* free result */
dc8c34
             ndn = slapi_ch_malloc(ndn_ht_val->len + 1);
dc8c34
             memcpy(ndn, ndn_ht_val->ndn, ndn_ht_val->len);
dc8c34
             ndn[ndn_ht_val->len] = '\0';
dc8c34
             *result = ndn;
dc8c34
+        } else {
dc8c34
+            /* the dn was already normalized, just return the dn as the result */
dc8c34
+            *result = dn;
dc8c34
+            *rc = 0;
dc8c34
         }
dc8c34
         rv = 1;
dc8c34
     } else {
dc8c34
-- 
dc8c34
1.9.3
dc8c34