File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -422,15 +422,13 @@ std::string clangimport::AstNode::getSpelling() const
422422 if (nodeType == FunctionDecl || nodeType == CXXConstructorDecl || nodeType == CXXMethodDecl) {
423423 while (typeIndex >= 0 && mExtTokens [typeIndex][0 ] != ' \' ' )
424424 typeIndex--;
425- if (typeIndex <= 0 )
426- return " " ;
427425 }
428426 if (nodeType == DeclRefExpr) {
429427 while (typeIndex > 0 && std::isalpha (mExtTokens [typeIndex][0 ]))
430428 typeIndex--;
431- if (typeIndex <= 0 )
432- return " " ;
433429 }
430+ if (typeIndex <= 0 )
431+ return " " ;
434432 const std::string &str = mExtTokens [typeIndex - 1 ];
435433 if (startsWith (str," col:" ))
436434 return " " ;
Original file line number Diff line number Diff line change @@ -139,6 +139,7 @@ class TestClangImport : public TestFixture {
139139 TEST_CASE (valueType2);
140140
141141 TEST_CASE (crash);
142+ TEST_CASE (crash2);
142143 }
143144
144145 std::string parse (const char clang[]) {
@@ -1372,6 +1373,13 @@ class TestClangImport : public TestFixture {
13721373 " `-CompoundStmt 0x5603791b5700 <col:54, col:55>\n " ;
13731374 (void )parse (clang); // don't crash
13741375 }
1376+
1377+ void crash2 () {
1378+ // getSpelling() indexed mExtTokens[typeIndex - 1] without a lower-bound
1379+ // check, so a node whose line carries no ext tokens (typeIndex <= 0) read
1380+ // out of bounds.
1381+ (void )parse (" `-RecordDecl " ); // don't crash
1382+ }
13751383};
13761384
13771385REGISTER_TEST (TestClangImport)
You can’t perform that action at this time.
0 commit comments