GP-2011: Fix AddressOutOfBounds issue in mapper

This commit is contained in:
Dan 2022-05-16 16:24:35 -04:00
parent 3d0e5bc882
commit cd40985bcc
2 changed files with 29 additions and 7 deletions

View file

@ -95,13 +95,12 @@ public class DebuggerStaticMappingServicePlugin extends Plugin
}
public Address addOrMax(Address start, long length) {
try {
return start.addNoWrap(length);
}
catch (AddressOverflowException e) {
Msg.warn(this, "Mapping entry cause overflow in static address space");
Address result = start.addWrapSpace(length);
if (result.compareTo(start) < 0) {
Msg.warn(this, "Mapping entry caused overflow in static address space");
return start.getAddressSpace().getMaxAddress();
}
return result;
}
public boolean programOpened(Program opened) {
@ -176,7 +175,7 @@ public class DebuggerStaticMappingServicePlugin extends Plugin
protected Address mapTraceAddressToProgram(Address address) {
assert isInTraceRange(address, null);
long offset = address.subtract(mapping.getMinTraceAddress());
return staticRange.getMinAddress().add(offset);
return staticRange.getMinAddress().addWrapSpace(offset);
}
public ProgramLocation mapTraceAddressToProgramLocation(Address address) {
@ -197,7 +196,7 @@ public class DebuggerStaticMappingServicePlugin extends Plugin
protected Address mapProgramAddressToTrace(Address address) {
assert isInProgramRange(address);
long offset = address.subtract(staticRange.getMinAddress());
return mapping.getMinTraceAddress().add(offset);
return mapping.getMinTraceAddress().addWrapSpace(offset);
}
protected TraceLocation mapProgramAddressToTraceLocation(Address address) {

View file

@ -611,4 +611,27 @@ public class DebuggerStaticMappingServiceTest extends AbstractGhidraHeadedDebugg
DebuggerStaticMappingProposals.groupRegionsByLikelyModule(mm.getAllRegions());
assertEquals(Set.of(Set.of(echoText, echoData), Set.of(libText, libData)), actual);
}
protected void assertMapsTwoWay(long stOff, long dynOff) {
TraceLocation dynLoc =
new DefaultTraceLocation(tb.trace, null, Range.atLeast(0L), tb.addr(dynOff));
ProgramLocation stLoc = new ProgramLocation(program, stSpace.getAddress(stOff));
assertEquals(stLoc, mappingService.getOpenMappedLocation(dynLoc));
assertEquals(dynLoc, mappingService.getOpenMappedLocation(tb.trace, stLoc, 0));
}
@Test
public void testMapFullSpace() throws Exception {
try (UndoableTransaction tid = tb.startTransaction()) {
TraceLocation traceLoc =
new DefaultTraceLocation(tb.trace, null, Range.atLeast(0L), tb.addr(0));
ProgramLocation progLoc = new ProgramLocation(program, stSpace.getAddress(0));
// NB. 0 indicates 1 << 64
mappingService.addMapping(traceLoc, progLoc, 0, true);
}
waitForPass(() -> assertMapsTwoWay(0L, 0L));
assertMapsTwoWay(-1L, -1L);
assertMapsTwoWay(Long.MAX_VALUE, Long.MAX_VALUE);
assertMapsTwoWay(Long.MIN_VALUE, Long.MIN_VALUE);
}
}