flash: code cleanups

pull/3246/head
Victor Julien 8 years ago
parent e251c45d3d
commit 7078b4e8e4

@ -165,17 +165,16 @@ int FileSwfDecompression(const uint8_t *buffer, uint32_t buffer_len,
} else if ((swf_type == HTTP_SWF_COMPRESSION_LZMA || swf_type == HTTP_SWF_COMPRESSION_BOTH) &&
compression_type == FILE_SWF_LZMA_COMPRESSION)
{
#ifndef HAVE_LIBLZMA
goto error;
#else
/* we need to setup the lzma header */
/*
* | 5 bytes | 8 bytes | n bytes |
* | LZMA properties | Uncompressed length | Compressed data |
*/
compressed_data_len += 13;
uint8_t *compressed_data = SCMalloc(compressed_data_len);
if (compressed_data == NULL) {
DetectEngineSetEvent(det_ctx, FILE_DECODER_EVENT_NO_MEM);
goto error;
}
uint8_t compressed_data[compressed_data_len];
/* put lzma properties */
memcpy(compressed_data, buffer + 12, 5);
/* put lzma end marker */
@ -189,9 +188,9 @@ int FileSwfDecompression(const uint8_t *buffer, uint32_t buffer_len,
r = FileSwfLzmaDecompression(det_ctx,
compressed_data, compressed_data_len,
out_buffer->buf + 8, out_buffer->len - 8);
SCFree(compressed_data);
if (r == 0)
goto error;
#endif
} else {
goto error;
}

@ -125,11 +125,11 @@ int FileSwfZlibDecompression(DetectEngineThreadCtx *det_ctx,
* | 4 bytes | 4 bytes | 4 bytes | 5 bytes | n bytes | 6 bytes |
* | 'ZWS' + version | script len | compressed len | LZMA props | LZMA data | LZMA end marker |
*/
#ifdef HAVE_LIBLZMA
int FileSwfLzmaDecompression(DetectEngineThreadCtx *det_ctx,
uint8_t *compressed_data, uint32_t compressed_data_len,
uint8_t *decompressed_data, uint32_t decompressed_data_len)
{
#ifdef HAVE_LIBLZMA
int ret = 1;
lzma_stream strm = LZMA_STREAM_INIT;
lzma_ret result = lzma_alone_decoder(&strm, UINT64_MAX /* memlimit */);
@ -177,7 +177,5 @@ int FileSwfLzmaDecompression(DetectEngineThreadCtx *det_ctx,
lzma_end(&strm);
return ret;
#else
return 0;
#endif /* HAVE_LIBLZMA */
}
#endif /* HAVE_LIBLZMA */

@ -35,8 +35,10 @@ uint32_t FileGetSwfDecompressedLen(const uint8_t *buffer, uint32_t buffr_len);
int FileSwfZlibDecompression(DetectEngineThreadCtx *det_ctx,
uint8_t *compressed_data, uint32_t compressed_data_len,
uint8_t *decompressed_data, uint32_t decompressed_data_len);
#ifdef HAVE_LIBLZMA
int FileSwfLzmaDecompression(DetectEngineThreadCtx *det_ctx,
uint8_t *compressed_data, uint32_t compressed_data_len,
uint8_t *decompressed_data, uint32_t decompressed_data_len);
#endif
#endif /* __UTIL_FILE_SWF_DECOMPRESSION_H__ */

Loading…
Cancel
Save