Skip to content
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

CXCursor.LambdaContextDecl cause AccessViolationException #184

Closed
phizch opened this issue Nov 10, 2020 · 1 comment
Closed

CXCursor.LambdaContextDecl cause AccessViolationException #184

phizch opened this issue Nov 10, 2020 · 1 comment

Comments

@phizch
Copy link
Contributor

phizch commented Nov 10, 2020

When the LambdaContextDecl property on a CXCursor that represents a CXXRecordDecl invalid memory might be accessed

Cause:

An assert raised in libClang.
see:
https://github.com/llvm/llvm-project/blob/ef4ffcafbb2deeb30ccc30ebcdf9a5a843a27ec1/clang/lib/AST/DeclCXX.cpp#L1534-L1538

If CXXRecordDecl::isLambda() is false an assert is caused, which somehow writes to invalid memory.

Solution:

Check CXXRecordDecl::isLambda() before accessing CXXRecordDecl::getLambdaContextDecl()

 CXCursor clangsharp_Cursor_getLambdaContextDecl(CXCursor C) { 
     if (clang_isDeclaration(C.kind)) { 
         const Decl* D = getCursorDecl(C); 
  
         if (const CXXRecordDecl* CRD = dyn_cast<CXXRecordDecl>(D)) { 
            if( CRD->isLambda() )
                return MakeCXCursor(CRD->getLambdaContextDecl(), getCursorTU(C));
         } 
     } 
  
     return clang_getNullCursor(); 
 } 

I've implemented the change and it fixed the problem.

Source location:

https://github.com/microsoft/ClangSharp/blob/2e4f410e6c065a2e51b54889f202b61c3c4a5438/sources/libClangSharp/ClangSharp.cpp#L1690-L1700

@tannergooding
Copy link
Member

This was resolved in #185

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants