From d76874a6651f4fcc62ddfa6fd7cfefb302bdefbe Mon Sep 17 00:00:00 2001 From: Jeff Pohlmeyer Date: Sat, 17 Jul 2010 20:04:02 +0200 Subject: 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. --- src/main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/main.c') 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; -- cgit v1.2.3