From c411a93dc50d093a98a34453ac7fdf8e02def299 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Sat, 29 Sep 2018 22:39:44 +0200 Subject: [PATCH] [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. --- lib/entropy/tools.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/entropy/tools.py b/lib/entropy/tools.py index ee31d9b94..44ec935d2 100644 --- a/lib/entropy/tools.py +++ b/lib/entropy/tools.py @@ -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),