about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-09-24 15:45:48 +0000
committerbors <bors@rust-lang.org>2014-09-24 15:45:48 +0000
commit9e3bf02c381c9d4dd6b5ace6815febab3b89fecf (patch)
tree7954143350a0b4ed555a5c1193f16cd0c84620c2
parent5366cfecf3fd4e3b589c140b85eee4bb4b35d97c (diff)
parent3e8ad539397743045cb0b4337afc79c37b77ca65 (diff)
downloadrust-9e3bf02c381c9d4dd6b5ace6815febab3b89fecf.tar.gz
rust-9e3bf02c381c9d4dd6b5ace6815febab3b89fecf.zip
auto merge of #17472 : kaseyc/rust/ICE_fix, r=aturon
Add checks for null bytes in the value strings for the export_name and link_section attributes, reporting an error if any are found, before calling with_c_str on them.

Fixes #16478
-rw-r--r--src/librustc/middle/trans/base.rs23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs
index 72e0401e7ab..cac6a8bbfed 100644
--- a/src/librustc/middle/trans/base.rs
+++ b/src/librustc/middle/trans/base.rs
@@ -2670,6 +2670,10 @@ fn exported_name(ccx: &CrateContext, id: ast::NodeId,
     }
 }
 
+fn contains_null(s: &str) -> bool {
+    s.bytes().any(|b| b == 0)
+}
+
 pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
     debug!("get_item_val(id=`{:?}`)", id);
 
@@ -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)
                         });
@@ -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 => ()
             }