From: Victor Julien Date: Fri, 2 Feb 2018 14:45:47 +0000 (+0100) Subject: flash: code cleanups X-Git-Tag: suricata-4.1.0-beta1~133 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F3246%2Fhead;p=thirdparty%2Fsuricata.git flash: code cleanups --- diff --git a/src/util-file-decompression.c b/src/util-file-decompression.c index 9d561e0833..43f323f5c0 100644 --- a/src/util-file-decompression.c +++ b/src/util-file-decompression.c @@ -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; } diff --git a/src/util-file-swf-decompression.c b/src/util-file-swf-decompression.c index 81b07d8163..aeb6fdfdf6 100644 --- a/src/util-file-swf-decompression.c +++ b/src/util-file-swf-decompression.c @@ -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 */ diff --git a/src/util-file-swf-decompression.h b/src/util-file-swf-decompression.h index aa2af4b106..79034b89e4 100644 --- a/src/util-file-swf-decompression.h +++ b/src/util-file-swf-decompression.h @@ -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__ */