aboutsummaryrefslogtreecommitdiffstats
path: root/prog
diff options
context:
space:
mode:
authorJoey Jiaojg <joeyjiaojg@gmail.com>2021-05-26 19:38:04 +0800
committerGitHub <noreply@github.com>2021-05-26 13:38:04 +0200
commit3da9017c17c7d2432c4b76345c4d2efbeedd2935 (patch)
tree47e9b10fc542a1f5a1c785027ec6d2fce1a7dfef /prog
parent1f4e6ed95868861aae449b3630e6cfe5a2b96c93 (diff)
pkg/compiler: add glob type
* all: add new typename dirname The current way to check files under sysfs or proc is: - define a string to represent each file - open the file - pass the fd to write / read / close The issues above are: - Need to know what file present on target device - Need to write openat for each file With dirname added, which will open one file in the directory randomly and then pass the fd to write/read/close. * all: use typename glob to match filename Fixes #481
Diffstat (limited to 'prog')
-rw-r--r--prog/encoding.go2
-rw-r--r--prog/hints.go2
-rw-r--r--prog/mutation.go6
-rw-r--r--prog/prio.go2
-rw-r--r--prog/rand.go2
-rw-r--r--prog/target.go25
-rw-r--r--prog/types.go1
7 files changed, 37 insertions, 3 deletions
diff --git a/prog/encoding.go b/prog/encoding.go
index 140636865..e66535e2a 100644
--- a/prog/encoding.go
+++ b/prog/encoding.go
@@ -853,7 +853,7 @@ func encodeData(buf *bytes.Buffer, data []byte, readable, cstr bool) {
}
func isReadableDataType(typ *BufferType) bool {
- return typ.Kind == BufferString || typ.Kind == BufferFilename
+ return typ.Kind == BufferString || typ.Kind == BufferFilename || typ.Kind == BufferGlob
}
func isReadableData(data []byte) bool {
diff --git a/prog/hints.go b/prog/hints.go
index a26185010..c66242357 100644
--- a/prog/hints.go
+++ b/prog/hints.go
@@ -102,7 +102,7 @@ func generateHints(compMap CompMap, arg Arg, exec func()) {
case BufferFilename:
// This can generate escaping paths and is probably not too useful anyway.
return
- case BufferString:
+ case BufferString, BufferGlob:
if len(t.Values) != 0 {
// These are frequently file names or complete enumerations.
// Mutating these may be useful iff we intercept strcmp
diff --git a/prog/mutation.go b/prog/mutation.go
index af6a458f0..9d6dc2118 100644
--- a/prog/mutation.go
+++ b/prog/mutation.go
@@ -349,6 +349,12 @@ func (t *BufferType) mutate(r *randGen, s *state, arg Arg, ctx ArgCtx) (calls []
}
case BufferFilename:
a.data = []byte(r.filename(s, t))
+ case BufferGlob:
+ if len(t.Values) != 0 {
+ a.data = r.randString(s, t)
+ } else {
+ a.data = []byte(r.filename(s, t))
+ }
case BufferText:
data := append([]byte{}, a.Data()...)
a.data = r.mutateText(t.Text, data)
diff --git a/prog/prio.go b/prog/prio.go
index 2c3436151..4cf3daf90 100644
--- a/prog/prio.go
+++ b/prog/prio.go
@@ -97,7 +97,7 @@ func (target *Target) calcResourceUsage() map[string]map[int]weights {
case *BufferType:
switch a.Kind {
case BufferBlobRand, BufferBlobRange, BufferText:
- case BufferString:
+ case BufferString, BufferGlob:
if a.SubKind != "" {
noteUsage(uses, c, 2, ctx.Dir, fmt.Sprintf("str-%v", a.SubKind))
}
diff --git a/prog/rand.go b/prog/rand.go
index a78f7e343..7ab5068cb 100644
--- a/prog/rand.go
+++ b/prog/rand.go
@@ -734,6 +734,8 @@ func (a *BufferType) generate(r *randGen, s *state, dir Dir) (arg Arg, calls []*
return MakeOutDataArg(a, dir, sz), nil
}
return MakeDataArg(a, dir, []byte(r.filename(s, a))), nil
+ case BufferGlob:
+ return MakeDataArg(a, dir, r.randString(s, a)), nil
case BufferText:
if dir == DirOut {
return MakeOutDataArg(a, dir, uint64(r.Intn(100))), nil
diff --git a/prog/target.go b/prog/target.go
index f2eaf6ead..974880c22 100644
--- a/prog/target.go
+++ b/prog/target.go
@@ -227,6 +227,31 @@ func (target *Target) DefaultChoiceTable() *ChoiceTable {
return target.defaultChoiceTable
}
+func (target *Target) GetGlobs() []string {
+ var globs []string
+ ForeachType(target.Syscalls, func(typ Type, ctx TypeCtx) {
+ switch a := typ.(type) {
+ case *BufferType:
+ if a.Kind == BufferGlob && a.SubKind != "" {
+ globs = append(globs, a.SubKind)
+ }
+ }
+ })
+
+ return globs
+}
+
+func (target *Target) UpdateGlobFilesForType(globFiles map[string][]string) {
+ ForeachType(target.Syscalls, func(typ Type, ctx TypeCtx) {
+ switch a := typ.(type) {
+ case *BufferType:
+ if a.Kind == BufferGlob && a.SubKind != "" {
+ a.Values = globFiles[a.SubKind]
+ }
+ }
+ })
+}
+
type Gen struct {
r *randGen
s *state
diff --git a/prog/types.go b/prog/types.go
index fb680f0a1..66ce3ced0 100644
--- a/prog/types.go
+++ b/prog/types.go
@@ -481,6 +481,7 @@ const (
BufferString
BufferFilename
BufferText
+ BufferGlob
)
type TextKind int