Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions v3/dn.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,21 @@ func ParseDN(str string) (*DN, error) {
}

var (
rdn = &RelativeDN{}
attr = &AttributeTypeAndValue{}
escaping bool
rdn = &RelativeDN{}
attr = &AttributeTypeAndValue{}
escaping bool
// typeSet records whether the current attribute's type has been
// consumed. attr.Type being empty cannot serve as that marker: setType
// accepts a segment that decodes to the empty string, and treating the
// type as still unset would let a second '=' re-bind it, silently
// swallowing the empty leading segment ("=a=b" would parse as "a=b").
// The empty type itself is rejected by the length checks below.
typeSet bool
startPos int
appendAttributesToRDN = func(end bool) {
rdn.Attributes = append(rdn.Attributes, attr)
attr = &AttributeTypeAndValue{}
typeSet = false
if end {
dn.RDNs = append(dn.RDNs, rdn)
rdn = &RelativeDN{}
Expand All @@ -307,10 +315,11 @@ func ParseDN(str string) (*DN, error) {
escaping = false
case char == '\\':
escaping = true
case char == '=' && len(attr.Type) == 0:
case char == '=' && !typeSet:
if err := attr.setType(str[startPos:i]); err != nil {
return nil, err
}
typeSet = true
startPos = i + 1
case char == ',' || char == '+' || char == ';':
if len(attr.Type) == 0 {
Expand Down
4 changes: 4 additions & 0 deletions v3/dn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ func TestErrorDNParsing(t *testing.T) {
"cn=Jim\\0Test": "failed to decode escaped character: encoding/hex: invalid byte: U+0054 'T'",
"cn=Jim\\0": "failed to decode escaped character: encoding/hex: invalid byte: 0",
"DC=example,=net": "DN ended with incomplete type, value pair",
"=DC=example": "DN ended with incomplete type, value pair",
"DC=example,=DC=net": "DN ended with incomplete type, value pair",
"cn=a+=cn=b": "DN ended with incomplete type, value pair",
"=cn=admin,dc=net": "incomplete type, value pair",
"1=#0402486": "failed to decode BER encoding: encoding/hex: odd length hex string",
"1=#0402486900": "failed to decode BER encoding: trailing bytes after value",
"1=#04024869ffff,DC=net": "failed to decode BER encoding: trailing bytes after value",
Expand Down
Loading