From bc57f3cfada779521b579ba184d70e0a6f98d62f Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Tue, 5 Jul 2011 11:13:37 +0000 Subject: [PATCH] Don't overread the buffer when an %x escape in inline asm ends prematurely. Tested by valgrind & Sema/asm.c. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134404 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Stmt.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index 39f23fba9e..e293f324ab 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -366,6 +366,10 @@ unsigned AsmStmt::AnalyzeAsmString(llvm::SmallVectorImpl&Pieces, // Handle %x4 and %x[foo] by capturing x as the modifier character. char Modifier = '\0'; if (isalpha(EscapedChar)) { + if (CurPtr == StrEnd) { // Premature end. + DiagOffs = CurPtr-StrStart-1; + return diag::err_asm_invalid_escape; + } Modifier = EscapedChar; EscapedChar = *CurPtr++; } -- 2.50.1