@@ -2670,6 +2670,15 @@ fn exported_name(ccx: &CrateContext, id: ast::NodeId,
26702670 }
26712671}
26722672
2673+ fn contains_null ( s : & str ) -> bool {
2674+ for b in s. bytes ( ) {
2675+ if b == 0 {
2676+ return true
2677+ }
2678+ }
2679+ false
2680+ }
2681+
26732682pub fn get_item_val ( ccx : & CrateContext , id : ast:: NodeId ) -> ValueRef {
26742683 debug ! ( "get_item_val(id=`{:?}`)" , id) ;
26752684
@@ -2701,6 +2710,11 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
27012710
27022711 unsafe {
27032712 let llty = llvm:: LLVMTypeOf ( v) ;
2713+ if contains_null ( sym. as_slice ( ) ) {
2714+ ccx. sess ( ) . fatal (
2715+ format ! ( "Illegal null byte in export_name value: `{}`" ,
2716+ sym) . as_slice ( ) ) ;
2717+ }
27042718 let g = sym. as_slice ( ) . with_c_str ( |buf| {
27052719 llvm:: LLVMAddGlobal ( ccx. llmod ( ) , llty, buf)
27062720 } ) ;
@@ -2764,10 +2778,16 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
27642778
27652779 match attr:: first_attr_value_str_by_name ( i. attrs . as_slice ( ) ,
27662780 "link_section" ) {
2767- Some ( sect) => unsafe {
2768- sect. get ( ) . with_c_str ( |buf| {
2769- llvm:: LLVMSetSection ( v, buf) ;
2770- } )
2781+ Some ( sect) => {
2782+ if contains_null ( sect. get ( ) ) {
2783+ ccx. sess ( ) . fatal ( format ! ( "Illegal null byte in link_section value: `{}`" ,
2784+ sect. get( ) ) . as_slice ( ) ) ;
2785+ }
2786+ unsafe {
2787+ sect. get ( ) . with_c_str ( |buf| {
2788+ llvm:: LLVMSetSection ( v, buf) ;
2789+ } )
2790+ }
27712791 } ,
27722792 None => ( )
27732793 }
0 commit comments