file_capture.c (snort-2.9.16.1) | : | file_capture.c (snort-2.9.17) | ||
---|---|---|---|---|
skipping to change at line 143 | skipping to change at line 143 | |||
if (block_size & 7) | if (block_size & 7) | |||
block_size += (8 - (block_size & 7)); | block_size += (8 - (block_size & 7)); | |||
max_files = max_file_mem_in_bytes / block_size ; | max_files = max_file_mem_in_bytes / block_size ; | |||
file_mempool = (SafeMemPool *)calloc(1, sizeof(SafeMemPool)); | file_mempool = (SafeMemPool *)calloc(1, sizeof(SafeMemPool)); | |||
if ((!file_mempool)|| | if ((!file_mempool)|| | |||
(safe_mempool_init(file_mempool, max_files, block_size) != 0)) | (safe_mempool_init(file_mempool, max_files, block_size) != 0)) | |||
{ | { | |||
FILE_CRITICAL( "File capture: Could not allocate file buffer mempool."); | ||||
FatalError( "File capture: Could not allocate file buffer mempool.\n"); | FatalError( "File capture: Could not allocate file buffer mempool.\n"); | |||
} | } | |||
return file_mempool; | return file_mempool; | |||
} | } | |||
/* | /* | |||
* Initialize the file memory pool | * Initialize the file memory pool | |||
* | * | |||
* Arguments: | * Arguments: | |||
skipping to change at line 216 | skipping to change at line 215 | |||
if (fileInfo) | if (fileInfo) | |||
{ | { | |||
/*free mempool*/ | /*free mempool*/ | |||
if(!fileInfo->reserved) | if(!fileInfo->reserved) | |||
{ | { | |||
_free_file_buffer(fileInfo); | _free_file_buffer(fileInfo); | |||
} | } | |||
context->file_capture = NULL; | context->file_capture = NULL; | |||
} | } | |||
context->file_capture_enabled = false; | context->file_capture_enabled = false; | |||
FILE_DEBUG("Capture stopped"); | ||||
} | } | |||
/* | /* | |||
* Create file buffer in file mempool | * Create file buffer in file mempool | |||
* | * | |||
* Args: | * Args: | |||
* SafeMemPool *file_mempool: file mempool | * SafeMemPool *file_mempool: file mempool | |||
* FileContext* context: file context | * FileContext* context: file context | |||
* | * | |||
* Returns: | * Returns: | |||
skipping to change at line 274 | skipping to change at line 272 | |||
* Returns: | * Returns: | |||
* 0: successful or file capture is disabled | * 0: successful or file capture is disabled | |||
* 1: fail to capture the file | * 1: fail to capture the file | |||
*/ | */ | |||
static inline int _save_to_file_buffer(SafeMemPool *file_mempool, | static inline int _save_to_file_buffer(SafeMemPool *file_mempool, | |||
FileContext* context, uint8_t* file_data, int data_size, | FileContext* context, uint8_t* file_data, int data_size, | |||
int64_t max_size) | int64_t max_size) | |||
{ | { | |||
FileCaptureInfo *fileInfo = (FileCaptureInfo *) context->file_capture; | FileCaptureInfo *fileInfo = (FileCaptureInfo *) context->file_capture; | |||
FileCaptureInfo *lastBlock = fileInfo->last; | FileCaptureInfo *lastBlock = fileInfo->last; | |||
int64_t available_bytes; | uint64_t available_bytes; | |||
FileConfig *file_config = (FileConfig *)(snort_conf->file_config); | FileConfig *file_config = (FileConfig *)(snort_conf->file_config); | |||
DEBUG_WRAP(verify_file_capture_info(context, fileInfo);); | DEBUG_WRAP(verify_file_capture_info(context, fileInfo);); | |||
if ( data_size + (signed)fileInfo->file_size > max_size) | if ( data_size + (signed)fileInfo->file_size > max_size) | |||
{ | { | |||
FILE_DEBUG("Exceeding max file capture size!"); | FILE_DEBUG("Exceeding max file capture size!"); | |||
file_capture_stats.file_size_exceeded++; | file_capture_stats.file_size_exceeded++; | |||
context->file_state.capture_state = FILE_CAPTURE_MAX; | context->file_state.capture_state = FILE_CAPTURE_MAX; | |||
return -1; | return -1; | |||
} | } | |||
/* Check whether current file block can hold file data*/ | /* Check whether current file block can hold file data*/ | |||
available_bytes = file_config->file_capture_block_size - lastBlock->length; | available_bytes = file_config->file_capture_block_size - lastBlock->length; | |||
if ( available_bytes > file_config->file_capture_block_size) | ||||
{ | ||||
context->file_state.capture_state = FILE_CAPTURE_MEMCAP; | ||||
return -1; | ||||
} | ||||
if ( data_size > available_bytes) | if ( data_size > available_bytes) | |||
{ | { | |||
FileCaptureInfo *new_block; | FileCaptureInfo *new_block; | |||
uint8_t* file_current = file_data; | uint8_t* file_current = file_data; | |||
uint8_t* file_end = file_data + data_size; | uint8_t* file_end = file_data + data_size; | |||
/*can't hold all, use current block first*/ | /*can't hold all, use current block first*/ | |||
memcpy((uint8_t *)lastBlock + lastBlock->length + sizeof (*lastBlock), | memcpy((uint8_t *)lastBlock + lastBlock->length + sizeof (*lastBlock), | |||
file_current, available_bytes ); | file_current, available_bytes ); | |||
End of changes. 4 change blocks. | ||||
3 lines changed or deleted | 6 lines changed or added |