1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-06-16 06:15:24 +00:00

Feature: Use proper \xHH escaping for log lines

This commit is contained in:
Philipp Schafft 2018-09-12 09:13:57 +00:00
parent dd0cfacb61
commit 19b665ba5c

View File

@ -440,6 +440,7 @@ void log_contents (int log_id, char **_contents, unsigned int *_len)
} }
static void __vsnprintf(char *str, size_t size, const char *format, va_list ap) { static void __vsnprintf(char *str, size_t size, const char *format, va_list ap) {
static const char hextable[] = "0123456789abcdef";
int in_block = 0; int in_block = 0;
int block_size = 0; int block_size = 0;
int block_len = 0; int block_len = 0;
@ -554,10 +555,22 @@ static void __vsnprintf(char *str, size_t size, const char *format, va_list ap)
{ {
for (; *arg && block_len && size; arg++, size--, block_len--) for (; *arg && block_len && size; arg++, size--, block_len--)
{ {
if ((*arg <= '"' || *arg == '`' || *arg == '\\') && !(block_space && *arg == ' ')) if ((*arg <= '"' || *arg == '`' || *arg == '\\') && !(block_space && *arg == ' ')) {
*(str++) = '.'; if (size < 4) {
else /* Use old system if we do not have space for new one */
*(str++) = '.';
} else {
*(str++) = '\\';
*(str++) = 'x';
*(str++) = hextable[(*arg >> 0) & 0x0F];
*(str++) = hextable[(*arg >> 4) & 0x0F];
/* Also count the additional chars for string size and block length */
size -= 3;
block_len -= 3;
}
} else {
*(str++) = *arg; *(str++) = *arg;
}
} }
} }
else else