GP-2785 Match up token field bounds checking between compilers

This commit is contained in:
caheckman 2020-03-25 11:17:24 -04:00
parent 1cdb59e1bb
commit e0a5cf1720
3 changed files with 38 additions and 12 deletions

View file

@ -2479,6 +2479,16 @@ TokenSymbol *SleighCompile::defineToken(string *name,uintb *sz,int4 endian)
void SleighCompile::addTokenField(TokenSymbol *sym,FieldQuality *qual)
{
if (qual->high < qual->low) {
ostringstream s;
s << "Field '" << qual->name << "' starts at " << qual->low << " and ends at " << qual->high;
reportError(getCurrentLocation(), s.str());
}
if (sym->getToken()->getSize() * 8 <= qual->high) {
ostringstream s;
s << "Field '" << qual->name << "' high must be less than token size";
reportError(getCurrentLocation(), s.str());
}
TokenField *field = new TokenField(sym->getToken(),qual->signext,qual->low,qual->high);
addSymbol(new ValueSymbol(qual->name,field));
delete qual;
@ -2491,6 +2501,16 @@ void SleighCompile::addTokenField(TokenSymbol *sym,FieldQuality *qual)
bool SleighCompile::addContextField(VarnodeSymbol *sym,FieldQuality *qual)
{
if (qual->high < qual->low) {
ostringstream s;
s << "Context field '" << qual->name << "' starts at " << qual->low << " and ends at " << qual->high;
reportError(getCurrentLocation(), s.str());
}
if (sym->getSize() * 8 <= qual->high) {
ostringstream s;
s << "Context field '" << qual->name << "' high must be less than context size";
reportError(getCurrentLocation(), s.str());
}
if (contextlock)
return false; // Context layout has already been satisfied