diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/msg.h | 17 | ||||
-rw-r--r-- | runtime/parser.c | 16 | ||||
-rw-r--r-- | runtime/prop.c | 2 | ||||
-rw-r--r-- | runtime/queue.c | 2 | ||||
-rw-r--r-- | runtime/rule.c | 2 | ||||
-rw-r--r-- | runtime/ruleset.c | 2 |
6 files changed, 30 insertions, 11 deletions
diff --git a/runtime/msg.h b/runtime/msg.h index 98b3599a..b006cbec 100644 --- a/runtime/msg.h +++ b/runtime/msg.h @@ -192,6 +192,23 @@ uchar *propIDToName(propid_t propID); extern void (*funcMsgPrepareEnqueue)(msg_t *pMsg); #define MsgPrepareEnqueue(pMsg) funcMsgPrepareEnqueue(pMsg) + +/* ------------------------------ some inline functions ------------------------------ */ + +/* set raw message size. This is needed in some cases where a trunctation is necessary + * but the raw message must not be newly set. The most important (and currently only) + * use case is if we remove trailing LF or NUL characters. Note that the size can NOT + * be extended, only shrunk! + * rgerhards, 2009-08-26 + */ +static inline void +MsgSetRawMsgSize(msg_t *pMsg, size_t newLen) +{ + assert(newLen <= (size_t) pMsg->iLenRawMsg); + pMsg->iLenRawMsg = newLen; +} + + #endif /* #ifndef MSG_H_INCLUDED */ /* vim:set ai: */ diff --git a/runtime/parser.c b/runtime/parser.c index a2538fa3..db11ac5b 100644 --- a/runtime/parser.c +++ b/runtime/parser.c @@ -163,6 +163,7 @@ sanitizeMessage(msg_t *pMsg) size_t iDst; size_t iMaxLine; size_t maxDest; + bool bUpdatedLen = FALSE; uchar szSanBuf[32*1024]; /* buffer used for sanitizing a string */ assert(pMsg != NULL); @@ -177,6 +178,7 @@ sanitizeMessage(msg_t *pMsg) /* remove NUL character at end of message (see comment in function header) */ if(pszMsg[lenMsg-1] == '\0') { DBGPRINTF("dropped NUL at very end of message\n"); + bUpdatedLen = TRUE; lenMsg--; } @@ -187,6 +189,7 @@ sanitizeMessage(msg_t *pMsg) */ if(bDropTrailingLF && pszMsg[lenMsg-1] == '\n') { DBGPRINTF("dropped LF at very end of message (DropTrailingLF is set)\n"); + bUpdatedLen = TRUE; lenMsg--; } @@ -197,7 +200,7 @@ sanitizeMessage(msg_t *pMsg) */ int bNeedSanitize = 0; for(iSrc = 0 ; iSrc < lenMsg ; iSrc++) { - if(pszMsg[iSrc] < 32) { + if(iscntrl(pszMsg[iSrc])) { if(pszMsg[iSrc] == '\0' || bEscapeCCOnRcv) { bNeedSanitize = 1; break; @@ -205,8 +208,11 @@ sanitizeMessage(msg_t *pMsg) } } - if(!bNeedSanitize) + if(!bNeedSanitize) { + if(bUpdatedLen == TRUE) + MsgSetRawMsgSize(pMsg, lenMsg); FINALIZE; + } /* now copy over the message and sanitize it */ iMaxLine = glbl.GetMaxLine(); @@ -219,8 +225,10 @@ sanitizeMessage(msg_t *pMsg) CHKmalloc(pDst = malloc(sizeof(uchar) * (iMaxLine + 1))); iSrc = iDst = 0; while(iSrc < lenMsg && iDst < maxDest - 3) { /* leave some space if last char must be escaped */ - if(pszMsg[iSrc] == '\0') { /* guard against \0 characters... */ - } else if(iscntrl((int) pszMsg[iSrc])) { + if(iscntrl((int) pszMsg[iSrc])) { + /* note: \0 must always be escaped, the rest of the code currently + * can not handle it! -- rgerhards, 2009-08-26 + */ if(pszMsg[iSrc] == '\0' || bEscapeCCOnRcv) { /* we are configured to escape control characters. Please note * that this most probably break non-western character sets like diff --git a/runtime/prop.c b/runtime/prop.c index 804f3491..d188b2ed 100644 --- a/runtime/prop.c +++ b/runtime/prop.c @@ -174,7 +174,7 @@ rsRetVal CreateOrReuseStringProp(prop_t **ppThis, uchar *psz, int len) } else { /* already exists, check if we can re-use it */ GetString(*ppThis, &pszPrev, &lenPrev); - if(len != lenPrev && ustrcmp(psz, pszPrev)) { + if(len != lenPrev || ustrcmp(psz, pszPrev)) { /* different, need to discard old & create new one */ propDestruct(ppThis); CHKiRet(CreateStringProp(ppThis, psz, len)); diff --git a/runtime/queue.c b/runtime/queue.c index 8388d00e..cb14b58d 100644 --- a/runtime/queue.c +++ b/runtime/queue.c @@ -1044,7 +1044,6 @@ static rsRetVal qAddDirect(qqueue_t *pThis, void* pUsr) iRet = pThis->pConsumer(pThis->pUsr, &singleBatch); objDestruct(pUsr); -dbgprintf("XXXX: qAddDirect returns %d\n", iRet); RETiRet; } @@ -2443,7 +2442,6 @@ doEnqSingleObj(qqueue_t *pThis, flowControl_t flowCtlType, void *pUsr) CHKiRet(qqueueAdd(pThis, pUsr)); finalize_it: -dbgprintf("XXXX: queueEnqObj returns %d\n", iRet); RETiRet; } diff --git a/runtime/rule.c b/runtime/rule.c index bcd82e5f..182d616a 100644 --- a/runtime/rule.c +++ b/runtime/rule.c @@ -83,7 +83,6 @@ DEFFUNC_llExecFunc(processMsgDoActions) } iRetMod = actionCallAction(pAction, pDoActData->pMsg); -dbgprintf("XXXX: processMsgDoActions returns %d\n", iRet); if(iRetMod == RS_RET_DISCARDMSG) { ABORT_FINALIZE(RS_RET_DISCARDMSG); } else if(iRetMod == RS_RET_SUSPENDED) { @@ -272,7 +271,6 @@ processMsg(rule_t *pThis, msg_t *pMsg) } finalize_it: -dbgprintf("XXXX: rule.processMsg returns %d\n", iRet); RETiRet; } diff --git a/runtime/ruleset.c b/runtime/ruleset.c index c1b6d490..5ac9a8fd 100644 --- a/runtime/ruleset.c +++ b/runtime/ruleset.c @@ -141,7 +141,6 @@ DEFFUNC_llExecFunc(processMsgDoRules) rsRetVal iRet; ISOBJ_TYPE_assert(pData, rule); iRet = rule.ProcessMsg((rule_t*) pData, (msg_t*) pParam); -dbgprintf("XXXX: pcoessMsgDoRules returns %d\n", iRet); return iRet; } @@ -162,7 +161,6 @@ processMsg(msg_t *pMsg) CHKiRet(llExecFunc(&pThis->llRules, processMsgDoRules, pMsg)); finalize_it: -dbgprintf("XXXX: processMsg got return state %d\n", iRet); //if(iRet == RS_RET_DISCARDMSG) //iRet = RS_RET_OK; |