From 2280f91c9c4a2261f44e19dadb4f450ef6c92e77 Mon Sep 17 00:00:00 2001 From: Vishwesh M Rudramuni Date: Thu, 5 Oct 2017 03:37:35 +0530 Subject: common code: KW fixes for common code This patch fixes KW issues seen with the common code. Change-Id: I4f90369152345ea2ea9316b04ac946c0c69fd7d1 Signed-off-by: Vishwesh M Rudramuni --- common/VIL/alg/lib_sip_alg.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'common/VIL/alg/lib_sip_alg.c') diff --git a/common/VIL/alg/lib_sip_alg.c b/common/VIL/alg/lib_sip_alg.c index 9940d59a..0e281200 100644 --- a/common/VIL/alg/lib_sip_alg.c +++ b/common/VIL/alg/lib_sip_alg.c @@ -162,6 +162,7 @@ void lib_sip_alg_init(void) } char *itoa(long n); +char itoa_buf[25]; char *itoa(long n) { int len = n == 0 ? 1 : floor(log10l(labs(n))) + 1; @@ -169,10 +170,8 @@ char *itoa(long n) if (n < 0) len++; /* room for negative sign '-' */ - char *buf = calloc(sizeof(char), len + 1); // +1 for null - if(buf != NULL) - snprintf(buf, len + 1, "%ld", n); - return buf; + snprintf(itoa_buf, len + 1, "%ld", n); + return (char *)&itoa_buf; } struct sip_alg_table_entry *retrieve_sip_alg_entry( @@ -340,6 +339,10 @@ int sip_alg_dpi(struct rte_mbuf *pkt, enum pkt_dir pkt_direction, sip_call_id = getSipCallIdStr(pSipMsg + pos + TAG_TO_DATAPOS(SIP_ALG_CALLID)); + if (!sip_call_id) { + printf("sip_call_id returned is NULL\n"); + return 0; + } if (ALG_DEBUG) printf("sipalgdpi: %d call id %s\n", __LINE__, @@ -572,6 +575,9 @@ char *sip_alg_process(struct rte_mbuf *pkt, uint16_t pkt_direction, int sipMsgLen = (pTmpSipMsg - pSipMsg); + if ((sipMsgLen + sdpDataLen) > strlen(pSipMsg)) + return NULL; + char *pSipMsgEnd = pSipMsg + sipMsgLen + sdpDataLen; if (ALG_DEBUG) @@ -1889,7 +1895,11 @@ SipMsgAdvance2: sdpMsgLen += sdpDataLen; tmpSdpLen = itoa(sdpMsgLen); - int tmpStrLen = strlen(tmpSdpLen); + int tmpStrLen; + if (tmpSdpLen) + tmpStrLen = strlen(tmpSdpLen); + else + tmpStrLen = 0; /* move to Content length field & change the length to sipMsgLen */ if (natSipAlgMsgFieldPos(pSipMsg, SIP_ALG_CONTENT_LEN, &pos, 0) @@ -2225,6 +2235,9 @@ char *natSipAlgModifyPayloadAddrPort( if (newStrLen > oldStrLen) *diffLen = newStrLen - oldStrLen; + if (tmpPort) + free(tmpPort); + return pSipMsg; /* modified SIP Msg */ } -- cgit 1.2.3-korg