mime-decode: don't scan attachment's data for URLs.

move event pointer lookup inside extract_urls and protect pointer walk.
pull/1195/head
Tom DeCanio 11 years ago committed by Victor Julien
parent 6467a5d563
commit 471967aafd

@ -164,26 +164,58 @@ MimeDecConfig * MimeDecGetConfig(void) {
} }
/** /**
* \brief Recursively frees a mime entity tree * \brief Follow the 'next' pointers to the leaf
*
* \param node The root entity
*
* \return Pointer to leaf on 'next' side
*
*/
static MimeDecEntity *findLastSibling(MimeDecEntity *node)
{
if (node == NULL)
return NULL;
while(node->next != NULL)
node = node->next;
return node;
}
/**
* \brief Frees a mime entity tree
* *
* \param entity The root entity * \param entity The root entity
* *
* \return none * \return none
* *
*/ */
void MimeDecFreeEntity (MimeDecEntity *entity) { void MimeDecFreeEntity (MimeDecEntity *entity)
{
if (entity != NULL) { if (entity == NULL)
return;
MimeDecEntity *lastSibling = findLastSibling(entity);
while (entity != NULL)
{
/**
* Move child to next
* Transform tree into list
*/
if (entity->child != NULL)
{
lastSibling->next = entity->child;
lastSibling = findLastSibling(lastSibling);
}
MimeDecFreeField(entity->field_list); /**
MimeDecFreeUrl(entity->url_list); * Move to next element
SCFree(entity->filename); */
MimeDecEntity *old = entity;
entity = entity->next;
/* Use recursion */ MimeDecFreeField(old->field_list);
MimeDecFreeEntity(entity->child); MimeDecFreeUrl(old->url_list);
MimeDecFreeEntity(entity->next); SCFree(old->filename);
SCFree(entity); SCFree(old);
} }
} }
@ -1085,15 +1117,17 @@ static int ProcessDecodedDataChunk(const uint8_t *chunk, uint32_t len,
MimeDecParseState *state) { MimeDecParseState *state) {
int ret = MIME_DEC_OK; int ret = MIME_DEC_OK;
MimeDecEntity *entity = (MimeDecEntity *) state->stack->top->data;
char *remainPtr, *tok; char *remainPtr, *tok;
uint32_t tokLen; uint32_t tokLen;
MimeDecConfig *mdcfg = MimeDecGetConfig(); MimeDecConfig *mdcfg = MimeDecGetConfig();
if (mdcfg != NULL && mdcfg->extract_urls) { if (mdcfg != NULL && mdcfg->extract_urls) {
if ((state->stack != NULL) && (state->stack->top != NULL)) {
MimeDecEntity *entity = (MimeDecEntity *) state->stack->top->data;
/* If plain text or html, then look for URLs */ /* If plain text or html, then look for URLs */
if ((entity->ctnt_flags & CTNT_IS_TEXT) || if (((entity->ctnt_flags & CTNT_IS_TEXT) ||
(entity->ctnt_flags & CTNT_IS_HTML)) { (entity->ctnt_flags & CTNT_IS_HTML)) &&
((entity->ctnt_flags & CTNT_IS_ATTACHMENT) == 0)) {
/* Remainder from previous line */ /* Remainder from previous line */
if (state->linerem_len > 0) { if (state->linerem_len > 0) {
@ -1127,6 +1161,9 @@ static int ProcessDecodedDataChunk(const uint8_t *chunk, uint32_t len,
} while (tok != remainPtr && remainPtr - (char *) chunk < len); } while (tok != remainPtr && remainPtr - (char *) chunk < len);
} }
} }
} else {
SCLogDebug("Error: Stack pointer missing");
}
} }
/* Now invoke callback */ /* Now invoke callback */

Loading…
Cancel
Save