diff options
author | Evan Martin <martine@danga.com> | 2011-12-29 20:44:15 (GMT) |
---|---|---|
committer | Evan Martin <martine@danga.com> | 2011-12-29 20:44:15 (GMT) |
commit | 47ba90bd530cfd269f40e61e5d41e87298812ddb (patch) | |
tree | 036c43c3d07eab02b49ca593eca4e54b5a9a8727 /src/depfile_parser.in.cc | |
parent | eaf1ff190423b1cf41eb1b905192be07aeb6b22e (diff) | |
download | Ninja-47ba90bd530cfd269f40e61e5d41e87298812ddb.zip Ninja-47ba90bd530cfd269f40e61e5d41e87298812ddb.tar.gz Ninja-47ba90bd530cfd269f40e61e5d41e87298812ddb.tar.bz2 |
handle nuls more carefully in re2c rules
- '.' in re2c matches anything except \n, which means it matches \000.
Be more careful about which characters we match.
- The fallback rule [^] reads ahead another character, which means it
can read past the trailing \000. Add a separate rule to match it
specifically.
This was found by Valgrind.
Diffstat (limited to 'src/depfile_parser.in.cc')
-rw-r--r-- | src/depfile_parser.in.cc | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/depfile_parser.in.cc b/src/depfile_parser.in.cc index c469a2c..b310c58 100644 --- a/src/depfile_parser.in.cc +++ b/src/depfile_parser.in.cc @@ -55,6 +55,7 @@ bool DepfileParser::Parse(string* content, string* err) { re2c:yych:emit = 0; + nul = "\000"; escape = [ \\#*$[|]; '\\' escape { @@ -62,7 +63,7 @@ bool DepfileParser::Parse(string* content, string* err) { *out++ = yych; continue; } - '\\'. { + '\\'[^\000\n] { // Let backslash before other characters through verbatim. *out++ = '\\'; *out++ = yych; @@ -76,6 +77,9 @@ bool DepfileParser::Parse(string* content, string* err) { out += len; continue; } + nul { + break; + } [^] { // For any other character (e.g. whitespace), swallow it here, // allowing the outer logic to loop around again. |