https://bugs.openldap.org/show_bug.cgi?id=10563
--- Comment #7 from Howard Chu hyc@openldap.org --- (In reply to Erwin Hoffmann from comment #5)
Hi Quanah,
I did a very basic loop over the results. Here is my code:
LDAP *ld; LDAPMessage *result, *msg, *entry; unsigned long scope = LDAP_SCOPE_BASE; char *search = "mail"; char **mail; char *mailfrom;
....
if ((r = ldap_search_ext_s(ld,binddn.s,scope,filters.s,NULL,0,NULL,NULL,NULL, LDAP_NO_LIMIT,&result)) != LDAP_SUCCESS) { log_error("search failed: ",ldap_err2string(r),"ERROR"); exit(110); }
for (msg = ldap_first_message(ld,result); msg != NULL; msg = ldap_next_message(ld,msg)) switch (ldap_msgtype(msg)) { case LDAP_RES_SEARCH_ENTRY: entry = ldap_first_entry(ld,result); if (!entry) { ldap_unbind(ld); exit(1); } // Not found case LDAP_RES_SEARCH_RESULT: mail = ldap_get_values(ld,entry,search);
for (int i = 0; i < ldap_count_values(mail); ++i) if (case_equals(mailfrom,mail[i])) addrok++;}
Thus, in case ldap_count_values() returns with '1' even for none-existing mail objects, any lookup in the structure will give you a core-dump.
Thanks for looking at this.
The algorithm works well for the 'deprecated' LDAP modules now in place. --eh.
Your initial report is about ldap_count_messages() but your example code uses ldap_count_values(). Which is it?