Skip to content

Commit 191cca8

Browse files
authored
Revert "fix: Limit maximum BER packet length in FuzzParseDN to 6553… (#500)
* Revert "fix: Limit maximum BER packet length in `FuzzParseDN` to 65536 bytes (#466)" This reverts commit 80095a3 * Fix index out of range crash
1 parent ff74b2c commit 191cca8

File tree

3 files changed

+5
-22
lines changed

3 files changed

+5
-22
lines changed

‎dn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (d *DN) String() string {
149149
func decodeString(str string) (string, error) {
150150
s := []rune(strings.TrimSpace(str))
151151
// Re-add the trailing space if the last character was an escaped space character
152-
if len(s) > 0 && s[len(s)-1] == '\\' && str[len(str)-2] == ' ' {
152+
if len(s) > 0 && s[len(s)-1] == '\\' && str[len(str)-1] == ' ' {
153153
s = append(s, ' ')
154154
}
155155

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

‎fuzz_test.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,7 @@
33

44
package ldap
55

6-
import (
7-
"os"
8-
"testing"
9-
10-
ber "github.com/go-asn1-ber/asn1-ber"
11-
)
12-
13-
func TestMain(m *testing.M) {
14-
// For fuzz tests
15-
// See https://github.com/go-asn1-ber/asn1-ber/blob/04301b4b1c5ff66221f8f8a394f814a9917d678a/fuzz_test.go#L33-L37
16-
// for why this limitation is necessary
17-
ber.MaxPacketLengthBytes = 65536
18-
19-
code := m.Run()
20-
os.Exit(code)
21-
}
6+
import "testing"
227

238
func FuzzParseDN(f *testing.F) {
249
f.Add("*")
@@ -33,7 +18,6 @@ func FuzzParseDN(f *testing.F) {
3318
}
3419

3520
func FuzzDecodeEscapedSymbols(f *testing.F) {
36-
3721
f.Add([]byte("a\u0100\x80"))
3822
f.Add([]byte(`start\d`))
3923
f.Add([]byte(`\`))
@@ -46,7 +30,6 @@ func FuzzDecodeEscapedSymbols(f *testing.F) {
4630
}
4731

4832
func FuzzEscapeDN(f *testing.F) {
49-
5033
f.Add("test,user")
5134
f.Add("#test#user#")
5235
f.Add("\\test\\user\\")

‎v3/dn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (d *DN) String() string {
149149
func decodeString(str string) (string, error) {
150150
s := []rune(strings.TrimSpace(str))
151151
// Re-add the trailing space if the last character was an escaped space character
152-
if len(s) > 0 && s[len(s)-1] == '\\' && str[len(str)-2] == ' ' {
152+
if len(s) > 0 && s[len(s)-1] == '\\' && str[len(str)-1] == ' ' {
153153
s = append(s, ' ')
154154
}
155155

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

0 commit comments

Comments
 (0)