From f4fb7c54a806be54b3d0be7d39c83893d1594361 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Tue, 21 Feb 2023 02:25:35 +0000 Subject: [PATCH] Make opaque closure constructor more robust By type checking the nargs argument rather than just assuming. It's easy for people to end up with the wrong integer type here. --- src/method.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/method.c b/src/method.c index b1f4051e28a82..69390c7841a14 100644 --- a/src/method.c +++ b/src/method.c @@ -99,14 +99,16 @@ static jl_value_t *resolve_globals(jl_value_t *expr, jl_module_t *module, jl_sve jl_error("opaque_closure_method: invalid syntax"); } jl_value_t *name = jl_exprarg(e, 0); - jl_value_t *nargs = jl_exprarg(e, 1); + jl_value_t *oc_nargs = jl_exprarg(e, 1); int isva = jl_exprarg(e, 2) == jl_true; jl_value_t *functionloc = jl_exprarg(e, 3); jl_value_t *ci = jl_exprarg(e, 4); if (!jl_is_code_info(ci)) { jl_error("opaque_closure_method: lambda should be a CodeInfo"); + } else if (!jl_is_long(oc_nargs)) { + jl_type_error("opaque_closure_method", (jl_value_t*)jl_long_type, oc_nargs); } - jl_method_t *m = jl_make_opaque_closure_method(module, name, jl_unbox_long(nargs), functionloc, (jl_code_info_t*)ci, isva); + jl_method_t *m = jl_make_opaque_closure_method(module, name, jl_unbox_long(oc_nargs), functionloc, (jl_code_info_t*)ci, isva); return (jl_value_t*)m; } if (e->head == jl_cfunction_sym) {