Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Add note to docs that private fields of structs cannot be fuzzed using this package #44

Open
ericcornelissen opened this issue Jul 23, 2020 · 2 comments

Comments

@ericcornelissen
Copy link
Contributor

ericcornelissen commented Jul 23, 2020

I tried to use this package (through go-fuzz) for the first time when I was fuzzing a struct that has only private fields. It took me a while to figure out that this package doesn't put any values into private fields...

Now, I'm not terribly familiar with reflection in Go but from what I can tell based on the reflection docs and some testing is that it would be impossible for this package to set the value of private fields. Am i correct?

If the above statement is correct, I think it would be useful if there was a note in the README (or somewhere else in the docs) stating that private fields cannot be populated by this package. Thoughts?

@lavalamp
Copy link
Contributor

Yes, you're correct, and I agree a note in the README seems useful.

@ericcornelissen
Copy link
Contributor Author

I'm not sure where in the README you would want to add this, but I think having a note somewhere stating something as simple as:

"gofuzz cannot set the value of private fields."

Would suffice.

Maybe after the first example with a struct like so:


...
Customize the chance of getting a nil pointer:

f := fuzz.New().NilChance(.5)
var fancyStruct struct {
  A, B, C, D *string
}
f.Fuzz(&fancyStruct) // About half the pointers should be set.

ℹ️ Note: gofuzz cannot set the value of private fields.

You can even customize the randomization completely if needed:
...


Or just at the end of the document, so that it's easy in the future to add more notes like this one:


...
Happy testing!

Caveats

  • gofuzz cannot set the value of private fields.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants