From 45c6938be878ca877589d6412367bc0c43bc32bf Mon Sep 17 00:00:00 2001 From: Micah Snyder Date: Mon, 25 Mar 2024 11:33:56 -0400 Subject: [PATCH] Remove libbz2 dead code As of ClamAV 0.105, libbz2 is required. There is also no option to disable bz2 support. This commit removes the dead code associated with the old build option. --- CMakeLists.txt | 3 --- clamav-config.h.cmake.in | 3 --- clamconf/clamconf.c | 3 --- libclamav/bytecode.c | 2 -- libclamav/bytecode_api.c | 18 ------------------ libclamav/bytecode_priv.h | 4 ---- libclamav/dmg.c | 11 ----------- libclamav/egg.c | 10 ---------- libclamav/scanners.c | 12 ------------ libclamav/unzip.c | 8 +------- unit_tests/check_clamav.c | 6 ------ 11 files changed, 1 insertion(+), 79 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e2e2bad9..6559bc9d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -467,9 +467,6 @@ if(ZLIB_FOUND) endif() find_package(BZip2 REQUIRED) -if(BZIP2_FOUND) - set(HAVE_BZLIB_H 1) -endif() # Disable CMAKE_FIND_PACKAGE_PREFER_CONFIG, temporarily, because # we don't presently support the using libxml2's Config.cmake diff --git a/clamav-config.h.cmake.in b/clamav-config.h.cmake.in index b5ac6e1b9..aa51f4afd 100644 --- a/clamav-config.h.cmake.in +++ b/clamav-config.h.cmake.in @@ -104,9 +104,6 @@ /* attrib packed */ #cmakedefine HAVE_ATTRIB_PACKED 1 -/* have bzip2 */ -#cmakedefine HAVE_BZLIB_H 1 - /* Define to 1 if you have the `ctime_r' function. */ #cmakedefine HAVE_CTIME_R 1 diff --git a/clamconf/clamconf.c b/clamconf/clamconf.c index be77e52cb..7a3e15baf 100644 --- a/clamconf/clamconf.c +++ b/clamconf/clamconf.c @@ -462,9 +462,6 @@ int main(int argc, char **argv) if (get_fpu_endian() != FPU_ENDIAN_UNKNOWN) #endif printf("AUTOIT_EA06 "); -#ifdef HAVE_BZLIB_H - printf("BZIP2 "); -#endif #ifdef HAVE_ICONV printf("ICONV "); diff --git a/libclamav/bytecode.c b/libclamav/bytecode.c index faf8dbb3b..06bcf601e 100644 --- a/libclamav/bytecode.c +++ b/libclamav/bytecode.c @@ -195,13 +195,11 @@ static void bytecode_context_reset(struct cli_bc_ctx *ctx) ctx->lzmas = NULL; ctx->nlzmas = 0; -#if HAVE_BZLIB_H for (i = 0; i < ctx->nbzip2s; i++) cli_bcapi_bzip2_done(ctx, i); free(ctx->bzip2s); ctx->bzip2s = NULL; ctx->nbzip2s = 0; -#endif for (i = 0; i < ctx->nbuffers; i++) cli_bcapi_buffer_pipe_done(ctx, i); diff --git a/libclamav/bytecode_api.c b/libclamav/bytecode_api.c index 5a77fb0aa..99877f4db 100644 --- a/libclamav/bytecode_api.c +++ b/libclamav/bytecode_api.c @@ -38,9 +38,7 @@ #if HAVE_JSON #include #endif -#if HAVE_BZLIB_H #include -#endif #include "clamav.h" #include "clambc.h" @@ -72,13 +70,11 @@ struct bc_lzma { int32_t to; }; -#if HAVE_BZLIB_H struct bc_bzip2 { bz_stream stream; int32_t from; int32_t to; }; -#endif uint32_t cli_bcapi_test1(struct cli_bc_ctx *ctx, uint32_t a, uint32_t b) { @@ -1048,7 +1044,6 @@ int32_t cli_bcapi_lzma_done(struct cli_bc_ctx *ctx, int32_t id) int32_t cli_bcapi_bzip2_init(struct cli_bc_ctx *ctx, int32_t from, int32_t to) { -#if HAVE_BZLIB_H int ret; struct bc_bzip2 *b; unsigned n = ctx->nbzip2s + 1; @@ -1086,23 +1081,17 @@ int32_t cli_bcapi_bzip2_init(struct cli_bc_ctx *ctx, int32_t from, int32_t to) } return n - 1; -#else - return -1; -#endif } -#if HAVE_BZLIB_H static struct bc_bzip2 *get_bzip2(struct cli_bc_ctx *ctx, int32_t id) { if (id < 0 || (unsigned int)id >= ctx->nbzip2s || !ctx->bzip2s) return NULL; return &ctx->bzip2s[id]; } -#endif int32_t cli_bcapi_bzip2_process(struct cli_bc_ctx *ctx, int32_t id) { -#if HAVE_BZLIB_H int ret; unsigned avail_in_orig, avail_out_orig; struct bc_bzip2 *b = get_bzip2(ctx, id); @@ -1135,23 +1124,16 @@ int32_t cli_bcapi_bzip2_process(struct cli_bc_ctx *ctx, int32_t id) } return ret; -#else - return -1; -#endif } int32_t cli_bcapi_bzip2_done(struct cli_bc_ctx *ctx, int32_t id) { -#if HAVE_BZLIB_H struct bc_bzip2 *b = get_bzip2(ctx, id); if (!b || b->from == -1 || b->to == -1) return -1; BZ2_bzDecompressEnd(&b->stream); b->from = b->to = -1; return 0; -#else - return -1; -#endif } int32_t cli_bcapi_bytecode_rt_error(struct cli_bc_ctx *ctx, int32_t id) diff --git a/libclamav/bytecode_priv.h b/libclamav/bytecode_priv.h index b786febeb..43695c104 100644 --- a/libclamav/bytecode_priv.h +++ b/libclamav/bytecode_priv.h @@ -199,9 +199,7 @@ struct cli_bc_ctx { unsigned found; unsigned ninflates; unsigned nlzmas; -#if HAVE_BZLIB_H unsigned nbzip2s; -#endif bc_dbg_callback_trace trace; bc_dbg_callback_trace_op trace_op; bc_dbg_callback_trace_val trace_val; @@ -216,9 +214,7 @@ struct cli_bc_ctx { mpool_t *mpool; struct bc_inflate *inflates; struct bc_lzma *lzmas; -#if HAVE_BZLIB_H struct bc_bzip2 *bzip2s; -#endif struct bc_buffer *buffers; unsigned nbuffers; unsigned nhashsets; diff --git a/libclamav/dmg.c b/libclamav/dmg.c index de4293565..043be79ed 100644 --- a/libclamav/dmg.c +++ b/libclamav/dmg.c @@ -37,14 +37,12 @@ #if HAVE_LIBZ #include #endif -#if HAVE_BZLIB_H #include #ifdef NOBZ2PREFIX #define BZ2_bzDecompress bzDecompress #define BZ2_bzDecompressEnd bzDecompressEnd #define BZ2_bzDecompressInit bzDecompressInit #endif -#endif #include @@ -552,13 +550,8 @@ static int dmg_track_sectors(uint64_t *total, uint8_t *data_to_write, #endif break; case DMG_STRIPE_BZ: -#if HAVE_BZLIB_H *data_to_write = 1; usable = 1; -#else - cli_warnmsg("dmg_track_sectors: Need bzip2 decompression to properly scan this file.\n"); - return CL_EFORMAT; -#endif break; case DMG_STRIPE_EMPTY: case DMG_STRIPE_ZEROES: @@ -846,16 +839,13 @@ static int dmg_stripe_bzip(cli_ctx *ctx, int fd, uint32_t index, struct dmg_mish size_t len = mish_set->stripes[index].dataLength; uint64_t size_so_far = 0; uint64_t expected_len = mish_set->stripes[index].sectorCount * DMG_SECTOR_SIZE; -#if HAVE_BZLIB_H int rc; bz_stream strm; uint8_t obuf[BUFSIZ]; -#endif cli_dbgmsg("dmg_stripe_bzip: stripe " STDu32 " initial len " STDu64 " expected len " STDu64 "\n", index, (uint64_t)len, (uint64_t)expected_len); -#if HAVE_BZLIB_H memset(&strm, 0, sizeof(strm)); strm.next_out = (char *)obuf; strm.avail_out = sizeof(obuf); @@ -953,7 +943,6 @@ static int dmg_stripe_bzip(cli_ctx *ctx, int fd, uint32_t index, struct dmg_mish } while ((rc == BZ_OK) && (len > 0)); BZ2_bzDecompressEnd(&strm); -#endif if (ret == CL_CLEAN) { if (size_so_far != expected_len) { diff --git a/libclamav/egg.c b/libclamav/egg.c index 2d74ff4d3..9a725c944 100644 --- a/libclamav/egg.c +++ b/libclamav/egg.c @@ -64,10 +64,7 @@ #include #include #include - -#if HAVE_BZLIB_H #include -#endif #include "lzma_iface.h" @@ -2040,7 +2037,6 @@ done: return status; } -#ifdef HAVE_BZLIB_H cl_error_t cli_egg_bzip2_decompress(char* compressed, size_t compressed_size, char** decompressed, size_t* decompressed_size) { cl_error_t status = CL_EPARSE; @@ -2153,7 +2149,6 @@ done: return status; } -#endif cl_error_t cli_egg_lzma_decompress(char* compressed, size_t compressed_size, char** decompressed, size_t* decompressed_size) { @@ -2402,7 +2397,6 @@ cl_error_t cli_egg_extract_file(void* hArchive, const char** filename, const cha break; } case BLOCK_HEADER_COMPRESS_ALGORITHM_BZIP2: { -#if HAVE_BZLIB_H char* decompressed_block = NULL; size_t decompressed_block_size = 0; @@ -2429,10 +2423,6 @@ cl_error_t cli_egg_extract_file(void* hArchive, const char** filename, const cha retval = CL_SUCCESS; break; -#else - cli_warnmsg("cli_egg_extract_file: BZIP2 decompression support not available.\n"); - goto done; -#endif } case BLOCK_HEADER_COMPRESS_ALGORITHM_AZO: { cli_warnmsg("cli_egg_extract_file: AZO decompression not yet supported.\n"); diff --git a/libclamav/scanners.c b/libclamav/scanners.c index f5bb8be40..923e5f425 100644 --- a/libclamav/scanners.c +++ b/libclamav/scanners.c @@ -121,9 +121,7 @@ // libclamunrar_iface #include "unrar_iface.h" -#ifdef HAVE_BZLIB_H #include -#endif #include #include @@ -1236,15 +1234,6 @@ static cl_error_t cli_scangzip(cli_ctx *ctx) return ret; } -#ifndef HAVE_BZLIB_H -static cl_error_t cli_scanbzip(cli_ctx *ctx) -{ - cli_warnmsg("cli_scanbzip: bzip2 support not compiled in\n"); - return CL_CLEAN; -} - -#else - #ifdef NOBZ2PREFIX #define BZ2_bzDecompressInit bzDecompressInit #define BZ2_bzDecompress bzDecompress @@ -1341,7 +1330,6 @@ static cl_error_t cli_scanbzip(cli_ctx *ctx) return ret; } -#endif static cl_error_t cli_scanxz(cli_ctx *ctx) { diff --git a/libclamav/unzip.c b/libclamav/unzip.c index 74fe0c120..f3cd598de 100644 --- a/libclamav/unzip.c +++ b/libclamav/unzip.c @@ -39,9 +39,8 @@ #include #include "inflate64.h" -#if HAVE_BZLIB_H + #include -#endif #include "explode.h" #include "others.h" @@ -242,7 +241,6 @@ static cl_error_t unz( break; } -#if HAVE_BZLIB_H #ifdef NOBZ2PREFIX #define BZ2_bzDecompress bzDecompress #define BZ2_bzDecompressEnd bzDecompressEnd @@ -284,7 +282,6 @@ static cl_error_t unz( if (res == BZ_STREAM_END) res = 0; break; } -#endif /* HAVE_BZLIB_H */ case ALG_IMPLODE: { struct xplstate strm; @@ -322,9 +319,6 @@ static cl_error_t unz( case ALG_LZMA: /* easy but there's not a single sample in the zoo */ -#if !HAVE_BZLIB_H - case ALG_BZIP2: -#endif case ALG_SHRUNK: case ALG_REDUCE1: case ALG_REDUCE2: diff --git a/unit_tests/check_clamav.c b/unit_tests/check_clamav.c index f160ce661..1d55f1763 100644 --- a/unit_tests/check_clamav.c +++ b/unit_tests/check_clamav.c @@ -543,12 +543,6 @@ static unsigned skip_files(void) skipped += 2; } - /* skip .bz2 files if bzip is disabled */ -#if HAVE_BZLIB_H -#else - skipped += 2; -#endif - #if HAVE_UNRAR #else skipped += 2;