aboutsummaryrefslogtreecommitdiffstats
path: root/prog/rand.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2022-08-09 12:40:58 +0200
committerDmitry Vyukov <dvyukov@google.com>2022-08-10 11:45:49 +0200
commit8fad22bf840fc968171bee6cf294f026eb1e0d3a (patch)
tree2bad644606904f4e75ef6fe689bac49e91877c40 /prog/rand.go
parenta12254451cfa5e5129a0c091255d502b6805adf6 (diff)
prog: generate very long file names
Generate very long file names once in a while to provoke bugs like: https://github.com/google/gvisor/commit/f857f268eceb1cdee0b2bdfa218c969c84033fcd
Diffstat (limited to 'prog/rand.go')
-rw-r--r--prog/rand.go28
1 files changed, 25 insertions, 3 deletions
diff --git a/prog/rand.go b/prog/rand.go
index 24662f6ff..1db5cd07a 100644
--- a/prog/rand.go
+++ b/prog/rand.go
@@ -278,6 +278,8 @@ func escapingFilename(file string) bool {
var specialFiles = []string{"", "."}
+const specialFileLenPad = "a"
+
func (r *randGen) filenameImpl(s *state) string {
if r.oneOf(100) {
return specialFiles[r.Intn(len(specialFiles))]
@@ -296,6 +298,15 @@ func (r *randGen) filenameImpl(s *state) string {
}
for i := 0; ; i++ {
f := fmt.Sprintf("%v/file%v", dir, i)
+ if r.oneOf(100) {
+ // Make file name very long using target.SpecialFileLenghts consts.
+ // Add/subtract some small const to account for our file name prefix
+ // and potential kernel off-by-one's.
+ fileLen := r.randFilenameLength()
+ if add := fileLen - len(f); add > 0 {
+ f += strings.Repeat(specialFileLenPad, add)
+ }
+ }
if !s.files[f] {
return f
}
@@ -304,6 +315,19 @@ func (r *randGen) filenameImpl(s *state) string {
return r.randFromMap(s.files)
}
+func (r *randGen) randFilenameLength() int {
+ off := r.biasedRand(10, 5)
+ if r.bin() {
+ off = -off
+ }
+ lens := r.target.SpecialFileLenghts
+ res := lens[r.Intn(len(lens))] + off
+ if res < 0 {
+ res = 0
+ }
+ return res
+}
+
func (r *randGen) randFromMap(m map[string]bool) string {
files := make([]string, 0, len(m))
for f := range m {
@@ -721,10 +745,8 @@ func (a *BufferType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*
sz = a.Size()
case r.nOutOf(1, 3):
sz = r.rand(100)
- case r.nOutOf(1, 2):
- sz = 108 // UNIX_PATH_MAX
default:
- sz = 4096 // PATH_MAX
+ sz = uint64(r.randFilenameLength())
}
return MakeOutDataArg(a, dir, sz), nil
}