Date: Thu, 15 Mar 2001 11:57:27 +0000 From: Tony Finch <dot@dotat.at> To: FreeBSD-gnats-submit@freebsd.org Subject: bin/25833: LOG_FAC() is bogus Message-ID: <E14dWNj-0001Qn-00@hand.dotat.at>
next in thread | raw e-mail | index | archive | help
>Number: 25833
>Category: bin
>Synopsis: LOG_FAC() is bogus
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Thu Mar 15 11:20:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Tony Finch <dot@dotat.at>
>Release: FreeBSD 4.3-BETA i386
>Organization:
Covalent Technologies, Inc.
>Environment:
System: FreeBSD hand.dotat.at 4.3-BETA FreeBSD 4.3-BETA #6: Thu Mar 15 04:57:36 GMT 2001 fanf@hand.dotat.at:/FreeBSD/releng4/sys/compile/DELL-Latitude-CSx i386
>Description:
There was recently a problem with syslogd looping messages that were
printed to the console, because of the following code:
if (LOG_FAC(pri) == LOG_CONSOLE)
/* blah */;
the problem being that the value of the LOG_FAC() macro cannot be
compared with a facility value, which is bogus.
There are still a couple of harmless instances of this brokenness
(in syslogd.c and dmesg.c) where the facility in question is
LOG_KERN, which is fortunately zero.
>How-To-Repeat:
>Fix:
This patch sanitizes LOG_FAC(), and adds a LOG_FACSHIFT macro to
replace the lost semantics. I have also replaced uses of LOG_FACMASK
that are now more correctly done with LOG_FAC() (where before that
would have been broken).
An alternative fix would be to replace the code in syslogd.c and
dmesg.c that bogusly compares the value of LOG_FAC() with LOG_KERN.
There's also some code in src/contrib/ipfilter which uses
LOG_PRIMASK and LOG_FACMASK instead of LOG_PRI() and LOG_FAC()
but I haven't touched it since it is contrib code.
Index: sys/sys/syslog.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/syslog.h,v
retrieving revision 1.19.2.1
diff -u -r1.19.2.1 syslog.h
--- sys/sys/syslog.h 2001/01/09 06:51:34 1.19.2.1
+++ sys/sys/syslog.h 2001/03/15 11:54:45
@@ -121,8 +121,9 @@
#define LOG_NFACILITIES 24 /* current number of facilities */
#define LOG_FACMASK 0x03f8 /* mask to extract facility part */
+#define LOG_FACSHIFT 3 /* number of bits below the facility */
/* facility of pri */
-#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3)
+#define LOG_FAC(p) ((p) & LOG_FACMASK)
#ifdef SYSLOG_NAMES
CODE facilitynames[] = {
Index: usr.sbin/syslogd/syslogd.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.59.2.6
diff -u -r1.59.2.6 syslogd.c
--- usr.sbin/syslogd/syslogd.c 2001/02/18 16:22:59 1.59.2.6
+++ usr.sbin/syslogd/syslogd.c 2001/03/15 11:45:18
@@ -710,7 +710,7 @@
pri = 10 * pri + (*p - '0');
if (*p == '>')
++p;
- if ((pri & LOG_FACMASK) == LOG_CONSOLE)
+ if (LOG_FAC(pri) == LOG_CONSOLE)
flags |= IGN_CONS;
} else {
/* kernel printf's come out on console */
@@ -771,7 +771,7 @@
if (flags & MARK)
fac = LOG_NFACILITIES;
else
- fac = LOG_FAC(pri);
+ fac = LOG_FAC(pri) >> LOG_FACSHIFT;
prilev = LOG_PRI(pri);
/* extract program name */
@@ -913,7 +913,7 @@
if (LogFacPri) {
static char fp_buf[30]; /* Hollow laugh */
- int fac = f->f_prevpri & LOG_FACMASK;
+ int fac = LOG_FAC(f->f_prevpri);
int pri = LOG_PRI(f->f_prevpri);
char *f_s = 0;
char f_n[5]; /* Hollow laugh */
@@ -937,7 +937,7 @@
}
}
if (!f_s) {
- snprintf(f_n, sizeof f_n, "%d", LOG_FAC(fac));
+ snprintf(f_n, sizeof f_n, "%d", fac >> LOG_FACSHIFT);
f_s = f_n;
}
if (!p_s) {
Index: lib/libc/gen/syslog.c
===================================================================
RCS file: /home/ncvs/src/lib/libc/gen/syslog.c,v
retrieving revision 1.21
diff -u -r1.21 syslog.c
--- lib/libc/gen/syslog.c 2000/01/27 23:06:20 1.21
+++ lib/libc/gen/syslog.c 2001/03/15 11:36:26
@@ -161,7 +161,7 @@
saved_errno = errno;
/* Set default facility if none specified. */
- if ((pri & LOG_FACMASK) == 0)
+ if (LOG_FAC(pri) == 0)
pri |= LogFacility;
/* Create the primary stdio hook */
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E14dWNj-0001Qn-00>
