aboutsummaryrefslogtreecommitdiffstats
path: root/prog/encoding.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-03-07 13:12:35 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-03-13 13:16:53 +0100
commit9b1f3e665308ee2ddd5b3f35a078219b5c509cdb (patch)
tree56e177dcb9b249381d27abacec5e59e9d2cf410f /prog/encoding.go
parent05359321bb37f035e55ccfad2cc36b0ea3b50998 (diff)
prog: control program length
We have _some_ limits on program length, but they are really soft. When we ask to generate a program with 10 calls, sometimes we get 100-150 calls. There are also no checks when we accept external programs from corpus/hub. Issue #1630 contains an example where this crashes VM (executor limit on number of 1000 resources is violated). Larger programs also harm the process overall (slower, consume more memory, lead to monster reproducers, etc). Add a set of measure for hard control over program length. Ensure that generated/mutated programs are not too long; drop too long programs coming from corpus/hub in manager; drop too long programs in hub. As a bonus ensure that mutation don't produce programs with 0 calls (which is currently possible and happens). Fixes #1630
Diffstat (limited to 'prog/encoding.go')
-rw-r--r--prog/encoding.go14
1 files changed, 8 insertions, 6 deletions
diff --git a/prog/encoding.go b/prog/encoding.go
index b36bf9637..6bded49d5 100644
--- a/prog/encoding.go
+++ b/prog/encoding.go
@@ -1130,8 +1130,9 @@ func (p *parser) strictFailf(msg string, args ...interface{}) {
// CallSet returns a set of all calls in the program.
// It does very conservative parsing and is intended to parse past/future serialization formats.
-func CallSet(data []byte) (map[string]struct{}, error) {
+func CallSet(data []byte) (map[string]struct{}, int, error) {
calls := make(map[string]struct{})
+ ncalls := 0
s := bufio.NewScanner(bytes.NewReader(data))
s.Buffer(nil, maxLineLen)
for s.Scan() {
@@ -1141,7 +1142,7 @@ func CallSet(data []byte) (map[string]struct{}, error) {
}
bracket := bytes.IndexByte(ln, '(')
if bracket == -1 {
- return nil, fmt.Errorf("line does not contain opening bracket")
+ return nil, 0, fmt.Errorf("line does not contain opening bracket")
}
call := ln[:bracket]
if eq := bytes.IndexByte(call, '='); eq != -1 {
@@ -1152,15 +1153,16 @@ func CallSet(data []byte) (map[string]struct{}, error) {
call = call[eq:]
}
if len(call) == 0 {
- return nil, fmt.Errorf("call name is empty")
+ return nil, 0, fmt.Errorf("call name is empty")
}
calls[string(call)] = struct{}{}
+ ncalls++
}
if err := s.Err(); err != nil {
- return nil, err
+ return nil, 0, err
}
if len(calls) == 0 {
- return nil, fmt.Errorf("program does not contain any calls")
+ return nil, 0, fmt.Errorf("program does not contain any calls")
}
- return calls, nil
+ return calls, ncalls, nil
}