diff options
-rw-r--r-- | runtime/msg.c | 27 | ||||
-rw-r--r-- | runtime/msg.h | 1 | ||||
-rw-r--r-- | runtime/rsyslog.h | 1 | ||||
-rw-r--r-- | tools/syslogd.c | 26 |
4 files changed, 17 insertions, 38 deletions
diff --git a/runtime/msg.c b/runtime/msg.c index 2ff63d9c..1a864648 100644 --- a/runtime/msg.c +++ b/runtime/msg.c @@ -1303,19 +1303,6 @@ static inline char *getMSGID(msg_t *pM) } -/* Set the TAG to a caller-provided string. This is thought - * to be a heap buffer that the caller will no longer use. This - * function is a performance optimization over MsgSetTAG(). - * rgerhards 2004-11-19 - */ -void MsgAssignTAG(msg_t *pMsg, uchar *pBuf) -{ - assert(pMsg != NULL); - MsgSetTAG(pMsg, pBuf, ustrlen(pBuf)); - free(pBuf); -} - - /* rgerhards 2009-06-12: set associated ruleset */ void MsgSetRuleset(msg_t *pMsg, ruleset_t *pRuleset) @@ -1361,10 +1348,10 @@ void MsgSetTAG(msg_t *pMsg, uchar* pszBuf, size_t lenBuf) * if there is a TAG and, if not, if it can emulate it. * rgerhards, 2005-11-24 */ -static void tryEmulateTAG(msg_t *pM) +static inline void tryEmulateTAG(msg_t *pM) { - int iTAGLen; - uchar *pBuf; + size_t lenTAG; + uchar bufTAG[CONF_TAG_MAXSIZE]; assert(pM != NULL); if(pM->iLenTAG > 0) @@ -1376,11 +1363,9 @@ static void tryEmulateTAG(msg_t *pM) MsgSetTAG(pM, (uchar*) getAPPNAME(pM), getAPPNAMELen(pM)); } else { /* now we can try to emulate */ - iTAGLen = getAPPNAMELen(pM) + getPROCIDLen(pM) + 3; - if((pBuf = malloc(iTAGLen * sizeof(char))) == NULL) - return; /* nothing we can do */ - snprintf((char*)pBuf, iTAGLen, "%s[%s]", getAPPNAME(pM), getPROCID(pM)); - MsgAssignTAG(pM, pBuf); + lenTAG = snprintf((char*)bufTAG, CONF_TAG_MAXSIZE, "%s[%s]", getAPPNAME(pM), getPROCID(pM)); + bufTAG[32] = '\0'; /* just to make sure... */ + MsgSetTAG(pM, bufTAG, lenTAG); } } } diff --git a/runtime/msg.h b/runtime/msg.h index 34983704..0f9bd95e 100644 --- a/runtime/msg.h +++ b/runtime/msg.h @@ -145,7 +145,6 @@ void MsgSetInputName(msg_t *pMsg, uchar*, size_t); rsRetVal MsgSetAPPNAME(msg_t *pMsg, char* pszAPPNAME); rsRetVal MsgSetPROCID(msg_t *pMsg, char* pszPROCID); rsRetVal MsgSetMSGID(msg_t *pMsg, char* pszMSGID); -void MsgAssignTAG(msg_t *pMsg, uchar *pBuf); void MsgSetTAG(msg_t *pMsg, uchar* pszBuf, size_t lenBuf); void MsgSetRuleset(msg_t *pMsg, ruleset_t*); rsRetVal MsgSetFlowControlType(msg_t *pMsg, flowControl_t eFlowCtl); diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h index 2e0a4150..692b1327 100644 --- a/runtime/rsyslog.h +++ b/runtime/rsyslog.h @@ -30,6 +30,7 @@ * # Config Settings # * * ############################################################# */ #define RS_STRINGBUF_ALLOC_INCREMENT 128 +#define CONF_TAG_MAXSIZE 512 /* a value that is deemed far too large for any valid TAG */ /* ############################################################# * * # End Config Settings # * diff --git a/tools/syslogd.c b/tools/syslogd.c index 16f08c21..ed826fc1 100644 --- a/tools/syslogd.c +++ b/tools/syslogd.c @@ -1173,9 +1173,9 @@ int parseLegacySyslogMsg(msg_t *pMsg, int flags) uchar *p2parse; char *pBuf; char *pWork; - cstr_t *pStrB; - int iCnt; int bTAGCharDetected; + int i; /* general index for parsing */ + uchar bufParseTAG[CONF_TAG_MAXSIZE]; BEGINfunc assert(pMsg != NULL); @@ -1293,23 +1293,16 @@ int parseLegacySyslogMsg(msg_t *pMsg, int flags) * is the max size ;) we need to shuffle the code again... Just for * the records: the code is currently clean, but we could optimize it! */ if(!bTAGCharDetected) { - uchar *pszTAG; - if(cstrConstruct(&pStrB) != RS_RET_OK) - return 1; - rsCStrSetAllocIncrement(pStrB, 33); - pWork = pBuf; - iCnt = 0; - while(*p2parse && *p2parse != ':' && *p2parse != ' ') { - cstrAppendChar(pStrB, *p2parse++); - ++iCnt; + i = 0; + while(*p2parse && *p2parse != ':' && *p2parse != ' ' && i < CONF_TAG_MAXSIZE) { + bufParseTAG[i++] = *p2parse++; } if(*p2parse == ':') { ++p2parse; - cstrAppendChar(pStrB, ':'); + bufParseTAG[i++] = ':'; } - cstrFinalize(pStrB); - cstrConvSzStrAndDestruct(pStrB, &pszTAG, 1); - if(pszTAG == NULL) + + if(i == 0) { /* rger, 2005-11-10: no TAG found - this implies that what * we have considered to be the HOSTNAME is most probably the * TAG. We consider it so probable, that we now adjust it @@ -1322,7 +1315,8 @@ int parseLegacySyslogMsg(msg_t *pMsg, int flags) moveHOSTNAMEtoTAG(pMsg); MsgSetHOSTNAME(pMsg, getRcvFrom(pMsg)); } else { /* we have a TAG, so we can happily set it ;) */ - MsgAssignTAG(pMsg, pszTAG); + bufParseTAG[i] = '\0'; /* terminate string */ + MsgSetTAG(pMsg, bufParseTAG, i); } } else { /* we have no TAG, so we ... */ |