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
This commit is contained in:
Patrick Monnerat 2022-10-04 16:50:45 +02:00 committed by Daniel Stenberg
parent 3664bccc54
commit 172259c4de
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
2 changed files with 8 additions and 3 deletions

View file

@ -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++ = '.';

Binary file not shown.