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

[Fuzzing] Add fuzz testing #448

Merged
merged 3 commits into from
Aug 5, 2023
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
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ test:
quicktest:
go test ./...

fuzz:
go test -fuzz=FuzzParseDN -fuzztime=600s .
go test -fuzz=FuzzDecodeEscapedSymbols -fuzztime=600s .
go test -fuzz=FuzzEscapeDN -fuzztime=600s .

# Capture output and force failure when there is non-empty output
fmt:
@echo gofmt -l .
Expand Down
47 changes: 47 additions & 0 deletions fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//go:build go1.18
// +build go1.18
Comment on lines +1 to +2
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review this hack.


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 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)
})
}