Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add null check for module-default-defs #35363

Merged
merged 7 commits into from
Apr 10, 2020

Conversation

ssikdar1
Copy link
Contributor

@ssikdar1 ssikdar1 commented Apr 5, 2020

Description

Issue #34544.
In PR #35337 there was a suggestion to add a check for body in module-default-defs in src/jlfrontend.scm. This adds that check.

Testing

In the julia repl I tried a couple more variations that would cause a segfault

julia> eval(Expr(:call, :eval, Expr(:quote, Expr(:module, true, :bar, Expr(:block)))))
Main.bar

julia> eval(Expr(:module, true, :bar, Expr(:block)))
WARNING: replacing module bar.
Main.bar

julia> eval(Expr(:module, true, :bar, Expr(:quote)))
WARNING: replacing module bar.
Main.bar

julia> eval(Expr(:call, :eval, Expr(:quote, Expr(:module, true, :bar, Expr(:block)))))
WARNING: replacing module bar.
Main.bar

@JeffBezanson
Copy link
Member

Great, thanks! Could you add a test case to test/syntax.jl?

@ssikdar1
Copy link
Contributor Author

ssikdar1 commented Apr 8, 2020

5a0b565 adds a fix for #35367 as well

Output for those two lines in the REPL:

$ ./julia 
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.5.0-DEV.572 (2020-04-06)
 _/ |\__'_|_|_|\__'_|  |  linenumber/0b9ed994df* (fork: 2 commits, 4 days)
|__/                   |

julia> eval(Expr(:quote, Expr(:module, true, :bar, Expr(:quote))))
:(module bar
  end)

julia> eval(Expr(:call, :eval, Expr(:quote, Expr(:module, true, :bar, Expr(:quote)))))
Main.bar

src/ast.c Outdated
@@ -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))))) {
else if ((sym == inert_sym || (sym == quote_sym && (!iscons(car_(e))))) && iscons(e)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iscons(e) needs to be checked before car_(e); car is only valid if e is a cons.

test/core.jl Outdated
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)))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be valid; the 3rd argument to module has to be a block expression. That can be checked at the top of jl_eval_module_expr.

@ssikdar1
Copy link
Contributor Author

ssikdar1 commented Apr 8, 2020

@JeffBezanson added an if check inside jl_eval_module_expr in dce7897.

The following now throw an Exception:

julia> eval(Expr(:call, :eval, Expr(:quote, Expr(:module, true, :bar, Expr(:quote)))))
ERROR: syntax: module expression third argument must be a block

julia> eval(Expr(:module, true, :bar, Expr(:foo)))
ERROR: syntax: module expression third argument must be a block

julia> eval(Expr(:module, true, :bar, Expr(:quote)))
ERROR: syntax: module expression third argument must be a block

The following does not return an ErrorException (but no longer segfaults ):

julia> eval(Expr(:quote, Expr(:module, true, :bar, Expr(:quote))))
:(module bar
  end)

I think due to the quoting? Which I think is fine?

@mbauman
Copy link
Member

mbauman commented Apr 10, 2020

I just hit this bug myself — glad to see a fix already here! My use-case was a macro:

julia> macro foo()
           Expr(:module, true, esc(:Bar), Expr(:block))
       end
@foo (macro with 1 method)

julia> @foo
WARNING: replacing module Bar.

signal (11): Segmentation fault: 11

@JeffBezanson
Copy link
Member

I think due to the quoting? Which I think is fine?

Right; the eval just strips off the quote, so the module expression itself is never evaluated, so the error doesn't happen.

@JeffBezanson JeffBezanson merged commit 8057c60 into JuliaLang:master Apr 10, 2020
@ssikdar1 ssikdar1 deleted the linenumber branch April 10, 2020 16:06
ztultrebor pushed a commit to ztultrebor/julia that referenced this pull request Apr 17, 2020
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
staticfloat pushed a commit that referenced this pull request Apr 21, 2020
add null check for module-default-defs, fix #34544

fix #35367 as well

change jl_eval_module_expr to check 3rd arg is block
KristofferC pushed a commit that referenced this pull request May 10, 2020
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)
@KristofferC KristofferC mentioned this pull request May 10, 2020
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants