summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib
diff options
context:
space:
mode:
authorEvgenii Stepanov <eugenis@google.com>2019-12-20 12:07:04 -0800
committerEvgenii Stepanov <eugenis@google.com>2019-12-23 11:34:49 -0800
commitcaa48a6b88aeed8ae80e6ddb1eae8c6a7cbe260b (patch)
tree091e1b7e05ffa0876828677e60e7fcd61a6d5ef5 /compiler-rt/lib
parent7a9ebe95125ea87a494d0c18f44f10bd70e12188 (diff)
downloadbcm5719-llvm-caa48a6b88aeed8ae80e6ddb1eae8c6a7cbe260b.tar.gz
bcm5719-llvm-caa48a6b88aeed8ae80e6ddb1eae8c6a7cbe260b.zip
[msan] Check qsort input.
Summary: Qsort interceptor suppresses all checks by unpoisoning the data in the wrapper of a comparator function, and then unpoisoning the output array as well. This change adds an explicit run of the comparator on all elements of the input array to catch any sanitizer bugs. Reviewers: vitalybuka Subscribers: #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D71780
Diffstat (limited to 'compiler-rt/lib')
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc18
1 files changed, 18 insertions, 0 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
index 2d9636a9c87..68a9db5bba7 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -9665,6 +9665,15 @@ INTERCEPTOR(void, qsort, void *base, SIZE_T nmemb, SIZE_T size,
qsort_compar_f compar) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, qsort, base, nmemb, size, compar);
+ // Run the comparator over all array elements to detect any memory issues.
+ for (SIZE_T i = 0; i < nmemb; ++i) {
+ void *p = (void *)((char *)base + i * size);
+ COMMON_INTERCEPTOR_UNPOISON_PARAM(2);
+ // Compare each element with itself to trigger an equality check, which
+ // typically requires the comparator to look as many of the object fields as
+ // possible.
+ compar(p, p);
+ }
qsort_compar_f old_compar = qsort_compar;
qsort_compar = compar;
SIZE_T old_size = qsort_size;
@@ -9694,6 +9703,15 @@ INTERCEPTOR(void, qsort_r, void *base, SIZE_T nmemb, SIZE_T size,
qsort_r_compar_f compar, void *arg) {
void *ctx;
COMMON_INTERCEPTOR_ENTER(ctx, qsort_r, base, nmemb, size, compar, arg);
+ // Run the comparator over all array elements to detect any memory issues.
+ for (SIZE_T i = 0; i < nmemb; ++i) {
+ void *p = (void *)((char *)base + i * size);
+ COMMON_INTERCEPTOR_UNPOISON_PARAM(3);
+ // Compare each element with itself to trigger an equality check, which
+ // typically requires the comparator to look as many of the object fields as
+ // possible.
+ compar(p, p, arg);
+ }
qsort_r_compar_f old_compar = qsort_r_compar;
qsort_r_compar = compar;
SIZE_T old_size = qsort_r_size;
OpenPOWER on IntegriCloud