Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
|
fuzz.go
Outdated
@@ -263,7 +273,11 @@ func (fc *fuzzerContext) doFuzz(v reflect.Value, flags uint64) { | |||
defer func() { fc.curDepth-- }() | |||
|
|||
if !v.CanSet() { | |||
return | |||
if fc.fuzzer.allowUnexportedFields{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure the field is addressable -- I think it always should be but verifying seems good.
if fc.fuzzer.allowUnexportedFields{ | |
if fc.fuzzer.allowUnexportedFields && v.CanAddr() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Daniel,
Thanks for the suggestion! I added that
fuzz.go
Outdated
return | ||
if fc.fuzzer.allowUnexportedFields{ | ||
v = reflect.NewAt(v.Type(), unsafe.Pointer(v.UnsafeAddr())).Elem() | ||
}else{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please run gofmt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just did gofmt, please checkout the latest files
fuzz.go
Outdated
@@ -263,7 +273,11 @@ func (fc *fuzzerContext) doFuzz(v reflect.Value, flags uint64) { | |||
defer func() { fc.curDepth-- }() | |||
|
|||
if !v.CanSet() { | |||
return | |||
if fc.fuzzer.allowUnexportedFields && v.CanAddr() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I was too slow making this comment -- can you flip the logic around on this?
if !fc.fuzzer.allowUnexportedFields || !v.CanAddr() {
return
}
v = reflect.NewAt(v.Type(), unsafe.Pointer(v.UnsafeAddr())).Elem()
This reduces the indentation. Minor style nit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem! I just did that.
And all tests passed
LGTM, I'll double check the tests in a bit because the CI integration seems to be off or not working. |
Cool! Looking forward to my first contribution to google lol |
Thanks for the change! |
The current
gofuzz
only support fuzzing the exported fields (i.e. the fields that start with an uppercase letter), other fields are simply filtered out according to this line.However, a lot of
struct
also contains un-exported fields (i.e. fields start with lowercase letters) and sometimes people want to do fuzzing on those structs. In this pr I fixed this problem by addingallowUnexportedFields
to the fuzzer, which allows user to decide whether they want to include unexported fields while fuzzing. It is set tofalse
by default. But it can be turned on withAllowUnexportedFields
function.Tests are also added.