mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GP-2785 Match up token field bounds checking between compilers
This commit is contained in:
parent
1cdb59e1bb
commit
e0a5cf1720
3 changed files with 38 additions and 12 deletions
|
@ -212,23 +212,14 @@ fielddef
|
|||
}
|
||||
: ^(t=OP_FIELDDEF n=unbound_identifier["field"] s=integer e=integer {
|
||||
if (n != null) {
|
||||
long start = $s.value.longValue();
|
||||
long finish = $e.value.longValue();
|
||||
if (finish < start) {
|
||||
reportError(find($t), "field '" + $n.value.getText() + "' starts at " + start + " and ends at " + finish);
|
||||
}
|
||||
$fielddef::fieldQuality = new FieldQuality($n.value.getText(), find($t), $s.value.longValue(), $e.value.longValue());
|
||||
}
|
||||
} fieldmods) {
|
||||
if ($fielddef.size() > 0 && $fielddef::fieldQuality != null) {
|
||||
if ($tokendef.size() > 0 && $tokendef::tokenSymbol != null) {
|
||||
if ($tokendef::tokenSymbol.getToken().getSize()*8 <= $fielddef::fieldQuality.high) {
|
||||
reportError(find($t), "field high must be less than token size");
|
||||
} else {
|
||||
sc.addTokenField(find(n), $tokendef::tokenSymbol, $fielddef::fieldQuality);
|
||||
}
|
||||
sc.addTokenField(find(n), $tokendef::tokenSymbol, $fielddef::fieldQuality);
|
||||
} else if ($contextdef.size() > 0 && $contextdef::varnode != null) {
|
||||
if (!sc.addContextField($contextdef::varnode, $fielddef::fieldQuality)) {
|
||||
if (!sc.addContextField(find(n), $contextdef::varnode, $fielddef::fieldQuality)) {
|
||||
reportError(find($t), "all context definitions must come before constructors");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -923,13 +923,28 @@ public class SleighCompile extends SleighBase {
|
|||
|
||||
public void addTokenField(Location location, TokenSymbol sym, FieldQuality qual) {
|
||||
entry("addTokenField", location, sym, qual);
|
||||
if (qual.high < qual.low) {
|
||||
reportError(location, "Field '" + qual.name + "' starts at " +
|
||||
Integer.toString(qual.low) + " and ends at " + Integer.toString(qual.high));
|
||||
}
|
||||
if (sym.getToken().getSize() * 8 <= qual.high) {
|
||||
reportError(location, "Field '" + qual.name + "' high must be less than token size");
|
||||
}
|
||||
TokenField field =
|
||||
new TokenField(location, sym.getToken(), qual.signext, qual.low, qual.high);
|
||||
addSymbol(new ValueSymbol(location, qual.name, field));
|
||||
}
|
||||
|
||||
public boolean addContextField(VarnodeSymbol sym, FieldQuality qual) {
|
||||
public boolean addContextField(Location location, VarnodeSymbol sym, FieldQuality qual) {
|
||||
entry("addContextField", sym, qual);
|
||||
if (qual.high < qual.low) {
|
||||
reportError(location, "Context field '" + qual.name + "' starts at " +
|
||||
Integer.toString(qual.low) + " and ends at " + Integer.toString(qual.high));
|
||||
}
|
||||
if (sym.getSize() * 8 <= qual.high) {
|
||||
reportError(location,
|
||||
"Context field '" + qual.name + "' high must be less than context size");
|
||||
}
|
||||
if (contextlock) {
|
||||
return false; // Context layout has already been satisfied
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue