diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6344c4b36e357..cb4442e99a6ae 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -252,6 +252,9 @@ clang-format libclang -------- +- Fixed a buffer overflow in ``CXString`` implementation. The fix may result in + increased memory allocation. + Code Completion --------------- diff --git a/clang/tools/libclang/CXString.cpp b/clang/tools/libclang/CXString.cpp index 5e427957a1092..aaa8f8eeb67a1 100644 --- a/clang/tools/libclang/CXString.cpp +++ b/clang/tools/libclang/CXString.cpp @@ -87,19 +87,7 @@ CXString createRef(StringRef String) { if (String.empty()) return createEmpty(); - // If the string is not nul-terminated, we have to make a copy. - - // FIXME: This is doing a one past end read, and should be removed! For memory - // we don't manage, the API string can become unterminated at any time outside - // our control. - - if (String.data()[String.size()] != 0) - return createDup(String); - - CXString Result; - Result.data = String.data(); - Result.private_flags = (unsigned) CXS_Unmanaged; - return Result; + return createDup(String); } CXString createDup(StringRef String) {