summaryrefslogtreecommitdiffstats
path: root/runtime/parser.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2013-09-13 02:39:42 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2013-09-13 02:39:42 +0200
commit7903677bfba6fd897010d9c5dbb56531bfe0d825 (patch)
tree110e409834bab0fb1edd8f869e911c8d8d510493 /runtime/parser.c
parentad777330629c31447018e47b4033a7ebaa9fe655 (diff)
parent15921d4e4e9d03e0cfd4ca5a9745c89b5dcd37c3 (diff)
downloadrsyslog-7903677bfba6fd897010d9c5dbb56531bfe0d825.tar.gz
rsyslog-7903677bfba6fd897010d9c5dbb56531bfe0d825.tar.bz2
rsyslog-7903677bfba6fd897010d9c5dbb56531bfe0d825.zip
Merge branch 'v7-stable' into v7-stable-tlsfix
Conflicts: ChangeLog runtime/rsyslog.h
Diffstat (limited to 'runtime/parser.c')
-rw-r--r--runtime/parser.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/runtime/parser.c b/runtime/parser.c
index b40edf4c..74b28f4c 100644
--- a/runtime/parser.c
+++ b/runtime/parser.c
@@ -362,11 +362,10 @@ SanitizeMsg(msg_t *pMsg)
*/
int bNeedSanitize = 0;
for(iSrc = 0 ; iSrc < lenMsg ; iSrc++) {
- if(iscntrl(pszMsg[iSrc])) {
+ if(pszMsg[iSrc] < 32) {
if(bSpaceLFOnRcv && pszMsg[iSrc] == '\n')
pszMsg[iSrc] = ' ';
- else
- if(pszMsg[iSrc] == '\0' || bEscapeCCOnRcv) {
+ else if(pszMsg[iSrc] == '\0' || bEscapeCCOnRcv) {
bNeedSanitize = 1;
if (!bSpaceLFOnRcv)
break;
@@ -383,7 +382,9 @@ SanitizeMsg(msg_t *pMsg)
FINALIZE;
}
- /* now copy over the message and sanitize it */
+ /* now copy over the message and sanitize it. Note that up to iSrc-1 there was
+ * obviously no need to sanitize, so we can go over that quickly...
+ */
iMaxLine = glbl.GetMaxLine();
maxDest = lenMsg * 4; /* message can grow at most four-fold */
if(maxDest > iMaxLine)
@@ -392,9 +393,13 @@ SanitizeMsg(msg_t *pMsg)
pDst = szSanBuf;
else
CHKmalloc(pDst = MALLOC(sizeof(uchar) * (iMaxLine + 1)));
- iSrc = iDst = 0;
+ if(iSrc > 0) {
+ iSrc--; /* go back to where everything is OK */
+ memcpy(pDst, pszMsg, iSrc); /* fast copy known good */
+ }
+ iDst = iSrc;
while(iSrc < lenMsg && iDst < maxDest - 3) { /* leave some space if last char must be escaped */
- if(iscntrl((int) pszMsg[iSrc]) && (pszMsg[iSrc] != '\t' || bEscapeTab)) {
+ if((pszMsg[iSrc] < 32) && (pszMsg[iSrc] != '\t' || bEscapeTab)) {
/* note: \0 must always be escaped, the rest of the code currently
* can not handle it! -- rgerhards, 2009-08-26
*/