Skip to content

It's possible to cast 0 as extern fn() in safe code #8728

New issue

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

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

Already on GitHub? # to your account

Closed
bluss opened this issue Aug 24, 2013 · 3 comments · Fixed by #9788
Closed

It's possible to cast 0 as extern fn() in safe code #8728

bluss opened this issue Aug 24, 2013 · 3 comments · Fixed by #9788
Labels
A-type-system Area: Type system

Comments

@bluss
Copy link
Member

bluss commented Aug 24, 2013

Rust allows casting 0 to a function pointer type like extern "Rust" fn(). This is unsafe.

rusti: let f = 0 as extern "Rust" fn() -> int; f()
-rusti:#rust- application terminated abnormally with signal 11 (Segmentation fault)
@bluss
Copy link
Member Author

bluss commented Aug 24, 2013

dup of #8730

@bluss bluss closed this as completed Aug 24, 2013
@huonw
Copy link
Member

huonw commented Aug 24, 2013

Disagree that this is a dup; the other should be made specific to the type inference, since this is a glaring hole and not at all specific to extern "C" fn (like that issue).

cc @nikomatsakis.

@nikomatsakis
Copy link
Contributor

Sounds like a bug all right.

bors added a commit that referenced this issue Nov 14, 2013
Bare functions are another example of a scalar but non-numeric
type (like char) that should be handled separately in casts.
This disallows expressions like `0 as extern "Rust" fn() -> int;`.

It might be advantageous to allow casts between bare functions
and raw pointers in unsafe code in the future, to pass function
pointers between Rust and C.

Closes #8728
@bors bors closed this as completed in e538c95 Nov 14, 2013
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants