[libcxx-commits] [libcxx] [libc++][hardening] Enable comparator checks for safe mode too (PR #66458)

Daniel Kutenin via libcxx-commits libcxx-commits at lists.llvm.org
Mon Sep 18 07:20:38 PDT 2023


danlark1 wrote:

> > What are the implications of a bad comparator? Could it cause an algorithm to go off the rails in an unsafe way, e.g. returning an out-of-bounds element, or would it "just" lead to returning an incorrect result (or fail to return)?
> 
> Potential OOBs should be caught by other checks that are enabled in the safe mode. This is the case of the `sort` algorithm for example: if you pass an invalid comparator, it could try to go OOB but we added additional checks to ensure that it didn't happen.

Current implementation of std::sort might go OOB only if there are at least 6 elements in the range, below this range it will never get OOB. This check helps to identify earlier bad comparators because in tests it usually goes below this threshold

https://github.com/llvm/llvm-project/pull/66458


More information about the libcxx-commits mailing list