From 7bfbbb6126987bf6eedffd03fab4aa4cc537f1e9 Mon Sep 17 00:00:00 2001 From: "mostang.com!davidm" Date: Wed, 19 Mar 2003 19:25:18 +0000 Subject: [PATCH] (lookup_symbol): Return -UNW_ENOINFO if symbol cannot be looked up for some reason. Return -UNW_ENOMEM if string buffer is too small. This makes the routine compatible with the definition of the unw_get_proc_name(3). (Logical change 1.63) --- src/elfxx.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/elfxx.c b/src/elfxx.c index a9383479..965275b6 100644 --- a/src/elfxx.c +++ b/src/elfxx.c @@ -53,11 +53,11 @@ elfW (lookup_symbol) (unw_word_t ip, struct elf_image *ei, ElfW (Off) soff, str_soff; ElfW (Shdr) *shdr, *str_shdr; ElfW (Addr) val, min_dist = ~(ElfW (Addr))0; + int i, ret = 0; char *strtab; - int i; if (!elfW (valid_object) (ei)) - return -1; + return -UNW_ENOINFO; soff = ehdr->e_shoff; if (soff + ehdr->e_shnum * ehdr->e_shentsize > ei->size) @@ -65,7 +65,7 @@ elfW (lookup_symbol) (unw_word_t ip, struct elf_image *ei, debug (1, "%s: section table outside of image? (%lu > %lu)\n", __FUNCTION__, soff + ehdr->e_shnum * ehdr->e_shentsize, ei->size); - return -1; + return -UNW_ENOINFO; } shdr = (ElfW (Shdr) *) ((char *) ei->image + soff); @@ -110,9 +110,10 @@ elfW (lookup_symbol) (unw_word_t ip, struct elf_image *ei, if ((ElfW (Addr)) (ip - val) < min_dist) { min_dist = (ElfW (Addr)) (ip - val); - buf[buf_len - 1] = 'x'; strncpy (buf, strtab + sym->st_name, buf_len); buf[buf_len - 1] = '\0'; + if (strlen (strtab + sym->st_name) >= buf_len) + ret = -UNW_ENOMEM; } } } @@ -124,10 +125,10 @@ elfW (lookup_symbol) (unw_word_t ip, struct elf_image *ei, shdr = (Elf64_Shdr *) (((char *) shdr) + ehdr->e_shentsize); } if (min_dist >= ei->size) - return -1; /* not found */ + return -UNW_ENOINFO; /* not found */ if (offp) *offp = min_dist; - return 0; + return ret; } /* Find the ELF image that contains IP and return the "closest"