This is an archive of the discontinued LLVM Phabricator instance.

[msan] Check qsort input.
ClosedPublic

Authored by eugenis on Dec 20 2019, 12:16 PM.

Details

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.

Diff Detail

Event Timeline

eugenis created this revision.Dec 20 2019, 12:16 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 20 2019, 12:16 PM
Herald added a subscriber: Restricted Project. · View Herald Transcript

Unit tests: unknown.

clang-tidy: unknown.

clang-format: unknown.

Build artifacts: diff.json, console-log.txt

This revision is now accepted and ready to land.Dec 20 2019, 12:34 PM
This revision was automatically updated to reflect the committed changes.

This change actually broke llvm bootstrap and had to be reverted.
A stateful comparator? Investigating...

CompareOptionRecords checks that there are no duplicate options in the sorting comparator function.
I believe this is wrong, because I could not find a promise in POSIX nor in linux manpages that the comparator would never be called with the same object on both left and right hand side.

Nevertheless, I don't want sanitizers to enforce this peculiarity in the standard.

eugenis reopened this revision.Dec 26 2019, 1:06 PM
This revision is now accepted and ready to land.Dec 26 2019, 1:06 PM
eugenis updated this revision to Diff 235373.Dec 26 2019, 1:06 PM

avoid comparing an element to itself

vitalybuka accepted this revision.Dec 26 2019, 1:09 PM
vitalybuka added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
9678

maybe just:

compar(p, q);
compar(q, p);
eugenis updated this revision to Diff 235374.Dec 26 2019, 1:15 PM

removed the (i % 2) thing. Comparators should not be sensitive to the argument order.

eugenis marked an inline comment as done.Dec 26 2019, 1:17 PM
eugenis added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
9678

A sensible comparator should do the same work no matter what the order of arguments is. Just compar(p, q) should suffice.

Unit tests: pass. 61127 tests passed, 0 failed and 728 were skipped.

clang-tidy: pass.

clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or applying this patch.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Unit tests: pass. 61127 tests passed, 0 failed and 728 were skipped.

clang-tidy: pass.

clang-format: fail. Please format your changes with clang-format by running git-clang-format HEAD^ or applying this patch.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

vitalybuka accepted this revision.Jan 6 2020, 2:00 PM

what is about clang-format?

what is about clang-format?

it's nonsense

This revision was automatically updated to reflect the committed changes.