Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search_s() clobbers ATTRS parameter #8

Closed
phillipod opened this issue Apr 29, 2015 · 0 comments
Closed

search_s() clobbers ATTRS parameter #8

phillipod opened this issue Apr 29, 2015 · 0 comments
Assignees
Labels
Milestone

Comments

@phillipod
Copy link
Collaborator

The following code:

print "===== SEARCH\n";

my $search_msg = $ld->search(
  -basedn => "o=Test Data,c=NZ",
  -scope => LDAP_SCOPE_SUBTREE,
  -filter => "(sn=Last)",
  -attrs => \@{['cn']},
  -attrsonly => 0);

my $search_result = $ld->parse_result($ld->result($search_msg));

if ($search_result->{'errcode'} != 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";
    }
  }
}

print "===== SEARCH_S\n";

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

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";
    }
  }
}

produces the following output:

===== SEARCH
dn: cn=Full,ou=Users,o=Test Data,c=nz
cn: Full
===== SEARCH_S
dn: cn=Full,ou=Users,o=Test Data,c=nz
cn: Full
sn: Last
objectClass: inetOrgPerson
objectClass: organizationalPerson
objectClass: person
objectClass: top
givenName: First

search() looks like the following:

sub search
{
...;
    if( !defined($attrs) ) {
        my @null_array = ();
        $attrs = \@null_array;
    }
...
}

search_s() looks like the following:

sub search_s
{
...;
    if( !defined($attrs) == undef ) {
        my @null_array = ();
        $attrs = \@null_array;
    }
...;
}

I think the conditional in search_s() is being parsed as:

if (!(defined($attrs) == undef)) {
}

In effect, if $attrs isn't passed at all, it's essentially a NOP - $attrs = undef and defined(undef) == undef.
But if $attrs is passed, defined($attrs) != undef - so the negation proceeds into the conditional block.

I'll submit a pull request for this shortly. :)

@phillipod phillipod added the bug label Apr 29, 2015
@phillipod phillipod self-assigned this Apr 29, 2015
quanah added a commit that referenced this issue Apr 29, 2015
 - Fixes #8: search_s() clobbers ATTRS parameter
@phillipod phillipod added this to the 3.0.4 milestone May 5, 2015
rra pushed a commit to whm/libnet-ldapapi-perl that referenced this issue Dec 25, 2020
  * New upstream release.
  * Fix undef comparison
  * Misc variable initializations to quiet warnings
  * Fixed sasl mechanisms initializtion
  * Examples cleanup
  * LDAPv3 extended operation support
  * New developer mode test suite
  * Fixed quanah/net-ldapapi#3: ldap_set_rebind_proc XS being called with
    invalid arguments from set_rebind_proc
  * Fixed quanah/net-ldapapi#6: ldap_sasl_bind has wrong prototype in
    LDAPapi.xs
  * Fixed quanah/net-ldapapi#8: search_s() clobbers ATTRS parameter
  * Fixed quanah/net-ldapapi#11: result() blocking when called with output
    from rename()
  * Fixed quanah/net-ldapapi#20: ldap_result() doesn't honour passed
    timeout value
  * Fixed quanah/net-ldapapi#21: ldap_set_option(LDAP_OPT_TIMEOUT, 1) on
    OpenLDAP returns -1
  * Fixed quanah/net-ldapapi#28: Server control responses get eaten after
    a NULL character in the berval
  * Fixed quanah/net-ldapapi#30: ldap_search_ext() and ldap_search_ext_s()
    segfault when used with timeout
  * Fixed quanah/net-ldapapi#31: ldap_result() and ldap_url_search_st()
    timeout parameters have a granularity of 1 second
  * Fixed quanah/net-ldapapi#40: Server control requests get eaten after a
    NULL character in the berval
  * Correct merge problem with POD error.
  * Update standards version to 3.9.8 (no changes required).

[dgit import package libnet-ldapapi-perl 3.0.4-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant