quanah / net-ldapapi

The Net::LDAPapi Perl Module uses the OpenLDAP and Mozilla C api's to directly access and manipulate an LDAP v2 or LDAP v3 server.
8 stars 6 forks source link

ldap_search_ext() and ldap_search_ext_s() segfault when used with timeout #30

Closed phillipod closed 9 years ago

phillipod commented 9 years ago

While undocumented in the POD, the OO interface exposes the time out parameter accepted by ldap_search_ext(_s)(). When used in an idiomatic manner, there is a segfault. See below example code and output:

print "===== SEARCH_S WITH TIMEOUT\n";

my $search_s_result = $ld->search_s(
  -basedn => "o=Test Data,c=NZ",
  -scope => LDAP_SCOPE_SUBTREE,
  -filter => "(sn=Last)",
  -attrs => ['cn', 'sn'],
  -attrsonly => 0,
  -timeout => 1);

if ($search_s_result != LDAP_SUCCESS) {
  print "- Fail\n";
}

for (my $entry = $ld->first_entry(); $entry; $entry = $ld->next_entry) {
  print "dn: " . $ld->get_dn() . "\n";

  for (my $attribute = $ld->first_attribute; $attribute; $attribute = $ld->next_attribute) {
    foreach my $value ($ld->get_values($attribute)) {
      print $attribute . ": " . $value . "\n";
    }
  }
}

Output:

===== SEARCH_S WITH TIMEOUT
Segmentation fault (core dumped)

Anaysis indicates that the XS wrappers ldap_search_ext(_s)() both expect a 'struct timeval *' passed from perl-space, which is strange considering ldap_result does accept idiomatic time outs.

See below function definition:

int
ldap_search_ext_s(ld, base, scope, filter, attrs, attrsonly, sctrls, cctrls, timeout, sizelimit, res)
    LDAP *           ld
    LDAP_CHAR *      base
    int              scope
    LDAP_CHAR *      filter
    SV *             attrs
    int              attrsonly
    LDAPControl **   sctrls
    LDAPControl **   cctrls
    struct timeval * timeout
    int              sizelimit
    LDAPMessage *    res = NO_INIT
    CODE:
    { ... }

I am currently working on a larger refactor in relation to timeouts in order to resolve #21