Skip to content

Commit

Permalink
add some checks for invalid expressions (#35363)
Browse files Browse the repository at this point in the history
add null check for module-default-defs, fix #34544

fix #35367 as well

change jl_eval_module_expr to check 3rd arg is block

(cherry picked from commit 8057c60)
  • Loading branch information
ssikdar1 authored and KristofferC committed May 10, 2020
1 parent d04036f commit fe43406
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,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))))) {
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
2 changes: 1 addition & 1 deletion src/jlfrontend.scm
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
(jl-expand-to-thunk
(let* ((name (caddr e))
(body (cadddr e))
(loc (cadr body))
(loc (if (null? (cdr body)) () (cadr body)))
(loc (if (and (pair? loc) (eq? (car loc) 'line))
(list loc)
'()))
Expand Down
5 changes: 5 additions & 0 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,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
11 changes: 11 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,17 @@ h35201(x; k=1) = (x, k)
f35201(c) = h35201((;c...), k=true)
@test f35201(Dict(:a=>1,:b=>3)) === ((a=1,b=3), true)


@testset "issue #34544/35367" begin
# Test these evals shouldnt 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)))
end

# issue #35391
macro a35391(b)
:(GC.@preserve ($(esc(b)),) )
Expand Down

0 comments on commit fe43406

Please sign in to comment.