diff options
author | Daniel Stenberg <daniel@haxx.se> | 2020-10-01 22:59:30 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2020-10-01 22:59:30 +0200 |
commit | da00d983b2933d81594ec12a7a10ff9fe5c83bfc (patch) | |
tree | f85be973a59814baecd73ca7d24c35ac8379edb1 | |
parent | 9a13f7c2a7ca5fca99622a6feeb29abc3b05d713 (diff) | |
download | curl-da00d983b2933d81594ec12a7a10ff9fe5c83bfc.tar.gz |
curl: make --libcurl show binary posts correctly
Reported-by: Stephan Mühlstrasser
Fixes #6031
-rw-r--r-- | src/tool_operate.c | 4 | ||||
-rw-r--r-- | src/tool_setopt.c | 13 | ||||
-rw-r--r-- | src/tool_setopt.h | 11 |
3 files changed, 18 insertions, 10 deletions
diff --git a/src/tool_operate.c b/src/tool_operate.c index e03bbedb8..54c99e3bc 100644 --- a/src/tool_operate.c +++ b/src/tool_operate.c @@ -320,8 +320,10 @@ static CURLcode pre_transfer(struct GlobalConfig *global, if(S_ISREG(fileinfo.st_mode)) uploadfilesize = fileinfo.st_size; - if(uploadfilesize != -1) + if(uploadfilesize != -1) { + struct OperationConfig *config = per->config; /* for the macro below */ my_setopt(per->curl, CURLOPT_INFILESIZE_LARGE, uploadfilesize); + } per->input.fd = per->infd; } return result; diff --git a/src/tool_setopt.c b/src/tool_setopt.c index 9858d49c9..0cf1a1da6 100644 --- a/src/tool_setopt.c +++ b/src/tool_setopt.c @@ -238,7 +238,8 @@ static char *c_escape(const char *str, size_t len) return NULL; e = escaped; - for(s = str; (c = *s) != '\0'; s++) { + for(s = str; len; s++, len--) { + c = *s; if(c == '\n') { strcpy(e, "\\n"); e += 2; @@ -623,7 +624,8 @@ CURLcode tool_setopt_slist(CURL *curl, struct GlobalConfig *config, /* generic setopt wrapper for all other options. * Some type information is encoded in the tag value. */ -CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *config, +CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global, + struct OperationConfig *config, const char *name, CURLoption tag, ...) { va_list arg; @@ -711,14 +713,17 @@ CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *config, va_end(arg); - if(config->libcurl && !skip && !ret) { + if(global->libcurl && !skip && !ret) { /* we only use this for real if --libcurl was used */ if(remark) REM2("%s set to a %s", name, value); else { if(escape) { - escaped = c_escape(value, CURL_ZERO_TERMINATED); + size_t len = CURL_ZERO_TERMINATED; + if(tag == CURLOPT_POSTFIELDS) + len = config->postfieldsize; + escaped = c_escape(value, len); NULL_CHECK(escaped); CODE2("curl_easy_setopt(hnd, %s, \"%s\");", name, escaped); } diff --git a/src/tool_setopt.h b/src/tool_setopt.h index 9fe142cf1..3db88c6bf 100644 --- a/src/tool_setopt.h +++ b/src/tool_setopt.h @@ -98,14 +98,15 @@ CURLcode tool_setopt_mimepost(CURL *curl, struct GlobalConfig *config, CURLcode tool_setopt_slist(CURL *curl, struct GlobalConfig *config, const char *name, CURLoption tag, struct curl_slist *list); -CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *config, +CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global, + struct OperationConfig *config, const char *name, CURLoption tag, ...); #define my_setopt(x,y,z) \ - SETOPT_CHECK(tool_setopt(x, FALSE, global, #y, y, z), y) + SETOPT_CHECK(tool_setopt(x, FALSE, global, config, #y, y, z), y) #define my_setopt_str(x,y,z) \ - SETOPT_CHECK(tool_setopt(x, TRUE, global, #y, y, z), y) + SETOPT_CHECK(tool_setopt(x, TRUE, global, config, #y, y, z), y) #define my_setopt_enum(x,y,z) \ SETOPT_CHECK(tool_setopt_enum(x, global, #y, y, setopt_nv_ ## y, z), y) @@ -122,9 +123,9 @@ CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *config, #define my_setopt_slist(x,y,z) \ SETOPT_CHECK(tool_setopt_slist(x, global, #y, y, z), y) -#define res_setopt(x,y,z) tool_setopt(x, FALSE, global, #y, y, z) +#define res_setopt(x,y,z) tool_setopt(x, FALSE, global, config, #y, y, z) -#define res_setopt_str(x,y,z) tool_setopt(x, TRUE, global, #y, y, z) +#define res_setopt_str(x,y,z) tool_setopt(x, TRUE, global, config, #y, y, z) #else /* CURL_DISABLE_LIBCURL_OPTION */ |