aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-09-05 16:28:58 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-09-05 19:02:12 +0200
commiteb45aa4244bffd937b4175de5ca1d42c1cf2dbba (patch)
treed2d1b8987832303d416fbf1352c028b618ce8516
parent58efb7c6a566c512206af66b2183875e78dd7f65 (diff)
prog, sys: move dictionary of special strings to sys
It is target-specific.
-rw-r--r--prog/rand.go9
-rw-r--r--prog/target.go14
-rw-r--r--sys/init.go7
3 files changed, 20 insertions, 10 deletions
diff --git a/prog/rand.go b/prog/rand.go
index 1993d7461..7d69d758a 100644
--- a/prog/rand.go
+++ b/prog/rand.go
@@ -199,18 +199,15 @@ func (r *randGen) randStringImpl(s *state, vals []string) []byte {
}
return []byte(strings[r.Intn(len(strings))])
}
- dict := []string{"user", "keyring", "trusted", "system", "security", "selinux",
- "posix_acl_access", "mime_type", "md5sum", "nodev", "self",
- "bdev", "proc", "cgroup", "cpuset",
- "lo", "eth0", "eth1", "em0", "em1", "wlan0", "wlan1", "ppp0", "ppp1",
- "vboxnet0", "vboxnet1", "vmnet0", "vmnet1", "GPL"}
punct := []byte{'!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '\\',
'/', ':', '.', ',', '-', '\'', '[', ']', '{', '}'}
buf := new(bytes.Buffer)
for r.nOutOf(3, 4) {
switch {
case r.nOutOf(10, 21):
- buf.WriteString(dict[r.Intn(len(dict))])
+ if len(stringDictionary) != 0 {
+ buf.WriteString(stringDictionary[r.Intn(len(stringDictionary))])
+ }
case r.nOutOf(10, 11):
buf.Write([]byte{punct[r.Intn(len(punct))]})
default:
diff --git a/prog/target.go b/prog/target.go
index f5dde79f4..dee61b8e2 100644
--- a/prog/target.go
+++ b/prog/target.go
@@ -38,6 +38,10 @@ type Target struct {
// and optionally any calls that need to be inserted before the arg reference.
SpecialStructs map[string]func(g *Gen, typ *StructType, old *GroupArg) (Arg, []*Call)
+ // Special strings that can matter for the target.
+ // Used as fallback when string type does not have own dictionary.
+ StringDictionary []string
+
resourceMap map[string]*ResourceDesc
syscallMap map[string]*Syscall
resourceCtors map[string][]*Syscall
@@ -72,6 +76,7 @@ func RegisterTarget(target *Target) {
analyzeMmap = target.AnalyzeMmap
sanitizeCall = target.SanitizeCall
specialStructs = target.SpecialStructs
+ stringDictionary = target.StringDictionary
}
func initTarget(target *Target) {
@@ -110,8 +115,9 @@ var (
Resources map[string]*ResourceDesc
resourceCtors map[string][]*Syscall
- makeMmap func(start, npages uint64) *Call
- analyzeMmap func(c *Call) (start, npages uint64, mapped bool)
- sanitizeCall func(c *Call)
- specialStructs map[string]func(g *Gen, typ *StructType, old *GroupArg) (Arg, []*Call)
+ makeMmap func(start, npages uint64) *Call
+ analyzeMmap func(c *Call) (start, npages uint64, mapped bool)
+ sanitizeCall func(c *Call)
+ specialStructs map[string]func(g *Gen, typ *StructType, old *GroupArg) (Arg, []*Call)
+ stringDictionary []string
)
diff --git a/sys/init.go b/sys/init.go
index d0d3de82a..11d279ead 100644
--- a/sys/init.go
+++ b/sys/init.go
@@ -26,6 +26,7 @@ func init() {
"timespec": generateTimespec,
"timeval": generateTimespec,
},
+ StringDictionary: stringDictionary,
}
prog.RegisterTarget(target)
}
@@ -41,6 +42,12 @@ const (
var (
mmapSyscall *prog.Syscall
clockGettimeSyscall *prog.Syscall
+
+ stringDictionary = []string{"user", "keyring", "trusted", "system", "security", "selinux",
+ "posix_acl_access", "mime_type", "md5sum", "nodev", "self",
+ "bdev", "proc", "cgroup", "cpuset",
+ "lo", "eth0", "eth1", "em0", "em1", "wlan0", "wlan1", "ppp0", "ppp1",
+ "vboxnet0", "vboxnet1", "vmnet0", "vmnet1", "GPL"}
)
// createMmapCall creates a "normal" mmap call that maps [start, start+npages) page range.