a8c9f4
From a6fcd8a32f3b1c5d80e524f8b2c1de32e6ecdb2b Mon Sep 17 00:00:00 2001
a8c9f4
From: Daniel Stenberg <daniel@haxx.se>
a8c9f4
Date: Sun, 31 May 2020 23:09:59 +0200
a8c9f4
Subject: [PATCH] tool_getparam: -i is not OK if -J is used
a8c9f4
a8c9f4
Reported-by: sn on hackerone
a8c9f4
Bug: https://curl.haxx.se/docs/CVE-2020-8177.html
a8c9f4
a8c9f4
Upstream-commit: 8236aba58542c5f89f1d41ca09d84579efb05e22
a8c9f4
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
a8c9f4
---
a8c9f4
 src/tool_cb_hdr.c   | 13 ++++---------
a8c9f4
 src/tool_getparam.c |  5 +++++
a8c9f4
 2 files changed, 9 insertions(+), 9 deletions(-)
a8c9f4
a8c9f4
diff --git a/src/tool_cb_hdr.c b/src/tool_cb_hdr.c
a8c9f4
index 3b10238..b80707f 100644
a8c9f4
--- a/src/tool_cb_hdr.c
a8c9f4
+++ b/src/tool_cb_hdr.c
a8c9f4
@@ -132,16 +132,11 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
a8c9f4
       filename = parse_filename(p, len);
a8c9f4
       if(filename) {
a8c9f4
         if(outs->stream) {
a8c9f4
-          /* already opened and possibly written to */
a8c9f4
-          if(outs->fopened)
a8c9f4
-            fclose(outs->stream);
a8c9f4
-          outs->stream = NULL;
a8c9f4
-
a8c9f4
-          /* rename the initial file name to the new file name */
a8c9f4
-          rename(outs->filename, filename);
a8c9f4
-          if(outs->alloc_filename)
a8c9f4
-            free(outs->filename);
a8c9f4
+          /* indication of problem, get out! */
a8c9f4
+          free(filename);
a8c9f4
+          return failure;
a8c9f4
         }
a8c9f4
+
a8c9f4
         outs->is_cd_filename = TRUE;
a8c9f4
         outs->s_isreg = TRUE;
a8c9f4
         outs->fopened = FALSE;
a8c9f4
diff --git a/src/tool_getparam.c b/src/tool_getparam.c
a8c9f4
index 764caa2..c5c7429 100644
a8c9f4
--- a/src/tool_getparam.c
a8c9f4
+++ b/src/tool_getparam.c
a8c9f4
@@ -1745,6 +1745,11 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
a8c9f4
       }
a8c9f4
       break;
a8c9f4
     case 'i':
a8c9f4
+      if(config->content_disposition) {
a8c9f4
+        warnf(global,
a8c9f4
+              "--include and --remote-header-name cannot be combined.\n");
a8c9f4
+        return PARAM_BAD_USE;
a8c9f4
+      }
a8c9f4
       config->show_headers = toggle; /* show the headers as well in the
a8c9f4
                                         general output stream */
a8c9f4
       break;
a8c9f4
-- 
a8c9f4
2.21.3
a8c9f4