We stop strnvisx(3)ing logs to FILE: by default.

Our logging framework used to strnvisx(3) each and every line
iff it is written to a FILE.  This is often unhelpful because
the line usually contains a number of elements that have already
been quoted and it makes the logs much more difficult to read in
this case.  An example if krb5_unparse_name() which will already
quote most characters that one cares about.

We change the behaviour to simply drop unprintable characters
rather than encoding them.  We thus rely on the rest of the
code to properly encode data elements written into the logs.
This commit is contained in:
Roland C. Dowdeswell
2019-11-18 21:26:09 +00:00
committed by Viktor Dukhovni
parent 575c67806b
commit fb9a78223c

View File

@@ -214,7 +214,8 @@ log_file(krb5_context context, const char *timestr, const char *msg, void *data)
struct timeval tv;
struct file_data *f = data;
char *msgclean;
size_t len = strlen(msg);
size_t i;
size_t j;
if (f->disp != FILEDISP_KEEPOPEN) {
char *filename;
@@ -249,11 +250,20 @@ log_file(krb5_context context, const char *timestr, const char *msg, void *data)
}
if(f->fd == NULL)
return;
/* make sure the log doesn't contain special chars */
msgclean = malloc((len + 1) * 4);
/*
* make sure the log doesn't contain special chars:
* we used to use strvisx(3) to encode the log, but this is
* inconsistent with our syslog(3) code which does not do this.
* It also makes it inelegant to write data which has already
* been quoted such as what krb5_unparse_principal() gives us.
* So, we change here to eat the special characters, instead.
*/
msgclean = strdup(msg);
if (msgclean == NULL)
goto out;
strvisx(msgclean, rk_UNCONST(msg), len, VIS_OCTAL);
for (i=0, j=0; msg[i]; i++)
if (msg[i] >= 32 || msg[i] == '\t')
msgclean[j++] = msg[i];
fprintf(f->fd, "%s %s\n", timestr, msgclean);
free(msgclean);
out: