]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
libc/qsort: Don't allow interposing recursive calls
authorAlex Richardson <arichardson@FreeBSD.org>
Thu, 18 Feb 2021 10:12:29 +0000 (10:12 +0000)
committerAlex Richardson <arichardson@FreeBSD.org>
Thu, 18 Feb 2021 14:02:48 +0000 (14:02 +0000)
commitcbcfe28f9d5f975f97b7fb4a0d72bc9780eb0c46
tree31a056c00f8fb5cb6d63abb0e4601d75e9e9ef38
parent2aa3ef285a23d802f0bd6c7281612e16834e9b68
libc/qsort: Don't allow interposing recursive calls

This causes problems when using ASAN with a runtime older than 12.0 since
the intercept does not expect qsort() to call itself using an interposable
function call. This results in infinite recursion and stack exhaustion
when a binary compiled with -fsanitize=address calls qsort.
See also https://bugs.llvm.org/show_bug.cgi?id=46832 and
https://reviews.llvm.org/D84509 (ASAN runtime patch).

To prevent this problem, this patch uses a static helper function
for the actual qsort() implementation. This prevents interposition and
allows for direct calls. As a nice side-effect, we can also move the
qsort_s checks to the top-level function and out of the recursive calls.

Reviewed By: kib
Differential Revision: https://reviews.freebsd.org/D28133
lib/libc/stdlib/qsort.c