Terminate on code EOF when not checking input

This commit is contained in:
lash 2023-04-10 09:19:18 +01:00
parent 602ca92b6a
commit 765bc2a269
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
3 changed files with 40 additions and 10 deletions

View File

@ -1,7 +1,8 @@
package state package state
const ( const (
FLAG_INMATCH = 1 FLAG_READIN = 1
FLAG_TERMINATE = 2 FLAG_INMATCH = 2
FLAG_TERMINATE = 3
FLAG_DIRTY = 4 FLAG_DIRTY = 4
) )

View File

@ -125,7 +125,19 @@ func(vm *Vm) RunDeadCheck(b []byte, ctx context.Context) ([]byte, error) {
if len(b) > 0 { if len(b) > 0 {
return b, nil return b, nil
} }
r, err := vm.st.MatchFlag(state.FLAG_TERMINATE, false) r, err := vm.st.MatchFlag(state.FLAG_READIN, true)
if err != nil {
panic(err)
}
if r {
log.Printf("Not processing input. Setting terminate")
_, err := vm.st.SetFlag(state.FLAG_TERMINATE)
if err != nil {
panic(err)
}
return b, nil
}
r, err = vm.st.MatchFlag(state.FLAG_TERMINATE, false)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -133,6 +145,8 @@ func(vm *Vm) RunDeadCheck(b []byte, ctx context.Context) ([]byte, error) {
log.Printf("Terminate found!!") log.Printf("Terminate found!!")
return b, nil return b, nil
} }
log.Printf("no code remaining but not terminating") log.Printf("no code remaining but not terminating")
location, _ := vm.st.Where() location, _ := vm.st.Where()
if location == "" { if location == "" {
@ -252,13 +266,25 @@ func(vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error) {
if err != nil { if err != nil {
return b, err return b, err
} }
v, err := vm.st.GetFlag(state.FLAG_INMATCH)
change, err := vm.st.SetFlag(state.FLAG_READIN)
if err != nil { if err != nil {
return b, err panic(err)
} }
if v { have, err := vm.st.GetFlag(state.FLAG_INMATCH)
if err != nil {
panic(err)
}
if have {
if change {
_, err = vm.st.ResetFlag(state.FLAG_INMATCH)
if err != nil {
panic(err)
}
} else {
return b, nil return b, nil
} }
}
input, err := vm.st.GetInput() input, err := vm.st.GetInput()
if err != nil { if err != nil {
return b, err return b, err
@ -275,7 +301,11 @@ func(vm *Vm) RunInCmp(b []byte, ctx context.Context) ([]byte, error) {
_, err = vm.st.SetFlag(state.FLAG_INMATCH) _, err = vm.st.SetFlag(state.FLAG_INMATCH)
if err != nil { if err != nil {
return b, err panic(err)
}
_, err = vm.st.ResetFlag(state.FLAG_READIN)
if err != nil {
panic(err)
} }
target, _, err = applyTarget([]byte(target), vm.st, vm.ca, ctx) target, _, err = applyTarget([]byte(target), vm.st, vm.ca, ctx)
@ -300,7 +330,6 @@ func(vm *Vm) RunHalt(b []byte, ctx context.Context) ([]byte, error) {
return b, err return b, err
} }
log.Printf("found HALT, stopping") log.Printf("found HALT, stopping")
_, err = vm.st.ResetFlag(state.FLAG_INMATCH)
return b, err return b, err
} }

View File

@ -396,6 +396,6 @@ func TestRunReturn(t *testing.T) {
} }
location, _ = st.Where() location, _ = st.Where()
if location != "root" { if location != "root" {
t.Fatalf("expected location 'foo', got '%s'", location) t.Fatalf("expected location 'root', got '%s'", location)
} }
} }