1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

Simplify string escapes

Treat backslash as a universal escape character: "\n" is a newline,
backslash escapes any non-alphanumeric character.

This affects some test cases that had "\," standing for backslash-comma.
With the new uniform treatment of backslashes, this needs to be "\\,".

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine
2022-12-03 23:48:25 +01:00
parent ca25deee12
commit 1a24895bfd
3 changed files with 18 additions and 18 deletions

View File

@ -180,24 +180,24 @@ static int parse_arguments(char *buf, size_t len, char **params,
p++;
}
/* Replace newlines, question marks and colons in strings */
/* Replace backslash escapes in strings */
for (i = 0; i < cnt; i++) {
p = params[i];
q = params[i];
while (*p != '\0') {
if (*p == '\\' && *(p + 1) == 'n') {
p += 2;
*(q++) = '\n';
} else if (*p == '\\' && *(p + 1) == ':') {
p += 2;
*(q++) = ':';
} else if (*p == '\\' && *(p + 1) == '?') {
p += 2;
*(q++) = '?';
} else {
*(q++) = *(p++);
if (*p == '\\') {
++p;
switch (*p) {
case 'n':
*p = '\n';
break;
default:
// Fall through to copying *p
break;
}
}
*(q++) = *(p++);
}
*q = '\0';
}