diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2013-09-10 11:52:30 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2013-09-10 11:52:30 +0200 |
commit | c1ad4f99347ee98e20e1ccac4a1f80267b8a28ef (patch) | |
tree | 8837878fe90c729b33cf51ee0788e409d5dc3817 | |
parent | ea9c81ce3c512d1835e323ef7e817014e109b25a (diff) | |
download | rsyslog-c1ad4f99347ee98e20e1ccac4a1f80267b8a28ef.tar.gz rsyslog-c1ad4f99347ee98e20e1ccac4a1f80267b8a28ef.tar.bz2 rsyslog-c1ad4f99347ee98e20e1ccac4a1f80267b8a28ef.zip |
imfile: support LF escaping in read mode 2
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | runtime/stream.c | 22 |
2 files changed, 29 insertions, 6 deletions
@@ -1,5 +1,18 @@ --------------------------------------------------------------------------- Version 7.5.3 [devel] 2013-07-?? +- imfile: support for escaping LF characters added + embedded LF in syslog messages cause a lot of trouble. imfile now has + the capability to escape them to "#012" (just like the regular control + character escape option). This requires new-style input statements to be + used. If legacy configuration statements are used, LF escaping is always + turned off to preserve compatibility. + NOTE: if input() statements were already used, there is a CHANGE OF + BEHAVIOUR: starting with this version, escaping is enabled by + default. So if you do not want it, you need to add + escapeLF="off" + to the input statement. Given the trouble LFs cause and the fact + that the majority of installations still use legacy config, we + considered this behaviour change acceptable and useful. - bugfix: queue file size was not correctly processed this could lead to using one queue file per message for sizes >2GiB Thanks to Tomas Heinrich for the patch. diff --git a/runtime/stream.c b/runtime/stream.c index 5ffbf10a..b35d6a11 100644 --- a/runtime/stream.c +++ b/runtime/stream.c @@ -745,6 +745,7 @@ strmReadLine(strm_t *pThis, cstr_t **ppCStr, uint8_t mode, sbool bEscapeLF) } else if(mode == 2) { /* indented follow-up lines */ finished=0; + bPrevWasNL = 0; while(finished == 0){ if ((*ppCStr)->iStrLen == 0){ if(c != '\n') { @@ -755,22 +756,31 @@ strmReadLine(strm_t *pThis, cstr_t **ppCStr, uint8_t mode, sbool bEscapeLF) finished=1; /* this is a blank line, a \n with nothing since the last complete record */ } } else { - if ((*ppCStr)->pBuf[(*ppCStr)->iStrLen -1 ] != '\n'){ - /* not the first character after a newline, add it to the buffer */ - CHKiRet(cstrAppendChar(*ppCStr, c)); - CHKiRet(strmReadChar(pThis, &c)); - } else { + if(bPrevWasNL) { if ((c == ' ') || (c == '\t')){ CHKiRet(cstrAppendChar(*ppCStr, c)); CHKiRet(strmReadChar(pThis, &c)); + bPrevWasNL = 0; } else { /* clean things up by putting the character we just read back into * the input buffer and removing the LF character that is currently at the * end of the output string */ CHKiRet(strmUnreadChar(pThis, c)); - rsCStrTruncate(*ppCStr,1); + rsCStrTruncate(*ppCStr, (bEscapeLF) ? 4 : 1); finished=1; } + } else { /* not the first character after a newline, add it to the buffer */ + if(c == '\n') { + bPrevWasNL = 1; + if(bEscapeLF) { + CHKiRet(rsCStrAppendStrWithLen(*ppCStr, (uchar*)"#012", sizeof("#012")-1)); + } else { + CHKiRet(cstrAppendChar(*ppCStr, c)); + } + } else { + CHKiRet(cstrAppendChar(*ppCStr, c)); + } + CHKiRet(strmReadChar(pThis, &c)); } } } |