From 172259c4de33036e231748205eaa61087d1b9de4 Mon Sep 17 00:00:00 2001 From: Patrick Monnerat Date: Tue, 4 Oct 2022 16:50:45 +0200 Subject: [PATCH] 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 --- src/tool_setopt.c | 11 ++++++++--- tests/data/test1465 | Bin 3095 -> 3163 bytes 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/tool_setopt.c b/src/tool_setopt.c index b051388895..917191ef29 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++ = '.'; diff --git a/tests/data/test1465 b/tests/data/test1465 index 356b1e1b9439058dc7b6779cdd31dc42bac49cdf..9703f68cf2c0786711876fb52d12bbda2b765b48 100644 GIT binary patch delta 184 zc-osTaa&@8JQFu#T6#vNR91FQF4JTcCKUsPy!^b>@|?`PR9mIW)M6z&F4c_Gis;0o zHKy#N3J -- 2.47.3