2010-05-03 23:18:30 +02:00
|
|
|
--- BinariesCheck.py
|
2008-04-21 18:36:30 +02:00
|
|
|
+++ BinariesCheck.py
|
2010-10-15 17:16:45 +02:00
|
|
|
@@ -17,6 +17,7 @@
|
|
|
|
import AbstractCheck
|
|
|
|
import Config
|
|
|
|
import Pkg
|
|
|
|
+import os
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_SYSTEM_LIB_PATHS = (
|
|
|
|
@@ -37,6 +38,9 @@
|
2010-01-27 18:18:50 +01:00
|
|
|
unused_regex = re.compile('^\s+(\S+)')
|
2009-03-13 16:06:45 +01:00
|
|
|
exit_call_regex = re.compile('\s+FUNC\s+.*?\s+(_?exit(?:@\S+)?)(?:\s|$)')
|
|
|
|
fork_call_regex = re.compile('\s+FUNC\s+.*?\s+(fork(?:@\S+)?)(?:\s|$)')
|
2008-04-21 18:36:30 +02:00
|
|
|
+ debuginfo_regex=re.compile('^\s+\[\s*\d+\]\s+\.debug_.*\s+')
|
|
|
|
+ symtab_regex=re.compile('^\s+\[\s*\d+\]\s+\.symtab\s+')
|
2010-05-03 23:18:30 +02:00
|
|
|
+ gethostbyname_call_regex = re.compile('\s+FUNC\s+.*?\s+(gethostbyname(?:@\S+)?)(?:\s|$)')
|
2008-04-21 18:36:30 +02:00
|
|
|
|
2009-03-13 16:06:45 +01:00
|
|
|
def __init__(self, pkg, path, file, is_ar, is_shlib):
|
2009-09-16 18:41:21 +02:00
|
|
|
self.readelf_error = False
|
2010-10-15 17:16:45 +02:00
|
|
|
@@ -50,7 +54,10 @@
|
2010-05-03 23:18:30 +02:00
|
|
|
self.stack = False
|
2009-09-16 18:41:21 +02:00
|
|
|
self.exec_stack = False
|
2009-03-13 16:06:45 +01:00
|
|
|
self.exit_calls = []
|
2010-05-03 23:18:30 +02:00
|
|
|
+ self.calls_gethostbyname = False
|
2009-09-16 18:41:21 +02:00
|
|
|
fork_called = False
|
2009-03-13 16:06:45 +01:00
|
|
|
+ self.debuginfo = 0
|
2008-04-21 18:36:30 +02:00
|
|
|
+ self.symtab=0
|
2009-03-13 16:06:45 +01:00
|
|
|
self.tail = ''
|
2008-04-21 18:36:30 +02:00
|
|
|
|
2010-01-27 18:18:50 +01:00
|
|
|
is_debug = path.endswith('.debug')
|
2010-10-15 17:16:45 +02:00
|
|
|
@@ -93,6 +100,11 @@
|
2010-05-03 23:18:30 +02:00
|
|
|
self.exec_stack = True
|
|
|
|
continue
|
|
|
|
|
|
|
|
+ r = BinaryInfo.gethostbyname_call_regex.search(l)
|
|
|
|
+ if r:
|
|
|
|
+ self.calls_gethostbyname = True
|
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
if is_shlib:
|
|
|
|
r = BinaryInfo.exit_call_regex.search(l)
|
|
|
|
if r:
|
2010-10-15 17:16:45 +02:00
|
|
|
@@ -103,6 +115,14 @@
|
2009-09-16 18:41:21 +02:00
|
|
|
fork_called = True
|
2009-03-13 16:06:45 +01:00
|
|
|
continue
|
2008-06-25 19:08:32 +02:00
|
|
|
|
|
|
|
+ if BinaryInfo.debuginfo_regex.search(l):
|
|
|
|
+ self.debuginfo=1
|
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
+ if BinaryInfo.symtab_regex.search(l):
|
|
|
|
+ self.symtab=1
|
|
|
|
+ continue
|
|
|
|
+
|
2008-04-21 18:36:30 +02:00
|
|
|
if self.non_pic:
|
2010-01-27 18:18:50 +01:00
|
|
|
self.non_pic = 'TEXTREL' in res[1]
|
2009-03-13 16:06:45 +01:00
|
|
|
|
2010-10-15 17:16:45 +02:00
|
|
|
@@ -270,6 +290,17 @@
|
2010-10-14 14:32:03 +02:00
|
|
|
is_shlib = so_regex.search(fname)
|
|
|
|
bin_info = BinaryInfo(pkg, pkgfile.path, fname, is_ar, is_shlib)
|
2008-06-25 19:08:32 +02:00
|
|
|
|
2010-10-14 14:32:03 +02:00
|
|
|
+ # stripped static library
|
|
|
|
+ if is_ar:
|
|
|
|
+ if bin_info.readelf_error:
|
|
|
|
+ pass
|
|
|
|
+ elif not bin_info.symtab:
|
|
|
|
+ printError(pkg, 'static-library-without-symtab', fname)
|
|
|
|
+ elif not bin_info.debuginfo and \
|
|
|
|
+ (os.environ.get('BUILD_IS_RUNNING', None) == None or \
|
|
|
|
+ os.environ.get('BUILD_DEBUG_FLAGS','').find('-g') != -1):
|
|
|
|
+ printWarning(pkg, 'static-library-without-debuginfo', fname)
|
2008-06-25 19:08:32 +02:00
|
|
|
+
|
2010-10-14 14:32:03 +02:00
|
|
|
if is_shlib:
|
|
|
|
has_lib = True
|
2010-05-03 23:18:30 +02:00
|
|
|
|
2010-10-15 17:16:45 +02:00
|
|
|
@@ -319,6 +350,10 @@
|
2010-10-14 14:32:03 +02:00
|
|
|
for ec in bin_info.exit_calls:
|
|
|
|
printWarning(pkg, 'shared-lib-calls-exit', fname, ec)
|
|
|
|
|
|
|
|
+ # gethostbyname ?
|
|
|
|
+ if bin_info.calls_gethostbyname:
|
|
|
|
+ printError(pkg, 'binary-or-shlib-calls-gethostbyname', fname)
|
2010-05-03 23:18:30 +02:00
|
|
|
+
|
2010-10-14 14:32:03 +02:00
|
|
|
# rpath ?
|
|
|
|
if bin_info.rpath:
|
|
|
|
for p in bin_info.rpath:
|
2010-10-15 17:16:45 +02:00
|
|
|
@@ -504,6 +539,14 @@
|
2008-04-21 18:36:30 +02:00
|
|
|
'ldd-failed',
|
|
|
|
'''Executing ldd on this file failed, all checks could not be run.''',
|
2008-06-25 19:08:32 +02:00
|
|
|
|
2008-04-21 18:36:30 +02:00
|
|
|
+'static-library-without-symtab',
|
|
|
|
+'''The static library doesn't contain any symbols and therefore can't be linked
|
|
|
|
+against. This may indicated that it was strip.''',
|
|
|
|
+
|
|
|
|
+'static-library-without-debuginfo',
|
|
|
|
+'''The static library doesn't contain any debuginfo. Binaries linking against
|
|
|
|
+this static library can't be properly debugged.''',
|
2008-06-25 19:08:32 +02:00
|
|
|
+
|
|
|
|
'executable-stack',
|
|
|
|
'''The binary declares the stack as executable. Executable stack is usually an
|
|
|
|
error as it is only needed if the code contains GCC trampolines or similar
|
2010-10-15 17:16:45 +02:00
|
|
|
@@ -516,6 +559,10 @@
|
2010-05-03 23:18:30 +02:00
|
|
|
make the stack executable. Usual suspects include use of a non-GNU linker or
|
|
|
|
an old GNU linker version.''',
|
|
|
|
|
|
|
|
+'binary-or-shlib-calls-gethostbyname',
|
|
|
|
+'''The binary calls gethostbyname(). Please port the code to use
|
|
|
|
+getaddrinfo().''',
|
|
|
|
+
|
|
|
|
'shared-lib-calls-exit',
|
|
|
|
'''This library package calls exit() or _exit(), probably in a non-fork()
|
|
|
|
context. Doing so from a library is strongly discouraged - when a library
|