[llvm] r180836 - Fixes a buffer overrun where the allocated buffer wasn't large enough to accommodate the closing quote escape rules in some instances.

Aaron Ballman aaron at aaronballman.com
Tue Apr 30 19:53:14 PDT 2013


Author: aaronballman
Date: Tue Apr 30 21:53:14 2013
New Revision: 180836

URL: http://llvm.org/viewvc/llvm-project?rev=180836&view=rev
Log:
Fixes a buffer overrun where the allocated buffer wasn't large enough to accommodate the closing quote escape rules in some instances.

Modified:
    llvm/trunk/lib/Support/Windows/Program.inc

Modified: llvm/trunk/lib/Support/Windows/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Program.inc?rev=180836&r1=180835&r2=180836&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Program.inc (original)
+++ llvm/trunk/lib/Support/Windows/Program.inc Tue Apr 30 21:53:14 2013
@@ -155,7 +155,8 @@ static char *EscapePrecedingEscapes(char
 /// 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(con
     ++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;
 }
 





More information about the llvm-commits mailing list