forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++][hardening] Add checks to
forward_list
element access. (llv…
…m#120858) In our implementation, failing these checks would result in a null pointer access rather than an out-of-bounds access.
- Loading branch information
Showing
3 changed files
with
58 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -407,7 +407,7 @@ Hardened containers status | |
- ✅ | ||
- ❌ | ||
* - ``forward_list`` | ||
- ❌ | ||
- ✅ | ||
- ❌ | ||
* - ``deque`` | ||
- ✅ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
libcxx/test/libcxx/containers/sequences/forwardlist/assert.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <forward_list> | ||
|
||
// Test hardening assertions for std::forward_list. | ||
|
||
// REQUIRES: has-unix-headers | ||
// REQUIRES: libcpp-hardening-mode={{extensive|debug}} | ||
// UNSUPPORTED: c++03 | ||
// XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing | ||
|
||
#include <forward_list> | ||
|
||
#include "check_assertion.h" | ||
|
||
int main(int, char**) { | ||
{ // Default-constructed list. | ||
std::forward_list<int> c; | ||
const auto& const_c = c; | ||
TEST_LIBCPP_ASSERT_FAILURE(c.front(), "forward_list::front called on an empty list"); | ||
TEST_LIBCPP_ASSERT_FAILURE(const_c.front(), "forward_list::front called on an empty list"); | ||
TEST_LIBCPP_ASSERT_FAILURE(c.pop_front(), "forward_list::pop_front called on an empty list"); | ||
} | ||
|
||
{ // Non-empty list becomes empty. | ||
std::forward_list<int> c; | ||
const auto& const_c = c; | ||
c.push_front(1); | ||
|
||
// Check that there's no assertion on valid access. | ||
(void)c.front(); | ||
(void)const_c.front(); | ||
|
||
c.pop_front(); | ||
TEST_LIBCPP_ASSERT_FAILURE(c.pop_front(), "forward_list::pop_front called on an empty list"); | ||
TEST_LIBCPP_ASSERT_FAILURE(c.front(), "forward_list::front called on an empty list"); | ||
TEST_LIBCPP_ASSERT_FAILURE(const_c.front(), "forward_list::front called on an empty list"); | ||
} | ||
|
||
return 0; | ||
} |