From 2490e399dc08fb9c11c62ce571204aef49f0e65e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Tue, 8 Mar 2016 16:39:15 +0100 Subject: [PATCH] ldso: check binary pointer before lookup Check if the binary pointer is valid before attempting to lookup the symbol. Shared objects with unresolved symbols and missing depencies, e.g a library that references 'errno' but is not linked against libc, will now produce an error message when they are loaded by the dynamic linker. Fixes #1904. --- repos/base/src/lib/ldso/main.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/repos/base/src/lib/ldso/main.cc b/repos/base/src/lib/ldso/main.cc index 8161e5536f..c51c958582 100644 --- a/repos/base/src/lib/ldso/main.cc +++ b/repos/base/src/lib/ldso/main.cc @@ -484,8 +484,14 @@ Elf::Sym const *Linker::lookup_symbol(char const *name, Dependency const *dep, } /* try searching binary's dependencies */ - if (!weak_symbol && dep->root && dep != binary->dep.head()) - return lookup_symbol(name, binary->dep.head(), base, undef, other); + if (!weak_symbol && dep->root) { + if (binary && dep != binary->dep.head()) { + return lookup_symbol(name, binary->dep.head(), base, undef, other); + } else { + PERR("Could not lookup symbol \"%s\"", name); + throw Not_found(); + } + } if (dep->root && verbose_lookup) PDBG("Return %p", weak_symbol);