Skip to content

Commit d3805b0

Browse files
authored
fix(builtin): bounds check to get() (#918)
Validate argument count before accessing params slice in the get() function. This prevents a runtime panic when malformed input bypasses compile-time validation, as discovered by OSS-Fuzz. Includes regression test for the specific fuzz case. Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
1 parent 9c83063 commit d3805b0

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

builtin/builtin_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,21 @@ func TestBuiltin_errors(t *testing.T) {
300300
}
301301
}
302302

303+
// The get() builtin must return an error when called with
304+
// insufficient arguments at runtime, even if compile-time checks
305+
// are bypassed (regression test for OSS-Fuzz #479270603).
306+
func TestBuiltin_get_runtime_args_check(t *testing.T) {
307+
code := `$env(''matches'i'?t:get().UTC())`
308+
env := map[string]any{"t": 1}
309+
310+
program, err := expr.Compile(code, expr.Env(env))
311+
require.NoError(t, err)
312+
313+
_, err = expr.Run(program, env)
314+
require.Error(t, err)
315+
assert.Contains(t, err.Error(), "invalid number of arguments")
316+
}
317+
303318
func TestBuiltin_types(t *testing.T) {
304319
env := map[string]any{
305320
"num": 42,

builtin/lib.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,9 @@ func flatten(arg reflect.Value, depth int) ([]any, error) {
564564
}
565565

566566
func get(params ...any) (out any, err error) {
567+
if len(params) < 2 {
568+
return nil, fmt.Errorf("invalid number of arguments (expected 2, got %d)", len(params))
569+
}
567570
from := params[0]
568571
i := params[1]
569572
v := reflect.ValueOf(from)

0 commit comments

Comments
 (0)