Avoid potential panic in LDAP client (#8047)

* fix potential panic

* add comment

* vendor the ldap update

* use localhost in test
This commit is contained in:
Becca Petrin 2019-12-17 16:33:59 -08:00 committed by GitHub
parent bbb32238d5
commit 3d7cdea66f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 6 deletions

View File

@ -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
}
/*

View File

@ -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",

View File

@ -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
}
/*