Don't overread the buffer when an %x escape in inline asm ends prematurely.

Tested by valgrind & Sema/asm.c.

llvm-svn: 134404
This commit is contained in:
Benjamin Kramer 2011-07-05 11:13:37 +00:00
parent de1d62314a
commit e87c38b229
1 changed files with 4 additions and 0 deletions

View File

@ -366,6 +366,10 @@ unsigned AsmStmt::AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece>&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++;
}