summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2013-05-01 02:53:14 +0000
committerAaron Ballman <aaron@aaronballman.com>2013-05-01 02:53:14 +0000
commitfd86e16dbd23ab2494ef4e5f938708e78a7705e3 (patch)
treea1fac9d0648207f069e9581612870115c0c1a7b1 /llvm/lib/Support
parent64dd73e5e12fa2585e22fc4d75301a2a6c833c63 (diff)
downloadbcm5719-llvm-fd86e16dbd23ab2494ef4e5f938708e78a7705e3.tar.gz
bcm5719-llvm-fd86e16dbd23ab2494ef4e5f938708e78a7705e3.zip
Fixes a buffer overrun where the allocated buffer wasn't large enough to accommodate the closing quote escape rules in some instances.
llvm-svn: 180836
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/Windows/Program.inc9
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/Support/Windows/Program.inc b/llvm/lib/Support/Windows/Program.inc
index 4a4ed2f84b1..619ae5d8f71 100644
--- a/llvm/lib/Support/Windows/Program.inc
+++ b/llvm/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;
}
OpenPOWER on IntegriCloud