Remove two fixed-size buffers in the dwarf readers.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14820
This commit is contained in:
Florian Krohm 2014-12-17 19:52:25 +00:00
parent 5734a854d5
commit 601ef384bb
2 changed files with 20 additions and 27 deletions

View File

@ -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)

View File

@ -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");