Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions terms.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ func parseTerm(desc string, fp *Failpoint) *term {
modStr, mods := parseMod(desc)
t.mods = &modList{mods}
actStr, act := parseAct(desc[len(modStr):])
if act == nil {
// A term without an action has nothing to run, and calling its
// nil act func later panics.
return nil
}
t.act = act
valStr, val := parseVal(desc[len(modStr)+len(actStr):])
t.val = val
Expand Down
27 changes: 27 additions & 0 deletions terms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,30 @@ func TestTermsTypes(t *testing.T) {
}
}
}

func TestTermsRejectsMissingAction(t *testing.T) {
const fpname = "github.com/pingcap/failpoint/missingAction"
// A term is "<mod> <act> [ ( <val> ) ]". With the action left out there
// is nothing to run, and the chain used to be accepted and then call a
// nil act func on the first evaluation.
for _, desc := range []string{`1*`, `100%`, `1*2*`, `100.0%`} {
if _, err := newTerms(desc, nil); err == nil {
t.Errorf("newTerms(%q) was accepted, want a parse error", desc)
}
if err := Enable(fpname, desc); err != nil {
continue
}
func() {
defer func() {
if r := recover(); r != nil {
t.Errorf("Enable(%q) was accepted and the failpoint then panicked: %v", desc, r)
}
}()
_, _ = Eval(fpname)
t.Errorf("Enable(%q) was accepted, want a parse error", desc)
}()
if err := Disable(fpname); err != nil {
t.Fatal(err)
}
}
}
Loading