Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a memory bug in ldap's ParseDN function by disabling part of the functionality #6770

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/util/pki/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,12 @@ func TestMustKeepOrderInRawDerBytes(t *testing.T) {
assert.Equal(t, expectedRdnSeq, rdnSeq)
assert.Equal(t, subject, rdnSeq.String())
}

func TestShouldFailForHexDER(t *testing.T) {
_, err := ParseSubjectStringToRawDERBytes("DF=#6666666666665006838820013100000746939546349182108463491821809FBFFFFFFFFF")
if err == nil {
t.Fatal("expected error, but got none")
}

assert.Contains(t, err.Error(), "unsupported distinguished name (DN) \"DF=#6666666666665006838820013100000746939546349182108463491821809FBFFFFFFFFF\": notation does not support x509.subject identities containing \"=#\"")
}
6 changes: 6 additions & 0 deletions pkg/util/pki/subject.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"crypto/x509/pkix"
"encoding/asn1"
"errors"
"fmt"
"strings"

"github.com/go-ldap/ldap/v3"
)
Expand Down Expand Up @@ -66,6 +68,10 @@ var attributeTypeNames = map[string][]int{
}

func UnmarshalSubjectStringToRDNSequence(subject string) (pkix.RDNSequence, error) {
if strings.Contains(subject, "=#") {
return nil, fmt.Errorf("unsupported distinguished name (DN) %q: notation does not support x509.subject identities containing \"=#\"", subject)
}

dns, err := ldap.ParseDN(subject)
if err != nil {
return nil, err
Expand Down