diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2013-05-01 02:53:14 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2013-05-01 02:53:14 +0000 |
commit | af35d86bbd9a970d5bb55595a569ea60962bf23d (patch) | |
tree | 1f367d3cb2d1b0ef8721ff4556d20a5a45eaa149 /lib/Support/Windows/Program.inc | |
parent | 10cc563bfe330cf4118b2f0db6706c244e77ebb3 (diff) | |
download | external_llvm-af35d86bbd9a970d5bb55595a569ea60962bf23d.zip external_llvm-af35d86bbd9a970d5bb55595a569ea60962bf23d.tar.gz external_llvm-af35d86bbd9a970d5bb55595a569ea60962bf23d.tar.bz2 |
Fixes a buffer overrun where the allocated buffer wasn't large enough to accommodate the closing quote escape rules in some instances.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180836 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Windows/Program.inc')
-rw-r--r-- | lib/Support/Windows/Program.inc | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/Support/Windows/Program.inc b/lib/Support/Windows/Program.inc index 4a4ed2f..619ae5d 100644 --- a/lib/Support/Windows/Program.inc +++ b/lib/Support/Windows/Program.inc @@ -155,7 +155,8 @@ static char *EscapePrecedingEscapes(char *Dst, const char *Start, /// CreateProcess and returns length of quoted arg with escaped quotes static unsigned int ArgLenWithQuotes(const char *Str) { const char *Start = Str; - unsigned int len = ArgNeedsQuotes(Str) ? 2 : 0; + bool Quoted = ArgNeedsQuotes(Str); + unsigned int len = Quoted ? 2 : 0; while (*Str != '\0') { if (*Str == '\"') { @@ -171,6 +172,12 @@ static unsigned int ArgLenWithQuotes(const char *Str) { ++Str; } + if (Quoted) { + // Make sure the closing quote doesn't get escaped by a trailing backslash. + unsigned PrecedingEscapes = CountPrecedingBackslashes(Start, Str); + len += PrecedingEscapes + 1; + } + return len; } |