diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2026-02-06 10:18:00 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2026-02-06 09:29:53 +0000 |
| commit | 5f7c2dee8fbb40bb5418c441edb8a8efe5f260e2 (patch) | |
| tree | 4fa72589c27dc74a69bbcbfb6e1cbd65835c0433 /pkg/aflow/tool | |
| parent | 04f20e27d89a599725baf1048aba0db288c01153 (diff) | |
pkg/aflow/tool/grepper: fix grep invocation
If LLM searches for "->", grep considered it as a flag and failed.
Add "--" before the expression to fix such cases.
Diffstat (limited to 'pkg/aflow/tool')
| -rw-r--r-- | pkg/aflow/tool/grepper/grepper.go | 19 | ||||
| -rw-r--r-- | pkg/aflow/tool/grepper/grepper_test.go | 10 |
2 files changed, 21 insertions, 8 deletions
diff --git a/pkg/aflow/tool/grepper/grepper.go b/pkg/aflow/tool/grepper/grepper.go index ea3737c88..954508471 100644 --- a/pkg/aflow/tool/grepper/grepper.go +++ b/pkg/aflow/tool/grepper/grepper.go @@ -5,9 +5,10 @@ package grepper import ( "bytes" + "errors" "fmt" + "os/exec" "slices" - "strings" "time" "github.com/google/syzkaller/pkg/aflow" @@ -44,14 +45,16 @@ type results struct { func grepper(ctx *aflow.Context, state state, args args) (results, error) { output, err := osutil.RunCmd(time.Hour, state.KernelSrc, "git", "grep", "--extended-regexp", - "--line-number", "--show-function", "-C1", "--no-color", args.Expression) + "--line-number", "--show-function", "-C1", "--no-color", "--", args.Expression) if err != nil { - // This should mean an invalid expression. - if bytes.Contains(output, []byte("fatal:")) { - return results{}, aflow.BadCallError("bad expression: %s", bytes.TrimSpace(output)) - } - if strings.Contains(err.Error(), "exit status 1") && len(output) == 0 { - return results{}, aflow.BadCallError("no matches") + if exitErr := new(exec.ExitError); errors.As(err, &exitErr) { + if exitErr.ExitCode() == 1 && len(output) == 0 { + return results{}, aflow.BadCallError("no matches") + } + // This should mean an invalid expression. + if exitErr.ExitCode() == 128 && bytes.Contains(output, []byte("fatal:")) { + return results{}, aflow.BadCallError("bad expression: %s", bytes.TrimSpace(output)) + } } return results{}, fmt.Errorf("%w\n%s", err, output) } diff --git a/pkg/aflow/tool/grepper/grepper_test.go b/pkg/aflow/tool/grepper/grepper_test.go index 6f93df2dd..8f2123d82 100644 --- a/pkg/aflow/tool/grepper/grepper_test.go +++ b/pkg/aflow/tool/grepper/grepper_test.go @@ -81,4 +81,14 @@ foo.c-6- line; args{Expression: "bad expression ("}, results{}, `bad expression: fatal: command line, 'bad expression (': Unmatched ( or \(`) + aflow.TestTool(t, Tool, + state{KernelSrc: repo.Dir}, + args{Expression: "->root"}, + results{}, + "no matches") + aflow.TestTool(t, Tool, + state{KernelSrc: repo.Dir}, + args{Expression: `-\>root`}, + results{}, + "no matches") } |
