From 20d87f19ac70562df042c5381f929facf8171448 Mon Sep 17 00:00:00 2001 From: Hanno Hecker Date: Tue, 27 Jun 2017 07:42:34 +0200 Subject: [PATCH] fix dn parsing without attr or value fixes #114 --- dn.go | 3 +++ dn_test.go | 12 +++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dn.go b/dn.go index a8ece314..857b2ca7 100644 --- a/dn.go +++ b/dn.go @@ -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) diff --git a/dn_test.go b/dn_test.go index 5055cc15..af5fc146 100644 --- a/dn_test.go +++ b/dn_test.go @@ -75,11 +75,13 @@ 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", + "=test,DC=example,DC=com": "incomplete type, value pair", } for test, answer := range testcases {