Merge remote-tracking branch 'origin/GP-1796_NullPtrPaths' (Addresses

comment in #3878)
This commit is contained in:
Ryan Kurtz 2022-03-09 11:01:13 -05:00
commit 12c051867c
6 changed files with 29 additions and 14 deletions

View file

@ -763,8 +763,9 @@ ProtoModel *Architecture::parseProto(const Element *el)
ProtoModel *other = protoModels[res->getName()];
if (other != (ProtoModel *)0) {
string errMsg = "Duplicate ProtoModel name: " + res->getName();
delete res;
throw LowlevelError("Duplicate ProtoModel name: "+res->getName());
throw LowlevelError(errMsg);
}
protoModels[res->getName()] = res;
return res;

View file

@ -2064,6 +2064,9 @@ GrammarToken::GrammarToken(void)
{
type = 0;
value.integer = 0;
lineno = -1;
colno = -1;
filenum = -1;
}
GrammarLexer::GrammarLexer(int4 maxbuffer)
@ -2617,6 +2620,9 @@ CParse::CParse(Architecture *g,int4 maxbuf)
{
glb = g;
firsttoken = -1;
lineno = -1;
colno = -1;
filenum = -1;
lastdecls = (vector<TypeDeclarator *> *)0;
keywords["typedef"] = f_typedef;
keywords["extern"] = f_extern;

View file

@ -279,6 +279,9 @@ GrammarToken::GrammarToken(void)
{
type = 0;
value.integer = 0;
lineno = -1;
colno = -1;
filenum = -1;
}
GrammarLexer::GrammarLexer(int4 maxbuffer)
@ -832,6 +835,9 @@ CParse::CParse(Architecture *g,int4 maxbuf)
{
glb = g;
firsttoken = -1;
lineno = -1;
colno = -1;
filenum = -1;
lastdecls = (vector<TypeDeclarator *> *)0;
keywords["typedef"] = f_typedef;
keywords["extern"] = f_extern;

View file

@ -350,10 +350,7 @@ void PcodeCompile::newLocalDefinition(string *varname,uint4 size)
{ // Create a new temporary symbol (without generating any pcode)
VarnodeSymbol *sym;
VarnodeTpl *tmpvn = buildTemporary();
if (size != 0)
tmpvn->setSize(ConstTpl(ConstTpl::real,size)); // Size was explicitly specified
sym = new VarnodeSymbol(*varname,tmpvn->getSpace().getSpace(),tmpvn->getOffset().getReal(),tmpvn->getSize().getReal());
sym = new VarnodeSymbol(*varname,uniqspace,allocateTemp(),size);
addSymbol(sym);
delete varname;
}

View file

@ -1523,8 +1523,8 @@ void PrintC::pushEnumConstant(uintb val,const TypeEnum *ct,
/// If so push the string, if not return \b false to indicate a token was not pushed
/// \param val is the value of the given constant pointer
/// \param ct is the pointer data-type attached to the value
/// \param vn is the Varnode holding the value
/// \param op is the PcodeOp using the value
/// \param vn is the Varnode holding the value (may be null)
/// \param op is the PcodeOp using the value (may be null)
/// \return \b true if a quoted string was pushed to the RPN stack
bool PrintC::pushPtrCharConstant(uintb val,const TypePointer *ct,const Varnode *vn,const PcodeOp *op)
@ -1532,7 +1532,10 @@ bool PrintC::pushPtrCharConstant(uintb val,const TypePointer *ct,const Varnode *
if (val==0) return false;
AddrSpace *spc = glb->getDefaultDataSpace();
uintb fullEncoding;
Address stringaddr = glb->resolveConstant(spc,val,ct->getSize(),op->getAddr(),fullEncoding);
Address point;
if (op != (const PcodeOp *)0)
point = op->getAddr();
Address stringaddr = glb->resolveConstant(spc,val,ct->getSize(),point,fullEncoding);
if (stringaddr.isInvalid()) return false;
if (!glb->symboltab->getGlobalScope()->isReadOnly(stringaddr,1,Address()))
return false; // Check that string location is readonly

View file

@ -365,16 +365,18 @@ void AddrSpaceManager::insertSpace(AddrSpace *spc)
}
if (nameTypeMismatch || duplicateName || duplicateId) {
string errMsg = "Space " + spc->getName();
if (nameTypeMismatch)
errMsg = errMsg + " was initialized with wrong type";
if (duplicateName)
errMsg = errMsg + " was initialized more than once";
if (duplicateId)
errMsg = errMsg + " was assigned as id duplicating: "+baselist[spc->index]->getName();
if (spc->refcount == 0)
delete spc;
spc = (AddrSpace *)0;
throw LowlevelError(errMsg);
}
if (nameTypeMismatch)
throw LowlevelError("Space "+spc->getName()+" was initialized with wrong type");
if (duplicateName)
throw LowlevelError("Space "+spc->getName()+" was initialized more than once");
if (duplicateId)
throw LowlevelError("Space "+spc->getName()+" was assigned as id duplicating: "+baselist[spc->index]->getName());
baselist[spc->index] = spc;
spc->refcount += 1;
assignShortcut(spc);