From: Florian Krohm Date: Wed, 17 Dec 2014 19:52:25 +0000 (+0000) Subject: Remove two fixed-size buffers in the dwarf readers. X-Git-Tag: svn/VALGRIND_3_11_0~766 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=601ef384bb28aa657133c1ce3eb5d2002ba108c3;p=thirdparty%2Fvalgrind.git Remove two fixed-size buffers in the dwarf readers. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14820 --- diff --git a/coregrind/m_debuginfo/readdwarf.c b/coregrind/m_debuginfo/readdwarf.c index ec6fd49006..66ffd93751 100644 --- a/coregrind/m_debuginfo/readdwarf.c +++ b/coregrind/m_debuginfo/readdwarf.c @@ -518,35 +518,33 @@ void read_dwarf2_lineblock ( struct _DebugInfo* di, while (ML_(cur_read_UChar)(data) != 0) { -# define NBUF 4096 - static HChar buf[NBUF]; - HChar* data_str = ML_(cur_read_strdup)(data, "di.rd2l.1"); if (di->ddump_line) VG_(printf)(" %s\n", data_str); /* If data[0] is '/', then 'data' is an absolute path and we - don't mess with it. Otherwise, if we can, construct the + don't mess with it. Otherwise, construct the path 'ui->compdir' ++ "/" ++ 'data'. */ if (data_str[0] != '/' /* not an absolute path */ && ML_(cur_is_valid)(ui->compdir) /* actually got something sensible for compdir */ - && ML_(cur_strlen)(ui->compdir) - + VG_(strlen)(data_str) + 5/*paranoia*/ < NBUF - /* it's short enough to concatenate */) + && ML_(cur_strlen)(ui->compdir)) { - buf[0] = 0; HChar* compdir_str = ML_(cur_read_strdup)(ui->compdir, "di.rd2l.1b"); - VG_(strcat)(buf, compdir_str); + SizeT len = VG_(strlen)(compdir_str) + 1 + VG_(strlen)(data_str); + HChar *buf = ML_(dinfo_zalloc)("di.rd2l.1c", len + 1); + + VG_(strcpy)(buf, compdir_str); VG_(strcat)(buf, "/"); VG_(strcat)(buf, data_str); - vg_assert(VG_(strlen)(buf) < NBUF); - dirname = ML_(addStr)(di,buf,-1); + + dirname = ML_(addStr)(di, buf, len); VG_(addToXA) (dirname_xa, &dirname); if (0) VG_(printf)("rel path %s\n", buf); ML_(dinfo_free)(compdir_str); + ML_(dinfo_free)(buf); } else { /* just use 'data'. */ dirname = ML_(addStr)(di,data_str,-1); @@ -556,8 +554,6 @@ void read_dwarf2_lineblock ( struct _DebugInfo* di, data = ML_(cur_plus)(data, VG_(strlen)(data_str) + 1); ML_(dinfo_free)(data_str); - -# undef NBUF } if (di->ddump_line) diff --git a/coregrind/m_debuginfo/readdwarf3.c b/coregrind/m_debuginfo/readdwarf3.c index 4be17620cc..d89af4fa5b 100644 --- a/coregrind/m_debuginfo/readdwarf3.c +++ b/coregrind/m_debuginfo/readdwarf3.c @@ -1794,14 +1794,14 @@ XArray* read_dirname_xa (DebugInfo* di, const HChar *compdir, { XArray* dirname_xa; /* xarray of HChar* dirname */ const HChar* dirname; - UInt compdir_len = 0; + UInt compdir_len; dirname_xa = VG_(newXA) (ML_(dinfo_zalloc), "di.rdxa.1", ML_(dinfo_free), sizeof(HChar*) ); if (compdir == NULL) { dirname = "."; - compdir_len = 0; + compdir_len = 1; } else { dirname = compdir; compdir_len = VG_(strlen)(compdir); @@ -1813,32 +1813,31 @@ XArray* read_dirname_xa (DebugInfo* di, const HChar *compdir, while (peek_UChar(c) != 0) { -# define NBUF 4096 - static HChar buf[NBUF]; DiCursor cur = get_AsciiZ(c); HChar* data_str = ML_(cur_read_strdup)( cur, "dirname_xa.1" ); TRACE_D3(" %s\n", data_str); /* If data_str[0] is '/', then 'data' is an absolute path and we - don't mess with it. Otherwise, if we can, construct the + don't mess with it. Otherwise, construct the path 'compdir' ++ "/" ++ 'data'. */ if (data_str[0] != '/' /* not an absolute path */ && compdir /* actually got something sensible for compdir */ - && compdir_len - + VG_(strlen)(data_str) + 5/*paranoia*/ < NBUF - /* it's short enough to concatenate */) + && compdir_len) { - buf[0] = 0; - VG_(strcat)(buf, compdir); + SizeT len = compdir_len + 1 + VG_(strlen)(data_str); + HChar *buf = ML_(dinfo_zalloc)("dirname_xa.2", len + 1); + + VG_(strcpy)(buf, compdir); VG_(strcat)(buf, "/"); VG_(strcat)(buf, data_str); - vg_assert(VG_(strlen)(buf) < NBUF); - dirname = ML_(addStr)(di,buf,-1); + + dirname = ML_(addStr)(di, buf, len); VG_(addToXA) (dirname_xa, &dirname); if (0) VG_(printf)("rel path %s\n", buf); + ML_(dinfo_free)(buf); } else { /* just use 'data'. */ dirname = ML_(addStr)(di,data_str,-1); @@ -1847,8 +1846,6 @@ XArray* read_dirname_xa (DebugInfo* di, const HChar *compdir, } ML_(dinfo_free)(data_str); - -# undef NBUF } TRACE_D3 ("\n");