summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatrick Monnerat <patrick@monnerat.net>2022-10-04 16:50:45 +0200
committerDaniel Stenberg <daniel@haxx.se>2022-10-05 16:09:46 +0200
commit172259c4de33036e231748205eaa61087d1b9de4 (patch)
tree04997377419a3f6c8e2d62e2e6ec4f32919b19eb /src
parent3664bccc54c2026d4d1fb7d99fa1a7b83ca9ae9b (diff)
downloadcurl-172259c4de33036e231748205eaa61087d1b9de4.tar.gz
tool: avoid generating ambiguous escaped characters in --libcurl
C string hexadecimal-escaped characters may have more than 2 digits. This results in a wrong C compiler interpretation of a 2-digit escaped character when followed by an hex digit character. The solution retained here is to represent such characters as 3-digit octal escapes. Adjust and extend test 1465 for this case. Closes #9643
Diffstat (limited to 'src')
-rw-r--r--src/tool_setopt.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/tool_setopt.c b/src/tool_setopt.c
index b05138889..917191ef2 100644
--- a/src/tool_setopt.c
+++ b/src/tool_setopt.c
@@ -252,12 +252,17 @@ static char *c_escape(const char *str, curl_off_t len)
strcpy(e, "\\?");
e += 2;
}
- else if(!ISPRINT(c)) {
+ else if(ISPRINT(c))
+ *e++ = c;
+ else if(len > 1 && ISXDIGIT(s[1])) {
+ /* Octal escape to avoid >2 digit hex. */
+ msnprintf(e, 5, "\\%03o", (unsigned)c);
+ e += 4;
+ }
+ else {
msnprintf(e, 5, "\\x%02x", (unsigned)c);
e += 4;
}
- else
- *e++ = c;
}
while(cutoff--)
*e++ = '.';