Handle %%m properly in syslog format string. Previously it would expand
the %m into the errno and then vfprintf would expand the % and the first character of the strerror(3) return causing possible data corruption.
This commit is contained in:
parent
687e6ad79b
commit
e6cfb1ccd3
@ -189,13 +189,23 @@ vsyslog(pri, fmt, ap)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Substitute error message for %m. */
|
||||
for ( ; (ch = *fmt); ++fmt)
|
||||
/*
|
||||
* Substitute error message for %m. Be careful not to
|
||||
* molest an escaped percent "%%m". We want to pass it
|
||||
* on untouched as the format is later parsed by vfprintf.
|
||||
*/
|
||||
for ( ; (ch = *fmt); ++fmt) {
|
||||
if (ch == '%' && fmt[1] == 'm') {
|
||||
++fmt;
|
||||
fputs(strerror(saved_errno), fmt_fp);
|
||||
} else
|
||||
} else if (ch == '%' && fmt[1] == '%') {
|
||||
++fmt;
|
||||
fputc(ch, fmt_fp);
|
||||
fputc(ch, fmt_fp);
|
||||
} else {
|
||||
fputc(ch, fmt_fp);
|
||||
}
|
||||
}
|
||||
|
||||
/* Null terminate if room */
|
||||
fputc(0, fmt_fp);
|
||||
|
Loading…
Reference in New Issue
Block a user