Skip to content

Commit

Permalink
Avoid potential panic in LDAP client (#8047)
Browse files Browse the repository at this point in the history
* fix potential panic

* add comment

* vendor the ldap update

* use localhost in test
  • Loading branch information
tyrannosaurus-becks authored Dec 18, 2019
1 parent 0715c8b commit 39455f3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
7 changes: 4 additions & 3 deletions sdk/helper/ldaputil/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ func (c *Client) DialLDAP(cfg *ConfigEntry) (Connection, error) {
}
retErr = multierror.Append(retErr, errwrap.Wrapf(fmt.Sprintf("error connecting to host %q: {{err}}", uut), err))
}

if retErr != nil {
return nil, retErr
}
if timeout := cfg.RequestTimeout; timeout > 0 {
conn.SetTimeout(time.Duration(timeout) * time.Second)
}

return conn, retErr.ErrorOrNil()
return conn, nil
}

/*
Expand Down
20 changes: 20 additions & 0 deletions sdk/helper/ldaputil/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,28 @@ package ldaputil

import (
"testing"

"github.com/hashicorp/go-hclog"
)

// TestDialLDAP duplicates a potential panic that was
// present in the previous version of TestDialLDAP,
// then confirms its fix by passing.
func TestDialLDAP(t *testing.T) {
ldapClient := Client{
Logger: hclog.NewNullLogger(),
LDAP: NewLDAP(),
}

ce := &ConfigEntry{
Url: "ldap://localhost:384654786",
RequestTimeout: 3,
}
if _, err := ldapClient.DialLDAP(ce); err == nil {
t.Fatal("expected error")
}
}

func TestLDAPEscape(t *testing.T) {
testcases := map[string]string{
"#test": "\\#test",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 39455f3

Please sign in to comment.