Skip to content

Commit 8057c60

Browse files
authored
add some checks for invalid expressions (JuliaLang#35363)
add null check for module-default-defs, fix JuliaLang#34544 fix JuliaLang#35367 as well change jl_eval_module_expr to check 3rd arg is block
1 parent a6a2d26 commit 8057c60

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

src/ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ static jl_value_t *scm_to_julia_(fl_context_t *fl_ctx, value_t e, jl_module_t *m
577577
assert(jl_is_symbol(ex));
578578
temp = jl_module_globalref(jl_core_module, (jl_sym_t*)ex);
579579
}
580-
else if (sym == inert_sym || (sym == quote_sym && (!iscons(car_(e))))) {
580+
else if (iscons(e) && (sym == inert_sym || (sym == quote_sym && (!iscons(car_(e)))))) {
581581
ex = scm_to_julia_(fl_ctx, car_(e), mod);
582582
temp = jl_new_struct(jl_quotenode_type, ex);
583583
}

src/jlfrontend.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
(jl-expand-to-thunk
177177
(let* ((name (caddr e))
178178
(body (cadddr e))
179-
(loc (cadr body))
179+
(loc (if (null? (cdr body)) () (cadr body)))
180180
(loc (if (and (pair? loc) (eq? (car loc) 'line))
181181
(list loc)
182182
'()))

src/toplevel.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ jl_value_t *jl_eval_module_expr(jl_module_t *parent_module, jl_expr_t *ex)
115115
if (jl_array_len(ex->args) != 3 || !jl_is_expr(jl_exprarg(ex, 2))) {
116116
jl_error("syntax: malformed module expression");
117117
}
118+
119+
if (((jl_expr_t *)(jl_exprarg(ex, 2)))->head != jl_symbol("block")) {
120+
jl_error("syntax: module expression third argument must be a block");
121+
}
122+
118123
int std_imports = (jl_exprarg(ex, 0) == jl_true);
119124
jl_sym_t *name = (jl_sym_t*)jl_exprarg(ex, 1);
120125
if (!jl_is_symbol(name)) {

test/syntax.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,6 +2224,17 @@ h35201(x; k=1) = (x, k)
22242224
f35201(c) = h35201((;c...), k=true)
22252225
@test f35201(Dict(:a=>1,:b=>3)) === ((a=1,b=3), true)
22262226

2227+
2228+
@testset "issue #34544/35367" begin
2229+
# Test these evals shouldnt segfault
2230+
eval(Expr(:call, :eval, Expr(:quote, Expr(:module, true, :bar1, Expr(:block)))))
2231+
eval(Expr(:module, true, :bar2, Expr(:block)))
2232+
eval(Expr(:quote, Expr(:module, true, :bar3, Expr(:quote))))
2233+
@test_throws ErrorException eval(Expr(:call, :eval, Expr(:quote, Expr(:module, true, :bar4, Expr(:quote)))))
2234+
@test_throws ErrorException eval(Expr(:module, true, :bar5, Expr(:foo)))
2235+
@test_throws ErrorException eval(Expr(:module, true, :bar6, Expr(:quote)))
2236+
end
2237+
22272238
# issue #35391
22282239
macro a35391(b)
22292240
:(GC.@preserve ($(esc(b)),) )

0 commit comments

Comments
 (0)