summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-05-22 19:07:45 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-05-22 19:07:45 +0000
commit0f656c39e1a079f37ac46ea965890243e611a656 (patch)
tree6f33c285ee7df36d6e211dab5d9ba84ea208de8d
parentacfe667eab02405cab9f98b92a056f6311a8d031 (diff)
downloadbcm5719-llvm-0f656c39e1a079f37ac46ea965890243e611a656.tar.gz
bcm5719-llvm-0f656c39e1a079f37ac46ea965890243e611a656.zip
Don't allow the UnEscape code to read or write beyond the end of yytext.
Make sure we convert \\ into \. llvm-svn: 37293
-rw-r--r--llvm/lib/AsmParser/Lexer.l31
1 files changed, 20 insertions, 11 deletions
diff --git a/llvm/lib/AsmParser/Lexer.l b/llvm/lib/AsmParser/Lexer.l
index 7183e0e3ce2..ca6ee2cf73d 100644
--- a/llvm/lib/AsmParser/Lexer.l
+++ b/llvm/lib/AsmParser/Lexer.l
@@ -102,15 +102,22 @@ static double HexToFP(const char *Buffer) {
// UnEscapeLexed - Run through the specified buffer and change \xx codes to the
// appropriate character.
-char *UnEscapeLexed(char *Buffer) {
+char *UnEscapeLexed(char *Buffer, char* EndBuffer) {
char *BOut = Buffer;
for (char *BIn = Buffer; *BIn; ) {
- if (BIn[0] == '\\' && isxdigit(BIn[1]) && isxdigit(BIn[2])) {
- char Tmp = BIn[3]; BIn[3] = 0; // Terminate string
- *BOut = (char)strtol(BIn+1, 0, 16); // Convert to number
- BIn[3] = Tmp; // Restore character
- BIn += 3; // Skip over handled chars
- ++BOut;
+ if (BIn[0] == '\\') {
+ if (BIn < EndBuffer-1 && BIn[1] == '\\') {
+ *BOut++ = '\\'; // Two \ becomes one
+ BIn += 2;
+ } else if (BIn < EndBuffer-2 && isxdigit(BIn[1]) && isxdigit(BIn[2])) {
+ char Tmp = BIn[3]; BIn[3] = 0; // Terminate string
+ *BOut = (char)strtol(BIn+1, 0, 16); // Convert to number
+ BIn[3] = Tmp; // Restore character
+ BIn += 3; // Skip over handled chars
+ ++BOut;
+ } else {
+ *BOut++ = *BIn++;
+ }
} else {
*BOut++ = *BIn++;
}
@@ -326,28 +333,30 @@ shufflevector { RET_TOK(OtherOpVal, ShuffleVector, SHUFFLEVECTOR); }
}
{QuoteLabel} {
yytext[yyleng-2] = 0; // nuke colon, end quote
- const char* EndChar = UnEscapeLexed(yytext+1);
+ const char* EndChar = UnEscapeLexed(yytext+1, yytext+yyleng);
llvmAsmlval.StrVal =
new std::string(yytext+1, EndChar - yytext - 1);
return LABELSTR;
}
{StringConstant} { yytext[yyleng-1] = 0; // nuke end quote
- const char* EndChar = UnEscapeLexed(yytext+1);
+ const char* EndChar = UnEscapeLexed(yytext+1, yytext+yyleng);
llvmAsmlval.StrVal =
new std::string(yytext+1, EndChar - yytext - 1);
return STRINGCONSTANT;
}
{AtStringConstant} {
yytext[yyleng-1] = 0; // nuke end quote
- const char* EndChar = UnEscapeLexed(yytext+2);
+ const char* EndChar =
+ UnEscapeLexed(yytext+2, yytext+yyleng);
llvmAsmlval.StrVal =
new std::string(yytext+2, EndChar - yytext - 2);
return ATSTRINGCONSTANT;
}
{PctStringConstant} {
yytext[yyleng-1] = 0; // nuke end quote
- const char* EndChar = UnEscapeLexed(yytext+2);
+ const char* EndChar =
+ UnEscapeLexed(yytext+2, yytext+yyleng);
llvmAsmlval.StrVal =
new std::string(yytext+2, EndChar - yytext - 2);
return PCTSTRINGCONSTANT;
OpenPOWER on IntegriCloud