diff options
author | Daniel Stenberg <daniel@haxx.se> | 2022-04-17 11:18:16 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2022-04-17 11:18:17 +0200 |
commit | 01a1697a79205faa9c5e3b0d8a63f98dc4fb8fa0 (patch) | |
tree | 921efb1b2ce0c3afc009f3cdab52a27ca66d9134 | |
parent | 6968fb9d54dc3a1aaa1b16088f038eaf5dd8b2d7 (diff) | |
download | curl-01a1697a79205faa9c5e3b0d8a63f98dc4fb8fa0.tar.gz |
curl: error out if -T and -d are used for the same URL
As one implies PUT and the other POST, both cannot be used
simultaneously.
Add test 378 to verify.
Reported-by: Boris Verkhovskiy
Fixes #8704
Closes #8715
-rw-r--r-- | src/tool_helpers.c | 8 | ||||
-rw-r--r-- | src/tool_operate.c | 6 | ||||
-rw-r--r-- | src/tool_sdecls.h | 5 | ||||
-rw-r--r-- | tests/data/Makefile.inc | 2 | ||||
-rw-r--r-- | tests/data/test378 | 39 |
5 files changed, 54 insertions, 6 deletions
diff --git a/src/tool_helpers.c b/src/tool_helpers.c index 9244d1fb5..d47a8d244 100644 --- a/src/tool_helpers.c +++ b/src/tool_helpers.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -85,7 +85,8 @@ int SetHTTPrequest(struct OperationConfig *config, HttpReq req, HttpReq *store) "GET (-G, --get)", "HEAD (-I, --head)", "multipart formpost (-F, --form)", - "POST (-d, --data)" + "POST (-d, --data)", + "PUT (-T, --upload-file)" }; if((*store == HTTPREQ_UNSPEC) || @@ -109,7 +110,8 @@ void customrequest_helper(struct OperationConfig *config, HttpReq req, "GET", "HEAD", "POST", - "POST" + "POST", + "PUT" }; if(!method) diff --git a/src/tool_operate.c b/src/tool_operate.c index cc9fc9a57..bf6aff6ee 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -917,6 +917,12 @@ static CURLcode single_transfer(struct GlobalConfig *global, result = CURLE_OUT_OF_MEMORY; break; } + if(SetHTTPrequest(config, HTTPREQ_PUT, &config->httpreq)) { + Curl_safefree(per->uploadfile); + curl_easy_cleanup(curl); + result = CURLE_FAILED_INIT; + break; + } } *added = TRUE; per->config = config; diff --git a/src/tool_sdecls.h b/src/tool_sdecls.h index 543a953fd..ed7d77966 100644 --- a/src/tool_sdecls.h +++ b/src/tool_sdecls.h @@ -7,7 +7,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -127,7 +127,8 @@ typedef enum { HTTPREQ_GET, HTTPREQ_HEAD, HTTPREQ_MIMEPOST, - HTTPREQ_SIMPLEPOST + HTTPREQ_SIMPLEPOST, + HTTPREQ_PUT } HttpReq; diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc index 9863a9d21..7e9b6b4fb 100644 --- a/tests/data/Makefile.inc +++ b/tests/data/Makefile.inc @@ -61,7 +61,7 @@ test334 test335 test336 test337 test338 test339 test340 test341 test342 \ test343 test344 test345 test346 test347 test348 test349 test350 test351 \ test352 test353 test354 test355 test356 test357 test358 test359 test360 \ test361 test362 test363 test364 test365 test366 test367 test368 test369 \ -test370 test371 test372 test373 test374 test375 test376 \ +test370 test371 test372 test373 test374 test375 test376 test378 \ \ test380 test381 test383 test384 test385 test386 \ \ diff --git a/tests/data/test378 b/tests/data/test378 new file mode 100644 index 000000000..650e7d4e1 --- /dev/null +++ b/tests/data/test378 @@ -0,0 +1,39 @@ +<testcase> +<info> +<keywords> +HTTP PUT +HTTP POST +</keywords> +</info> + +# +# Server-side +<reply> +</reply> + +# +# Client-side +<client> +<server> +none +</server> + <name> +Reject using -T and -d at once + </name> + <command> +-T log/%TESTNUMBER -d input http://never-accessed +</command> +</client> + +# +# Verify data after the test has been "shot" +<verify> +<errorcode> +2 +</errorcode> +<stderr mode="text"> +Warning: You can only select one HTTP request method! You asked for both PUT +Warning: (-T, --upload-file) and POST (-d, --data). +</stderr> +</verify> +</testcase> |