Skip to content

Commit

Permalink
fix unbalanced parenthesis panic when compiling filter
Browse files Browse the repository at this point in the history
fixes #117
  • Loading branch information
vetinari committed Jun 26, 2017
1 parent 13cedcf commit 72bdde1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ func CompileFilter(filter string) (*ber.Packet, error) {
if err != nil {
return nil, err
}
if pos != len(filter) {
switch {
case pos > len(filter):
return nil, NewError(ErrorFilterCompile, errors.New("ldap: unexpected end of filter"))
case pos < len(filter):
return nil, NewError(ErrorFilterCompile, errors.New("ldap: finished compiling filter with extra at end: "+fmt.Sprint(filter[pos:])))
}
return packet, nil
Expand Down
6 changes: 6 additions & 0 deletions filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ var testFilters = []compileTest{
expectedType: 0,
expectedErr: "unexpected end of filter",
},
compileTest{
filterStr: `((cn=)`,
expectedFilter: ``,
expectedType: 0,
expectedErr: "unexpected end of filter",
},
compileTest{
filterStr: `(&(objectclass=inetorgperson)(cn=中文))`,
expectedFilter: `(&(objectclass=inetorgperson)(cn=\e4\b8\ad\e6\96\87))`,
Expand Down

0 comments on commit 72bdde1

Please sign in to comment.