diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-01-05 11:46:35 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-01-05 11:46:35 +0100 |
| commit | 026aaeb2b5393e0c838873306e1c5f2084a8a1aa (patch) | |
| tree | 348d47a986a845325a08fe21ab833f0ea81ec31e /prog/encoding.go | |
| parent | 90408076e697f47d8da739b9ee6ea1da33c74bbd (diff) | |
prog: don't mutate strings with enumerated values
Strings with enumerated values are frequently file names
or have complete enumeration of relevant values.
Mutating complete enumeration if not very profitable.
Mutating file names leads to escaping paths and
fuzzer messing with things it is not supposed to mess with as in:
r0 = openat$apparmor_task_exec(0xffffffffffffff9c, &(0x7f0000000440)='/proc/self//exe\x00', 0x3, 0x0)
Diffstat (limited to 'prog/encoding.go')
| -rw-r--r-- | prog/encoding.go | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/prog/encoding.go b/prog/encoding.go index 943dfe350..f288dbc93 100644 --- a/prog/encoding.go +++ b/prog/encoding.go @@ -506,10 +506,11 @@ func (p *parser) parseArgAddr(typ Type) (Arg, error) { return arg, nil } -func (p *parser) parseArgString(typ Type) (Arg, error) { - if _, ok := typ.(*BufferType); !ok { +func (p *parser) parseArgString(t Type) (Arg, error) { + typ, ok := t.(*BufferType) + if !ok { p.eatExcessive(true, "wrong string arg") - return typ.DefaultArg(), nil + return t.DefaultArg(), nil } data, err := p.deserializeData() if err != nil { @@ -541,6 +542,19 @@ func (p *parser) parseArgString(typ Type) (Arg, error) { data = append(data, make([]byte, diff)...) } data = data[:size] + if typ.Kind == BufferString && len(typ.Values) != 0 { + matched := false + for _, val := range typ.Values { + if string(data) == val { + matched = true + break + } + } + if !matched { + p.strictFailf("bad string value %q, expect %q", data, typ.Values) + data = []byte(typ.Values[0]) + } + } return MakeDataArg(typ, data), nil } |
