bin/67139: [PATCH] Merge some OpenBSD improvements to syslogd
Xin LI
delphij at FreeBSD.org.cn
Mon May 24 13:50:50 PDT 2004
>Number: 67139
>Category: bin
>Synopsis: [PATCH] Merge some OpenBSD improvements to syslogd
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Mon May 24 13:50:32 PDT 2004
>Closed-Date:
>Last-Modified:
>Originator: Xin LI
>Release: 5.2-CURRENT
>Organization:
The FreeBSD Simplified Chinese Project
>Environment:
FreeBSD beastie.frontfree.net 5.2-CURRENT FreeBSD 5.2-CURRENT #41: Sat May 22 18:20:51 CST 2004 delphij at beastie.frontfree.net:/usr/obj/usr/src/sys/BEASTIE i386
>Description:
There are many improvements taken place in OpenBSD which are valuable for us to have a look at. The attached patch includes:
- Comment updates
- Some security related changes
The attached patch essentially brings the following revisions:
1.3(only partly), 1.53, 1.64, 1.67, 1.61+1.62, 1.17, 1.22 and 1.16.
>How-To-Repeat:
>Fix:
Index: syslogd.c
===================================================================
RCS file: /home/fcvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.120
diff -u -r1.120 syslogd.c
--- syslogd.c 31 Jan 2004 17:44:27 -0000 1.120
+++ syslogd.c 24 May 2004 20:22:42 -0000
@@ -59,7 +59,7 @@
*
* Defined Constants:
*
- * MAXLINE -- the maximimum line length that can be handled.
+ * MAXLINE -- the maximum line length that can be handled.
* DEFUPRI -- the default priority for user messages
* DEFSPRI -- the default priority for kernel messages
*
@@ -77,7 +77,7 @@
#define DEFUPRI (LOG_USER|LOG_NOTICE)
#define DEFSPRI (LOG_KERN|LOG_CRIT)
#define TIMERINTVL 30 /* interval for checking flush, mark */
-#define TTYMSGTIME 1 /* timed out passed to ttymsg */
+#define TTYMSGTIME 1 /* timeout passed to ttymsg */
#include <sys/param.h>
#include <sys/ioctl.h>
@@ -387,7 +387,12 @@
use_bootfile = 1;
break;
case 'p': /* path */
- funixn[0] = optarg;
+ if (strlen(optarg) >= sizeof(sunx.sun_path)) {
+ fprintf(stderr,
+ "syslogd: socket path too long, exiting\n");
+ exit(1);
+ } else
+ funixn[0] = optarg;
break;
case 'P': /* path for alt. PID */
PidFile = optarg;
@@ -401,7 +406,6 @@
case 'v': /* log facility and priority */
LogFacPri++;
break;
- case '?':
default:
usage();
}
@@ -664,9 +668,13 @@
if (pri &~ (LOG_FACMASK|LOG_PRIMASK))
pri = DEFUPRI;
- /* don't allow users to log kernel messages */
+ /*
+ * Don't allow users to log kernel messages.
+ * NOTE: since LOG_KERN == 0 this will also match
+ * messages with no facility specified.
+ */
if (LOG_FAC(pri) == LOG_KERN && !KeepKernFac)
- pri = LOG_MAKEPRI(LOG_USER, LOG_PRI(pri));
+ pri = LOG_USER | LOG_PRI(pri);
q = line;
@@ -887,6 +895,7 @@
sizeof(f->f_lasttime));
fprintlog(f, flags, msg);
(void)close(f->f_file);
+ f->f_file = -1;
}
(void)sigsetmask(omask);
return;
@@ -1136,7 +1145,10 @@
v->iov_len = 1;
if (writev(f->f_file, iov, 7) < 0) {
int e = errno;
- (void)close(f->f_file);
+ if (f->f_file >= 0) {
+ (void)close(f->f_file);
+ f->f_file = -1;
+ }
f->f_type = F_UNUSED;
errno = e;
logerror(f->f_un.f_fname);
@@ -1227,7 +1239,9 @@
while (fread((char *)&ut, sizeof(ut), 1, uf) == 1) {
if (ut.ut_name[0] == '\0')
continue;
- (void)strlcpy(line, ut.ut_line, sizeof(line));
+ /* must use strncpy since ut_* may not be NUL terminated */
+ strncpy(line, ut.ut_line, sizeof(line) - 1);
+ line[sizeof(line) - 1] = '\0';
if (f->f_type == F_WALL) {
if ((p = ttymsg(iov, 7, line, TTYMSGTIME)) != NULL) {
errno = 0; /* already in msg */
@@ -1535,9 +1549,13 @@
prog[i] = 0;
continue;
}
- for (p = strchr(cline, '\0'); isspace(*--p);)
- continue;
- *++p = '\0';
+ p = cline + strlen(cline);
+ while (p > cline)
+ if (!isspace(*--p)) {
+ p++;
+ break;
+ }
+ *p = '\0';
f = (struct filed *)calloc(1, sizeof(*f));
if (f == NULL) {
logerror("calloc");
@@ -1715,6 +1733,12 @@
pri = LOG_PRIMASK + 1;
pri_cmp = PRI_LT | PRI_EQ | PRI_GT;
} else {
+ /* ignore trailing spaces */
+ int i;
+ for (i=strlen(buf)-1; i >= 0 && buf[i] == ' '; i--) {
+ buf[i]='\0';
+ }
+
pri = decode(buf, prioritynames);
if (pri < 0) {
(void)snprintf(ebuf, sizeof ebuf,
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list