aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Pohlmeyer <yetanothergeek@gmail.com>2010-07-17 20:04:02 +0200
committerDaniel Stenberg <daniel@haxx.se>2010-07-17 20:12:47 +0200
commitd76874a6651f4fcc62ddfa6fd7cfefb302bdefbe (patch)
tree7b5895843a778c664f5dcd32776eca5eb5ade41d
parentc8d42b2f1c105706098309644c2aa90ae6a1206f (diff)
remote-header-name: chop filename at next semicolon
The --remote-header-name option for the command-line tool assumes that everything beyond the filename= field is part of the filename, but that might not always be the case, for example: Content-Disposition: attachment; filename=file.txt; modification-date=... This fix chops the filename off at the next semicolon, if there is one.
-rw-r--r--src/main.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index 35a352a8d..f35fc62d5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4388,6 +4388,7 @@ header_callback(void *ptr, size_t size, size_t nmemb, void *stream)
const char* str = (char*)ptr;
const size_t cb = size*nmemb;
const char* end = (char*)ptr + cb;
+ size_t len;
if (cb > 20 && curlx_strnequal(str, "Content-disposition:", 20)) {
char *p = (char*)str + 20;
@@ -4396,6 +4397,7 @@ header_callback(void *ptr, size_t size, size_t nmemb, void *stream)
(encoded filenames (*=) are not supported) */
for(;;) {
char *filename;
+ char *semi;
while (*p && (p < end) && !ISALPHA(*p))
p++;
@@ -4409,7 +4411,13 @@ header_callback(void *ptr, size_t size, size_t nmemb, void *stream)
continue;
}
p+=9;
- filename = parse_filename(p, cb - (p - str));
+ semi = strchr(p, ';');
+
+ /* this expression below typecasts 'cb' only to avoid
+ warning: signed and unsigned type in conditional expression
+ */
+ len = semi ? (semi - p) : (ssize_t)cb - (p - str);
+ filename = parse_filename(p, len);
if (filename) {
outs->filename = filename;
break;