@@ -54,13 +54,6 @@ const ELF_ALLOWED_LIBRARIES: &[&str] = &[
54
54
"libpthread.so.0" ,
55
55
"librt.so.1" ,
56
56
"libutil.so.1" ,
57
- // Our set.
58
- "libpython3.8.so.1.0" ,
59
- "libpython3.8d.so.1.0" ,
60
- "libpython3.9.so.1.0" ,
61
- "libpython3.9d.so.1.0" ,
62
- "libpython3.10.so.1.0" ,
63
- "libpython3.10d.so.1.0" ,
64
57
] ;
65
58
66
59
const PE_ALLOWED_LIBRARIES : & [ & str ] = & [
@@ -384,6 +377,7 @@ fn allowed_dylibs_for_triple(triple: &str) -> Vec<MachOAllowedDylib> {
384
377
385
378
fn validate_elf (
386
379
target_triple : & str ,
380
+ python_major_minor : & str ,
387
381
path : & Path ,
388
382
elf : & goblin:: elf:: Elf ,
389
383
bytes : & [ u8 ] ,
@@ -413,13 +407,19 @@ fn validate_elf(
413
407
) ) ;
414
408
}
415
409
416
- let mut allowed_libraries = ELF_ALLOWED_LIBRARIES . to_vec ( ) ;
410
+ let mut allowed_libraries = ELF_ALLOWED_LIBRARIES
411
+ . iter ( )
412
+ . map ( |x| x. to_string ( ) )
413
+ . collect :: < Vec < _ > > ( ) ;
417
414
if let Some ( extra) = ELF_ALLOWED_LIBRARIES_BY_TRIPLE . get ( target_triple) {
418
- allowed_libraries. extend ( extra. iter ( ) ) ;
415
+ allowed_libraries. extend ( extra. iter ( ) . map ( |x| x . to_string ( ) ) ) ;
419
416
}
420
417
418
+ allowed_libraries. push ( format ! ( "libpython{}.so.1.0" , python_major_minor) ) ;
419
+ allowed_libraries. push ( format ! ( "libpython{}d.so.1.0" , python_major_minor) ) ;
420
+
421
421
for lib in & elf. libraries {
422
- if !allowed_libraries. contains ( lib) {
422
+ if !allowed_libraries. contains ( & lib. to_string ( ) ) {
423
423
errors. push ( format ! ( "{} loads illegal library {}" , path. display( ) , lib) ) ;
424
424
}
425
425
}
@@ -578,6 +578,11 @@ fn validate_distribution(dist_path: &Path) -> Result<Vec<String>> {
578
578
let mut seen_dylibs = BTreeSet :: new ( ) ;
579
579
let mut seen_paths = BTreeSet :: new ( ) ;
580
580
581
+ let dist_filename = dist_path
582
+ . file_name ( )
583
+ . expect ( "unable to obtain filename" )
584
+ . to_string_lossy ( ) ;
585
+
581
586
let fh = std:: fs:: File :: open ( & dist_path)
582
587
. with_context ( || format ! ( "unable to open {}" , dist_path. display( ) ) ) ?;
583
588
@@ -595,6 +600,16 @@ fn validate_distribution(dist_path: &Path) -> Result<Vec<String>> {
595
600
)
596
601
} ) ?;
597
602
603
+ let python_major_minor = if dist_filename. starts_with ( "cpython-3.8." ) {
604
+ "3.8"
605
+ } else if dist_filename. starts_with ( "cpython-3.9." ) {
606
+ "3.9"
607
+ } else if dist_filename. starts_with ( "cpython-3.10." ) {
608
+ "3.10"
609
+ } else {
610
+ return Err ( anyhow ! ( "could not parse Python version from filename" ) ) ;
611
+ } ;
612
+
598
613
let reader = std:: io:: BufReader :: new ( fh) ;
599
614
let dctx = zstd:: stream:: Decoder :: new ( reader) ?;
600
615
let mut tf = tar:: Archive :: new ( dctx) ;
@@ -611,7 +626,13 @@ fn validate_distribution(dist_path: &Path) -> Result<Vec<String>> {
611
626
if let Ok ( object) = goblin:: Object :: parse ( & data) {
612
627
match object {
613
628
goblin:: Object :: Elf ( elf) => {
614
- errors. extend ( validate_elf ( triple, path. as_ref ( ) , & elf, & data) ?) ;
629
+ errors. extend ( validate_elf (
630
+ triple,
631
+ python_major_minor,
632
+ path. as_ref ( ) ,
633
+ & elf,
634
+ & data,
635
+ ) ?) ;
615
636
}
616
637
goblin:: Object :: Mach ( mach) => match mach {
617
638
goblin:: mach:: Mach :: Binary ( macho) => {
0 commit comments