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
*
* \return none
*
*/
void MimeDecFreeEntity (MimeDecEntity *entity) {
if (entity != NULL) {
void MimeDecFreeEntity (MimeDecEntity *entity)
{
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);
SCFree(entity->filename);
/**
* Move to next element
*/
MimeDecEntity *old = entity;
entity = entity->next;
/* Use recursion */
MimeDecFreeEntity(entity->child);
MimeDecFreeEntity(entity->next);
MimeDecFreeField(old->field_list);
MimeDecFreeUrl(old->url_list);
SCFree(old->filename);
SCFree(entity);
SCFree(old);
}
}
@ -1085,15 +1117,17 @@ static int ProcessDecodedDataChunk(const uint8_t *chunk, uint32_t len,
MimeDecParseState *state) {
int ret = MIME_DEC_OK;
MimeDecEntity *entity = (MimeDecEntity *) state->stack->top->data;
char *remainPtr, *tok;
uint32_t tokLen;
MimeDecConfig *mdcfg = MimeDecGetConfig();
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 ((entity->ctnt_flags & CTNT_IS_TEXT) ||
(entity->ctnt_flags & CTNT_IS_HTML)) {
if (((entity->ctnt_flags & CTNT_IS_TEXT) ||
(entity->ctnt_flags & CTNT_IS_HTML)) &&
((entity->ctnt_flags & CTNT_IS_ATTACHMENT) == 0)) {
/* Remainder from previous line */
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);
}
}
} else {
SCLogDebug("Error: Stack pointer missing");
}
}
/* Now invoke callback */

Loading…
Cancel
Save