mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 10:49:34 +02:00
Merge remote-tracking branch 'origin/GP-999_caheckman_NullPointer_from_Ptrnulls' into Ghidra_10.0
This commit is contained in:
commit
3b1204f074
4 changed files with 44 additions and 29 deletions
|
@ -72,15 +72,15 @@ public enum MetaDataType {
|
|||
}
|
||||
|
||||
public static DataType getMostSpecificDataType(DataType a, DataType b) {
|
||||
if (a == null) {
|
||||
return b;
|
||||
}
|
||||
if (b == null) {
|
||||
return a;
|
||||
}
|
||||
DataType aCopy = a;
|
||||
DataType bCopy = b;
|
||||
for (;;) {
|
||||
if (a == null) {
|
||||
return bCopy;
|
||||
}
|
||||
if (b == null) {
|
||||
return aCopy;
|
||||
}
|
||||
MetaDataType aMeta = MetaDataType.getMeta(a);
|
||||
MetaDataType bMeta = MetaDataType.getMeta(b);
|
||||
int compare = aMeta.compareTo(bMeta);
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.util.TreeMap;
|
|||
* the final field entries.
|
||||
*/
|
||||
public class NoisyStructureBuilder {
|
||||
private TreeMap<Long, DataType> offsetToDataTypeMap = new TreeMap<Long, DataType>();
|
||||
private TreeMap<Long, DataType> offsetToDataTypeMap = new TreeMap<>();
|
||||
private Structure structDT = null;
|
||||
private long sizeOfStruct = 0;
|
||||
|
||||
|
@ -83,11 +83,14 @@ public class NoisyStructureBuilder {
|
|||
computeMax(offset, 1);
|
||||
return;
|
||||
}
|
||||
if (dt instanceof Pointer && ((Pointer) dt).getDataType().equals(structDT)) {
|
||||
// Be careful of taking a pointer to the structure when the structure
|
||||
// is not fully defined
|
||||
DataTypeManager manager = dt.getDataTypeManager();
|
||||
dt = manager.getPointer(DataType.DEFAULT, dt.getLength());
|
||||
if (dt instanceof Pointer) {
|
||||
DataType baseType = ((Pointer) dt).getDataType();
|
||||
if (baseType != null && baseType.equals(structDT)) {
|
||||
// Be careful of taking a pointer to the structure when the structure
|
||||
// is not fully defined
|
||||
DataTypeManager manager = dt.getDataTypeManager();
|
||||
dt = manager.getPointer(DataType.DEFAULT, dt.getLength());
|
||||
}
|
||||
}
|
||||
computeMax(offset, dt.getLength());
|
||||
Entry<Long, DataType> firstEntry = checkForOverlap(offset, dt.getLength());
|
||||
|
@ -127,7 +130,7 @@ public class NoisyStructureBuilder {
|
|||
public void addReference(long offset, DataType dt) {
|
||||
if (dt != null && dt instanceof Pointer) {
|
||||
dt = ((Pointer) dt).getDataType();
|
||||
if (dt.equals(structDT)) {
|
||||
if (dt != null && dt.equals(structDT)) {
|
||||
return; // Don't allow structure to contain itself
|
||||
}
|
||||
if (dt instanceof Structure) {
|
||||
|
|
|
@ -98,4 +98,20 @@ public class NoisyStructureBuilderTest extends AbstractGTest {
|
|||
testNextField(iter, 8, DWordDataType.dataType);
|
||||
Assert.assertFalse(iter.hasNext());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPointerNulls() {
|
||||
NoisyStructureBuilder builder = new NoisyStructureBuilder();
|
||||
DataType pointerNull = new Pointer32DataType(null);
|
||||
builder.addDataType(4, Undefined4DataType.dataType);
|
||||
builder.addDataType(8, Undefined4DataType.dataType);
|
||||
builder.addDataType(4, pointerNull);
|
||||
builder.addReference(16, pointerNull);
|
||||
|
||||
Iterator<Entry<Long, DataType>> iter = builder.iterator();
|
||||
testNextField(iter, 4, pointerNull);
|
||||
testNextField(iter, 8, Undefined4DataType.dataType);
|
||||
Assert.assertFalse(iter.hasNext());
|
||||
Assert.assertEquals(builder.getSize(), 17);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue