mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
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
1 changed files with 13 additions and 3 deletions
|
|
@ -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 a new issue