From 320b76139ae04eea3cbe74c424cda489bbf61882 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 28 Jan 2016 17:38:43 -0500 Subject: lddtree: handle exceptions thrown when parsing other ELFs We have a top level exception handler for catching ELF errors, but if we hit a problem with a dependency, we end up diagnosing it as a problem in the first ELF. e.g. If "foo" is linked against "libc.so", and "libc.so" is a linker script, when we try to read the libc.so ELF, it fails, and we end up saying: lddtree: warning: foo: Magic number does not match This makes no sense because "foo" is a proper ELF with the right magic, and we end up halting the whole parsing process. Now we show: lddtree: warning: /usr/lib/libc.so: Magic number does not match foo (interpreter => /some/interp) libc.so => None --- lddtree.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lddtree.py b/lddtree.py index 100f475..e663d32 100755 --- a/lddtree.py +++ b/lddtree.py @@ -338,9 +338,12 @@ def FindLib(elf, lib, ldpaths, root='/', debug=False): if os.path.exists(target): with open(target, 'rb') as f: - libelf = ELFFile(f) - if CompatibleELFs(elf, libelf): - return (target, path) + try: + libelf = ELFFile(f) + if CompatibleELFs(elf, libelf): + return (target, path) + except exceptions.ELFError as e: + warn('%s: %s' % (target, e)) return (None, None) @@ -475,8 +478,11 @@ def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[ 'needed': [], } if fullpath: - lret = ParseELF(realpath, root, prefix, ldpaths, display=fullpath, - debug=debug, _first=False, _all_libs=_all_libs) + try: + lret = ParseELF(realpath, root, prefix, ldpaths, display=fullpath, + debug=debug, _first=False, _all_libs=_all_libs) + except exceptions.ELFError as e: + warn('%s: %s' % (realpath, e)) _all_libs[lib]['needed'] = lret['needed'] del elf -- cgit v1.2.3-18-g5258