mirror of
https://github.com/reactos/syzkaller-ros.git
synced 2025-03-03 17:08:10 +00:00
prog: validate deserialized programs
The optimization change removed validation too aggressively. We do need program validation during deserialization, because we can get bad programs from corpus or hub. Restore program validation after deserialization.
This commit is contained in:
parent
40c6a8ebf5
commit
40723a067e
@ -15,8 +15,10 @@ func (p *Prog) Clone() *Prog {
|
||||
}
|
||||
p1.Calls = append(p1.Calls, c1)
|
||||
}
|
||||
if err := p1.validate(); err != nil {
|
||||
panic(err)
|
||||
if debug {
|
||||
if err := p1.validate(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return p1
|
||||
}
|
||||
|
@ -27,8 +27,10 @@ func (p *Prog) String() string {
|
||||
}
|
||||
|
||||
func (p *Prog) Serialize() []byte {
|
||||
if err := p.validate(); err != nil {
|
||||
panic("serializing invalid program")
|
||||
if debug {
|
||||
if err := p.validate(); err != nil {
|
||||
panic("serializing invalid program")
|
||||
}
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
vars := make(map[*Arg]int)
|
||||
@ -173,6 +175,9 @@ func Deserialize(data []byte) (prog *Prog, err error) {
|
||||
if err := p.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// This validation is done even in non-debug mode because deserialization
|
||||
// procedure does not catch all bugs (e.g. mismatched types).
|
||||
// And we can receive bad programs from corpus and hub.
|
||||
if err := prog.validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -35,8 +35,10 @@ const (
|
||||
// SerializeForExec serializes program p for execution by process pid into the provided buffer.
|
||||
// If the provided buffer is too small for the program an error is returned.
|
||||
func (p *Prog) SerializeForExec(buffer []byte, pid int) error {
|
||||
if err := p.validate(); err != nil {
|
||||
panic(fmt.Errorf("serializing invalid program: %v", err))
|
||||
if debug {
|
||||
if err := p.validate(); err != nil {
|
||||
panic(fmt.Errorf("serializing invalid program: %v", err))
|
||||
}
|
||||
}
|
||||
var instrSeq uintptr
|
||||
w := &execContext{
|
||||
|
@ -20,8 +20,10 @@ func Generate(rs rand.Source, ncalls int, ct *ChoiceTable) *Prog {
|
||||
p.Calls = append(p.Calls, c)
|
||||
}
|
||||
}
|
||||
if err := p.validate(); err != nil {
|
||||
panic(err)
|
||||
if debug {
|
||||
if err := p.validate(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
@ -233,8 +233,10 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable, corpus []*Pro
|
||||
for _, c := range p.Calls {
|
||||
sanitizeCall(c)
|
||||
}
|
||||
if err := p.validate(); err != nil {
|
||||
panic(err)
|
||||
if debug {
|
||||
if err := p.validate(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,9 +17,6 @@ type validCtx struct {
|
||||
}
|
||||
|
||||
func (p *Prog) validate() error {
|
||||
if !debug {
|
||||
return nil
|
||||
}
|
||||
ctx := &validCtx{make(map[*Arg]bool), make(map[*Arg]*Arg)}
|
||||
for _, c := range p.Calls {
|
||||
if err := c.validate(ctx); err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user