Skip to content

Commit

Permalink
[LLDB][Reliability] Fix accessing invalid iterator
Browse files Browse the repository at this point in the history
Using invalidated vector iterator is at best a UB and could crash depending on STL implementation.
Fixing via minimal changes to preserve the existing code style.

Coverity warning 1454828  (scan.coverity.com)

Differential Revision: https://reviews.llvm.org/D130312
  • Loading branch information
fixathon committed Jul 22, 2022
1 parent 02fe96b commit 98186de
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,10 @@ bool DynamicLoaderMacOSXDYLD::RemoveModulesUsingImageInfosAddress(
// Also copy over the uuid from the old entry to the removed entry so we
// can use it to lookup the module in the module list.

ImageInfo::collection::iterator pos, end = m_dyld_image_infos.end();
for (pos = m_dyld_image_infos.begin(); pos != end; pos++) {
bool found = false;

for (ImageInfo::collection::iterator pos = m_dyld_image_infos.begin();
pos != m_dyld_image_infos.end(); pos++) {
if (image_infos[idx].address == (*pos).address) {
image_infos[idx].uuid = (*pos).uuid;

Expand All @@ -635,11 +637,12 @@ bool DynamicLoaderMacOSXDYLD::RemoveModulesUsingImageInfosAddress(
// Then remove it from the m_dyld_image_infos:

m_dyld_image_infos.erase(pos);
found = true;
break;
}
}

if (pos == end) {
if (!found) {
if (log) {
LLDB_LOGF(log, "Could not find image_info entry for unloading image:");
image_infos[idx].PutToLog(log);
Expand Down

0 comments on commit 98186de

Please sign in to comment.