[Coverity] Add bounds checking to #line processing in disassembly

This commit is contained in:
baldurk
2016-07-20 18:13:16 +02:00
parent e8e1b34d26
commit 331bd3fc69
@@ -418,16 +418,20 @@ void DXBCFile::MakeDisassemblyString()
// handle #line directives by inserting empty lines or erasing as necessary
char emptyString[] = "";
for(size_t srcLine = 0; srcLine < srclines.size(); srcLine++)
{
char *c = emptyString;
if(!srclines[srcLine].empty())
c = &srclines[srcLine][0];
if(srclines[srcLine].empty())
continue;
char *c = &srclines[srcLine][0];
char *end = c + srclines[srcLine].size();
while(*c == '\t' || *c == ' ' || *c == '\r')
c++;
if(c + 5 > end)
continue;
if(strncmp(c, "#line", 5))
{
// resize up to account for the current line, if necessary
@@ -449,9 +453,15 @@ void DXBCFile::MakeDisassemblyString()
// we have a #line directive
c += 5;
if(c >= end)
continue;
while(*c == '\t' || *c == ' ')
c++;
if(c >= end)
continue;
// invalid #line, no line number. Skip/ignore
if(*c < '0' || *c > '9')
continue;