From 6cdee89ef1c066351a373f89ca6d2483ed96c654 Mon Sep 17 00:00:00 2001
From: Andreas Ziegler <andreas.ziegler@fau.de>
Date: Thu, 28 Oct 2021 10:29:45 +0200
Subject: [PATCH] library: fix exception when parsing a recovered .plt

In commit 440aface1540 ("library: add support for PLT calls
with Intel CET"), we added detection logic for .plt.sec
sections but the change would only correctly work on a Section
object as the newly added code accesses a .name member of
the plt object.

Fix this by checking if we actually have a Section first.

Reported-by: Stefan Eschenbacher <stefan.eschenbacher@fau.de>
---
 librarytrader/library.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/librarytrader/library.py b/librarytrader/library.py
index ad82514..1d6e1ed 100644
--- a/librarytrader/library.py
+++ b/librarytrader/library.py
@@ -28,6 +28,7 @@ from elftools.common.exceptions import ELFError
 from elftools.elf.dynamic import DynamicSegment
 from elftools.elf.elffile import ELFFile
 from elftools.elf.relocation import RelocationSection
+from elftools.elf.sections import Section
 from elftools.common.utils import struct_parse
 from elftools.construct import Padding, SLInt32, Struct
 from elftools.elf.enums import ENUM_RELOC_TYPE_x64, ENUM_RELOC_TYPE_i386, \
@@ -546,7 +547,7 @@ class Library:
                 # entry in the .plt is in fact 16 bytes long, so round up to
                 # sh_addralign (see https://reviews.llvm.org/D9560).
                 increment = _round_up_to_alignment(plt['sh_entsize'], plt['sh_addralign'])
-                if plt.name == '.plt.sec':
+                if isinstance(plt, Section) and plt.name == '.plt.sec':
                     # .plt.sec does not contain a special first entry so the
                     # first entry (after incrementing) starts at offset 0.
                     plt_offset = -increment
-- 
GitLab