From 92e01bb100212df6dea51859e3129fa13997f74e Mon Sep 17 00:00:00 2001 From: comex Date: Wed, 27 Jan 2016 15:53:52 -0500 Subject: Fix incorrect handling if there is no local symbol info in the cache. --- lib/darwin/find-syms.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/darwin/find-syms.c b/lib/darwin/find-syms.c index d3524e2..1666f1c 100644 --- a/lib/darwin/find-syms.c +++ b/lib/darwin/find-syms.c @@ -39,7 +39,6 @@ static bool oscf_try_dir(const char *dir, const char *arch, if (memcmp(this_dch.uuid, dch->uuid, 16) || this_dch.localSymbolsSize != dch->localSymbolsSize /* just in case */) goto fail; - s_cur_shared_cache_fd = fd; struct dyld_cache_local_symbols_info *lsi = &s_cache_local_symbols_info; if (pread(fd, lsi, sizeof(*lsi), dch->localSymbolsOffset) != sizeof(*lsi)) goto fail; @@ -64,10 +63,12 @@ static bool oscf_try_dir(const char *dir, const char *arch, goto fail; } + s_cur_shared_cache_fd = fd; s_cache_local_symbols_entries = lses; return true; fail: + memset(lsi, 0, sizeof(*lsi)); close(fd); return false; } @@ -77,6 +78,8 @@ static void open_shared_cache_file_once() { const struct dyld_cache_header *dch = s_cur_shared_cache_hdr; if (memcmp(dch->magic, "dyld_v1 ", 8)) return; + if (dch->localSymbolsSize < sizeof(struct dyld_cache_local_symbols_info)) + return; const char *archp = &dch->magic[8]; while (*archp == ' ') archp++; -- cgit v1.2.3