Fixes a buffer overrun where the allocated buffer wasn't large enough to accommodate...
authorAaron Ballman <aaron@aaronballman.com>
Wed, 1 May 2013 02:53:14 +0000 (02:53 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Wed, 1 May 2013 02:53:14 +0000 (02:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180836 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/Windows/Program.inc

index 4a4ed2f84b11db8c3f9c6d4e78f7455fb4bc2ba3..619ae5d8f713760dc5359948adaeeaa25355fce7 100644 (file)
@@ -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;
 }