Skip to content

Commit

Permalink
[Fuzzing] Add fuzz testing
Browse files Browse the repository at this point in the history
Signed-off-by: Arjun Singh <[email protected]>
  • Loading branch information
0x34d committed Aug 1, 2023
1 parent 7778a1c commit cf5b879
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ test:
quicktest:
go test ./...

fuzz:
go test -fuzz=FuzzParseDN -fuzztime=10s $(PWD)/
go test -fuzz=FuzzDecodeEscapedSymbols -fuzztime=10s $(PWD)/
go test -fuzz=FuzzEscapeFilter -fuzztime=10s $(PWD)/
go test -fuzz=FuzzEscapeDN -fuzztime=10s $(PWD)/

# Capture output and force failure when there is non-empty output
fmt:
@echo gofmt -l .
Expand Down
57 changes: 57 additions & 0 deletions fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//go:build go1.18
// +build go1.18

package ldap

import "testing"

func FuzzParseDN(f *testing.F) {

f.Add("*")
f.Add("cn=Jim\\0Test")
f.Add("cn=Jim\\0")
f.Add("DC=example,=net")
f.Add("o=a+o=B")

f.Fuzz(func(t *testing.T, input_data string) {
_, _ = ParseDN(input_data)
})
}

func FuzzDecodeEscapedSymbols(f *testing.F) {

f.Add([]byte("a\u0100\x80"))
f.Add([]byte(`start\d`))
f.Add([]byte(`\`))
f.Add([]byte(`start\--end`))
f.Add([]byte(`start\d0\hh`))

f.Fuzz(func(t *testing.T, input_data []byte) {
_, _ = decodeEscapedSymbols(input_data)
})
}

func FuzzEscapeFilter(f *testing.F) {

f.Add("a\x00b(c)d*e\\f")
f.Add("Lučić")

f.Fuzz(func(t *testing.T, input_data string) {
_ = EscapeFilter(input_data)
})
}

func FuzzEscapeDN(f *testing.F) {

f.Add("test,user")
f.Add("#test#user#")
f.Add("\\test\\user\\")
f.Add(" test user ")
f.Add("\u0000te\x00st\x00user" + string(rune(0)))
f.Add("test\"+,;<>\\-_user")
f.Add("test\u0391user ")

f.Fuzz(func(t *testing.T, input_data string) {
_ = EscapeDN(input_data)
})
}

0 comments on commit cf5b879

Please sign in to comment.