Skip to content

Commit

Permalink
add code to prevent segfault during Eval of thunk Expr (#35429)
Browse files Browse the repository at this point in the history
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
Closes #32315
  • Loading branch information
ssikdar1 authored Jan 28, 2023
1 parent 8955828 commit 7d4309c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,9 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_value_t *e, int
int has_ccall = 0, has_defs = 0, has_loops = 0, has_opaque = 0, forced_compile = 0;
assert(head == jl_thunk_sym);
thk = (jl_code_info_t*)jl_exprarg(ex, 0);
assert(jl_is_code_info(thk));
assert(jl_typeis(thk->code, jl_array_any_type));
if (!jl_is_code_info(thk) || !jl_typeis(thk->code, jl_array_any_type)) {
jl_eval_errorf(m, "malformed \"thunk\" statement");
}
body_attributes((jl_array_t*)thk->code, &has_ccall, &has_defs, &has_loops, &has_opaque, &forced_compile);

jl_value_t *result;
Expand Down
7 changes: 6 additions & 1 deletion test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2330,14 +2330,19 @@ f35201(c) = h35201((;c...), k=true)
f44343(;kw...) = NamedTuple(kw)
@test f44343(u = (; :a => 1)) === (u = (; :a => 1),)

@testset "issue #34544/35367" begin
@testset "issue #34544/35367/35429" begin
# Test these evals shouldn't segfault
eval(Expr(:call, :eval, Expr(:quote, Expr(:module, true, :bar1, Expr(:block)))))
eval(Expr(:module, true, :bar2, Expr(:block)))
eval(Expr(:quote, Expr(:module, true, :bar3, Expr(:quote))))
@test_throws ErrorException eval(Expr(:call, :eval, Expr(:quote, Expr(:module, true, :bar4, Expr(:quote)))))
@test_throws ErrorException eval(Expr(:module, true, :bar5, Expr(:foo)))
@test_throws ErrorException eval(Expr(:module, true, :bar6, Expr(:quote)))

#35429
@test_throws ErrorException eval(Expr(:thunk, x->x+9))
@test_throws ErrorException eval(Expr(:thunk, Meta.parse("x=17")))
@test_throws ErrorException eval(Expr(:thunk, Meta.parse("17")))
end

# issue #35391
Expand Down

0 comments on commit 7d4309c

Please sign in to comment.