ldap/servers/slapd/dn.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)
New commits: commit c49b03070c275575ba879e4e9cee98fc038ce7e6 Author: Noriko Hosoi nhosoi@totoro.usersys.redhat.com Date: Wed Sep 26 16:55:39 2012 -0700
Coverity defects
13093: Resource leak Fix description: If udn is allocated in ndn_cache_lookup and it has no chance to be consumed in ndn_cache_add, udn is released.
(cherry picked from commit 4754fb7da3066119576a115a04470b91c4184257)
Conflicts: ldap/servers/slapd/dn.c
diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c index 53c378a..9c1084f 100644 --- a/ldap/servers/slapd/dn.c +++ b/ldap/servers/slapd/dn.c @@ -535,7 +535,7 @@ slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len) char *ends = NULL; char *endd = NULL; char *lastesc = NULL; - char *udn; + char *udn = NULL; /* rdn avs for the main DN */ char *typestart = NULL; int rdn_av_count = 0; @@ -1130,8 +1130,13 @@ bail: *d = '\0'; } /* add this dn to the normalized dn cache */ - if(*dest) - ndn_cache_add(udn, src_len, *dest, *dest_len); + if (udn) { + if(dest && *dest && dest_len && *dest_len) { + ndn_cache_add(udn, src_len, *dest, *dest_len); + } else { + slapi_ch_free_string(&udn); + } + }
return rc; } @@ -2774,6 +2779,10 @@ ndn_cache_lookup(char *dn, size_t dn_len, char **result, char **udn, int *rc) char *ndn, *key; int rv = 0;
+ if(NULL == udn){ + return rv; + } + *udn = NULL; if(ndn_started == 0){ return rv; }
commit 10ddfbc793a77f5c1a19302034239a53c07e3ab2 Author: Noriko Hosoi nhosoi@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!).
(cherry picked from commit 0c44a46448595fdb1e079b5f4c91d4d8bfa2e0f2)
Conflicts: ldap/servers/slapd/dn.c
diff --git a/ldap/servers/slapd/dn.c b/ldap/servers/slapd/dn.c index 283f265..53c378a 100644 --- a/ldap/servers/slapd/dn.c +++ b/ldap/servers/slapd/dn.c @@ -2788,16 +2788,19 @@ ndn_cache_lookup(char *dn, size_t dn_len, char **result, char **udn, int *rc) 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 { + 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 {
389-commits@lists.fedoraproject.org