Skip to content

Commit

Permalink
Fix #13492 Use-after-free in simplifyUsing() (#7143)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Dec 29, 2024
1 parent 360189d commit 1fb14d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 1 addition & 6 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3386,12 +3386,7 @@ bool Tokenizer::simplifyUsing()
Token *usingStart = it->startTok;
Token *usingEnd = it->endTok;
if (usingStart->previous()) {
if (usingEnd->next())
Token::eraseTokens(usingStart->previous(), usingEnd->next());
else {
Token::eraseTokens(usingStart->previous(), usingEnd);
usingEnd->deleteThis();
}
Token::eraseTokens(usingStart->previous(), usingEnd->next());
} else {
if (usingEnd->next()) {
Token::eraseTokens(usingStart, usingEnd->next());
Expand Down
9 changes: 9 additions & 0 deletions test/testsimplifyusing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class TestSimplifyUsing : public TestFixture {
TEST_CASE(simplifyUsing32);
TEST_CASE(simplifyUsing33);
TEST_CASE(simplifyUsing34);
TEST_CASE(simplifyUsing35);

TEST_CASE(simplifyUsing8970);
TEST_CASE(simplifyUsing8971);
Expand Down Expand Up @@ -854,6 +855,14 @@ class TestSimplifyUsing : public TestFixture {
ASSERT_EQUALS("", errout_str());
}

void simplifyUsing35() { // #13492
const char code[] = "using a = b;\n"
"using c = d;\n";
const char expected[] = ";";
ASSERT_EQUALS(expected, tok(code));
ASSERT_EQUALS("", errout_str());
}

void simplifyUsing8970() {
const char code[] = "using V = std::vector<int>;\n"
"struct A {\n"
Expand Down

0 comments on commit 1fb14d6

Please sign in to comment.