@@ -2670,6 +2670,15 @@ fn exported_name(ccx: &CrateContext, id: ast::NodeId,
2670
2670
}
2671
2671
}
2672
2672
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
+
2673
2682
pub fn get_item_val ( ccx : & CrateContext , id : ast:: NodeId ) -> ValueRef {
2674
2683
debug ! ( "get_item_val(id=`{:?}`)" , id) ;
2675
2684
@@ -2701,6 +2710,11 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
2701
2710
2702
2711
unsafe {
2703
2712
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
+ }
2704
2718
let g = sym. as_slice ( ) . with_c_str ( |buf| {
2705
2719
llvm:: LLVMAddGlobal ( ccx. llmod ( ) , llty, buf)
2706
2720
} ) ;
@@ -2764,10 +2778,16 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
2764
2778
2765
2779
match attr:: first_attr_value_str_by_name ( i. attrs . as_slice ( ) ,
2766
2780
"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
+ }
2771
2791
} ,
2772
2792
None => ( )
2773
2793
}
0 commit comments