Module Name:    src
Committed By:   gutteridge
Date:           Wed Aug 21 16:30:27 UTC 2024

Modified Files:
        src/sys/sys: syslog.h
        src/usr.sbin/syslogd: syslogd.c

Log Message:
syslog.h & syslogd.c: avoid incorrect facility double-shifting

As discussed in PR lib/57172, don't double-shift facility values when
calculating logging contexts. Patch suggested by RVP, an approach also
consistent with what OpenBSD did, which is to simply remove LOG_MAKEPRI
and adjust the only place it's used in the tree. (This has the benefit
of exposing any third-party software that may have also been using the
incorrect value all this time.)


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/sys/sys/syslog.h
cvs rdiff -u -r1.142 -r1.143 src/usr.sbin/syslogd/syslogd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/syslog.h
diff -u src/sys/sys/syslog.h:1.43 src/sys/sys/syslog.h:1.44
--- src/sys/sys/syslog.h:1.43	Thu Jul 11 06:05:58 2024
+++ src/sys/sys/syslog.h	Wed Aug 21 16:30:27 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: syslog.h,v 1.43 2024/07/11 06:05:58 riastradh Exp $	*/
+/*	$NetBSD: syslog.h,v 1.44 2024/08/21 16:30:27 gutteridge Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1988, 1993
@@ -62,12 +62,11 @@
 #define	LOG_PRIMASK	0x07	/* mask to extract priority part (internal) */
 				/* extract priority */
 #define	LOG_PRI(p)	((p) & LOG_PRIMASK)
-#define	LOG_MAKEPRI(fac, pri)	(((fac) << 3) | (pri))
 
 #ifdef SYSLOG_NAMES
 #define	INTERNAL_NOPRI	0x10	/* the "no priority" priority */
 				/* mark "facility" */
-#define	INTERNAL_MARK	LOG_MAKEPRI(LOG_NFACILITIES, 0)
+#define	INTERNAL_MARK	(LOG_NFACILITIES<<3)
 typedef struct _code {
 	const char	*c_name;
 	int	c_val;

Index: src/usr.sbin/syslogd/syslogd.c
diff -u src/usr.sbin/syslogd/syslogd.c:1.142 src/usr.sbin/syslogd/syslogd.c:1.143
--- src/usr.sbin/syslogd/syslogd.c:1.142	Sat Aug  3 02:43:37 2024
+++ src/usr.sbin/syslogd/syslogd.c	Wed Aug 21 16:30:27 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: syslogd.c,v 1.142 2024/08/03 02:43:37 gutteridge Exp $	*/
+/*	$NetBSD: syslogd.c,v 1.143 2024/08/21 16:30:27 gutteridge Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993, 1994
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19
 #if 0
 static char sccsid[] = "@(#)syslogd.c	8.3 (Berkeley) 4/4/94";
 #else
-__RCSID("$NetBSD: syslogd.c,v 1.142 2024/08/03 02:43:37 gutteridge Exp $");
+__RCSID("$NetBSD: syslogd.c,v 1.143 2024/08/21 16:30:27 gutteridge Exp $");
 #endif
 #endif /* not lint */
 
@@ -1554,7 +1554,7 @@ printline(const char *hname, char *msg, 
 	 *	 messages with no facility specified.
 	 */
 	if ((pri & LOG_FACMASK) == LOG_KERN)
-		pri = LOG_MAKEPRI(LOG_USER, LOG_PRI(pri));
+		pri = LOG_USER | LOG_PRI(pri);
 
 	if (bsdsyslog) {
 		buffer = printline_bsdsyslog(hname, p, flags, pri);

Reply via email to