diff options
author | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-10-04 18:42:50 +0000 |
---|---|---|
committer | bstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-10-04 18:42:50 +0000 |
commit | db7c8f2a08c7cd93e83d22de940e2b87a99704e2 (patch) | |
tree | 41404f9e1d751c449ad09ce30f02579a291e5e01 /libbacktrace | |
parent | b7ba1683bd64a4f9a3eb34525a390d79e2dbb7a5 (diff) | |
download | gcc-db7c8f2a08c7cd93e83d22de940e2b87a99704e2.tar.gz |
2012-10-04 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 192095 using svnmerge.py
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@192098 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libbacktrace')
-rw-r--r-- | libbacktrace/ChangeLog | 11 | ||||
-rw-r--r-- | libbacktrace/dwarf.c | 47 |
2 files changed, 46 insertions, 12 deletions
diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog index eca80147a1c..528b4930204 100644 --- a/libbacktrace/ChangeLog +++ b/libbacktrace/ChangeLog @@ -1,3 +1,14 @@ +2012-10-04 Ian Lance Taylor <iant@google.com> + + * dwarf.c: If the system header files do not declare strnlen, + provide our own version. + +2012-10-03 Ian Lance Taylor <iant@google.com> + + * dwarf.c (read_uleb128): Fix overflow test. + (read_sleb128): Likewise. + (build_address_map): Don't change unit_buf.start. + 2012-10-02 Uros Bizjak <ubizjak@gmail.com> PR other/54761 diff --git a/libbacktrace/dwarf.c b/libbacktrace/dwarf.c index 68ebb4e3ad1..4e13fc541ee 100644 --- a/libbacktrace/dwarf.c +++ b/libbacktrace/dwarf.c @@ -44,8 +44,22 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "internal.h" #if !defined(HAVE_DECL_STRNLEN) || !HAVE_DECL_STRNLEN -/* The function is defined in libiberty if needed. */ -extern size_t strnlen (const char *, size_t); + +/* If strnlen is not declared, provide our own version. */ + +static size_t +xstrnlen (const char *s, size_t maxlen) +{ + size_t i; + + for (i = 0; i < maxlen; ++i) + if (s[i] == '\0') + break; + return i; +} + +#define strnlen xstrnlen + #endif /* A buffer to read DWARF info. */ @@ -524,10 +538,12 @@ read_uleb128 (struct dwarf_buf *buf) { uint64_t ret; unsigned int shift; + int overflow; unsigned char b; ret = 0; shift = 0; + overflow = 0; do { const unsigned char *p; @@ -536,14 +552,17 @@ read_uleb128 (struct dwarf_buf *buf) if (!advance (buf, 1)) return 0; b = *p; - ret |= ((uint64_t) (b & 0x7f)) << shift; + if (shift < 64) + ret |= ((uint64_t) (b & 0x7f)) << shift; + else if (!overflow) + { + dwarf_buf_error (buf, "LEB128 overflows uint64_t"); + overflow = 1; + } shift += 7; } while ((b & 0x80) != 0); - if (shift > 64) - dwarf_buf_error (buf, "LEB128 overflows uint64_5"); - return ret; } @@ -554,10 +573,12 @@ read_sleb128 (struct dwarf_buf *buf) { uint64_t val; unsigned int shift; + int overflow; unsigned char b; val = 0; shift = 0; + overflow = 0; do { const unsigned char *p; @@ -566,15 +587,18 @@ read_sleb128 (struct dwarf_buf *buf) if (!advance (buf, 1)) return 0; b = *p; - val |= ((uint64_t) (b & 0x7f)) << shift; + if (shift < 64) + val |= ((uint64_t) (b & 0x7f)) << shift; + else if (!overflow) + { + dwarf_buf_error (buf, "signed LEB128 overflows uint64_t"); + overflow = 1; + } shift += 7; } while ((b & 0x80) != 0); - if (shift > 64) - dwarf_buf_error (buf, "signed LEB128 overflows uint64_t"); - - if ((b & 0x40) != 0) + if ((b & 0x40) != 0 && shift < 64) val |= ((uint64_t) -1) << shift; return (int64_t) val; @@ -1262,7 +1286,6 @@ build_address_map (struct backtrace_state *state, } unit_buf = info; - unit_buf.start = info.buf; unit_buf.left = len; if (!advance (&info, len)) |