diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2016-11-17 18:38:10 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2016-11-17 18:38:10 +0100 |
| commit | cd74cc9cf40795144dfbd7e933dcd10d220916f6 (patch) | |
| tree | 6c1e55891acf53909da12aad34c86409be8c20a6 /prog/encoding.go | |
| parent | 3ad1f7a214ba9f22499ae6b2b8cc1f0b824073eb (diff) | |
syz-hub: add program
syz-hub is used to exchange programs between syz-managers.
Diffstat (limited to 'prog/encoding.go')
| -rw-r--r-- | prog/encoding.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/prog/encoding.go b/prog/encoding.go index 7afe218be..11c86fb44 100644 --- a/prog/encoding.go +++ b/prog/encoding.go @@ -516,3 +516,36 @@ func (p *parser) Ident() string { func (p *parser) failf(msg string, args ...interface{}) { p.e = fmt.Errorf("%v\nline #%v: %v", fmt.Sprintf(msg, args...), p.l, p.s) } + +// CallSet returns a set of all calls in the program. +// It does very conservative parsing and is intended to parse paste/future serialization formats. +func CallSet(data []byte) (map[string]struct{}, error) { + calls := make(map[string]struct{}) + s := bufio.NewScanner(bytes.NewReader(data)) + for s.Scan() { + ln := s.Bytes() + if len(ln) == 0 || ln[0] == '#' { + continue + } + bracket := bytes.IndexByte(ln, '(') + if bracket == -1 { + return nil, fmt.Errorf("line does not contain opening bracket") + } + call := ln[:bracket] + if eq := bytes.IndexByte(call, '='); eq != -1 { + eq++ + for eq < len(call) && call[eq] == ' ' { + eq++ + } + call = call[eq:] + } + if len(call) == 0 { + return nil, fmt.Errorf("call name is empty") + } + calls[string(call)] = struct{}{} + } + if len(calls) == 0 { + return nil, fmt.Errorf("program does not contain any calls") + } + return calls, nil +} |
