asm goto: fix out-of-bounds read of Constraints after rC362045
authorFangrui Song <maskray@google.com>
Thu, 30 May 2019 08:03:02 +0000 (08:03 +0000)
committerFangrui Song <maskray@google.com>
Thu, 30 May 2019 08:03:02 +0000 (08:03 +0000)
When parsing goto labels, Names and Exprs are expanded but Constraints
is not, this may cause a out-of-bounds read later in:

// GCCAsmStmt::GCCAsmStmt
// `constraints` has only `NumExprs - NumLabels` elements
  Constraints = new (C) StringLiteral*[NumExprs];
  std::copy(constraints, constraints + NumExprs, Constraints);

llvm-svn: 362067

clang/lib/Parse/ParseStmtAsm.cpp

index 75f3ac3..e1c48da 100644 (file)
@@ -846,6 +846,7 @@ StmtResult Parser::ParseAsmStatement(bool &msAsm) {
       ExprResult Res =
           Actions.ActOnAddrLabel(Tok.getLocation(), Tok.getLocation(), LD);
       Exprs.push_back(Res.get());
+      Constraints.emplace_back();
       NumLabels++;
       ConsumeToken();
       if (!TryConsumeToken(tok::comma))