Skip to content

Commit 4d55b06

Browse files
committed
Add one more overflow safety check, const some stuff
1 parent 58501db commit 4d55b06

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -972,8 +972,8 @@ Status MinidumpFileBuilder::DumpDirectories() const {
972972
Status MinidumpFileBuilder::ReadWriteMemoryInChunks(
973973
const lldb_private::CoreFileMemoryRange &range, uint64_t *bytes_read) {
974974
Log *log = GetLog(LLDBLog::Object);
975-
lldb::addr_t addr = range.range.start();
976-
lldb::addr_t size = range.range.size();
975+
const lldb::addr_t addr = range.range.start();
976+
const lldb::addr_t size = range.range.size();
977977
// First we set the byte tally to 0, so if we do exit gracefully
978978
// the caller doesn't think the random garbage on the stack is a
979979
// success.
@@ -1024,7 +1024,13 @@ Status MinidumpFileBuilder::ReadWriteMemoryInChunks(
10241024
if (error.Fail())
10251025
return error;
10261026

1027-
// This check is so we don't overflow when the error code above sets the
1027+
// If the bytes read in this chunk would cause us to overflow, set the
1028+
// remaining bytes to 0 so we exit. This is a safety check so we don't
1029+
// get stuck building a bigger file forever.
1030+
if (bytes_read_for_chunk > bytes_remaining)
1031+
bytes_remaining = 0;
1032+
1033+
// This check is so we don't overflow when the error above sets the
10281034
// bytes to read to 0 (the graceful exit condition).
10291035
if (bytes_remaining > 0)
10301036
bytes_remaining -= bytes_read_for_chunk;

0 commit comments

Comments
 (0)