Skip to content

Commit 37f35d7

Browse files
vetinariliggitt
authored andcommitted
fix dn parsing without attr or value (#119)
fixes #114
1 parent b314d42 commit 37f35d7

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

dn.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ func ParseDN(str string) (*DN, error) {
143143
}
144144
} else if char == ',' || char == '+' {
145145
// We're done with this RDN or value, push it
146+
if len(attribute.Type) == 0 {
147+
return nil, errors.New("incomplete type, value pair")
148+
}
146149
attribute.Value = stringFromBuffer()
147150
rdn.Attributes = append(rdn.Attributes, attribute)
148151
attribute = new(AttributeTypeAndValue)

dn_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ func TestSuccessfulDNParsing(t *testing.T) {
7575

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

8587
for test, answer := range testcases {

0 commit comments

Comments
 (0)