[RemoteMirror] Add NULL checks to Remote Mirror malloc calls.

These calls can fail when passed absurd sizes, which can happen when we try to read data that's corrupt or doesn't contain what we think it should. Fail gracefully instead of crashing.

rdar://78210820
This commit is contained in:
Mike Ash
2021-05-19 13:25:09 -04:00
parent bf4a4af82a
commit 1aa30366e5
2 changed files with 7 additions and 0 deletions

View File

@@ -100,6 +100,8 @@ public:
virtual ReadBytesResult
readBytes(RemoteAddress address, uint64_t size) {
auto *Buf = malloc(size);
if (!Buf)
return ReadBytesResult{};
ReadBytesResult Result(Buf, [](const void *ptr) {
free(const_cast<void *>(ptr));
});