From owner-svn-src-all@freebsd.org Thu Jun 28 12:55:07 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E617A1032C4E; Thu, 28 Jun 2018 12:55:06 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 94F297A9F7; Thu, 28 Jun 2018 12:55:06 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 75FE8127CE; Thu, 28 Jun 2018 12:55:06 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5SCt6JN088753; Thu, 28 Jun 2018 12:55:06 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5SCt6qc088752; Thu, 28 Jun 2018 12:55:06 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201806281255.w5SCt6qc088752@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Thu, 28 Jun 2018 12:55:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r335761 - stable/11/usr.sbin/syslogd X-SVN-Group: stable-11 X-SVN-Commit-Author: ed X-SVN-Commit-Paths: stable/11/usr.sbin/syslogd X-SVN-Commit-Revision: 335761 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jun 2018 12:55:07 -0000 Author: ed Date: Thu Jun 28 12:55:05 2018 New Revision: 335761 URL: https://svnweb.freebsd.org/changeset/base/335761 Log: MFC r335565: Still parse messages that don't contain an RFC 3164 timestamp. The changes made in r326573 required that messages always start with an RFC 3164 timestamp. It looks like certain devices, but also certain logging libraries (Python 3's "logging" package) simply don't generate RFC 3164 formatted messages containing a timestamp. Make timestamps optional again. When the timestamp is missing, also assume that the message contains no hostname. The first word of the message likely already belongs to the message payload. PR: 229236 Modified: stable/11/usr.sbin/syslogd/syslogd.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.sbin/syslogd/syslogd.c ============================================================================== --- stable/11/usr.sbin/syslogd/syslogd.c Thu Jun 28 11:39:27 2018 (r335760) +++ stable/11/usr.sbin/syslogd/syslogd.c Thu Jun 28 12:55:05 2018 (r335761) @@ -1170,68 +1170,70 @@ parsemsg_rfc3164(const char *from, int pri, char *msg) size_t i, msglen; char line[MAXLINE + 1]; - /* Parse the timestamp provided by the remote side. */ - if (strptime(msg, RFC3164_DATEFMT, &tm_parsed) != - msg + RFC3164_DATELEN || msg[RFC3164_DATELEN] != ' ') { - dprintf("Failed to parse TIMESTAMP from %s: %s\n", from, msg); - return; - } - msg += RFC3164_DATELEN + 1; + /* + * Parse the TIMESTAMP provided by the remote side. If none is + * found, assume this is not an RFC 3164 formatted message, + * only containing a TAG and a MSG. + */ + timestamp = NULL; + if (strptime(msg, RFC3164_DATEFMT, &tm_parsed) == + msg + RFC3164_DATELEN && msg[RFC3164_DATELEN] == ' ') { + msg += RFC3164_DATELEN + 1; + if (!RemoteAddDate) { + struct tm tm_now; + time_t t_now; + int year; - if (!RemoteAddDate) { - struct tm tm_now; - time_t t_now; - int year; + /* + * As the timestamp does not contain the year + * number, daylight saving time information, nor + * a time zone, attempt to infer it. Due to + * clock skews, the timestamp may even be part + * of the next year. Use the last year for which + * the timestamp is at most one week in the + * future. + * + * This loop can only run for at most three + * iterations before terminating. + */ + t_now = time(NULL); + localtime_r(&t_now, &tm_now); + for (year = tm_now.tm_year + 1;; --year) { + assert(year >= tm_now.tm_year - 1); + timestamp_remote.tm = tm_parsed; + timestamp_remote.tm.tm_year = year; + timestamp_remote.tm.tm_isdst = -1; + timestamp_remote.usec = 0; + if (mktime(×tamp_remote.tm) < + t_now + 7 * 24 * 60 * 60) + break; + } + timestamp = ×tamp_remote; + } /* - * As the timestamp does not contain the year number, - * daylight saving time information, nor a time zone, - * attempt to infer it. Due to clock skews, the - * timestamp may even be part of the next year. Use the - * last year for which the timestamp is at most one week - * in the future. - * - * This loop can only run for at most three iterations - * before terminating. + * A single space character MUST also follow the HOSTNAME field. */ - t_now = time(NULL); - localtime_r(&t_now, &tm_now); - for (year = tm_now.tm_year + 1;; --year) { - assert(year >= tm_now.tm_year - 1); - timestamp_remote.tm = tm_parsed; - timestamp_remote.tm.tm_year = year; - timestamp_remote.tm.tm_isdst = -1; - timestamp_remote.usec = 0; - if (mktime(×tamp_remote.tm) < - t_now + 7 * 24 * 60 * 60) + msglen = strlen(msg); + for (i = 0; i < MIN(MAXHOSTNAMELEN, msglen); i++) { + if (msg[i] == ' ') { + if (RemoteHostname) { + msg[i] = '\0'; + from = msg; + } + msg += i + 1; break; - } - timestamp = ×tamp_remote; - } else - timestamp = NULL; - - /* - * A single space character MUST also follow the HOSTNAME field. - */ - msglen = strlen(msg); - for (i = 0; i < MIN(MAXHOSTNAMELEN, msglen); i++) { - if (msg[i] == ' ') { - if (RemoteHostname) { - msg[i] = '\0'; - from = msg; } - msg += i + 1; - break; + /* + * Support non RFC compliant messages, without hostname. + */ + if (msg[i] == ':') + break; } - /* - * Support non RFC compliant messages, without hostname. - */ - if (msg[i] == ':') - break; - } - if (i == MIN(MAXHOSTNAMELEN, msglen)) { - dprintf("Invalid HOSTNAME from %s: %s\n", from, msg); - return; + if (i == MIN(MAXHOSTNAMELEN, msglen)) { + dprintf("Invalid HOSTNAME from %s: %s\n", from, msg); + return; + } } /* Remove the TAG, if present. */