Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Sep 2021 07:32:11 GMT
From:      Eugene Grosbein <eugen@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 3b4cc56e524a - main - syslogd: undo regression after r326573
Message-ID:  <202109270732.18R7WB1h061284@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by eugen:

URL: https://cgit.FreeBSD.org/src/commit/?id=3b4cc56e524ac947ba0e6571e2c455139c2839ec

commit 3b4cc56e524ac947ba0e6571e2c455139c2839ec
Author:     Eugene Grosbein <eugen@FreeBSD.org>
AuthorDate: 2021-09-27 07:25:21 +0000
Commit:     Eugene Grosbein <eugen@FreeBSD.org>
CommitDate: 2021-09-27 07:25:21 +0000

    syslogd: undo regression after r326573
    
    Restore ability for our syslogd to collect pre-RFC3164 formatted
    messages from remote hosts that was broken with r326573.
    
    For example, the line from Cisco SCE8000 splitted for readability:
    
    1130: 03:37:57: %USER-6-PORT_OPERSTATUS_CHANGE_TRAP: CPU#000 trap:link
    down EntityAdminState: 4  EntityAlarmStatus: 32
    
    Such line was collected and stored before mentioned change
    but silently dropped after that. Now syslogd saves it again.
    
    Note that parsing of RFC5424 format not changed.
    
    MFC after:      1 month
---
 usr.sbin/syslogd/syslogd.c | 41 +++++++++++++++++------------------------
 1 file changed, 17 insertions(+), 24 deletions(-)

diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c
index 1837c41c4e8b..dc07d4781553 100644
--- a/usr.sbin/syslogd/syslogd.c
+++ b/usr.sbin/syslogd/syslogd.c
@@ -1357,31 +1357,25 @@ parsemsg(const char *from, char *msg)
 	size_t i;
 	int pri;
 
+	i = -1;
+	pri = DEFUPRI;
+
 	/* Parse PRI. */
-	if (msg[0] != '<' || !isdigit(msg[1])) {
-		dprintf("Invalid PRI from %s\n", from);
-		return;
-	}
-	for (i = 2; i <= 4; i++) {
-		if (msg[i] == '>')
-			break;
-		if (!isdigit(msg[i])) {
-			dprintf("Invalid PRI header from %s\n", from);
-			return;
+	if (msg[0] == '<' && isdigit(msg[1])) {
+	    for (i = 2; i <= 4; i++) {
+	        if (msg[i] == '>') {
+		    errno = 0;
+		    n = strtol(msg + 1, &q, 10);
+		    if (errno == 0 && *q == msg[i] && n >= 0 && n <= INT_MAX) {
+		        pri = n;
+		        msg += i + 1;
+		        i = 0;
+		    }
+		    break;
 		}
+    	    }
 	}
-	if (msg[i] != '>') {
-		dprintf("Invalid PRI header from %s\n", from);
-		return;
-	}
-	errno = 0;
-	n = strtol(msg + 1, &q, 10);
-	if (errno != 0 || *q != msg[i] || n < 0 || n >= INT_MAX) {
-		dprintf("Invalid PRI %ld from %s: %s\n",
-		    n, from, strerror(errno));
-		return;
-	}
-	pri = n;
+
 	if (pri &~ (LOG_FACMASK|LOG_PRIMASK))
 		pri = DEFUPRI;
 
@@ -1394,8 +1388,7 @@ parsemsg(const char *from, char *msg)
 		pri = LOG_MAKEPRI(LOG_USER, LOG_PRI(pri));
 
 	/* Parse VERSION. */
-	msg += i + 1;
-	if (msg[0] == '1' && msg[1] == ' ')
+	if (i == 0 && msg[0] == '1' && msg[1] == ' ')
 		parsemsg_rfc5424(from, pri, msg + 2);
 	else
 		parsemsg_rfc3164(from, pri, msg);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202109270732.18R7WB1h061284>