aboutsummaryrefslogtreecommitdiffstats
path: root/prog/minimization.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/minimization.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/minimization.go')
-rw-r--r--prog/minimization.go60
1 files changed, 42 insertions, 18 deletions
diff --git a/prog/minimization.go b/prog/minimization.go
index 26a4dfc93..fcb681054 100644
--- a/prog/minimization.go
+++ b/prog/minimization.go
@@ -4,6 +4,7 @@
package prog
import (
+ "bytes"
"fmt"
"reflect"
)
@@ -294,30 +295,53 @@ func (typ *ResourceType) minimize(ctx *minimizeArgsCtx, arg Arg, path string) bo
}
func (typ *BufferType) minimize(ctx *minimizeArgsCtx, arg Arg, path string) bool {
- // TODO: try to set individual bytes to 0
- if typ.Kind != BufferBlobRand && typ.Kind != BufferBlobRange || arg.Dir() == DirOut {
+ if arg.Dir() == DirOut {
return false
}
a := arg.(*DataArg)
- len0 := len(a.Data())
- minLen := int(typ.RangeBegin)
- for step := len(a.Data()) - minLen; len(a.Data()) > minLen && step > 0; {
- if len(a.Data())-step >= minLen {
- a.data = a.Data()[:len(a.Data())-step]
- ctx.target.assignSizesCall(ctx.call)
- if ctx.pred(ctx.p, ctx.callIndex0) {
- continue
+ switch typ.Kind {
+ case BufferBlobRand, BufferBlobRange:
+ // TODO: try to set individual bytes to 0
+ len0 := len(a.Data())
+ minLen := int(typ.RangeBegin)
+ for step := len(a.Data()) - minLen; len(a.Data()) > minLen && step > 0; {
+ if len(a.Data())-step >= minLen {
+ a.data = a.Data()[:len(a.Data())-step]
+ ctx.target.assignSizesCall(ctx.call)
+ if ctx.pred(ctx.p, ctx.callIndex0) {
+ continue
+ }
+ a.data = a.Data()[:len(a.Data())+step]
+ ctx.target.assignSizesCall(ctx.call)
+ }
+ step /= 2
+ if ctx.crash {
+ break
}
- a.data = a.Data()[:len(a.Data())+step]
- ctx.target.assignSizesCall(ctx.call)
}
- step /= 2
- if ctx.crash {
- break
+ if len(a.Data()) != len0 {
+ *ctx.p0 = ctx.p
+ ctx.triedPaths[path] = true
+ return true
+ }
+ case BufferFilename:
+ // Try to undo target.SpecialFileLenghts mutation
+ // and reduce file name length.
+ if !typ.Varlen() {
+ return false
+ }
+ data0 := append([]byte{}, a.Data()...)
+ a.data = bytes.TrimRight(a.Data(), specialFileLenPad+"\x00")
+ if !typ.NoZ {
+ a.data = append(a.data, 0)
+ }
+ if bytes.Equal(a.data, data0) {
+ return false
+ }
+ ctx.target.assignSizesCall(ctx.call)
+ if ctx.pred(ctx.p, ctx.callIndex0) {
+ *ctx.p0 = ctx.p
}
- }
- if len(a.Data()) != len0 {
- *ctx.p0 = ctx.p
ctx.triedPaths[path] = true
return true
}