Skip to content

Fix ICE from null character #17472

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

Merged
merged 2 commits into from
Sep 24, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2670,6 +2670,10 @@ fn exported_name(ccx: &CrateContext, id: ast::NodeId,
}
}

fn contains_null(s: &str) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this just be replaced with .bytes().contains(0)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't look like the iterator implements any contains method. I did change it to use any() though.

Copy link
Member

Choose a reason for hiding this comment

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

@kaseyc It doesn't look like you pushed this revision to the PR. Once you do, I think it's ready to go!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'm waiting for the change to finish a pass through make check, just to be thorough.

s.bytes().any(|b| b == 0)
}

pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
debug!("get_item_val(id=`{:?}`)", id);

Expand Down Expand Up @@ -2701,6 +2705,11 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {

unsafe {
let llty = llvm::LLVMTypeOf(v);
if contains_null(sym.as_slice()) {
ccx.sess().fatal(
format!("Illegal null byte in export_name value: `{}`",
sym).as_slice());
}
let g = sym.as_slice().with_c_str(|buf| {
llvm::LLVMAddGlobal(ccx.llmod(), llty, buf)
});
Expand Down Expand Up @@ -2764,10 +2773,16 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {

match attr::first_attr_value_str_by_name(i.attrs.as_slice(),
"link_section") {
Some(sect) => unsafe {
sect.get().with_c_str(|buf| {
llvm::LLVMSetSection(v, buf);
})
Some(sect) => {
if contains_null(sect.get()) {
ccx.sess().fatal(format!("Illegal null byte in link_section value: `{}`",
sect.get()).as_slice());
}
unsafe {
sect.get().with_c_str(|buf| {
llvm::LLVMSetSection(v, buf);
})
}
},
None => ()
}
Expand Down