feat(verify): scalar arguments for -call invocations

This commit is contained in:
2026-08-29 14:03:45 +02:00
parent 6fb9629ab6
commit e44162a749
3 changed files with 136 additions and 6 deletions
+28 -6
View File
@@ -1067,6 +1067,7 @@ decoders) that crash on random input but should succeed on valid data.
sweepOne := fs.String("sweep-one", "", "") // hidden: smoke/abi a single function (subprocess mode)
call := fs.String("call", "", "call a single function with -buf instead of the sweeps")
bufSpec := fs.String("buf", "", "buffer spec for -call: name:size:pattern[,name:size:pattern] (zero, ones, seq, or hex)")
scalarSpec := fs.String("args", "", "scalar args for -call: name=value[,name=value] (decimal or 0x hex)")
repeat := fs.Int("repeat", 1, "number of times to repeat a -call invocation")
fs.Parse(args)
if fs.NArg() != 1 {
@@ -1105,7 +1106,7 @@ decoders) that crash on random input but should succeed on valid data.
// Single-function call mode: invoke one function with user-supplied buffers.
if *call != "" {
return cmdVerifyCall(k, path, *call, *bufSpec, *repeat)
return cmdVerifyCall(k, path, *call, *bufSpec, *scalarSpec, *repeat)
}
// Subprocess mode: fuzz a single function and exit.
@@ -1451,11 +1452,11 @@ func runSweepChecks(k *verify.Kernel, path, name string, fl asm.FuncLayout, smok
return msgs, failed
}
// cmdVerifyCall implements `gasm verify --call <func> [--buf spec] [--repeat n]`.
// It invokes a single function with user-supplied buffers and prints the arg
// block before and after the call, so the user can inspect return values and
// any output written to the buffers.
func cmdVerifyCall(k *verify.Kernel, path, funcName, bufSpec string, repeat int) int {
// cmdVerifyCall implements `gasm verify --call <func> [--buf spec] [--args spec] [--repeat n]`.
// It invokes a single function with user-supplied buffers and scalar
// arguments and prints the arg block before and after the call, so the user
// can inspect return values and any output written to the buffers.
func cmdVerifyCall(k *verify.Kernel, path, funcName, bufSpec, scalarSpec string, repeat int) int {
fl, err := k.Func(funcName)
if err != nil {
fmt.Fprintf(os.Stderr, "gasm verify: %v\n", err)
@@ -1493,6 +1494,16 @@ func cmdVerifyCall(k *verify.Kernel, path, funcName, bufSpec string, repeat int)
defer pool.Close()
args := pool.BuildArgs(layout, fl.Args)
scalars, err := verify.ParseScalarArgs(scalarSpec)
if err != nil {
fmt.Fprintf(os.Stderr, "gasm verify: %v\n", err)
return 1
}
if err := verify.ApplyScalarArgs(args, layout, scalars); err != nil {
fmt.Fprintf(os.Stderr, "gasm verify: %v\n", err)
return 1
}
fmt.Printf("%s: %d bytes, args=%d\n", funcName, fl.Size, fl.Args)
fmt.Printf(" signature: func %s(%s) %s\n", sig.Name, formatParams(sig.Params), formatResults(sig.Results))
if len(specs) > 0 {
@@ -1501,6 +1512,17 @@ func cmdVerifyCall(k *verify.Kernel, path, funcName, bufSpec string, repeat int)
fmt.Printf(" %s: %d bytes, pattern=%s\n", s.Name, s.Size, s.Pattern)
}
}
if len(scalars) > 0 {
names := make([]string, 0, len(scalars))
for n := range scalars {
names = append(names, n)
}
sort.Strings(names)
fmt.Printf(" scalars:\n")
for _, n := range names {
fmt.Printf(" %s = %d\n", n, scalars[n])
}
}
fmt.Printf(" args before: %s\n", hexDump(args))
rc := 0