14
14
std:: {
15
15
convert:: TryInto ,
16
16
io:: Read ,
17
+ ops:: Deref ,
17
18
path:: { Path , PathBuf } ,
18
19
} ,
19
20
} ;
@@ -85,6 +86,8 @@ const PE_ALLOWED_LIBRARIES: &[&str] = &[
85
86
] ;
86
87
87
88
lazy_static ! {
89
+ static ref GLIBC_MAX_VERSION : version_compare:: Version <' static > =
90
+ version_compare:: Version :: from( "2.19" ) . unwrap( ) ;
88
91
static ref MACHO_ALLOWED_DYLIBS : Vec <MachOAllowedDylib > = {
89
92
[
90
93
MachOAllowedDylib {
@@ -174,7 +177,7 @@ lazy_static! {
174
177
} ;
175
178
}
176
179
177
- fn validate_elf ( path : & Path , elf : & goblin:: elf:: Elf ) -> Result < Vec < String > > {
180
+ fn validate_elf ( path : & Path , elf : & goblin:: elf:: Elf , bytes : & [ u8 ] ) -> Result < Vec < String > > {
178
181
let mut errors = vec ! [ ] ;
179
182
180
183
for lib in & elf. libraries {
@@ -183,6 +186,30 @@ fn validate_elf(path: &Path, elf: &goblin::elf::Elf) -> Result<Vec<String>> {
183
186
}
184
187
}
185
188
189
+ let mut undefined_symbols = tugger_binary_analysis:: find_undefined_elf_symbols ( & bytes, elf) ;
190
+ undefined_symbols. sort ( ) ;
191
+
192
+ for symbol in undefined_symbols {
193
+ if let Some ( version) = & symbol. version {
194
+ let parts: Vec < & str > = version. splitn ( 2 , '_' ) . collect ( ) ;
195
+
196
+ if parts. len ( ) == 2 {
197
+ if parts[ 0 ] == "GLIBC" {
198
+ let v =
199
+ version_compare:: Version :: from ( parts[ 1 ] ) . expect ( "unable to parse version" ) ;
200
+
201
+ if & v > GLIBC_MAX_VERSION . deref ( ) {
202
+ errors. push ( format ! (
203
+ "{} references too new glibc symbol {:?}" ,
204
+ path. display( ) ,
205
+ symbol
206
+ ) )
207
+ }
208
+ }
209
+ }
210
+ }
211
+ }
212
+
186
213
Ok ( errors)
187
214
}
188
215
@@ -253,7 +280,7 @@ fn validate_distribution(dist_path: &Path) -> Result<Vec<String>> {
253
280
if let Ok ( object) = goblin:: Object :: parse ( & data) {
254
281
match object {
255
282
goblin:: Object :: Elf ( elf) => {
256
- errors. extend ( validate_elf ( path. as_ref ( ) , & elf) ?) ;
283
+ errors. extend ( validate_elf ( path. as_ref ( ) , & elf, & data ) ?) ;
257
284
}
258
285
goblin:: Object :: Mach ( mach) => match mach {
259
286
goblin:: mach:: Mach :: Binary ( macho) => {
0 commit comments