llvm-project/libcxx/test/std
Petr Hosek 89385633ba [libc++] Set __file_ to 0 in basic_filebuf::close() even if fclose fails
This issue was detected by ASan in one of our tests. This test manually
invokes basic_filebuf::cloe(). fclose(__h.release() returned a non-zero
exit status, so __file_ wasn't set to 0. Later when basic_filebuf
destructor ran, we would enter the if (__file_) block again leading to
heap-use-after-free error.

The POSIX specification for fclose says that independently of the return
value, fclose closes the underlying file descriptor and any further
access (including another call to fclose()) to the stream results in
undefined behavior. This is exactly what happened in our test case.

To avoid this issue, we have to always set __file_ to 0 independently of
the fclose return value.

Differential Revision: https://reviews.llvm.org/D64979

llvm-svn: 366730
2019-07-22 19:54:34 +00:00
..
algorithms This patch makes swap functions constexpr. Both swap overloads, swap_ranges and iter_swap are updated (with tests). 2019-07-05 20:13:34 +00:00
atomics [libcxx] [test] Add void cast to result of compare_exchange_weak to suppress [[nodiscard]]. 2019-07-01 08:09:02 +00:00
containers [libc++] Add missing UNSUPPORTED for CTAD tests 2019-07-16 20:41:33 +00:00
depr AIX system headers need stdint.h and inttypes.h to be re-enterable 2019-06-20 15:36:32 +00:00
diagnostics Add include for 'test_macros.h' to all the tests that were missing them. Thanks to Zoe for the (big, but simple) patch. NFC intended. 2019-05-31 18:35:30 +00:00
experimental [libcxx] Slightly improved policy for handling experimental features 2019-06-11 14:48:40 +00:00
input.output [libc++] Set __file_ to 0 in basic_filebuf::close() even if fclose fails 2019-07-22 19:54:34 +00:00
iterators Add include for 'test_macros.h' to all the tests that were missing them. Thanks to Zoe for the (big, but simple) patch. NFC intended. 2019-05-31 18:35:30 +00:00
language.support [libcxx] Rejigger test for destroying delete feature-test macros 2019-07-16 21:13:40 +00:00
localization [libcxx] Add XFAIL for facet test when back-deploying to older macOS 2019-06-14 14:40:38 +00:00
numerics Bit Operations: P0556, P0553 and P1355. Reviewed as: https://reviews.llvm.org/D51262 2019-07-01 23:00:32 +00:00
re Add tests for regex_match ambiguity (aka LWG2273). NFC. Reviewed as https://reviews.llvm.org/D63051 2019-07-03 20:32:35 +00:00
strings Followup to revision 364545: Turns out that clang issues different errors for C++11 vs c++2a, so I tweaked the 'expected-error' bits that I added to match either of them. 2019-06-27 15:37:31 +00:00
thread Fix PR27658 - Make ~mutex trivial when possible. 2019-07-07 01:20:54 +00:00
utilities [libc++] Add C++17 deduction guides for std::function 2019-07-18 19:50:56 +00:00
nothing_to_do.pass.cpp Support tests in freestanding 2019-02-04 20:31:13 +00:00