]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
parse_filename: strip trailing CRs and LFs
authorDaniel Stenberg <daniel@haxx.se>
Mon, 19 Apr 2010 15:05:46 +0000 (17:05 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 19 Apr 2010 15:05:46 +0000 (17:05 +0200)
The feature that uses the file name given in a
Content-disposition: header didn't properly skip trailing
carriage returns and linefeed characters from the end of the file
name when it was given without quotes.

src/main.c

index 0670b5f5cd989f496d32bdd5e832fb07e0b81d7a..b7e438b1e638a4f62860bdb2807251f8520b668c 100644 (file)
@@ -4200,9 +4200,26 @@ parse_filename(char *ptr, size_t len)
     }
   }
 
-  q = strrchr(p, quote);
-  if (q)
-    *q = 0;
+  if(quote) {
+    /* if the file name started with a quote, then scan for the end quote and
+       stop there */
+    q = strrchr(p, quote);
+    if (q)
+      *q = 0;
+  }
+  else
+    q = NULL; /* no start quote, so no end has been found */
+
+  if(!q) {
+    /* make sure the file name doesn't end in \r or \n */
+    q = strchr(p, '\r');
+    if(q)
+      *q  = 0;
+
+    q = strchr(p, '\n');
+    if(q)
+      *q  = 0;
+  }
 
   if (copy!=p)
     memmove(copy, p, strlen(p)+1);