aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/curl/src/tool_setopt.c
diff options
context:
space:
mode:
authorrobot-contrib <robot-contrib@yandex-team.com>2022-12-02 16:18:16 +0300
committerrobot-contrib <robot-contrib@yandex-team.com>2022-12-02 16:18:16 +0300
commit22a73deb46c33ab8539b522286f0fb9b3364f856 (patch)
treeaf3cf69e9e6ebc887a5add5491b2fcebbfdff06a /contrib/libs/curl/src/tool_setopt.c
parent2e7d246d83a0077f08e6fed36594fc2087949502 (diff)
downloadydb-22a73deb46c33ab8539b522286f0fb9b3364f856.tar.gz
Update contrib/libs/curl to 7.86.0
Diffstat (limited to 'contrib/libs/curl/src/tool_setopt.c')
-rw-r--r--contrib/libs/curl/src/tool_setopt.c125
1 files changed, 46 insertions, 79 deletions
diff --git a/contrib/libs/curl/src/tool_setopt.c b/contrib/libs/curl/src/tool_setopt.c
index 5ff86c7f5b..3db2fe3c68 100644
--- a/contrib/libs/curl/src/tool_setopt.c
+++ b/contrib/libs/curl/src/tool_setopt.c
@@ -33,6 +33,7 @@
#include "tool_easysrc.h"
#include "tool_setopt.h"
#include "tool_msgs.h"
+#include "dynbuf.h"
#include "memdebug.h" /* keep this as LAST include */
@@ -145,35 +146,6 @@ const struct NameValue setopt_nv_CURL_NETRC[] = {
NVEND,
};
-/* These mappings essentially triplicated - see
- * tool_libinfo.c and tool_paramhlp.c */
-const struct NameValue setopt_nv_CURLPROTO[] = {
- NV(CURLPROTO_ALL), /* combination */
- NV(CURLPROTO_DICT),
- NV(CURLPROTO_FILE),
- NV(CURLPROTO_FTP),
- NV(CURLPROTO_FTPS),
- NV(CURLPROTO_GOPHER),
- NV(CURLPROTO_HTTP),
- NV(CURLPROTO_HTTPS),
- NV(CURLPROTO_IMAP),
- NV(CURLPROTO_IMAPS),
- NV(CURLPROTO_LDAP),
- NV(CURLPROTO_LDAPS),
- NV(CURLPROTO_POP3),
- NV(CURLPROTO_POP3S),
- NV(CURLPROTO_RTSP),
- NV(CURLPROTO_SCP),
- NV(CURLPROTO_SFTP),
- NV(CURLPROTO_SMB),
- NV(CURLPROTO_SMBS),
- NV(CURLPROTO_SMTP),
- NV(CURLPROTO_SMTPS),
- NV(CURLPROTO_TELNET),
- NV(CURLPROTO_TFTP),
- NVEND,
-};
-
/* These options have non-zero default values. */
static const struct NameValue setopt_nv_CURLNONZERODEFAULTS[] = {
NV1(CURLOPT_SSL_VERIFYPEER, 1),
@@ -223,7 +195,7 @@ static const struct NameValue setopt_nv_CURLNONZERODEFAULTS[] = {
#define REM0(s) ADD((&easysrc_toohard, s))
#define REM1(f,a) ADDF((&easysrc_toohard, f,a))
-#define REM2(f,a,b) ADDF((&easysrc_toohard, f,a,b))
+#define REM3(f,a,b,c) ADDF((&easysrc_toohard, f,a,b,c))
/* Escape string to C string syntax. Return NULL if out of memory.
* Is this correct for those wacky EBCDIC guys? */
@@ -234,9 +206,11 @@ static const struct NameValue setopt_nv_CURLNONZERODEFAULTS[] = {
static char *c_escape(const char *str, curl_off_t len)
{
const char *s;
- unsigned char c;
- char *escaped, *e;
unsigned int cutoff = 0;
+ CURLcode result;
+ struct curlx_dynbuf escaped;
+
+ curlx_dyn_init(&escaped, 4 * MAX_STRING_LENGTH_OUTPUT + 3);
if(len == ZERO_TERMINATED)
len = strlen(str);
@@ -247,51 +221,44 @@ static char *c_escape(const char *str, curl_off_t len)
cutoff = 3;
}
- /* Allocate space based on worst-case */
- escaped = malloc(4 * (size_t)len + 1 + cutoff);
- if(!escaped)
- return NULL;
-
- e = escaped;
- for(s = str; len; s++, len--) {
- c = *s;
- if(c == '\n') {
- strcpy(e, "\\n");
- e += 2;
- }
- else if(c == '\r') {
- strcpy(e, "\\r");
- e += 2;
- }
- else if(c == '\t') {
- strcpy(e, "\\t");
- e += 2;
- }
- else if(c == '\\') {
- strcpy(e, "\\\\");
- e += 2;
- }
- else if(c == '"') {
- strcpy(e, "\\\"");
- e += 2;
- }
- else if(c == '?') {
- /* escape question marks as well, to prevent generating accidental
- trigraphs */
- strcpy(e, "\\?");
- e += 2;
- }
- else if(!isprint(c)) {
- msnprintf(e, 5, "\\x%02x", (unsigned)c);
- e += 4;
+ result = curlx_dyn_addn(&escaped, STRCONST(""));
+ for(s = str; !result && len; s++, len--) {
+ /* escape question marks as well, to prevent generating accidental
+ trigraphs */
+ static const char from[] = "\t\r\n?\"\\";
+ static const char to[] = "\\t\\r\\n\\?\\\"\\\\";
+ const char *p = strchr(from, *s);
+
+ if(!p && ISPRINT(*s))
+ continue;
+
+ result = curlx_dyn_addn(&escaped, str, s - str);
+ str = s + 1;
+
+ if(!result) {
+ if(p && *p)
+ result = curlx_dyn_addn(&escaped, to + 2 * (p - from), 2);
+ else {
+ const char *format = "\\x%02x";
+
+ if(len > 1 && ISXDIGIT(s[1])) {
+ /* Octal escape to avoid >2 digit hex. */
+ format = "\\%03o";
+ }
+
+ result = curlx_dyn_addf(&escaped, format,
+ (unsigned int) *(unsigned char *) s);
+ }
}
- else
- *e++ = c;
}
- while(cutoff--)
- *e++ = '.';
- *e = '\0';
- return escaped;
+
+ if(!result)
+ result = curlx_dyn_addn(&escaped, str, s - str);
+
+ if(!result)
+ (void) !curlx_dyn_addn(&escaped, "...", cutoff);
+
+ return curlx_dyn_ptr(&escaped);
}
/* setopt wrapper for enum types */
@@ -668,7 +635,7 @@ CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global,
/* function pointers are never printable */
if(tag >= CURLOPTTYPE_FUNCTIONPOINT) {
if(pval) {
- value = "functionpointer";
+ value = "function pointer";
remark = TRUE;
}
else
@@ -680,7 +647,7 @@ CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global,
escape = TRUE;
}
else if(pval) {
- value = "objectpointer";
+ value = "object pointer";
remark = TRUE;
}
else
@@ -706,7 +673,7 @@ CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global,
/* blobs are never printable */
if(pblob) {
- value = "blobpointer";
+ value = "blob pointer";
remark = TRUE;
}
else
@@ -721,7 +688,7 @@ CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global,
/* we only use this for real if --libcurl was used */
if(remark)
- REM2("%s set to a %s", name, value);
+ REM3("%s was set to a%s %s", name, (*value == 'o' ? "n" : ""), value);
else {
if(escape) {
curl_off_t len = ZERO_TERMINATED;