From fe7948a7ae258822613d8eb441f1d60979ee1848 Mon Sep 17 00:00:00 2001 From: Pablo Rincon Date: Thu, 15 Apr 2010 18:54:04 +0200 Subject: [PATCH] Modifications on http body request handling --- src/app-layer-htp.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index 0a349199da..9eeb1c6e86 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -460,7 +460,17 @@ void HtpBodyAppendChunk(HtpBody *body, uint8_t *data, uint32_t len) } bd->len = len; - bd->data = data; + bd->data = SCMalloc(len); + if (bd->data == NULL) { + SCLogError(SC_ERR_MEM_ALLOC,"Couldn't allocate memory for a http body chunk"); + if (SCLogDebugEnabled()) { + abort(); + } + else { + exit(EXIT_FAILURE); + } + } + memcpy(bd->data, data, len); body->first = body->last = bd; body->nchunks++; bd->next = NULL; @@ -473,15 +483,41 @@ void HtpBodyAppendChunk(HtpBody *body, uint8_t *data, uint32_t len) * len, so updating the len */ body->last->len = len; bd = body->last; + bd->data = SCRealloc(bd->data, len); + if (bd->data == NULL) { + SCLogError(SC_ERR_MEM_ALLOC, "Fatal error, error allocationg memory"); + if (SCLogDebugEnabled()) { + abort(); + } + else { + exit(EXIT_FAILURE); + } + } + memcpy(bd->data, data, len); } else { bd = (HtpBodyChunk *)SCMalloc(sizeof(HtpBodyChunk)); if (bd == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Fatal error, error allocationg memory"); - exit(EXIT_FAILURE); + if (SCLogDebugEnabled()) { + abort(); + } + else { + exit(EXIT_FAILURE); + } } bd->len = len; - bd->data = data; + bd->data = SCMalloc(len); + if (bd->data == NULL) { + SCLogError(SC_ERR_MEM_ALLOC,"Couldn't allocate memory for a http body chunk"); + if (SCLogDebugEnabled()) { + abort(); + } + else { + exit(EXIT_FAILURE); + } + } + memcpy(bd->data, data, len); body->last->next = bd; body->last = bd; body->nchunks++;