Fix potential null dereference of ObjCTypeParamList in Cursor argument and type-param APIs#704
Merged
tannergooding merged 1 commit intoJul 12, 2026
Conversation
…t and type-param APIs ObjCCategoryDecl::getTypeParamList and ObjCInterfaceDecl::getTypeParamList can return null for declarations without a type-parameter list. clangsharp_Cursor_getArgument and clangsharp_Cursor_getTypeParam dereferenced the result via ->size() without a null check, unlike the sibling clangsharp_Cursor_getNumTypeParams which already guards it. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
clangsharp_Cursor_getArgumentandclangsharp_Cursor_getTypeParamdereference the result ofObjCCategoryDecl::getTypeParamList/ObjCInterfaceDecl::getTypeParamListvia->size()without a null check. These accessors returnnullfor an ObjC category/interface that has no type-parameter list, so this is a latent null dereference.The sibling
clangsharp_Cursor_getNumTypeParamsalready guards the same accessor with a null check, so this is just a same-operation-implemented-two-ways inconsistency. This makes all three unchecked sites match that existing pattern (if (typeParamList != nullptr && i < typeParamList->size())).Fixed sites in
sources/libClangSharp/ClangSharp.cpp:clangsharp_Cursor_getArgument(ObjCCategoryDecl)clangsharp_Cursor_getTypeParam(ObjCCategoryDecl)clangsharp_Cursor_getTypeParam(ObjCInterfaceDecl)Native-only change; no C# or generated files touched. Verified by inspection against the existing null-checked sibling code -- a full native build/test was not run locally as it requires the complete LLVM/Clang toolchain.
Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com