Skip to content

Commit

Permalink
fix dn parsing without attr or value
Browse files Browse the repository at this point in the history
fixes #114
  • Loading branch information
vetinari committed Jun 26, 2017
1 parent 13cedcf commit ffac451
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 3 additions & 0 deletions dn.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ func ParseDN(str string) (*DN, error) {
}
} else if char == ',' || char == '+' {
// We're done with this RDN or value, push it
if len(attribute.Type) == 0 {
return nil, errors.New("incomplete type, value pair")
}
attribute.Value = stringFromBuffer()
rdn.Attributes = append(rdn.Attributes, attribute)
attribute = new(AttributeTypeAndValue)
Expand Down
11 changes: 6 additions & 5 deletions dn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ func TestSuccessfulDNParsing(t *testing.T) {

func TestErrorDNParsing(t *testing.T) {
testcases := map[string]string{
"*": "DN ended with incomplete type, value pair",
"cn=Jim\\0Test": "Failed to decode escaped character: encoding/hex: invalid byte: U+0054 'T'",
"cn=Jim\\0": "Got corrupted escaped character",
"DC=example,=net": "DN ended with incomplete type, value pair",
"1=#0402486": "Failed to decode BER encoding: encoding/hex: odd length hex string",
"*": "DN ended with incomplete type, value pair",
"cn=Jim\\0Test": "Failed to decode escaped character: encoding/hex: invalid byte: U+0054 'T'",
"cn=Jim\\0": "Got corrupted escaped character",
"DC=example,=net": "DN ended with incomplete type, value pair",
"1=#0402486": "Failed to decode BER encoding: encoding/hex: odd length hex string",
"test,DC=example,DC=com": "incomplete type, value pair",
}

for test, answer := range testcases {
Expand Down

0 comments on commit ffac451

Please sign in to comment.