-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reland "[libclang] Always Dup in createRef(StringRef)" #127078
Merged
vitalybuka
merged 2 commits into
main
from
revert-127076-revert-125020-users/vitalybuka/spr/libclang-always-dup-in-createref
Feb 20, 2025
Merged
Reland "[libclang] Always Dup in createRef(StringRef)" #127078
vitalybuka
merged 2 commits into
main
from
revert-127076-revert-125020-users/vitalybuka/spr/libclang-always-dup-in-createref
Feb 20, 2025
Conversation
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
…)" This reverts commit a1345eb.
@llvm/pr-subscribers-clang Author: Vitaly Buka (vitalybuka) ChangesReverts llvm/llvm-project#127076 Full diff: https://github.com/llvm/llvm-project/pull/127078.diff 2 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 03bddbe3e983a..e41ad384b84f7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -257,6 +257,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) {
|
It passes now https://lab.llvm.org/buildbot/#/builders/24/builds/5488 |
@fmayer Looks like my patch exposed another UAF Looking, and will revert if there is no quick fix |
joaosaffran
pushed a commit
to joaosaffran/llvm-project
that referenced
this pull request
Feb 27, 2025
Reverts llvm#127076 to reland llvm#125020. Use-after-free should be fixed here llvm#127063
joaosaffran
pushed a commit
to joaosaffran/llvm-project
that referenced
this pull request
Feb 27, 2025
Passing after llvm#127078.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:as-a-library
libclang and C++ API
clang
Clang issues not falling into any other category
skip-precommit-approval
PR for CI feedback, not intended for review
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reverts #127076 to reland #125020
Use-after-free should be fixed here #127063