From f2449bf51a86ab81bcf1a0f62529325dfc18c514 Mon Sep 17 00:00:00 2001 From: Arpit Jain Date: Wed, 4 Nov 2026 12:03:08 -0500 Subject: [PATCH] terms: reject a term that has no action Co-Authored-By: Claude Signed-off-by: Arpit Jain --- terms.go | 5 +++++ terms_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/terms.go b/terms.go index 2595f90..91dd360 100644 --- a/terms.go +++ b/terms.go @@ -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 diff --git a/terms_test.go b/terms_test.go index d1b302f..79cda29 100644 --- a/terms_test.go +++ b/terms_test.go @@ -92,3 +92,30 @@ func TestTermsTypes(t *testing.T) { } } } + +func TestTermsRejectsMissingAction(t *testing.T) { + const fpname = "github.com/pingcap/failpoint/missingAction" + // A term is " [ ( ) ]". 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) + } + } +}