Skip to content

Commit a16fa3a

Browse files
authored
Reland "[libclang] Always Dup in createRef(StringRef)" (#127078)
Reverts #127076 to reland #125020. Use-after-free should be fixed here #127063
1 parent bf9b72e commit a16fa3a

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ clang-format
266266
libclang
267267
--------
268268

269+
- Fixed a buffer overflow in ``CXString`` implementation. The fix may result in
270+
increased memory allocation.
271+
269272
Code Completion
270273
---------------
271274

clang/tools/libclang/CXString.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,7 @@ CXString createRef(StringRef String) {
8787
if (String.empty())
8888
return createEmpty();
8989

90-
// If the string is not nul-terminated, we have to make a copy.
91-
92-
// FIXME: This is doing a one past end read, and should be removed! For memory
93-
// we don't manage, the API string can become unterminated at any time outside
94-
// our control.
95-
96-
if (String.data()[String.size()] != 0)
97-
return createDup(String);
98-
99-
CXString Result;
100-
Result.data = String.data();
101-
Result.private_flags = (unsigned) CXS_Unmanaged;
102-
return Result;
90+
return createDup(String);
10391
}
10492

10593
CXString createDup(StringRef String) {

0 commit comments

Comments
 (0)