Skip to content

Commit

Permalink
change jl_eval_module_expr to check 3rd arg is block
Browse files Browse the repository at this point in the history
  • Loading branch information
ssikdar1 committed Apr 8, 2020
1 parent 36fd682 commit dce7897
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ static jl_value_t *scm_to_julia_(fl_context_t *fl_ctx, value_t e, jl_module_t *m
assert(jl_is_symbol(ex));
temp = jl_module_globalref(jl_core_module, (jl_sym_t*)ex);
}
else if ((sym == inert_sym || (sym == quote_sym && (!iscons(car_(e))))) && iscons(e)) {
else if (iscons(e) && (sym == inert_sym || (sym == quote_sym && (!iscons(car_(e)))))) {
ex = scm_to_julia_(fl_ctx, car_(e), mod);
temp = jl_new_struct(jl_quotenode_type, ex);
}
Expand Down
5 changes: 5 additions & 0 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ jl_value_t *jl_eval_module_expr(jl_module_t *parent_module, jl_expr_t *ex)
if (jl_array_len(ex->args) != 3 || !jl_is_expr(jl_exprarg(ex, 2))) {
jl_error("syntax: malformed module expression");
}

if (((jl_expr_t *)(jl_exprarg(ex, 2)))->head != jl_symbol("block")) {
jl_error("syntax: module expression third argument must be a block");
}

int std_imports = (jl_exprarg(ex, 0) == jl_true);
jl_sym_t *name = (jl_sym_t*)jl_exprarg(ex, 1);
if (!jl_is_symbol(name)) {
Expand Down
6 changes: 4 additions & 2 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7200,9 +7200,11 @@ end
@test repr(NFANode34126()) == "$NFANode34126(Tuple{Nothing,$NFANode34126}[])"

@testset "issue #34544/35367" begin
# Test these evals dont throw an error
# Test these evals shouldnt segfault
eval(Expr(:call, :eval, Expr(:quote, Expr(:module, true, :bar, Expr(:block)))))
eval(Expr(:module, true, :bar, Expr(:block)))
eval(Expr(:quote, Expr(:module, true, :bar, Expr(:quote))))
eval(Expr(:call, :eval, Expr(:quote, Expr(:module, true, :bar, Expr(:quote)))))
@test_throws ErrorException eval(Expr(:call, :eval, Expr(:quote, Expr(:module, true, :bar, Expr(:quote)))))
@test_throws ErrorException eval(Expr(:module, true, :bar, Expr(:foo)))
@test_throws ErrorException eval(Expr(:module, true, :bar, Expr(:quote)))
end

0 comments on commit dce7897

Please sign in to comment.