Skip to content

Commit

Permalink
[ASan][libc++] Correct (explicit) annotation size (llvm#79292)
Browse files Browse the repository at this point in the history
A quick examination suggests that the current code in the codebase does
not lead to incorrect annotations. However, the intention is for the
object after the function to be annotated in a way that only its
contents are unpoisoned and the rest is poisoned. This commit makes it
explicit and avoids potential issues in future.

In addition, I have implemented a few tests for a function that helped
me identify the specific argument value.

Notice: there is no known scenario where old code results in incorrect
annotation.
  • Loading branch information
Tacet authored Jan 25, 2024
1 parent a7759fb commit a315fb1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libcxx/include/string
Original file line number Diff line number Diff line change
Expand Up @@ -2380,7 +2380,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
__old_sz = __n_copy + __n_add + __sec_cp_sz;
__set_long_size(__old_sz);
traits_type::assign(__p[__old_sz], value_type());
__annotate_new(__old_cap + __delta_cap);
__annotate_new(__old_sz);
}

// __grow_by is deprecated because it does not set the size. It may not update the size when the size is changed, and it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {
test(S(), "12345678901234567890", 1, S("1"));
test(S(), "12345678901234567890", 3, S("123"));
test(S(), "12345678901234567890", 20, S("12345678901234567890"));
test(S(), "1234567890123456789012345678901234567890", 40, S("1234567890123456789012345678901234567890"));

test(S("12345"), "", 0, S("12345"));
test(S("12345"), "12345", 5, S("1234512345"));
Expand All @@ -44,6 +45,23 @@ TEST_CONSTEXPR_CXX20 void test_string() {
test(S("12345678901234567890"), "", 0, S("12345678901234567890"));
test(S("12345678901234567890"), "12345", 5, S("1234567890123456789012345"));
test(S("12345678901234567890"), "12345678901234567890", 20, S("1234567890123456789012345678901234567890"));

// Starting from long string (no SSO)
test(S("1234567890123456789012345678901234567890"), "", 0, S("1234567890123456789012345678901234567890"));
test(S("1234567890123456789012345678901234567890"), "a", 1, S("1234567890123456789012345678901234567890a"));
test(S("1234567890123456789012345678901234567890"),
"aaaaaaaaaa",
10,
S("1234567890123456789012345678901234567890aaaaaaaaaa"));
test(S("1234567890123456789012345678901234567890"),
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
300,
S("1234567890123456789012345678901234567890aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaa"));
}

TEST_CONSTEXPR_CXX20 bool test() {
Expand Down

0 comments on commit a315fb1

Please sign in to comment.