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

Revert "fix: Limit maximum BER packet length in FuzzParseDN to 6553… #500

Merged
merged 2 commits into from
Apr 1, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 1 addition & 18 deletions fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,7 @@

package ldap

import (
"os"
"testing"

ber "github.com/go-asn1-ber/asn1-ber"
)

func TestMain(m *testing.M) {
// For fuzz tests
// See https://github.com/go-asn1-ber/asn1-ber/blob/04301b4b1c5ff66221f8f8a394f814a9917d678a/fuzz_test.go#L33-L37
// for why this limitation is necessary
ber.MaxPacketLengthBytes = 65536

code := m.Run()
os.Exit(code)
}
import "testing"

func FuzzParseDN(f *testing.F) {
f.Add("*")
Expand All @@ -33,7 +18,6 @@ func FuzzParseDN(f *testing.F) {
}

func FuzzDecodeEscapedSymbols(f *testing.F) {

f.Add([]byte("a\u0100\x80"))
f.Add([]byte(`start\d`))
f.Add([]byte(`\`))
Expand All @@ -46,7 +30,6 @@ func FuzzDecodeEscapedSymbols(f *testing.F) {
}

func FuzzEscapeDN(f *testing.F) {

f.Add("test,user")
f.Add("#test#user#")
f.Add("\\test\\user\\")
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
Loading