Skip to content

[lldb] Fix off by one in array index check in Objective C runtime plugin #118995

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

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

DavidSpickett
Copy link
Collaborator

@llvmbot llvmbot added the lldb label Dec 6, 2024
@DavidSpickett DavidSpickett changed the title [lldb] Fix off by one in array index check [lldb] Fix off by one in array index check in Objective C runtime code Dec 6, 2024
@DavidSpickett DavidSpickett changed the title [lldb] Fix off by one in array index check in Objective C runtime code [lldb] Fix off by one in array index check in Objective C runtime plugin Dec 6, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 6, 2024

@llvm/pr-subscribers-lldb

Author: David Spickett (DavidSpickett)

Changes

Reported in #116944 / https://pvs-studio.com/en/blog/posts/cpp/1188/.


Full diff: https://github.com/llvm/llvm-project/pull/118995.diff

1 Files Affected:

  • (modified) lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp (+1-1)
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
index 0083b499656979..c43871b08191db 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp
@@ -3278,7 +3278,7 @@ bool AppleObjCRuntimeV2::NonPointerISACache::EvaluateNonPointerISA(
       }
 
       // If the index is still out of range then this isn't a pointer.
-      if (index > m_indexed_isa_cache.size())
+      if (index >= m_indexed_isa_cache.size())
         return false;
 
       LLDB_LOGF(log, "AOCRT::NPI Evaluate(ret_isa = 0x%" PRIx64 ")",

@DavidSpickett
Copy link
Collaborator Author

Seems obvious but perhaps Apple folks can confirm that there isn't some hidden detail here, or a larger mistake hiding in the background.

@DavidSpickett DavidSpickett merged commit a46ee73 into llvm:main Dec 6, 2024
7 of 8 checks passed
@DavidSpickett DavidSpickett deleted the lldb-offbyone branch December 6, 2024 16:41
adrian-prantl pushed a commit to adrian-prantl/llvm-project that referenced this pull request Dec 6, 2024
adrian-prantl added a commit to swiftlang/llvm-project that referenced this pull request Dec 9, 2024
…-6.1-lldb-Fix-off-by-one-in-array-index-check-in-Objective-C-runtime-plugin-118995

[Cherry-pick into swift/release/6.1] [lldb] Fix off by one in array index check in Objective C runtime plugin (llvm#118995)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants