Bug 1260208 - part 0 - correctly compare EHTable when sorting; r=froydnj

operator< for EHTable compares the LHS start PC with the RHS *end* PC.
Because the ranges are non-overlapping, this works fine for two distinct
EHTables. However, the comparison doesn't work if LHS and RHS refer to
the same EHTable; in that case operator< returns true, even though it
should return false because the two operands are identical.

The operator is used to sort a std::vector using std::sort [1].  I think
the libc++ std::sort implementation has a quirk where, if the comparison
function has the above bug, sort will sometimes get confused, and start
sorting "values" outside of the memory range that it's given.  This
results in memory corruption and subsequent unpredictable behavior.

The fix is simply to compare only the start PCs in EHTable, so that
std::sort can work on it correctly.

[1] http://mxr.mozilla.org/mozilla-central/source/tools/profiler/core/EHABIStackWalk.cpp?rev=86730d0a8209#485
This commit is contained in:
Jim Chen 2016-05-03 09:13:49 -04:00
parent 94c96f680f
commit 0574002b30

View File

@ -475,7 +475,7 @@ bool EHInterp::unwind() {
bool operator<(const EHTable &lhs, const EHTable &rhs) {
return lhs.startPC() < rhs.endPC();
return lhs.startPC() < rhs.startPC();
}
// Async signal unsafe.