[entropy.tools] correctly parse scanelf output even when spaces are present everywhere.

This is a ";" separated data input (even though we may get directory
paths containing ";"... but none so far is expected to be legit.)

Split by ";" first and then deal with spaces in paths.
This commit is contained in:
Fabio Erculiani
2018-09-29 22:39:44 +02:00
parent 066ec3ac35
commit c411a93dc5

View File

@@ -2793,22 +2793,20 @@ def read_elf_metadata(elf_file):
for line in out.split("\n"):
if line:
try:
elfclass_str, soname, runpath, libs_and_path = line.strip().split(";")
except ValueError as err:
raise ValueError(
"Unexpected amount of sections from scanelf output: %s, error: %s" % (
line, err))
# Example of line:
# ELFCLASS64;;/opt/dmd-2.074/lib64;libdl.so.2,libvted-3.so.0,libgtkd-3.so.0,libX11.so.6,libphobos2.so.0.74,libpthread.so.0,libm.so.6,librt.so.1,libgcc_s.so.1,libc.so.6,ld-linux-x86-64.so.2 /var/tmp/entropy/entropy.spm._extractUmRpJu/pkg/usr/bin/tilix
# Normally sections contains two elements but there are
# cases with packages that use directory with spaces that could
# be greater then 2. I need drop only last.
sections = line.strip().split(" ", -1)
if len(sections) < 2:
raise Exception('Unexpected output on scanelf:\n\n%s\n' % (
line
))
else:
data = ' '.join(sections[:-1])
try:
libs = libs_and_path.split(" ", 1)[0]
except (IndexError, ValueError) as err:
raise ValueError("Unexpected data in libs_and_path: %s, error: %s" % (
libs_and_path, err))
elfclass_str, soname, runpath, libs = data.split(";")
libs = set(libs.split(","))
libs = set(libs.strip().split(","))
return {
'soname': soname,
'class': elf_class_strtoint(elfclass_str),