Skip to content

Commit a315fb1

Browse files
author
Tacet
authored
[ASan][libc++] Correct (explicit) annotation size (#79292)
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.
1 parent a7759fb commit a315fb1

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

libcxx/include/string

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2380,7 +2380,7 @@ _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__
23802380
__old_sz = __n_copy + __n_add + __sec_cp_sz;
23812381
__set_long_size(__old_sz);
23822382
traits_type::assign(__p[__old_sz], value_type());
2383-
__annotate_new(__old_cap + __delta_cap);
2383+
__annotate_new(__old_sz);
23842384
}
23852385

23862386
// __grow_by is deprecated because it does not set the size. It may not update the size when the size is changed, and it

libcxx/test/std/strings/basic.string/string.modifiers/string_append/pointer_size.pass.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ TEST_CONSTEXPR_CXX20 void test_string() {
3636
test(S(), "12345678901234567890", 1, S("1"));
3737
test(S(), "12345678901234567890", 3, S("123"));
3838
test(S(), "12345678901234567890", 20, S("12345678901234567890"));
39+
test(S(), "1234567890123456789012345678901234567890", 40, S("1234567890123456789012345678901234567890"));
3940

4041
test(S("12345"), "", 0, S("12345"));
4142
test(S("12345"), "12345", 5, S("1234512345"));
@@ -44,6 +45,23 @@ TEST_CONSTEXPR_CXX20 void test_string() {
4445
test(S("12345678901234567890"), "", 0, S("12345678901234567890"));
4546
test(S("12345678901234567890"), "12345", 5, S("1234567890123456789012345"));
4647
test(S("12345678901234567890"), "12345678901234567890", 20, S("1234567890123456789012345678901234567890"));
48+
49+
// Starting from long string (no SSO)
50+
test(S("1234567890123456789012345678901234567890"), "", 0, S("1234567890123456789012345678901234567890"));
51+
test(S("1234567890123456789012345678901234567890"), "a", 1, S("1234567890123456789012345678901234567890a"));
52+
test(S("1234567890123456789012345678901234567890"),
53+
"aaaaaaaaaa",
54+
10,
55+
S("1234567890123456789012345678901234567890aaaaaaaaaa"));
56+
test(S("1234567890123456789012345678901234567890"),
57+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
58+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
59+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
60+
300,
61+
S("1234567890123456789012345678901234567890aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
62+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
63+
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
64+
"aaaaaaaaaaaaa"));
4765
}
4866

4967
TEST_CONSTEXPR_CXX20 bool test() {

0 commit comments

Comments
 (0)