mirror of
https://github.com/siemens-mobile-hacks/llvm-c166.git
synced 2026-11-26 06:28:13 +00:00
`Process::DoReadMemoryRanges` asserts the caller's buffer is long enough
before it writes into it, and returns empty ranges when asserts are off.
`MemoryCache::ReadRanges` writes a cache hit into the same buffer with
no
such check, in `lldb/source/Target/Memory.cpp`:
```
316: results.push_back(buffer.take_front(len)); // take_front clamps 16 -> 8
317: buffer = buffer.drop_front(len); // asks to drop 16 from 8
318: memcpy(results.back().data(), cached, len); // writes 16 into 8 bytes
```
With assertions on, `MutableArrayRef::drop_front` aborts one line before
the `memcpy`, so the new test dies on the wrong message:
```
Death test: { read_results = cache.ReadRanges(ranges, short_buffer); }
Result: died but not with expected error.
Expected: contains regular expression "MemoryCache::ReadRanges: provided buffer is too short"
Actual msg:
[ DEATH ] Assertion failed: (this->size() >= N && "Dropping more elements than exist"), function drop_front, file ArrayRef.h, line 384.
```
With assertions off that abort is gone and the `memcpy` runs. An
AddressSanitizer build reports a heap-buffer-overflow write of 16 bytes
into the 8 byte buffer, 8 bytes past its end.
`Process::ReadMemoryRanges` goes through the cache unless it is
disabled,
so the cache is the first of the two to write and it needs the same
guard.
`TestReadMemoryRangesWithShortBuffer` did not catch this because both of
its ranges miss the cache, which leaves the whole buffer to
`DoReadMemoryRanges` and lets that assert fire first. Disable the cache
in it so it reaches the guard it is named after, and add a case whose
range hits the cache. Name the function in both assert messages: the old
message is a substring of the new one, and a death test matches by
substring, so naming only the new guard would leave that test accepting
either.
|
||
|---|---|---|
| .. | ||
| ABI.cpp | ||
| AssertFrameRecognizer.cpp | ||
| BorrowedStackFrame.cpp | ||
| CMakeLists.txt | ||
| CoreFileMemoryRanges.cpp | ||
| DynamicRegisterInfo.cpp | ||
| ExecutionContext.cpp | ||
| InstrumentationRuntime.cpp | ||
| InstrumentationRuntimeStopInfo.cpp | ||
| JITLoader.cpp | ||
| JITLoaderList.cpp | ||
| Language.cpp | ||
| LanguageRuntime.cpp | ||
| Memory.cpp | ||
| MemoryHistory.cpp | ||
| MemoryRegionInfo.cpp | ||
| MemoryRegionInfoCache.cpp | ||
| MemoryTagMap.cpp | ||
| ModuleCache.cpp | ||
| OperatingSystem.cpp | ||
| PathMappingList.cpp | ||
| Platform.cpp | ||
| Process.cpp | ||
| ProcessIOHandler.cpp | ||
| ProcessTrace.cpp | ||
| Queue.cpp | ||
| QueueItem.cpp | ||
| QueueList.cpp | ||
| RegisterContext.cpp | ||
| RegisterContextUnwind.cpp | ||
| RegisterNumber.cpp | ||
| RemoteAwarePlatform.cpp | ||
| ScriptedThreadPlan.cpp | ||
| SectionLoadHistory.cpp | ||
| SectionLoadList.cpp | ||
| StackFrame.cpp | ||
| StackFrameList.cpp | ||
| StackFrameRecognizer.cpp | ||
| StackID.cpp | ||
| Statistics.cpp | ||
| StopInfo.cpp | ||
| StructuredDataPlugin.cpp | ||
| SyntheticFrameProvider.cpp | ||
| SystemRuntime.cpp | ||
| Target.cpp | ||
| TargetAPIMutex.cpp | ||
| TargetList.cpp | ||
| TargetProperties.td | ||
| Thread.cpp | ||
| ThreadCollection.cpp | ||
| ThreadList.cpp | ||
| ThreadPlan.cpp | ||
| ThreadPlanBase.cpp | ||
| ThreadPlanCallFunction.cpp | ||
| ThreadPlanCallFunctionUsingABI.cpp | ||
| ThreadPlanCallOnFunctionExit.cpp | ||
| ThreadPlanCallUserExpression.cpp | ||
| ThreadPlanRunToAddress.cpp | ||
| ThreadPlanShouldStopHere.cpp | ||
| ThreadPlanSingleThreadTimeout.cpp | ||
| ThreadPlanStack.cpp | ||
| ThreadPlanStepInRange.cpp | ||
| ThreadPlanStepInstruction.cpp | ||
| ThreadPlanStepOut.cpp | ||
| ThreadPlanStepOverBreakpoint.cpp | ||
| ThreadPlanStepOverRange.cpp | ||
| ThreadPlanStepRange.cpp | ||
| ThreadPlanStepThrough.cpp | ||
| ThreadPlanStepUntil.cpp | ||
| ThreadPlanTracer.cpp | ||
| ThreadSpec.cpp | ||
| Trace.cpp | ||
| TraceCursor.cpp | ||
| TraceDumper.cpp | ||
| TraceExporter.cpp | ||
| UnixSignals.cpp | ||
| UnwindAssembly.cpp | ||
| UnwindLLDB.cpp | ||