Skip to content

Commit

Permalink
Fix index out of range crash
Browse files Browse the repository at this point in the history
  • Loading branch information
cpuschma committed Apr 1, 2024
1 parent 084aa8b commit aae72ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions dn.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (d *DN) String() string {
func decodeString(str string) (string, error) {
s := []rune(strings.TrimSpace(str))
// Re-add the trailing space if the last character was an escaped space character
if len(s) > 0 && s[len(s)-1] == '\\' && str[len(str)-2] == ' ' {
if len(s) > 0 && s[len(s)-1] == '\\' && str[len(str)-1] == ' ' {
s = append(s, ' ')
}

Expand Down Expand Up @@ -234,7 +234,7 @@ func decodeEncodedString(str string) (string, error) {
// The function respects https://tools.ietf.org/html/rfc4514
func ParseDN(str string) (*DN, error) {
var dn = &DN{RDNs: make([]*RelativeDN, 0)}
if str = strings.TrimSpace(str); len(str) == 0 {
if strings.TrimSpace(str) == "" {
return dn, nil
}

Expand Down
4 changes: 2 additions & 2 deletions v3/dn.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (d *DN) String() string {
func decodeString(str string) (string, error) {
s := []rune(strings.TrimSpace(str))
// Re-add the trailing space if the last character was an escaped space character
if len(s) > 0 && s[len(s)-1] == '\\' && str[len(str)-2] == ' ' {
if len(s) > 0 && s[len(s)-1] == '\\' && str[len(str)-1] == ' ' {
s = append(s, ' ')
}

Expand Down Expand Up @@ -234,7 +234,7 @@ func decodeEncodedString(str string) (string, error) {
// The function respects https://tools.ietf.org/html/rfc4514
func ParseDN(str string) (*DN, error) {
var dn = &DN{RDNs: make([]*RelativeDN, 0)}
if str = strings.TrimSpace(str); len(str) == 0 {
if strings.TrimSpace(str) == "" {
return dn, nil
}

Expand Down

0 comments on commit aae72ab

Please sign in to comment.