Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_empty_section(self):
# GIVEN
elf = Mock()
elf.get_section_by_name.return_value = None
# WHEN
symbols = list(elf_find_versioned_symbols(elf))
# THEN
assert len(symbols) == 0
def test_only_ld_linux(self, ld_name):
# GIVEN
elf = Mock()
verneed = Mock()
verneed.configure_mock(name=ld_name)
veraux = Mock()
veraux.configure_mock(name="foo-lib")
elf.get_section_by_name.return_value.iter_versions.return_value = (
(verneed, [veraux]),
)
# WHEN
symbols = list(elf_find_versioned_symbols(elf))
# THEN
assert len(symbols) == 0
def test_find_symbols(self):
# GIVEN
elf = Mock()
verneed = Mock()
verneed.configure_mock(name="foo-lib")
veraux = Mock()
veraux.configure_mock(name="foo-lib")
elf.get_section_by_name.return_value.iter_versions.return_value = (
(verneed, [veraux]),
)
# WHEN
symbols = list(elf_find_versioned_symbols(elf))
# THEN
assert symbols == [("foo-lib", "foo-lib")]
# Check for invalid binary wheel format: no shared library should
# be found in purelib
so_path_split = fn.split(os.sep)
# If this is in purelib, add it to the list of shared libraries in
# purelib
if 'purelib' in so_path_split:
shared_libraries_in_purelib.append(so_path_split[-1])
# If at least one shared library exists in purelib, this is going
# to fail and there's no need to do further checks
if not shared_libraries_in_purelib:
log.debug('processing: %s', fn)
elftree = lddtree(fn)
for key, value in elf_find_versioned_symbols(elf):
log.debug('key %s, value %s', key, value)
versioned_symbols[key].add(value)
is_py_ext, py_ver = elf_is_python_extension(fn, elf)
# If the ELF is a Python extention, we definitely need to
# include its external dependencies.
if is_py_ext:
full_elftree[fn] = elftree
uses_PyFPE_jbuf |= elf_references_PyFPE_jbuf(elf)
if py_ver == 2:
uses_ucs2_symbols |= any(
True for _ in elf_find_ucs2_symbols(elf))
full_external_refs[fn] = lddtree_external_references(
elftree,
ctx.path)
def get_versioned_symbols(libs):
"""Get versioned symbols used in libraries
:param libs: {realpath: soname} dict to search for versioned symbols e.g.
{'/path/to/external_ref.so.1.2.3': 'external_ref.so.1'}
:return: {soname: {depname: set([symbol_version])}} e.g.
{'external_ref.so.1': {'libc.so.6', set(['GLIBC_2.5','GLIBC_2.12'])}}
"""
result = {}
for path, elf in elf_file_filter(libs.keys()):
# {depname: set(symbol_version)}, e.g.
# {'libc.so.6', set(['GLIBC_2.5','GLIBC_2.12'])}
elf_versioned_symbols = defaultdict(lambda: set())
for key, value in elf_find_versioned_symbols(elf):
log.debug('path %s, key %s, value %s', path, key, value)
elf_versioned_symbols[key].add(value)
result[libs[path]] = elf_versioned_symbols
return result