Skip to content

Segfault using result of place_back() as a Place #44637

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

Closed
andy-hanson opened this issue Sep 16, 2017 · 4 comments
Closed

Segfault using result of place_back() as a Place #44637

andy-hanson opened this issue Sep 16, 2017 · 4 comments
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-bug Category: This is a bug. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness P-medium Medium priority T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@andy-hanson
Copy link

andy-hanson commented Sep 16, 2017

When trying to write a data structure that wraps a Vec and is a Placer, I got a segfault when trying to use the result of place_back() as a Place.

I tried this code:

#![feature(collection_placement)]
#![feature(placement_in_syntax)]
#![feature(placement_new_protocol)]

use std::ops::Placer;
use std::vec::PlaceBack;

fn main() {
	let mut stack = Stack::new();
	&mut stack <- 1;
	println!("Doesn't get here!");
}

pub struct Stack(Vec<u32>);
impl Stack {
	pub fn new() -> Self {
		Stack(Vec::new())
	}
}
impl<'a> Placer<u32> for &'a mut Stack {
	type Place = PlaceBack<'a, u32>;

	fn make_place(self) -> Self::Place {
		self.0.place_back() //.make_place()
	}
}

I expected to see this happen: Prints "Doesn't get here!", and exits with code 0.

Instead, this happened: Prints "Segmentation fault", and exits with code 139.

The error is fixed by uncommenting .make_place().

Meta

rustc --version --verbose:

rustc 1.22.0-nightly (fd4bef5 2017-09-15)
binary: rustc
commit-hash: fd4bef5
commit-date: 2017-09-15
host: x86_64-unknown-linux-gnu
release: 1.22.0-nightly
LLVM version: 4.0

Backtrace:

N/A?

@arielb1 arielb1 added I-nominated I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 17, 2017
@arielb1
Copy link
Contributor

arielb1 commented Sep 17, 2017

I don't think it's an essential unsoundness - PlaceBack is for some reason both a Placer and a Place, and if you call make_place and pointer in the wrong order, you can access the vec out of bounds and segfault.

@TimNN TimNN added the C-bug Category: This is a bug. label Sep 17, 2017
@bstrie bstrie added the B-unstable Blocker: Implemented in the nightly compiler and unstable. label Sep 20, 2017
@alexcrichton alexcrichton added P-medium Medium priority and removed I-nominated labels Sep 26, 2017
@alexcrichton
Copy link
Member

cc #27779, the tracking issue for this as well

@mattico
Copy link
Contributor

mattico commented Feb 11, 2018

Is the fix for this just to make separate types for Placer and Place so that you have to call make_place to actually get a Place?

@leoyvens
Copy link
Contributor

Triage: placement new has been unaccepted, this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-bug Category: This is a bug. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness P-medium Medium priority T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants