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:
Alfred Perlstein 2003-02-10 08:31:28 +00:00
parent 687e6ad79b
commit e6cfb1ccd3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=110635

View File

@ -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);