summaryrefslogtreecommitdiffstats
path: root/tools/syslogd.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2010-02-22 14:25:56 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2010-02-22 14:25:56 +0100
commitaf5fb078d48b364b20adf7e56e9869664e7424f9 (patch)
treedb487cd4783d23107f898dd9d405d1592d4b70dd /tools/syslogd.c
parentc577e9c64cec0eebf6b7c3bd964354ab90c045ae (diff)
downloadrsyslog-af5fb078d48b364b20adf7e56e9869664e7424f9.tar.gz
rsyslog-af5fb078d48b364b20adf7e56e9869664e7424f9.tar.xz
rsyslog-af5fb078d48b364b20adf7e56e9869664e7424f9.zip
message parser fixes and testbench enhancements
- improved testbench to contain samples for totally malformed messages which miss parts of the message content - bugfix: some malformed messages could lead to a missing LF inside files or some other missing parts of the template content. - bugfix: if a message ended immediately with a hostname, the hostname was mistakenly interpreted as TAG, and localhost be used as hostname
Diffstat (limited to 'tools/syslogd.c')
-rw-r--r--tools/syslogd.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/tools/syslogd.c b/tools/syslogd.c
index 3e6d51d3..caab1691 100644
--- a/tools/syslogd.c
+++ b/tools/syslogd.c
@@ -1192,12 +1192,12 @@ int parseLegacySyslogMsg(msg_t *pMsg, int flags)
int bTAGCharDetected;
int i; /* general index for parsing */
uchar bufParseTAG[CONF_TAG_MAXSIZE];
- uchar bufParseHOSTNAME[CONF_TAG_HOSTNAME];
+ uchar bufParseHOSTNAME[CONF_HOSTNAME_MAXSIZE];
BEGINfunc
assert(pMsg != NULL);
assert(pMsg->pszRawMsg != NULL);
- lenMsg = pMsg->iLenRawMsg - (pMsg->offAfterPRI + 1);
+ lenMsg = pMsg->iLenRawMsg - pMsg->offAfterPRI; /* note: offAfterPRI is already the number of PRI chars (do not add one!) */
p2parse = pMsg->pszRawMsg + pMsg->offAfterPRI; /* point to start of text, after PRI */
/* Check to see if msg contains a timestamp. We start by assuming
@@ -1254,12 +1254,20 @@ int parseLegacySyslogMsg(msg_t *pMsg, int flags)
if(lenMsg > 0 && flags & PARSE_HOSTNAME) {
i = 0;
while(i < lenMsg && (isalnum(p2parse[i]) || p2parse[i] == '.' || p2parse[i] == '.'
- || p2parse[i] == '_' || p2parse[i] == '-') && i < CONF_TAG_MAXSIZE) {
+ || p2parse[i] == '_' || p2parse[i] == '-') && i < (CONF_HOSTNAME_MAXSIZE - 1)) {
bufParseHOSTNAME[i] = p2parse[i];
++i;
}
- if(i > 0 && p2parse[i] == ' ' && isalnum(p2parse[i-1])) {
+ if(i == lenMsg) {
+ /* we have a message that is empty immediately after the hostname,
+ * but the hostname thus is valid! -- rgerhards, 2010-02-22
+ */
+ p2parse += i;
+ lenMsg -= i;
+ bufParseHOSTNAME[i] = '\0';
+ MsgSetHOSTNAME(pMsg, bufParseHOSTNAME, i);
+ } else if(i > 0 && p2parse[i] == ' ' && isalnum(p2parse[i-1])) {
/* we got a hostname! */
p2parse += i + 1; /* "eat" it (including SP delimiter) */
lenMsg -= i + 1;