Skip to content

Commit

Permalink
Detect Go binaries and skip some checks for them.
Browse files Browse the repository at this point in the history
Fixes #598.
  • Loading branch information
marxin committed Jan 12, 2021
1 parent 15b4e45 commit 751c9bc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
15 changes: 14 additions & 1 deletion rpmlint/checks/BinariesCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ def _check_non_pie(self, pkg, bin_name):
We suppose that the package is arch dependent and bin_name is binary
executable.
"""
if self.is_go_elf:
return

if not self.is_shobj and not self.is_pie_exec:
if any(regex.search(bin_name) for regex in self.pie_exec_regex_list):
self.output.add_info('E', pkg,
Expand Down Expand Up @@ -397,7 +400,9 @@ def _check_rpath(self, pkg, pkgfile_path, path):
def _check_library_dependency(self, pkg, pkgfile_path, path):
if self.is_archive:
return
if path.startswith('/lib/modules/'):
elif path.startswith('/lib/modules/'):
return
elif self.is_go_elf:
return

dyn_section = self.readelf_parser.dynamic_section_info
Expand Down Expand Up @@ -510,6 +515,7 @@ def _detect_attributes(self, magic):
self.is_archive = 'current ar archive' in magic
self.is_dynamically_linked = 'dynamically linked' in magic
self.is_pie_exec = 'pie executable' in magic
self.is_go_elf = False

def run_elf_checks(self, pkg, pkgfile_path, path):
if self.is_archive and not self._is_standard_archive(pkg, pkgfile_path, path):
Expand All @@ -521,6 +527,13 @@ def run_elf_checks(self, pkg, pkgfile_path, path):
self.output.add_info('E', pkg, 'readelf-failed', path, failed_reason)
return

# Detect go binary
for elf_file in self.readelf_parser.section_info.elf_files:
for section in elf_file:
if section.name == '.note.go.buildid':
self.is_go_elf = True
break

if not self.is_archive:
if self.is_dynamically_linked:
is_installed_pkg = isinstance(pkg, InstalledPkg) or isinstance(pkg, FakePkg)
Expand Down
Binary file added test/binary/go-package-1.0-0.x86_64.rpm
Binary file not shown.
8 changes: 8 additions & 0 deletions test/test_binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,11 @@ def test_dependency_information(tmpdir, package, binariescheck):
out = output.print_results(output.results)
assert 'E: shared-library-without-dependency-information /usr/lib64/ruby/enc/gb2312.so' in out
assert 'W: library-not-linked-against-libc /usr/lib64/ruby/continuation.so' in out


@pytest.mark.parametrize('package', ['binary/go-package'])
def test_go_package(tmpdir, package, binariescheck):
output, test = binariescheck
test.check(get_tested_package(package, tmpdir))
out = output.print_results(output.results)
assert not out

0 comments on commit 751c9bc

Please sign in to comment.