From owner-freebsd-bugs@FreeBSD.ORG Mon May 24 13:50:50 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3366516A4CE for ; Mon, 24 May 2004 13:50:50 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 26ED843D3F for ; Mon, 24 May 2004 13:50:50 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i4OKoXYx098100 for ; Mon, 24 May 2004 13:50:33 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i4OKoXVI098080; Mon, 24 May 2004 13:50:33 -0700 (PDT) (envelope-from gnats) Resent-Date: Mon, 24 May 2004 13:50:33 -0700 (PDT) Resent-Message-Id: <200405242050.i4OKoXVI098080@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Xin LI Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C9BCA16A507 for ; Mon, 24 May 2004 13:42:41 -0700 (PDT) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id AC74543D45 for ; Mon, 24 May 2004 13:42:41 -0700 (PDT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.12.11/8.12.11) with ESMTP id i4OKg35f044090 for ; Mon, 24 May 2004 13:42:03 -0700 (PDT) (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.12.11/8.12.11/Submit) id i4OKg3XY044089; Mon, 24 May 2004 13:42:03 -0700 (PDT) (envelope-from nobody) Message-Id: <200405242042.i4OKg3XY044089@www.freebsd.org> Date: Mon, 24 May 2004 13:42:03 -0700 (PDT) From: Xin LI To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Subject: bin/67139: [PATCH] Merge some OpenBSD improvements to syslogd X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 May 2004 20:50:50 -0000 >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@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 #include @@ -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: