From: Victor Julien Date: Fri, 19 Jun 2015 10:42:57 +0000 (+0200) Subject: file_data smtp: fix minor coverity warning X-Git-Tag: suricata-3.0RC1~293 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd2afd51f7cabc11a6303f14d7ef99c125ea0b05;p=thirdparty%2Fsuricata.git file_data smtp: fix minor coverity warning CID 1298891: Null pointer dereferences (REVERSE_INULL) Null-checking "curr_file" suggests that it may be null, but it has already been dereferenced on all paths leading to the check. --- diff --git a/src/detect-engine-filedata-smtp.c b/src/detect-engine-filedata-smtp.c index 423db75d2b..dc50d8c7d7 100644 --- a/src/detect-engine-filedata-smtp.c +++ b/src/detect-engine-filedata-smtp.c @@ -144,53 +144,51 @@ static uint8_t *DetectEngineSMTPGetBufferForTX(uint64_t tx_id, goto end; } - if (curr_file != NULL) { - int first = 1; - curr_chunk = curr_file->chunks_head; - while (curr_chunk != NULL) { - /* see if we can filter out chunks */ - if (curr_file->content_inspected > 0) { - if (curr_chunk->stream_offset < curr_file->content_inspected) { - if ((curr_file->content_inspected - curr_chunk->stream_offset) > smtp_config.content_inspect_window) { - curr_chunk = curr_chunk->next; - continue; - } else { - /* include this one */ - } + int first = 1; + curr_chunk = curr_file->chunks_head; + while (curr_chunk != NULL) { + /* see if we can filter out chunks */ + if (curr_file->content_inspected > 0) { + if (curr_chunk->stream_offset < curr_file->content_inspected) { + if ((curr_file->content_inspected - curr_chunk->stream_offset) > smtp_config.content_inspect_window) { + curr_chunk = curr_chunk->next; + continue; } else { /* include this one */ } + } else { + /* include this one */ } + } - if (first) { - det_ctx->smtp[index].offset = curr_chunk->stream_offset; - first = 0; - } + if (first) { + det_ctx->smtp[index].offset = curr_chunk->stream_offset; + first = 0; + } - /* see if we need to grow the buffer */ - if (det_ctx->smtp[index].buffer == NULL || (det_ctx->smtp[index].buffer_len + curr_chunk->len) > det_ctx->smtp[index].buffer_size) { - void *ptmp; - det_ctx->smtp[index].buffer_size += curr_chunk->len * 2; - - if ((ptmp = SCRealloc(det_ctx->smtp[index].buffer, det_ctx->smtp[index].buffer_size)) == NULL) { - SCFree(det_ctx->smtp[index].buffer); - det_ctx->smtp[index].buffer = NULL; - det_ctx->smtp[index].buffer_size = 0; - det_ctx->smtp[index].buffer_len = 0; - goto end; - } - det_ctx->smtp[index].buffer = ptmp; - } - memcpy(det_ctx->smtp[index].buffer + det_ctx->smtp[index].buffer_len, curr_chunk->data, curr_chunk->len); - det_ctx->smtp[index].buffer_len += curr_chunk->len; + /* see if we need to grow the buffer */ + if (det_ctx->smtp[index].buffer == NULL || (det_ctx->smtp[index].buffer_len + curr_chunk->len) > det_ctx->smtp[index].buffer_size) { + void *ptmp; + det_ctx->smtp[index].buffer_size += curr_chunk->len * 2; - curr_chunk = curr_chunk->next; + if ((ptmp = SCRealloc(det_ctx->smtp[index].buffer, det_ctx->smtp[index].buffer_size)) == NULL) { + SCFree(det_ctx->smtp[index].buffer); + det_ctx->smtp[index].buffer = NULL; + det_ctx->smtp[index].buffer_size = 0; + det_ctx->smtp[index].buffer_len = 0; + goto end; + } + det_ctx->smtp[index].buffer = ptmp; } + memcpy(det_ctx->smtp[index].buffer + det_ctx->smtp[index].buffer_len, curr_chunk->data, curr_chunk->len); + det_ctx->smtp[index].buffer_len += curr_chunk->len; - /* updat inspected tracker */ - curr_file->content_inspected = curr_file->chunks_tail->stream_offset + curr_file->chunks_tail->len; + curr_chunk = curr_chunk->next; } + /* updat inspected tracker */ + curr_file->content_inspected = curr_file->chunks_tail->stream_offset + curr_file->chunks_tail->len; + buffer = det_ctx->smtp[index].buffer; *buffer_len = det_ctx->smtp[index].buffer_len; *stream_start_offset = det_ctx->smtp[index].offset;