diff --git a/CMakeLists.txt b/CMakeLists.txt index 80de8c7d9e..ff0f67f0d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -456,20 +456,10 @@ include(CPack) # libclamav efficacy dependencies find_package(OpenSSL REQUIRED) -if(OPENSSL_FOUND) - set(HAVE_LIBSSL 1) -endif() find_package(ZLIB REQUIRED) -if(ZLIB_FOUND) - set(HAVE_ZLIB_H 1) - set(HAVE_LIBZ 1) -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 @@ -477,17 +467,11 @@ set(PACKAGE_PREFER_CONFIG_BAK ${CMAKE_FIND_PACKAGE_PREFER_CONFIG}) set(CMAKE_FIND_PACKAGE_PREFER_CONFIG FALSE) find_package(LibXml2 REQUIRED) -if(LibXml2_FOUND) - set(HAVE_LIBXML2 1) -endif() + # Restore the requested CMAKE_FIND_PACKAGE_PREFER_CONFIG setting set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ${PACKAGE_PREFER_CONFIG_BAK}) find_package(PCRE2 REQUIRED) -if(PCRE2_FOUND) - set(HAVE_PCRE 1) - set(USING_PCRE2 1) -endif() # libclamav feature dependencies if(NOT WIN32) @@ -502,8 +486,6 @@ else() set(JSONC_USE_STATIC ON) endif() find_package(JSONC REQUIRED) -# Set variable required by libclamav to use libjson-c -set(HAVE_JSON 1) set(LLVM_MAX_VER "13") set(LLVM_MIN_VER "8") diff --git a/clamav-config.h.cmake.in b/clamav-config.h.cmake.in index a1ae2e384e..a016d24e70 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 @@ -120,10 +117,6 @@ you don't. */ #cmakedefine HAVE_DECL_CYGWIN_CONV_PATH 1 -/* Define to 1 if you have a deprecated version of the 'libjson' library - (-ljson). */ -#cmakedefine HAVE_DEPRECATED_JSON 1 - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_DIRENT_H 1 @@ -181,9 +174,6 @@ /* Define to 1 if you have the header file (for libjson-c). */ #cmakedefine JSON_C_HAVE_INTTYPES_H 1 -/* Define to 1 if you have the 'libjson' library (-ljson). */ -#cmakedefine HAVE_JSON 1 - /* Define to '1' if you have the check.h library */ #cmakedefine HAVE_LIBCHECK 1 @@ -193,15 +183,6 @@ /* Define to '1' if you have the curses.h library */ #cmakedefine HAVE_LIBPDCURSES 1 -/* Define to 1 if you have the `ssl' library (-lssl). */ -#cmakedefine HAVE_LIBSSL 1 - -/* Define to 1 if you have the 'libxml2' library (-lxml2). */ -#cmakedefine HAVE_LIBXML2 1 - -/* Define to 1 if you have the `z' library (-lz). */ -#cmakedefine HAVE_LIBZ 1 - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_LIMITS_H 1 @@ -221,12 +202,6 @@ MAP_PRIVATE. */ #cmakedefine HAVE_MMAP 1 -/* Define to 1 if you have a pcre library (-lpcre). */ -#cmakedefine HAVE_PCRE 1 - -/* Define to 1 if you using the pcre2 library. */ -#cmakedefine USING_PCRE2 1 - /* Define to 1 if you have the `poll' function. */ #cmakedefine HAVE_POLL 1 @@ -389,9 +364,6 @@ /* yara sources are compiled in */ #define HAVE_YARA 1 -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_ZLIB_H 1 - /* For internal use only - DO NOT DEFINE */ #cmakedefine HAVE__INTERNAL__SHA_COLLECT 1 @@ -493,9 +465,6 @@ /* Define to if you have the ANSI C header files. */ #cmakedefine STDC_HEADERS 1 -/* Support for IPv6 */ -#cmakedefine SUPPORT_IPv6 1 - /* enable memory pools */ #cmakedefine USE_MPOOL 1 diff --git a/clamconf/clamconf.c b/clamconf/clamconf.c index 46620b9e2b..7dbfaae439 100644 --- a/clamconf/clamconf.c +++ b/clamconf/clamconf.c @@ -446,12 +446,6 @@ int main(int argc, char **argv) #ifdef USE_MPOOL printf("MEMPOOL "); #endif -#ifdef SUPPORT_IPv6 - printf("IPv6 "); -#endif -#ifdef CLAMUKO - printf("CLAMUKO "); -#endif #ifdef C_BIGSTACK printf("BIGSTACK "); #endif @@ -462,25 +456,9 @@ 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_LIBXML2 - printf("LIBXML2 "); -#endif -#ifdef HAVE_PCRE -#if USING_PCRE2 - printf("PCRE2 "); -#else - printf("PCRE "); -#endif -#endif #ifdef HAVE_ICONV printf("ICONV "); -#endif -#ifdef HAVE_JSON - printf("JSON "); #endif if (have_rar) printf("RAR "); diff --git a/clamd/server-th.c b/clamd/server-th.c index 06ecc27ab1..7dd30d5fb6 100644 --- a/clamd/server-th.c +++ b/clamd/server-th.c @@ -1377,17 +1377,9 @@ int recvloop(int *socketds, unsigned nsockets, struct cl_engine *engine, unsigne options.dev |= CL_SCAN_DEV_COLLECT_SHA; #endif -#if HAVE_JSON /* JSON check to prevent engine loading if specified without libjson-c */ if (optget(opts, "GenerateMetadataJson")->enabled) options.general |= CL_SCAN_GENERAL_COLLECT_METADATA; -#else - if (optget(opts, "GenerateMetadataJson")->enabled) { - logg(LOGG_ERROR, "Can't generate json (gen-json). libjson-c dev library was missing or misconfigured when ClamAV was built.\n"); - cl_engine_free(engine); - return 1; - } -#endif selfchk = optget(opts, "SelfCheck")->numarg; if (!selfchk) { diff --git a/clamscan/clamscan.c b/clamscan/clamscan.c index 08d256829e..2b10a1023b 100644 --- a/clamscan/clamscan.c +++ b/clamscan/clamscan.c @@ -336,11 +336,9 @@ void help(void) mprintf(LOGG_INFO, " --max-partitions=#n Maximum number of partitions in disk image to be scanned\n"); mprintf(LOGG_INFO, " --max-iconspe=#n Maximum number of icons in PE file to be scanned\n"); mprintf(LOGG_INFO, " --max-rechwp3=#n Maximum recursive calls to HWP3 parsing function\n"); -#if HAVE_PCRE mprintf(LOGG_INFO, " --pcre-match-limit=#n Maximum calls to the PCRE match function.\n"); mprintf(LOGG_INFO, " --pcre-recmatch-limit=#n Maximum recursive calls to the PCRE match function.\n"); mprintf(LOGG_INFO, " --pcre-max-filesize=#n Maximum size file to perform PCRE subsig matching.\n"); -#endif /* HAVE_PCRE */ mprintf(LOGG_INFO, " --disable-cache Disable caching and cache checks for hash sums of scanned files.\n"); mprintf(LOGG_INFO, "\n"); mprintf(LOGG_INFO, "Pass in - as the filename for stdin.\n"); diff --git a/clamscan/manager.c b/clamscan/manager.c index 0254d2209c..db3a8f46b6 100644 --- a/clamscan/manager.c +++ b/clamscan/manager.c @@ -1236,18 +1236,8 @@ int scanmanager(const struct optstruct *opts) } } - /* JSON check to prevent engine loading if specified without libjson-c */ -#if HAVE_JSON if (optget(opts, "gen-json")->enabled) options.general |= CL_SCAN_GENERAL_COLLECT_METADATA; -#else - if (optget(opts, "gen-json")->enabled) { - logg(LOGG_ERROR, "Can't generate json (gen-json). libjson-c dev library was missing or misconfigured when ClamAV was built.\n"); - - ret = 2; - goto done; - } -#endif if ((opt = optget(opts, "tempdir"))->enabled) { if ((ret = cl_engine_set_str(engine, CL_ENGINE_TMPDIR, opt->strarg))) { @@ -1676,13 +1666,11 @@ int scanmanager(const struct optstruct *opts) if (!strcasecmp(opt->strarg, "bytecode")) { cli_sigperf_print(); cli_sigperf_events_destroy(); - } -#if HAVE_PCRE - else if (!strcasecmp(opt->strarg, "pcre")) { + } else if (!strcasecmp(opt->strarg, "pcre")) { cli_pcre_perf_print(); cli_pcre_perf_events_destroy(); } -#endif + opt = opt->nextarg; } } diff --git a/libclamav/bytecode.c b/libclamav/bytecode.c index faf8dbb3b1..16108f94df 100644 --- a/libclamav/bytecode.c +++ b/libclamav/bytecode.c @@ -29,10 +29,7 @@ #include #include -#if HAVE_JSON #include "json.h" -#endif - #include "dconf.h" #include "clamav.h" #include "others.h" @@ -195,13 +192,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); @@ -231,11 +226,9 @@ static void bytecode_context_reset(struct cli_bc_ctx *ctx) /* Use input_switch() to free the extracted file fmap, if one exists */ cli_bcapi_input_switch(ctx, 0); -#if HAVE_JSON free((json_object **)(ctx->jsonobjs)); ctx->jsonobjs = NULL; ctx->njsonobjs = 0; -#endif ctx->containertype = CL_TYPE_ANY; } diff --git a/libclamav/bytecode_api.c b/libclamav/bytecode_api.c index 5a77fb0aa1..5de7239acb 100644 --- a/libclamav/bytecode_api.c +++ b/libclamav/bytecode_api.c @@ -35,12 +35,8 @@ #include #include -#if HAVE_JSON #include -#endif -#if HAVE_BZLIB_H #include -#endif #include "clamav.h" #include "clambc.h" @@ -72,13 +68,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 +1042,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 +1079,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 +1122,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) @@ -2025,21 +2005,15 @@ int32_t cli_bcapi_get_file_reliability(struct cli_bc_ctx *ctx) int32_t cli_bcapi_json_is_active(struct cli_bc_ctx *ctx) { -#if HAVE_JSON cli_ctx *cctx = (cli_ctx *)ctx->ctx; if (cctx->properties != NULL) { return 1; } -#else - UNUSEDPARAM(ctx); - cli_dbgmsg("bytecode api: libjson is not enabled!\n"); -#endif return 0; } static int32_t cli_bcapi_json_objs_init(struct cli_bc_ctx *ctx) { -#if HAVE_JSON unsigned n = ctx->njsonobjs + 1; json_object **j, **jobjs = (json_object **)(ctx->jsonobjs); cli_ctx *cctx = (cli_ctx *)ctx->ctx; @@ -2054,10 +2028,6 @@ static int32_t cli_bcapi_json_objs_init(struct cli_bc_ctx *ctx) j[n - 1] = cctx->properties; return 0; -#else - UNUSEDPARAM(ctx); - return -1; -#endif } #define INIT_JSON_OBJS(ctx) \ @@ -2071,7 +2041,6 @@ static int32_t cli_bcapi_json_objs_init(struct cli_bc_ctx *ctx) int32_t cli_bcapi_json_get_object(struct cli_bc_ctx *ctx, const int8_t *name, int32_t name_len, int32_t objid) { -#if HAVE_JSON unsigned n; json_object **j, *jobj, **jobjs; char *namep; @@ -2116,19 +2085,10 @@ int32_t cli_bcapi_json_get_object(struct cli_bc_ctx *ctx, const int8_t *name, in cli_dbgmsg("bytecode api[json_get_object]: assigned %s => ID %d\n", namep, n - 1); free(namep); return n - 1; -#else - UNUSEDPARAM(ctx); - UNUSEDPARAM(name); - UNUSEDPARAM(name_len); - UNUSEDPARAM(objid); - cli_dbgmsg("bytecode api: libjson is not enabled!\n"); - return -1; -#endif } int32_t cli_bcapi_json_get_type(struct cli_bc_ctx *ctx, int32_t objid) { -#if HAVE_JSON enum json_type type; json_object **jobjs; @@ -2159,17 +2119,11 @@ int32_t cli_bcapi_json_get_type(struct cli_bc_ctx *ctx, int32_t objid) cli_dbgmsg("bytecode api[json_get_type]: unrecognized json type %d\n", type); } -#else - UNUSEDPARAM(ctx); - UNUSEDPARAM(objid); - cli_dbgmsg("bytecode api: libjson is not enabled!\n"); -#endif return -1; } int32_t cli_bcapi_json_get_array_length(struct cli_bc_ctx *ctx, int32_t objid) { -#if HAVE_JSON enum json_type type; json_object **jobjs; @@ -2186,17 +2140,10 @@ int32_t cli_bcapi_json_get_array_length(struct cli_bc_ctx *ctx, int32_t objid) } return json_object_array_length(jobjs[objid]); -#else - UNUSEDPARAM(ctx); - UNUSEDPARAM(objid); - cli_dbgmsg("bytecode api: libjson is not enabled!\n"); - return -1; -#endif } int32_t cli_bcapi_json_get_array_idx(struct cli_bc_ctx *ctx, int32_t idx, int32_t objid) { -#if HAVE_JSON enum json_type type; unsigned n; int length; @@ -2241,18 +2188,10 @@ int32_t cli_bcapi_json_get_array_idx(struct cli_bc_ctx *ctx, int32_t idx, int32_ } return 0; -#else - UNUSEDPARAM(ctx); - UNUSEDPARAM(idx); - UNUSEDPARAM(objid); - cli_dbgmsg("bytecode api: libjson is not enabled!\n"); - return -1; -#endif } int32_t cli_bcapi_json_get_string_length(struct cli_bc_ctx *ctx, int32_t objid) { -#if HAVE_JSON enum json_type type; json_object *jobj, **jobjs; int32_t len; @@ -2279,17 +2218,10 @@ int32_t cli_bcapi_json_get_string_length(struct cli_bc_ctx *ctx, int32_t objid) len = strlen(jstr); return len; -#else - UNUSEDPARAM(ctx); - UNUSEDPARAM(objid); - cli_dbgmsg("bytecode api: libjson is not enabled!\n"); - return -1; -#endif } int32_t cli_bcapi_json_get_string(struct cli_bc_ctx *ctx, int8_t *str, int32_t str_len, int32_t objid) { -#if HAVE_JSON enum json_type type; json_object *jobj, **jobjs; int32_t len; @@ -2326,19 +2258,10 @@ int32_t cli_bcapi_json_get_string(struct cli_bc_ctx *ctx, int8_t *str, int32_t s str[len] = '\0'; return len + 1; } -#else - UNUSEDPARAM(ctx); - UNUSEDPARAM(str); - UNUSEDPARAM(str_len); - UNUSEDPARAM(objid); - cli_dbgmsg("bytecode api: libjson is not enabled!\n"); - return -1; -#endif } int32_t cli_bcapi_json_get_boolean(struct cli_bc_ctx *ctx, int32_t objid) { -#if HAVE_JSON json_object *jobj, **jobjs; INIT_JSON_OBJS(ctx); @@ -2350,17 +2273,10 @@ int32_t cli_bcapi_json_get_boolean(struct cli_bc_ctx *ctx, int32_t objid) jobj = jobjs[objid]; return json_object_get_boolean(jobj); -#else - UNUSEDPARAM(ctx); - UNUSEDPARAM(objid); - cli_dbgmsg("bytecode api: libjson is not enabled!\n"); - return 0; -#endif } int32_t cli_bcapi_json_get_int(struct cli_bc_ctx *ctx, int32_t objid) { -#if HAVE_JSON json_object *jobj, **jobjs; INIT_JSON_OBJS(ctx); @@ -2372,13 +2288,4 @@ int32_t cli_bcapi_json_get_int(struct cli_bc_ctx *ctx, int32_t objid) jobj = jobjs[objid]; return json_object_get_int(jobj); -#else - UNUSEDPARAM(ctx); - UNUSEDPARAM(objid); - cli_dbgmsg("bytecode api: libjson is not enabled!\n"); - return 0; -#endif } - -// int64_t cli_bcapi_json_get_int64(struct cli_bc_ctx *ctx, int32_t objid); -// double cli_bcapi_json_get_double(struct cli_bc_ctx *ctx, int32_t objid); diff --git a/libclamav/bytecode_priv.h b/libclamav/bytecode_priv.h index b786febeb6..b281c85f9d 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; @@ -236,10 +232,8 @@ struct cli_bc_ctx { cli_events_t *bc_events; int on_jit; int no_diff; -#if HAVE_JSON void **jsonobjs; unsigned njsonobjs; -#endif }; struct cli_all_bc; cl_error_t cli_vm_execute(const struct cli_bc *bc, struct cli_bc_ctx *ctx, const struct cli_bc_func *func, const struct cli_bc_inst *inst); diff --git a/libclamav/dconf.c b/libclamav/dconf.c index fb87c453b4..3bb5617739 100644 --- a/libclamav/dconf.c +++ b/libclamav/dconf.c @@ -310,7 +310,6 @@ void cli_dconf_print(struct cli_dconf *dconf) else continue; } else if (!strcmp(modules[i].mname, "PCRE")) { -#if HAVE_PCRE if (!pcre) { cli_dbgmsg("Module PCRE %s\n", dconf->pcre ? "On" : "Off"); pcre = 1; @@ -320,14 +319,6 @@ void cli_dconf_print(struct cli_dconf *dconf) cli_dbgmsg(" * Submodule %10s:\t%s\n", modules[i].sname, (dconf->pcre & modules[i].bflag) ? "On" : "** Off **"); else continue; -#else - if (!pcre) { - cli_dbgmsg("Module PCRE Off\n"); - pcre = 1; - } - - continue; -#endif } } } diff --git a/libclamav/dmg.c b/libclamav/dmg.c index e7fde7ef22..e873f623d2 100644 --- a/libclamav/dmg.c +++ b/libclamav/dmg.c @@ -34,21 +34,15 @@ #include /* for NAME_MAX */ #endif -#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 -#if HAVE_LIBXML2 #include -#endif #include "clamav.h" #include "others.h" @@ -85,9 +79,7 @@ enum dmgReadState { }; static int dmg_extract_xml(cli_ctx *, char *, struct dmg_koly_block *); -#if HAVE_LIBXML2 static int dmg_decode_mish(cli_ctx *, unsigned int *, xmlChar *, struct dmg_mish_with_stripes *); -#endif static int cmp_mish_stripes(const void *stripe_a, const void *stripe_b); static int dmg_track_sectors(uint64_t *, uint8_t *, uint32_t, uint32_t, uint64_t); static int dmg_handle_mish(cli_ctx *, unsigned int, char *, uint64_t, struct dmg_mish_with_stripes *); @@ -104,9 +96,7 @@ int cli_scandmg(cli_ctx *ctx) struct dmg_mish_with_stripes *mish_list = NULL, *mish_list_tail = NULL; enum dmgReadState state = DMG_FIND_BASE_PLIST; int stateDepth[DMG_MAX_STATE]; -#if HAVE_LIBXML2 xmlTextReaderPtr reader; -#endif if (!ctx || !ctx->fmap) { cli_errmsg("cli_scandmg: Invalid context\n"); @@ -204,9 +194,6 @@ int cli_scandmg(cli_ctx *ctx) /* each of those bottom level dict should have 4 parts */ /* [ Attributes, Data, ID, Name ], where Data is Base64 mish block */ -/* This is the block where we require libxml2 */ -#if HAVE_LIBXML2 - #define DMG_XML_PARSE_OPTS ((XML_PARSE_NONET | XML_PARSE_COMPACT) | CLAMAV_MIN_XMLREADER_FLAGS) reader = xmlReaderForMemory(outdata, (int)hdr.xmlLength, "toc.xml", NULL, DMG_XML_PARSE_OPTS); @@ -434,12 +421,6 @@ int cli_scandmg(cli_ctx *ctx) xmlFreeTextReader(reader); -#else - - cli_dbgmsg("cli_scandmg: libxml2 support is compiled out. It is required for full DMG support.\n"); - -#endif - /* Loop over mish array */ file = 0; while ((ret == CL_CLEAN) && (mish_list != NULL)) { @@ -465,7 +446,6 @@ int cli_scandmg(cli_ctx *ctx) return ret; } -#if HAVE_LIBXML2 /* Transform the base64-encoded string into the binary structure * After this, the base64 string (from xml) can be released * If mish_set->mish is set by this function, it must be freed by the caller */ @@ -535,7 +515,6 @@ static int dmg_decode_mish(cli_ctx *ctx, unsigned int *mishblocknum, xmlChar *mi mish_set->stripes = (struct dmg_block_data *)(decoded + sizeof(struct dmg_mish_block)); return CL_CLEAN; } -#endif /* Comparator for stripe sorting */ static int cmp_mish_stripes(const void *stripe_a, const void *stripe_b) @@ -560,22 +539,12 @@ static int dmg_track_sectors(uint64_t *total, uint8_t *data_to_write, usable = 1; break; case DMG_STRIPE_DEFLATE: -#if HAVE_LIBZ *data_to_write = 1; usable = 1; -#else - cli_warnmsg("dmg_track_sectors: Need zlib decompression to properly scan this file.\n"); - return CL_EFORMAT; -#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: @@ -863,16 +832,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); @@ -970,7 +936,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 2d74ff4d30..9a725c944b 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 @@ cl_error_t cli_egg_deflate_decompress(char* compressed, size_t compressed_size, 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 @@ cl_error_t cli_egg_bzip2_decompress(char* compressed, size_t compressed_size, ch 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/hwp.c b/libclamav/hwp.c index fc497add51..763775109f 100644 --- a/libclamav/hwp.c +++ b/libclamav/hwp.c @@ -23,10 +23,7 @@ #include "clamav-config.h" #endif -#if HAVE_LIBXML2 #include -#endif - #include #include #include @@ -48,9 +45,7 @@ #include "msxml.h" #include "json_api.h" #include "hwp.h" -#if HAVE_JSON #include "msdoc.h" -#endif #define HWP5_DEBUG 0 #define HWP3_DEBUG 0 @@ -304,7 +299,6 @@ cl_error_t cli_hwp5header(cli_ctx *ctx, hwp5_header_t *hwp5) if (!ctx || !hwp5) return CL_ENULLARG; -#if HAVE_JSON if (SCAN_COLLECT_METADATA) { json_object *header, *flags; @@ -363,7 +357,7 @@ cl_error_t cli_hwp5header(cli_ctx *ctx, hwp5_header_t *hwp5) cli_jsonstr(flags, NULL, "HWP5_CCL"); } } -#endif + return CL_SUCCESS; } @@ -422,7 +416,6 @@ cl_error_t cli_scanhwp5_stream(cli_ctx *ctx, hwp5_header_t *hwp5, char *name, in } } -#if HAVE_JSON /* JSON Output Summary Information */ if (SCAN_COLLECT_METADATA && ctx->properties != NULL) { if (name && !strncmp(name, "_5_hwpsummaryinformation", 24)) { @@ -432,8 +425,6 @@ cl_error_t cli_scanhwp5_stream(cli_ctx *ctx, hwp5_header_t *hwp5, char *name, in return CL_ETIMEOUT; } } - -#endif } /* normal streams */ @@ -535,7 +526,6 @@ static inline cl_error_t parsehwp3_docinfo(cli_ctx *ctx, size_t offset, struct h hwp3_debug("HWP3.x: di_compressed: %u\n", docinfo->di_compressed); hwp3_debug("HWP3.x: di_infoblksize: %u\n", docinfo->di_infoblksize); -#if HAVE_JSON if (SCAN_COLLECT_METADATA) { json_object *header, *flags; char *str; @@ -589,14 +579,12 @@ static inline cl_error_t parsehwp3_docinfo(cli_ctx *ctx, size_t offset, struct h cli_jsonstr(header, "Annotation", str); free(str); } -#endif return CL_SUCCESS; } static inline cl_error_t parsehwp3_docsummary(cli_ctx *ctx, size_t offset) { -#if HAVE_JSON const uint8_t *hwp3_ptr; char *str; size_t i; @@ -643,10 +631,7 @@ static inline cl_error_t parsehwp3_docsummary(cli_ctx *ctx, size_t offset) if (ret != CL_SUCCESS) return ret; } -#else - UNUSEDPARAM(ctx); - UNUSEDPARAM(offset); -#endif + return CL_SUCCESS; } @@ -1524,13 +1509,10 @@ static inline cl_error_t parsehwp3_infoblk_1(cli_ctx *ctx, fmap_t *dmap, size_t #if HWP3_DEBUG char field[HWP3_FIELD_LENGTH]; #endif -#if HAVE_JSON json_object *infoblk_1, *contents = NULL, *counter, *entry = NULL; -#endif hwp3_debug("HWP3.x: Information Block @ offset %llu\n", infoloc); -#if HAVE_JSON if (SCAN_COLLECT_METADATA) { infoblk_1 = cli_jsonobj(ctx->wrkproperty, "InfoBlk_1"); if (!infoblk_1) { @@ -1551,7 +1533,6 @@ static inline cl_error_t parsehwp3_infoblk_1(cli_ctx *ctx, fmap_t *dmap, size_t cli_jsonint(infoblk_1, "Count", value + 1); } } -#endif if (fmap_readn(map, &infoid, *offset, sizeof(infoid)) != sizeof(infoid)) { cli_errmsg("HWP3.x: Failed to read information block id @ %zu\n", *offset); @@ -1560,7 +1541,6 @@ static inline cl_error_t parsehwp3_infoblk_1(cli_ctx *ctx, fmap_t *dmap, size_t *offset += sizeof(infoid); infoid = le32_to_host(infoid); -#if HAVE_JSON if (SCAN_COLLECT_METADATA) { entry = cli_jsonobj(contents, NULL); if (!entry) { @@ -1570,16 +1550,16 @@ static inline cl_error_t parsehwp3_infoblk_1(cli_ctx *ctx, fmap_t *dmap, size_t cli_jsonint(entry, "ID", infoid); } -#endif + hwp3_debug("HWP3.x: Information Block[%llu]: ID: %u\n", infoloc, infoid); /* Booking Information(5) - no length field and no content */ if (infoid == 5) { hwp3_debug("HWP3.x: Information Block[%llu]: TYPE: Booking Information\n", infoloc); -#if HAVE_JSON + if (SCAN_COLLECT_METADATA) cli_jsonstr(entry, "Type", "Booking Information"); -#endif + return CL_SUCCESS; } @@ -1590,12 +1570,11 @@ static inline cl_error_t parsehwp3_infoblk_1(cli_ctx *ctx, fmap_t *dmap, size_t *offset += sizeof(infolen); infolen = le32_to_host(infolen); -#if HAVE_JSON if (SCAN_COLLECT_METADATA) { cli_jsonint64(entry, "Offset", infoloc); cli_jsonint(entry, "Length", infolen); } -#endif + hwp3_debug("HWP3.x: Information Block[%llu]: LEN: %u\n", infoloc, infolen); /* check information block bounds */ @@ -1609,10 +1588,10 @@ static inline cl_error_t parsehwp3_infoblk_1(cli_ctx *ctx, fmap_t *dmap, size_t case 0: /* Terminating */ if (infolen == 0) { hwp3_debug("HWP3.x: Information Block[%llu]: TYPE: Terminating Entry\n", infoloc); -#if HAVE_JSON + if (SCAN_COLLECT_METADATA) cli_jsonstr(entry, "Type", "Terminating Entry"); -#endif + if (last) *last = 1; return CL_SUCCESS; } else { @@ -1621,10 +1600,10 @@ static inline cl_error_t parsehwp3_infoblk_1(cli_ctx *ctx, fmap_t *dmap, size_t } case 1: /* Image Data */ hwp3_debug("HWP3.x: Information Block[%llu]: TYPE: Image Data\n", infoloc); -#if HAVE_JSON + if (SCAN_COLLECT_METADATA) cli_jsonstr(entry, "Type", "Image Data"); -#endif + #if HWP3_DEBUG /* additional fields can be added */ memset(field, 0, HWP3_FIELD_LENGTH); if (fmap_readn(map, field, *offset, 16) != 16) { @@ -1647,10 +1626,10 @@ static inline cl_error_t parsehwp3_infoblk_1(cli_ctx *ctx, fmap_t *dmap, size_t break; case 2: /* OLE2 Data */ hwp3_debug("HWP3.x: Information Block[%llu]: TYPE: OLE2 Data\n", infoloc); -#if HAVE_JSON + if (SCAN_COLLECT_METADATA) cli_jsonstr(entry, "Type", "OLE2 Data"); -#endif + if (infolen > 0) ret = cli_magic_scan_nested_fmap_type(map, *offset, infolen, ctx, CL_TYPE_ANY, NULL, LAYER_ATTRIBUTES_NONE); @@ -1664,12 +1643,11 @@ static inline cl_error_t parsehwp3_infoblk_1(cli_ctx *ctx, fmap_t *dmap, size_t count = (infolen / 617); hwp3_debug("HWP3.x: Information Block[%llu]: COUNT: %d entries\n", infoloc, count); -#if HAVE_JSON + if (SCAN_COLLECT_METADATA) { cli_jsonstr(entry, "Type", "Hypertext/Hyperlink Information"); cli_jsonint(entry, "Count", count); } -#endif for (i = 0; i < count; i++) { #if HWP3_DEBUG /* additional fields can be added */ @@ -1687,28 +1665,28 @@ static inline cl_error_t parsehwp3_infoblk_1(cli_ctx *ctx, fmap_t *dmap, size_t break; case 4: /* Presentation Information */ hwp3_debug("HWP3.x: Information Block[%llu]: TYPE: Presentation Information\n", infoloc); -#if HAVE_JSON + if (SCAN_COLLECT_METADATA) cli_jsonstr(entry, "Type", "Presentation Information"); -#endif + /* contains nothing of interest to scan */ break; case 5: /* Booking Information */ /* should never run this as it is short-circuited above */ hwp3_debug("HWP3.x: Information Block[%llu]: TYPE: Booking Information\n", infoloc); -#if HAVE_JSON + if (SCAN_COLLECT_METADATA) cli_jsonstr(entry, "Type", "Booking Information"); -#endif + break; case 6: /* Background Image Data */ hwp3_debug("HWP3.x: Information Block[%llu]: TYPE: Background Image Data\n", infoloc); -#if HAVE_JSON + if (SCAN_COLLECT_METADATA) { cli_jsonstr(entry, "Type", "Background Image Data"); cli_jsonint(entry, "ImageSize", infolen - 324); } -#endif + #if HWP3_DEBUG /* additional fields can be added */ memset(field, 0, HWP3_FIELD_LENGTH); if (fmap_readn(map, field, *offset + 24, 256) != 256) { @@ -1724,18 +1702,18 @@ static inline cl_error_t parsehwp3_infoblk_1(cli_ctx *ctx, fmap_t *dmap, size_t break; case 0x100: /* Table Extension */ hwp3_debug("HWP3.x: Information Block[%llu]: TYPE: Table Extension\n", infoloc); -#if HAVE_JSON + if (SCAN_COLLECT_METADATA) cli_jsonstr(entry, "Type", "Table Extension"); -#endif + /* contains nothing of interest to scan */ break; case 0x101: /* Press Frame Information Field Name */ hwp3_debug("HWP3.x: Information Block[%llu]: TYPE: Press Frame Information Field Name\n", infoloc); -#if HAVE_JSON + if (SCAN_COLLECT_METADATA) cli_jsonstr(entry, "Type", "Press Frame Information Field Name"); -#endif + /* contains nothing of interest to scan */ break; default: @@ -1756,9 +1734,7 @@ static cl_error_t hwp3_cb(void *cbdata, int fd, const char *filepath, cli_ctx *c size_t offset, start, new_offset; int i, p = 0, last = 0; uint16_t nstyles; -#if HAVE_JSON json_object *fonts = NULL; -#endif UNUSEDPARAM(filepath); @@ -1790,10 +1766,9 @@ static cl_error_t hwp3_cb(void *cbdata, int fd, const char *filepath, cli_ctx *c } /* Fonts - 7 entries of 2 + (n x 40) bytes where n is the first 2 bytes of the entry */ -#if HAVE_JSON if (SCAN_COLLECT_METADATA) fonts = cli_jsonarray(ctx->wrkproperty, "FontCounts"); -#endif + for (i = 0; i < 7; i++) { uint16_t nfonts; @@ -1804,10 +1779,9 @@ static cl_error_t hwp3_cb(void *cbdata, int fd, const char *filepath, cli_ctx *c } nfonts = le16_to_host(nfonts); -#if HAVE_JSON if (SCAN_COLLECT_METADATA) cli_jsonint(fonts, NULL, nfonts); -#endif + hwp3_debug("HWP3.x: Font Entry %d with %u entries @ offset %zu\n", i + 1, nfonts, offset); new_offset = offset + (2 + nfonts * 40); if ((new_offset <= offset) || (new_offset >= map->len)) { @@ -1827,10 +1801,9 @@ static cl_error_t hwp3_cb(void *cbdata, int fd, const char *filepath, cli_ctx *c } nstyles = le16_to_host(nstyles); -#if HAVE_JSON if (SCAN_COLLECT_METADATA) cli_jsonint(ctx->wrkproperty, "StyleCount", nstyles); -#endif + hwp3_debug("HWP3.x: %u Styles @ offset %zu\n", nstyles, offset); new_offset = offset + (2 + nstyles * 238); if ((new_offset <= offset) || (new_offset >= map->len)) { @@ -1851,10 +1824,10 @@ static cl_error_t hwp3_cb(void *cbdata, int fd, const char *filepath, cli_ctx *c funmap(dmap); return ret; } -#if HAVE_JSON + if (SCAN_COLLECT_METADATA) cli_jsonint(ctx->wrkproperty, "ParagraphCount", p); -#endif + last = 0; /* 'additional information block #1's - attachments and media */ @@ -1880,12 +1853,10 @@ cl_error_t cli_scanhwp3(cli_ctx *ctx) size_t offset = 0, new_offset = 0; fmap_t *map = ctx->fmap; -#if HAVE_JSON /* // version cli_jsonint(header, "RawVersion", hwp5->version); */ -#endif offset += HWP3_IDENTITY_INFO_SIZE; if ((ret = parsehwp3_docinfo(ctx, offset, &docinfo)) != CL_SUCCESS) @@ -1928,7 +1899,6 @@ cl_error_t cli_scanhwp3(cli_ctx *ctx) } /*** HWPML (hijacking the msxml parser) ***/ -#if HAVE_LIBXML2 static const struct key_entry hwpml_keys[] = { {"hwpml", "HWPML", MSXML_JSON_ROOT | MSXML_JSON_ATTRIB}, @@ -2102,13 +2072,11 @@ static cl_error_t hwpml_binary_cb(int fd, const char *filepath, cli_ctx *ctx, in } return ret; } -#endif /* HAVE_LIBXML2 */ cl_error_t cli_scanhwpml(cli_ctx *ctx) { cl_error_t ret = CL_SUCCESS; -#if HAVE_LIBXML2 struct msxml_cbdata cbdata; struct msxml_ctx mxctx; xmlTextReaderPtr reader = NULL; @@ -2125,9 +2093,8 @@ cl_error_t cli_scanhwpml(cli_ctx *ctx) if (!reader) { cli_dbgmsg("cli_scanhwpml: cannot initialize xmlReader\n"); -#if HAVE_JSON ret = cli_json_parse_error(ctx->wrkproperty, "HWPML_ERROR_XML_READER_IO"); -#endif + return ret; // libxml2 failed! } @@ -2137,11 +2104,6 @@ cl_error_t cli_scanhwpml(cli_ctx *ctx) xmlTextReaderClose(reader); xmlFreeTextReader(reader); -#else - UNUSEDPARAM(ctx); - cli_dbgmsg("in cli_scanhwpml()\n"); - cli_dbgmsg("cli_scanhwpml: scanning hwpml documents requires libxml2!\n"); -#endif return ret; } diff --git a/libclamav/json_api.c b/libclamav/json_api.c index 56a297eefa..5dac9fa2db 100644 --- a/libclamav/json_api.c +++ b/libclamav/json_api.c @@ -27,7 +27,6 @@ #include "others.h" #include "json_api.h" -#ifdef HAVE_JSON cl_error_t cli_json_timeout_cycle_check(cli_ctx *ctx, int *toval) { if (SCAN_COLLECT_METADATA) { @@ -353,30 +352,6 @@ json_object *cli_jsonobj(json_object *obj, const char *key) return newobj; } -#if HAVE_DEPRECATED_JSON -int json_object_object_get_ex(struct json_object *obj, const char *key, struct json_object **value) -{ - struct json_object *res; - - if (value != NULL) - *value = NULL; - - if (obj == NULL) - return 0; - - if (json_object_get_type(obj) != json_type_object) - return 0; - - res = json_object_object_get(obj, key); - if (value != NULL) { - *value = res; - return (res != NULL); - } - - return (res != NULL); -} -#endif - /* adding an object does NOT increment reference count */ cl_error_t cli_json_addowner(json_object *owner, json_object *child, const char *key, int idx) { @@ -464,77 +439,3 @@ cl_error_t cli_json_delowner(json_object *owner, const char *key, int idx) return CL_SUCCESS; } - -#else - -cl_error_t cli_json_nojson() -{ - nojson_func("nojson: json needs to be enabled for this feature\n"); - return CL_SUCCESS; -} - -cl_error_t cli_jsonnull_nojson(const char* key) -{ - nojson_func("nojson: %s: null\n", key); - return CL_SUCCESS; -} - -cl_error_t cli_jsonstr_nojson(const char* key, const char* s) -{ - nojson_func("nojson: %s: %s\n", key, s); - return CL_SUCCESS; -} - -cl_error_t cli_jsonstrlen_nojson(const char* key, const char* s, int len) -{ - char* sp = cli_max_malloc(len + 1); - if (NULL == sp) { - cli_errmsg("json: no memory for json strlen object.\n"); - return CL_EMEM; - } - strncpy(sp, s, len); - sp[len] = '\0'; - - nojson_func("nojson: %s: %s\n", key, sp); - - free(sp); - return CL_SUCCESS; -} - -cl_error_t cli_jsonint_nojson(const char* key, int32_t i) -{ - nojson_func("nojson: %s: %d\n", key, i); - return CL_SUCCESS; -} - -cl_error_t cli_jsonint64_nojson(const char* key, int64_t i) -{ - nojson_func("nojson: %s: %ld\n", key, (long int)i); - return CL_SUCCESS; -} - -cl_error_t cli_jsonbool_nojson(const char* key, int i) -{ - nojson_func("nojson: %s: %s\n", key, i ? "true" : "false"); - return CL_SUCCESS; -} - -cl_error_t cli_jsondouble_nojson(const char* key, double d) -{ - nojson_func("nojson: %s: %f\n", key, d); - return CL_SUCCESS; -} - -void* cli_jsonarray_nojson(const char* key) -{ - nojson_func("nojson: %s\n", key); - return NULL; -} - -cl_error_t cli_jsonint_array_nojson(int32_t val) -{ - nojson_func("nojson: %d\n", val); - return CL_SUCCESS; -} - -#endif diff --git a/libclamav/json_api.h b/libclamav/json_api.h index 00ad155f96..268ecf0129 100644 --- a/libclamav/json_api.h +++ b/libclamav/json_api.h @@ -26,14 +26,11 @@ #include "clamav-config.h" #endif -#if HAVE_JSON #include "json.h" -#endif #include "clamav-types.h" #include "others.h" -#if HAVE_JSON #define JSON_TIMEOUT_SKIP_CYCLES 3 cl_error_t cli_json_timeout_cycle_check(cli_ctx *ctx, int *toval); @@ -54,10 +51,6 @@ cl_error_t cli_json_addowner(json_object *owner, json_object *child, const char cl_error_t cli_json_delowner(json_object *owner, const char *key, int idx); #define cli_json_delobj(obj) json_object_put(obj) -#if HAVE_DEPRECATED_JSON -int json_object_object_get_ex(struct json_object *obj, const char *key, struct json_object **value); -#endif - #define JSON_KEY_FILETYPE "FileType" #define JSON_KEY_FILESIZE "FileSize" @@ -66,35 +59,4 @@ int json_object_object_get_ex(struct json_object *obj, const char *key, struct j #define JSON_VALUE_FILETYPE_WORD "CL_TYPE_WORD" #define JSON_VALUE_FILETYPE_EXCEL "CL_TYPE_MSXLS" -#else -#define nojson_func cli_dbgmsg - -/* internal functions */ -cl_error_t cli_json_nojson(void); - -cl_error_t cli_jsonnull_nojson(const char* key); -cl_error_t cli_jsonstr_nojson(const char* key, const char* s); -cl_error_t cli_jsonstrlen_nojson(const char* key, const char* s, int len); -cl_error_t cli_jsonint_nojson(const char* key, int32_t i); -cl_error_t cli_jsonint64_nojson(const char* key, int64_t i); -cl_error_t cli_jsonbool_nojson(const char* key, int i); -cl_error_t cli_jsondouble_nojson(const char* key, double d); -void* cli_jsonarray_nojson(const char* key); -cl_error_t cli_jsonint_array_nojson(int32_t val); - -#define cli_jsonnull(o, n) cli_jsonnull_nojson(n) -#define cli_jsonstr(o, n, s) cli_jsonstr_nojson(n, s) -#define cli_jsonstrlen(o, n, s, len) cli_jsonstrlen_nojson(n, s, len) -#define cli_jsonint(o, n, i) cli_jsonint_nojson(n, i) -#define cli_jsonint64(o, n, i) cli_jsonint64_nojson(n, i) -#define cli_jsonbool(o, n, b) cli_jsonbool_nojson(n, b) -#define cli_jsondouble(o, n, d) cli_jsondouble_nojson(n, d) -#define cli_jsonarray(o, k) cli_jsonarray_nojson(k) -#define cli_jsonint_array(o, v) cli_jsonint_array_nojson(v) -#define cli_json_addowner(o, c, k, i) cli_json_nojson() -#define cli_json_delowner(o, k, i) cli_json_nojson() -#define cli_json_delobj(o) cli_json_nojson() - -#endif - #endif /*__JSON_C_H__*/ diff --git a/libclamav/libclamav.map b/libclamav/libclamav.map index 457679721e..a34a05dbb6 100644 --- a/libclamav/libclamav.map +++ b/libclamav/libclamav.map @@ -82,7 +82,6 @@ CLAMAV_PRIVATE { cli_sigperf_events_destroy; cli_pcre_perf_print; cli_pcre_perf_events_destroy; - cli_pcre_init; cli_pcre_build; cli_pcre_scanbuf; cli_pcre_recaloff; diff --git a/libclamav/matcher-pcre.c b/libclamav/matcher-pcre.c index f2606450fc..8666d993cd 100644 --- a/libclamav/matcher-pcre.c +++ b/libclamav/matcher-pcre.c @@ -37,13 +37,8 @@ #include "regex_pcre.h" #include "str.h" -#if HAVE_PCRE -#if USING_PCRE2 #define PCRE2_CODE_UNIT_WIDTH 8 #include -#else -#include -#endif /* DEBUGGING */ // #define MATCHER_PCRE_DEBUG @@ -192,10 +187,6 @@ void cli_pcre_perf_events_destroy() } /* PCRE MATCHER FUNCTIONS */ -cl_error_t cli_pcre_init() -{ - return cli_pcre_init_internal(); -} cl_error_t cli_pcre_addpatt(struct cli_matcher *root, const char *virname, const char *trigger, const char *pattern, const char *cflags, const char *offset, const uint32_t *lsigid, unsigned int options) { @@ -338,7 +329,6 @@ cl_error_t cli_pcre_addpatt(struct cli_matcher *root, const char *virname, const } if (pm->pdata.options) { -#if USING_PCRE2 pm_dbgmsg("Compiler: %s%s%s%s%s%s%s\n", pm->pdata.options & PCRE2_CASELESS ? "PCRE2_CASELESS " : "", pm->pdata.options & PCRE2_DOTALL ? "PCRE2_DOTALL " : "", @@ -348,17 +338,6 @@ cl_error_t cli_pcre_addpatt(struct cli_matcher *root, const char *virname, const pm->pdata.options & PCRE2_ANCHORED ? "PCRE2_ANCHORED " : "", pm->pdata.options & PCRE2_DOLLAR_ENDONLY ? "PCRE2_DOLLAR_ENDONLY " : "", pm->pdata.options & PCRE2_UNGREEDY ? "PCRE2_UNGREEDY " : ""); -#else - pm_dbgmsg("Compiler: %s%s%s%s%s%s%s\n", - pm->pdata.options & PCRE_CASELESS ? "PCRE_CASELESS " : "", - pm->pdata.options & PCRE_DOTALL ? "PCRE_DOTALL " : "", - pm->pdata.options & PCRE_MULTILINE ? "PCRE_MULTILINE " : "", - pm->pdata.options & PCRE_EXTENDED ? "PCRE_EXTENDED " : "", - - pm->pdata.options & PCRE_ANCHORED ? "PCRE_ANCHORED " : "", - pm->pdata.options & PCRE_DOLLAR_ENDONLY ? "PCRE_DOLLAR_ENDONLY " : "", - pm->pdata.options & PCRE_UNGREEDY ? "PCRE_UNGREEDY " : ""); -#endif } else { pm_dbgmsg("Compiler: NONE\n"); } @@ -422,15 +401,9 @@ cl_error_t cli_pcre_build(struct cli_matcher *root, long long unsigned match_lim } /* options override through metadata manipulation */ -#if USING_PCRE2 // pm->pdata.options |= PCRE2_NEVER_UTF; /* disables (?UTF*) potential security vuln */ // pm->pdata.options |= PCRE2_UCP; // pm->pdata.options |= PCRE2_AUTO_CALLOUT; /* used with CALLOUT(-BACK) function */ -#else - // pm->pdata.options |= PCRE_NEVER_UTF; /* implemented in 8.33, disables (?UTF*) potential security vuln */ - // pm->pdata.options |= PCRE_UCP;/* implemented in 8.20 */ - // pm->pdata.options |= PCRE_AUTO_CALLOUT; /* used with CALLOUT(-BACK) function */ -#endif if (dconf && (dconf->pcre & PCRE_CONF_OPTIONS)) { /* compile the regex, no options override *wink* */ @@ -638,11 +611,7 @@ cl_error_t cli_pcre_scanbuf(const unsigned char *buffer, uint32_t length, const /* check for need to anchoring */ if (!rolling && !adjshift && (adjbuffer != CLI_OFF_ANY)) -#if USING_PCRE2 options |= PCRE2_ANCHORED; -#else - options |= PCRE_ANCHORED; -#endif else options = 0; @@ -810,69 +779,3 @@ void cli_pcre_freetable(struct cli_matcher *root) root->pcre_metatable = NULL; root->pcre_metas = 0; } - -#else -/* NO-PCRE FUNCTIONS */ -void cli_pcre_perf_print() -{ - cli_errmsg("cli_pcre_perf_print: Cannot print PCRE performance results without PCRE support\n"); - return; -} - -void cli_pcre_perf_events_destroy() -{ - cli_errmsg("cli_pcre_perf_events_destroy: Cannot destroy PCRE performance results without PCRE support\n"); - return; -} - -cl_error_t cli_pcre_init() -{ - cli_errmsg("cli_pcre_init: Cannot initialize PCRE without PCRE support\n"); - return CL_SUCCESS; -} - -cl_error_t cli_pcre_build(struct cli_matcher *root, long long unsigned match_limit, long long unsigned recmatch_limit, const struct cli_dconf *dconf) -{ - UNUSEDPARAM(root); - UNUSEDPARAM(match_limit); - UNUSEDPARAM(recmatch_limit); - UNUSEDPARAM(dconf); - - cli_errmsg("cli_pcre_build: Cannot build PCRE expression without PCRE support\n"); - return CL_SUCCESS; -} - -cl_error_t cli_pcre_scanbuf(const unsigned char *buffer, uint32_t length, const char **virname, struct cli_ac_result **res, const struct cli_matcher *root, struct cli_ac_data *mdata, const struct cli_pcre_off *data, cli_ctx *ctx) -{ - UNUSEDPARAM(buffer); - UNUSEDPARAM(length); - UNUSEDPARAM(virname); - UNUSEDPARAM(res); - UNUSEDPARAM(root); - UNUSEDPARAM(mdata); - UNUSEDPARAM(data); - UNUSEDPARAM(ctx); - - cli_errmsg("cli_pcre_scanbuf: Cannot scan buffer with PCRE expression without PCRE support\n"); - return CL_SUCCESS; -} - -cl_error_t cli_pcre_recaloff(struct cli_matcher *root, struct cli_pcre_off *data, struct cli_target_info *info, cli_ctx *ctx) -{ - UNUSEDPARAM(root); - UNUSEDPARAM(info); - UNUSEDPARAM(ctx); - if (data) { - data->offset = NULL; - data->shift = NULL; - } - return CL_SUCCESS; -} - -void cli_pcre_freeoff(struct cli_pcre_off *data) -{ - UNUSEDPARAM(data); - return; -} - -#endif /* HAVE_PCRE */ diff --git a/libclamav/matcher-pcre.h b/libclamav/matcher-pcre.h index 794b91ea2a..83af700101 100644 --- a/libclamav/matcher-pcre.h +++ b/libclamav/matcher-pcre.h @@ -44,7 +44,6 @@ struct cli_pcre_off { uint32_t *offset, *shift; }; -#if HAVE_PCRE #define PCRE_BYPASS "7374756c747a676574737265676578" #define CLI_PCRE_GLOBAL 0x00000001 /* g */ #define CLI_PCRE_ENCOMPASS 0x00000002 /* e */ @@ -70,14 +69,6 @@ cl_error_t cli_pcre_addpatt(struct cli_matcher *root, const char *virname, const void cli_pcre_freemeta(struct cli_matcher *root, struct cli_pcre_meta *pm); void cli_pcre_freetable(struct cli_matcher *root); -#else -#define PCRE_BYPASS "" -#endif /* HAVE_PCRE */ - -/* - * The following are defined to simple stub functions in matcher-pcre.c if HAVE_PCRE is not defined. - */ -cl_error_t cli_pcre_init(void); cl_error_t cli_pcre_build(struct cli_matcher *root, long long unsigned match_limit, long long unsigned recmatch_limit, const struct cli_dconf *dconf); cl_error_t cli_pcre_scanbuf(const unsigned char *buffer, uint32_t length, const char **virname, struct cli_ac_result **res, const struct cli_matcher *root, struct cli_ac_data *mdata, const struct cli_pcre_off *data, cli_ctx *ctx); cl_error_t cli_pcre_recaloff(struct cli_matcher *root, struct cli_pcre_off *data, struct cli_target_info *info, cli_ctx *ctx); diff --git a/libclamav/matcher.c b/libclamav/matcher.c index 986be4facd..c8d849427b 100644 --- a/libclamav/matcher.c +++ b/libclamav/matcher.c @@ -201,7 +201,6 @@ static inline cl_error_t matcher_run(const struct cli_matcher *root, break; } -#if HAVE_PCRE /* due to logical triggered, pcres cannot be evaluated until after full subsig matching */ /* cannot save pcre execution state without possible evasion; must scan entire buffer */ /* however, scanning the whole buffer may require the whole buffer being loaded into memory */ @@ -245,7 +244,7 @@ static inline cl_error_t matcher_run(const struct cli_matcher *root, ret = cli_pcre_scanbuf(buffer, length, virname, acres, root, mdata, poffdata, ctx); } } -#endif /* HAVE_PCRE */ + /* end experimental fragment */ if (ctx && ret == CL_VIRUS) { diff --git a/libclamav/matcher.h b/libclamav/matcher.h index ed2508eb87..2513bb0187 100644 --- a/libclamav/matcher.h +++ b/libclamav/matcher.h @@ -158,11 +158,9 @@ struct cli_matcher { uint8_t ac_only; /* Perl-Compiled Regular Expressions */ -#if HAVE_PCRE uint32_t pcre_metas; struct cli_pcre_meta **pcre_metatable; uint32_t pcre_reloff_num, pcre_absoff_num; -#endif /* Byte Compare */ uint32_t bcomp_metas; diff --git a/libclamav/mbox.c b/libclamav/mbox.c index 9bc6fe0456..f069b5ef22 100644 --- a/libclamav/mbox.c +++ b/libclamav/mbox.c @@ -77,12 +77,10 @@ #include "json_api.h" #include "msxml_parser.h" -#if HAVE_LIBXML2 #include #include #include #include -#endif #define DCONF_PHISHING mctx->ctx->dconf->phishing @@ -170,9 +168,7 @@ typedef struct mbox_ctx { const table_t *subtypeTable; cli_ctx *ctx; unsigned int files; /* number of files extracted */ -#if HAVE_JSON json_object *wrkobj; -#endif } mbox_ctx; /* if supported by the system, use the optimized @@ -385,9 +381,7 @@ cli_parse_mbox(const char *dir, cli_ctx *ctx) mctx.subtypeTable = subtype; mctx.ctx = ctx; mctx.files = 0; -#if HAVE_JSON - mctx.wrkobj = ctx->wrkproperty; -#endif + mctx.wrkobj = ctx->wrkproperty; /* * Is it a UNIX style mbox with more than one @@ -1402,7 +1396,6 @@ parseEmailHeader(message *m, const char *line, const table_t *rfc821, cli_ctx *c return ret; } -#if HAVE_LIBXML2 static const struct key_entry mhtml_keys[] = { /* root html tags for microsoft office document */ {"html", "RootHTML", MSXML_JSON_ROOT | MSXML_JSON_ATTRIB}, @@ -1435,7 +1428,6 @@ static const struct key_entry mhtml_comment_keys[] = { {"w:worddocument", "WordDocument", MSXML_IGNORE_ELEM}, {"w:latentstyles", "LatentStyles", MSXML_IGNORE_ELEM}}; static size_t num_mhtml_comment_keys = sizeof(mhtml_comment_keys) / sizeof(struct key_entry); -#endif /* * The related multipart root HTML file comment parsing wrapper. @@ -1447,7 +1439,6 @@ static cl_error_t parseMHTMLComment(const char *comment, cli_ctx *ctx, void *wrk { cl_error_t ret = CL_SUCCESS; -#if HAVE_LIBXML2 const char *xmlsrt, *xmlend; xmlTextReaderPtr reader; @@ -1466,10 +1457,9 @@ static cl_error_t parseMHTMLComment(const char *comment, cli_ctx *ctx, void *wrk if (!reader) { cli_dbgmsg("parseMHTMLComment: cannot initialize xmlReader\n"); -#if HAVE_JSON if (ctx->wrkproperty != NULL) ret = cli_json_parse_error(ctx->wrkproperty, "MHTML_ERROR_XML_READER_MEM"); -#endif + return ret; // libxml2 failed! } @@ -1483,15 +1473,6 @@ static cl_error_t parseMHTMLComment(const char *comment, cli_ctx *ctx, void *wrk if (ret != CL_SUCCESS) return ret; } -#else - UNUSEDPARAM(comment); - UNUSEDPARAM(ctx); - UNUSEDPARAM(wrkjobj); - UNUSEDPARAM(cbdata); - - cli_dbgmsg("in parseMHTMLComment\n"); - cli_dbgmsg("parseMHTMLComment: parsing html xml-comments requires libxml2!\n"); -#endif return ret; } @@ -1505,7 +1486,6 @@ static mbox_status parseRootMHTML(mbox_ctx *mctx, message *m, text *t) { cli_ctx *ctx = mctx->ctx; -#if HAVE_LIBXML2 #ifdef LIBXML_HTML_ENABLED struct msxml_ctx mxctx; blob *input = NULL; @@ -1513,9 +1493,7 @@ parseRootMHTML(mbox_ctx *mctx, message *m, text *t) xmlTextReaderPtr reader; int ret = CL_SUCCESS; mbox_status rc = OK; -#if HAVE_JSON json_object *rhtml; -#endif cli_dbgmsg("in parseRootMHTML\n"); @@ -1536,17 +1514,16 @@ parseRootMHTML(mbox_ctx *mctx, message *m, text *t) htmlDoc = htmlReadMemory((char *)input->data, input->len, "mhtml.html", NULL, CLAMAV_MIN_XMLREADER_FLAGS | HTML_PARSE_NOWARNING); if (htmlDoc == NULL) { cli_dbgmsg("parseRootMHTML: cannot initialize read html document\n"); -#if HAVE_JSON + if (ctx->wrkproperty != NULL) ret = cli_json_parse_error(ctx->wrkproperty, "MHTML_ERROR_HTML_READ"); if (ret != CL_SUCCESS) rc = FAIL; -#endif + blobDestroy(input); return rc; } -#if HAVE_JSON if (mctx->wrkobj) { rhtml = cli_jsonobj(mctx->wrkobj, "RootHTML"); if (rhtml != NULL) { @@ -1555,17 +1532,16 @@ parseRootMHTML(mbox_ctx *mctx, message *m, text *t) cli_jsonint(rhtml, "CompressMode", xmlGetDocCompressMode(htmlDoc)); } } -#endif reader = xmlReaderWalker(htmlDoc); if (reader == NULL) { cli_dbgmsg("parseRootMHTML: cannot initialize xmlTextReader\n"); -#if HAVE_JSON + if (ctx->wrkproperty != NULL) ret = cli_json_parse_error(ctx->wrkproperty, "MHTML_ERROR_XML_READER_IO"); if (ret != CL_SUCCESS) rc = FAIL; -#endif + blobDestroy(input); return rc; } @@ -1608,14 +1584,6 @@ parseRootMHTML(mbox_ctx *mctx, message *m, text *t) cli_dbgmsg("in parseRootMHTML\n"); cli_dbgmsg("parseRootMHTML: parsing html documents disabled in libxml2!\n"); #endif /* LIBXML_HTML_ENABLED */ -#else /* HAVE_LIBXML2 */ - UNUSEDPARAM(m); - UNUSEDPARAM(t); - cli_dbgmsg("in parseRootMHTML\n"); - cli_dbgmsg("parseRootMHTML: parsing html documents requires libxml2!\n"); - - return OK; -#endif /* HAVE_LIBXML2 */ } /* @@ -1638,10 +1606,8 @@ parseEmailBody(message *messageIn, text *textIn, mbox_ctx *mctx, unsigned int re bool infected = false; const struct cl_engine *engine = mctx->ctx->engine; const int doPhishingScan = engine->dboptions & CL_DB_PHISHING_URLS && (DCONF_PHISHING & PHISHING_CONF_ENGINE); -#if HAVE_JSON - json_object *saveobj = mctx->wrkobj; -#endif - bool heuristicFound = false; + json_object *saveobj = mctx->wrkobj; + bool heuristicFound = false; cli_dbgmsg("in parseEmailBody, %u files saved so far\n", mctx->files); @@ -1684,7 +1650,7 @@ parseEmailBody(message *messageIn, text *textIn, mbox_ctx *mctx, unsigned int re mimeType = messageGetMimeType(mainMessage); mimeSubtype = messageGetMimeSubtype(mainMessage); -#if HAVE_JSON + if (mctx->wrkobj != NULL) { mctx->wrkobj = cli_jsonobj(mctx->wrkobj, "Body"); cli_jsonstr(mctx->wrkobj, "MimeType", getMimeTypeStr(mimeType)); @@ -1699,7 +1665,6 @@ parseEmailBody(message *messageIn, text *textIn, mbox_ctx *mctx, unsigned int re cli_jsonstr(mctx->wrkobj, "Filename", "(inline)"); } } -#endif /* pre-process */ subtype = tableFind(mctx->subtypeTable, mimeSubtype); @@ -1759,10 +1724,8 @@ parseEmailBody(message *messageIn, text *textIn, mbox_ctx *mctx, unsigned int re cli_dbgmsg("Content-type 'multipart' handler\n"); boundary = messageFindArgument(mainMessage, "boundary"); -#if HAVE_JSON if (mctx->wrkobj != NULL) cli_jsonstr(mctx->wrkobj, "Boundary", boundary); -#endif if (boundary == NULL) { cli_dbgmsg("Multipart/%s MIME message contains no boundary header\n", @@ -2241,9 +2204,8 @@ parseEmailBody(message *messageIn, text *textIn, mbox_ctx *mctx, unsigned int re if (aText && (textIn == NULL)) textDestroy(aText); -#if HAVE_JSON mctx->wrkobj = saveobj; -#endif + /* * Nothing to do */ @@ -2299,11 +2261,10 @@ parseEmailBody(message *messageIn, text *textIn, mbox_ctx *mctx, unsigned int re if (htmltextPart == -1) { cli_dbgmsg("No HTML code found to be scanned\n"); } else { -#if HAVE_JSON /* Send root HTML file for preclassification */ if (mctx->ctx->wrkproperty) (void)parseRootMHTML(mctx, messages[htmltextPart], aText); -#endif + rc = parseEmailBody(messages[htmltextPart], aText, mctx, recursion_level + 1); if ((rc == OK) && messages[htmltextPart]) { messageDestroy(messages[htmltextPart]); @@ -2439,9 +2400,8 @@ parseEmailBody(message *messageIn, text *textIn, mbox_ctx *mctx, unsigned int re messages = NULL; } -#if HAVE_JSON mctx->wrkobj = saveobj; -#endif + return rc; case MESSAGE: @@ -2508,9 +2468,9 @@ parseEmailBody(message *messageIn, text *textIn, mbox_ctx *mctx, unsigned int re free(messages); messages = NULL; } -#if HAVE_JSON + mctx->wrkobj = saveobj; -#endif + return rc; default: @@ -2788,9 +2748,7 @@ parseEmailBody(message *messageIn, text *textIn, mbox_ctx *mctx, unsigned int re if ((rc != FAIL) && infected) rc = VIRUS; -#if HAVE_JSON mctx->wrkobj = saveobj; -#endif cli_dbgmsg("parseEmailBody() returning %d\n", (int)rc); @@ -3259,7 +3217,7 @@ parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const c #ifdef CL_THREAD_SAFE s = strtok_r(NULL, ";", &strptr); #else - s = strtok(NULL, ";"); + s = strtok(NULL, ";"); #endif if (s == NULL) break; @@ -4263,8 +4221,8 @@ do_multipart(message *mainMessage, message **messages, int i, mbox_status *rc, m #endif message *aMessage = messages[i]; const int doPhishingScan = mctx->ctx->engine->dboptions & CL_DB_PHISHING_URLS && (DCONF_PHISHING & PHISHING_CONF_ENGINE); -#if HAVE_JSON - json_object *thisobj = NULL, *saveobj = mctx->wrkobj; + json_object *thisobj = NULL; + json_object *saveobj = mctx->wrkobj; if (mctx->wrkobj != NULL) { json_object *multiobj = cli_jsonarray(mctx->wrkobj, "Multipart"); @@ -4276,13 +4234,10 @@ do_multipart(message *mainMessage, message **messages, int i, mbox_status *rc, m cli_errmsg("Cannot assign message preclass object to multipart preclass array\n"); } } -#endif if (aMessage == NULL) { -#if HAVE_JSON if (thisobj != NULL) cli_jsonstr(thisobj, "MimeType", "NULL"); -#endif return mainMessage; } @@ -4292,7 +4247,6 @@ do_multipart(message *mainMessage, message **messages, int i, mbox_status *rc, m cli_dbgmsg("Mixed message part %d is of type %d\n", i, messageGetMimeType(aMessage)); -#if HAVE_JSON if (thisobj != NULL) { cli_jsonstr(thisobj, "MimeType", getMimeTypeStr(messageGetMimeType(aMessage))); cli_jsonstr(thisobj, "MimeSubtype", messageGetMimeSubtype(aMessage)); @@ -4306,7 +4260,6 @@ do_multipart(message *mainMessage, message **messages, int i, mbox_status *rc, m cli_jsonstr(thisobj, "Filename", "(inline)"); } } -#endif switch (messageGetMimeType(aMessage)) { case APPLICATION: @@ -4434,10 +4387,9 @@ do_multipart(message *mainMessage, message **messages, int i, mbox_status *rc, m * This can save a lot of memory */ messageDestroy(messages[i]); - messages[i] = NULL; -#if HAVE_JSON + messages[i] = NULL; mctx->wrkobj = thisobj; -#endif + if (body) { messageSetCTX(body, mctx->ctx); *rc = parseEmailBody(body, NULL, mctx, recursion_level + 1); @@ -4445,9 +4397,8 @@ do_multipart(message *mainMessage, message **messages, int i, mbox_status *rc, m *rc = VIRUS; messageDestroy(body); } -#if HAVE_JSON + mctx->wrkobj = saveobj; -#endif #endif return mainMessage; case MULTIPART: @@ -4457,9 +4408,8 @@ do_multipart(message *mainMessage, message **messages, int i, mbox_status *rc, m * be an attachment */ cli_dbgmsg("Found multipart inside multipart\n"); -#if HAVE_JSON mctx->wrkobj = thisobj; -#endif + if (aMessage) { /* * The headers were parsed when reading in the @@ -4476,9 +4426,9 @@ do_multipart(message *mainMessage, message **messages, int i, mbox_status *rc, m } mainMessage = NULL; } -#if HAVE_JSON + mctx->wrkobj = saveobj; -#endif + return mainMessage; default: cli_dbgmsg("Only text and application attachments are fully supported, type = %d\n", @@ -4488,7 +4438,7 @@ do_multipart(message *mainMessage, message **messages, int i, mbox_status *rc, m if (*rc != VIRUS) { fileblob *fb = messageToFileblob(aMessage, mctx->dir, 1); -#if HAVE_JSON + json_object *arrobj; #if (JSON_C_MAJOR_VERSION == 0) && (JSON_C_MINOR_VERSION < 13) int arrlen = 0; @@ -4503,7 +4453,6 @@ do_multipart(message *mainMessage, message **messages, int i, mbox_status *rc, m } } -#endif if (fb) { /* aMessage doesn't always have a ctx set */ fileblobSetCTX(fb, mctx->ctx); @@ -4514,7 +4463,7 @@ do_multipart(message *mainMessage, message **messages, int i, mbox_status *rc, m mctx->files++; } } -#if HAVE_JSON + if (thisobj != NULL) { json_object *entry = NULL; const char *dtype = NULL; @@ -4534,7 +4483,7 @@ do_multipart(message *mainMessage, message **messages, int i, mbox_status *rc, m cli_jsonint(thisobj, "ContainedObjectsIndex", (int32_t)arrlen); cli_jsonstr(thisobj, "ClamAVFileType", dtype ? dtype : "UNKNOWN"); } -#endif + if (messageContainsVirus(aMessage)) { *rc = VIRUS; } diff --git a/libclamav/message.c b/libclamav/message.c index 2369f371a9..ae8ce8fe32 100644 --- a/libclamav/message.c +++ b/libclamav/message.c @@ -194,10 +194,8 @@ void messageReset(message *m) free(m->encodingTypes); } -#if HAVE_JSON if (m->jobj) cli_json_delobj(m->jobj); -#endif memset(m, '\0', sizeof(message)); m->mimeType = NOMIME; @@ -2670,7 +2668,6 @@ int isuuencodebegin(const char *line) isdigit(line[8]) && (line[9] == ' '); } -#if HAVE_JSON json_object *messageGetJObj(message *m) { if (m == NULL) { @@ -2682,4 +2679,3 @@ json_object *messageGetJObj(message *m) return m->jobj; } -#endif diff --git a/libclamav/message.h b/libclamav/message.h index 9e50744a73..4533eec931 100644 --- a/libclamav/message.h +++ b/libclamav/message.h @@ -51,9 +51,7 @@ typedef struct message { unsigned int isInfected : 1; unsigned int isTruncated : 1; -#if HAVE_JSON json_object *jobj; -#endif } message; message *messageCreate(void); @@ -89,8 +87,6 @@ int isuuencodebegin(const char *line); void messageSetCTX(message *m, cli_ctx *ctx); int messageContainsVirus(const message *m); int messageSavePartial(message *m, const char *dir, const char *id, unsigned part); -#if HAVE_JSON json_object *messageGetJObj(message *m); -#endif #endif /*_MESSAGE_H*/ diff --git a/libclamav/msdoc.c b/libclamav/msdoc.c index 8e996f6bea..c97092365b 100644 --- a/libclamav/msdoc.c +++ b/libclamav/msdoc.c @@ -49,9 +49,7 @@ #include "json_api.h" #include "entconv.h" -#if HAVE_JSON -static char * -ole2_convert_utf(summary_ctx_t *sctx, char *begin, size_t sz, const char *encoding) +static char *ole2_convert_utf(summary_ctx_t *sctx, char *begin, size_t sz, const char *encoding) { char *outbuf = NULL; #if HAVE_ICONV @@ -998,4 +996,3 @@ int cli_ole2_summary_json(cli_ctx *ctx, int fd, int mode) return cli_ole2_summary_json_cleanup(&sctx, CL_SUCCESS); } -#endif /* HAVE_JSON */ diff --git a/libclamav/msdoc.h b/libclamav/msdoc.h index 03a0b2ddfa..c28f7aed8e 100644 --- a/libclamav/msdoc.h +++ b/libclamav/msdoc.h @@ -27,8 +27,6 @@ #include "others.h" #include "uniq.h" -#if HAVE_JSON - #define PROPCNTLIMIT 25 #define PROPSTRLIMIT 256 /* affects property strs, NOT sanitized strs (may result in a buffer allocating PROPSTRLIMIT*6) */ #define UTF16_MS "UTF-16LE" @@ -170,6 +168,4 @@ typedef struct summary_ctx { /* Summary and Document Information Parsing to JSON */ int cli_ole2_summary_json(cli_ctx *ctx, int fd, int mode); -#endif /* HAVE_JSON */ - #endif /* __MSDOC_H_ */ diff --git a/libclamav/msxml.c b/libclamav/msxml.c index 57825c14c7..f242bbc9f2 100644 --- a/libclamav/msxml.c +++ b/libclamav/msxml.c @@ -35,7 +35,6 @@ #include "msxml.h" #include "msxml_parser.h" -#if HAVE_LIBXML2 #include #define MSXML_VERBIOSE 0 @@ -223,11 +222,9 @@ int msxml_read_cb(void *ctx, char *buffer, int buffer_len) cbdata->winpos = cbdata->winsize - rbytes; return (int)wbytes; } -#endif cl_error_t cli_scanmsxml(cli_ctx *ctx) { -#if HAVE_LIBXML2 struct msxml_cbdata cbdata; xmlTextReaderPtr reader = NULL; cl_error_t ret = CL_SUCCESS; @@ -244,9 +241,8 @@ cl_error_t cli_scanmsxml(cli_ctx *ctx) if (!reader) { cli_dbgmsg("cli_scanmsxml: cannot initialize xmlReader\n"); -#if HAVE_JSON ret = cli_json_parse_error(ctx->wrkproperty, "OOXML_ERROR_XML_READER_IO"); -#endif + return ret; // libxml2 failed! } @@ -255,11 +251,4 @@ cl_error_t cli_scanmsxml(cli_ctx *ctx) xmlTextReaderClose(reader); xmlFreeTextReader(reader); return ret; -#else - UNUSEDPARAM(ctx); - cli_dbgmsg("in cli_scanmsxml()\n"); - cli_dbgmsg("cli_scanmsxml: scanning msxml documents requires libxml2!\n"); - - return CL_SUCCESS; -#endif } diff --git a/libclamav/msxml_parser.c b/libclamav/msxml_parser.c index f5d3816411..6495578ef9 100644 --- a/libclamav/msxml_parser.c +++ b/libclamav/msxml_parser.c @@ -35,7 +35,6 @@ #include "json_api.h" #include "msxml_parser.h" -#if HAVE_LIBXML2 #include #define MSXML_VERBIOSE 0 @@ -63,11 +62,8 @@ struct msxml_ictx { uint32_t flags; const struct key_entry *keys; size_t num_keys; - -#if HAVE_JSON json_object *root; int toval; -#endif }; struct key_entry blank_key = {NULL, NULL, 0}; @@ -113,7 +109,6 @@ static void msxml_error_handler(void *arg, const char *msg, xmlParserSeverities free(URI); } -#if HAVE_JSON static int msxml_is_int(const char *value, size_t len, int32_t *val) { long val2; @@ -160,7 +155,6 @@ static int msxml_parse_value(json_object *wrkptr, const char *arrname, const xml json_object_array_add(arrobj, newobj); return CL_SUCCESS; } -#endif /* HAVE_JSON */ #define MAX_ATTRIBS 20 static cl_error_t msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr reader, int rlvl, void *jptr) @@ -172,14 +166,10 @@ static cl_error_t msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr cl_error_t ret; int state, node_type, endtag = 0, num_attribs = 0; cli_ctx *ctx = mxctx->ictx->ctx; -#if HAVE_JSON + json_object *root = mxctx->ictx->root; json_object *parent = (json_object *)jptr; json_object *thisjobj = NULL; -#else - void *parent = NULL; - void *thisjobj = NULL; -#endif cli_msxmlmsg("in msxml_parse_element @ layer %d\n", rlvl); @@ -187,13 +177,11 @@ static cl_error_t msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr if (rlvl >= MSXML_RECLEVEL_MAX) { cli_dbgmsg("msxml_parse_element: reached msxml json recursion limit\n"); -#if HAVE_JSON if (track_json(mxctx)) { cl_error_t tmp = cli_json_parse_error(root, "MSXML_RECURSIVE_LIMIT"); if (tmp != CL_SUCCESS) return tmp; } -#endif /* skip it */ state = xmlTextReaderNext(reader); @@ -218,13 +206,13 @@ static cl_error_t msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr element_name = node_name; if (!element_name) { cli_dbgmsg("msxml_parse_element: element tag node nameless\n"); -#if HAVE_JSON + if (track_json(mxctx)) { cl_error_t tmp = cli_json_parse_error(root, "MSXML_NAMELESS_ELEMENT"); if (tmp != CL_SUCCESS) return tmp; } -#endif + return CL_EPARSE; /* no name, nameless */ } @@ -244,7 +232,6 @@ static cl_error_t msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr return CL_SUCCESS; } -#if HAVE_JSON if (track_json(mxctx) && (keyinfo->type & MSXML_JSON_TRACK)) { if (keyinfo->type & MSXML_JSON_ROOT) thisjobj = cli_jsonobj(root, keyinfo->name); @@ -308,7 +295,7 @@ static cl_error_t msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr return CL_EPARSE; } } -#endif + /* populate attributes for scanning callback - BROKEN, probably from the fact the reader is pointed to the attribute from previously parsing attributes */ if ((keyinfo->type & MSXML_SCAN_CB) && mxctx->scan_cb) { state = xmlTextReaderHasAttributes(reader); @@ -358,10 +345,8 @@ static cl_error_t msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr check_state(state); while (!endtag) { -#if HAVE_JSON if (track_json(mxctx) && (cli_json_timeout_cycle_check(ctx, &(mxctx->ictx->toval)) != CL_SUCCESS)) return CL_ETIMEOUT; -#endif node_type = xmlTextReaderNodeType(reader); if (node_type == -1) @@ -380,7 +365,6 @@ static cl_error_t msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr cli_msxmlmsg("TEXT: %s\n", node_value); -#if HAVE_JSON if (thisjobj && (keyinfo->type & MSXML_JSON_VALUE)) { ret = msxml_parse_value(thisjobj, "Value", node_value); @@ -389,7 +373,7 @@ static cl_error_t msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr cli_msxmlmsg("msxml_parse_element: added json value [%s: %s]\n", keyinfo->name, (const char *)node_value); } -#endif + /* callback-based scanning mechanism for embedded objects (used by HWPML) */ if ((keyinfo->type & MSXML_SCAN_CB) && mxctx->scan_cb) { char name[1024]; @@ -482,11 +466,7 @@ static cl_error_t msxml_parse_element(struct msxml_ctx *mxctx, xmlTextReaderPtr /* callback-based scanning mechanism for comments (used by MHTML) */ if ((keyinfo->type & MSXML_COMMENT_CB) && mxctx->comment_cb) { -#if HAVE_JSON ret = mxctx->comment_cb((const char *)node_value, ctx, thisjobj, mxctx->comment_data); -#else - ret = mxctx->comment_cb((const char *)node_value, ctx, NULL, mxctx->comment_data); -#endif if (ret != CL_SUCCESS) { return ret; } @@ -572,7 +552,7 @@ cl_error_t cli_msxml_parse_document(cli_ctx *ctx, xmlTextReaderPtr reader, const ictx.flags = flags; ictx.keys = keys; ictx.num_keys = num_keys; -#if HAVE_JSON + if (flags & MSXML_FLAG_JSON) { ictx.root = ctx->wrkproperty; /* JSON Sanity Check */ @@ -582,9 +562,6 @@ cl_error_t cli_msxml_parse_document(cli_ctx *ctx, xmlTextReaderPtr reader, const } else { ictx.root = NULL; } -#else - ictx.flags &= ~MSXML_FLAG_JSON; -#endif mxctx->ictx = &ictx; /* Error Handler (setting handler on tree walker causes segfault) */ @@ -594,14 +571,10 @@ cl_error_t cli_msxml_parse_document(cli_ctx *ctx, xmlTextReaderPtr reader, const /* Main Processing Loop */ while ((state = xmlTextReaderRead(reader)) == 1) { -#if HAVE_JSON if ((ictx.flags & MSXML_FLAG_JSON) && (cli_json_timeout_cycle_check(ictx.ctx, &(ictx.toval)) != CL_SUCCESS)) return CL_ETIMEOUT; ret = msxml_parse_element(mxctx, reader, 0, ictx.root); -#else - ret = msxml_parse_element(mxctx, reader, 0, NULL); -#endif if (ret != CL_SUCCESS) { if (ret == CL_VIRUS || ret == CL_ETIMEOUT || ret == CL_BREAK) { cli_dbgmsg("cli_msxml_parse_document: encountered halt event in parsing xml document\n"); @@ -617,7 +590,6 @@ cl_error_t cli_msxml_parse_document(cli_ctx *ctx, xmlTextReaderPtr reader, const ret = CL_EPARSE; } -#if HAVE_JSON /* Parse General Error Handler */ if (ictx.flags & MSXML_FLAG_JSON) { cl_error_t tmp = CL_SUCCESS; @@ -650,7 +622,6 @@ cl_error_t cli_msxml_parse_document(cli_ctx *ctx, xmlTextReaderPtr reader, const return tmp; } } -#endif /* non-critical return suppression */ if (ret == CL_BREAK) @@ -664,5 +635,3 @@ cl_error_t cli_msxml_parse_document(cli_ctx *ctx, xmlTextReaderPtr reader, const return ret; } - -#endif /* HAVE_LIBXML2 */ diff --git a/libclamav/msxml_parser.h b/libclamav/msxml_parser.h index 7be8287f3d..c54eaa231a 100644 --- a/libclamav/msxml_parser.h +++ b/libclamav/msxml_parser.h @@ -23,8 +23,6 @@ #ifndef __MSXML_PARSER_H #define __MSXML_PARSER_H -#if HAVE_LIBXML2 - #if HAVE_CONFIG_H #include "clamav-config.h" #endif @@ -88,6 +86,4 @@ struct msxml_ctx { cl_error_t cli_msxml_parse_document(cli_ctx *ctx, xmlTextReaderPtr reader, const struct key_entry *keys, const size_t num_keys, uint32_t flags, struct msxml_ctx *mxctx); -#endif /* HAVE_LIBXML2 */ - #endif /* __MSXML_PARSER_H */ diff --git a/libclamav/ole2_extract.c b/libclamav/ole2_extract.c index 238ff7a689..1a0ef3e718 100644 --- a/libclamav/ole2_extract.c +++ b/libclamav/ole2_extract.c @@ -50,9 +50,7 @@ #include "scanners.h" #include "fmap.h" #include "json_api.h" -#if HAVE_JSON #include "msdoc.h" -#endif #include "rijndael.h" #include "ole2_encryption.h" @@ -611,10 +609,8 @@ static int ole2_walk_property_tree(ole2_header_t *hdr, const char *dir, int32_t char *dirname; ole2_list_t node_list; cl_error_t ret; -#if HAVE_JSON char *name; int toval = 0; -#endif ole2_listmsg("ole2_walk_property_tree() called\n"); ole2_list_init(&node_list); @@ -642,12 +638,11 @@ static int ole2_walk_property_tree(ole2_header_t *hdr, const char *dir, int32_t while (!ole2_list_is_empty(&node_list)) { ole2_listmsg("within working loop, worklist size: %d\n", ole2_list_size(&node_list)); -#if HAVE_JSON + if (cli_json_timeout_cycle_check(ctx, &toval) != CL_SUCCESS) { ole2_list_delete(&node_list); return CL_ETIMEOUT; } -#endif current_block = hdr->prop_start; @@ -779,7 +774,6 @@ static int ole2_walk_property_tree(ole2_header_t *hdr, const char *dir, int32_t case 1: /* Directory */ ole2_listmsg("directory node\n"); if (dir) { -#if HAVE_JSON if (SCAN_COLLECT_METADATA && (ctx->wrkproperty != NULL)) { if (!json_object_object_get_ex(ctx->wrkproperty, "DigitalSignatures", NULL)) { name = cli_ole2_get_property_name2(prop_block[idx].name, prop_block[idx].name_size); @@ -791,7 +785,7 @@ static int ole2_walk_property_tree(ole2_header_t *hdr, const char *dir, int32_t } } } -#endif + dirname = (char *)cli_max_malloc(strlen(dir) + 8); if (!dirname) { ole2_listmsg("OLE2: malloc failed for dirname\n"); @@ -1062,7 +1056,6 @@ static cl_error_t scan_biff_for_xlm_macros_and_images( default: switch (state->state) { case BIFF_PARSER_NAME_RECORD: -#if HAVE_JSON if (state->data_offset == 0) { state->tmp = buff[i] & 0x20; } else if ((state->data_offset == 14 || state->data_offset == 15) && state->tmp) { @@ -1081,14 +1074,13 @@ static cl_error_t scan_biff_for_xlm_macros_and_images( state->tmp = 0; } } -#endif break; case BIFF_PARSER_BOUNDSHEET_RECORD: if (state->data_offset == 4) { state->tmp = buff[i]; } else if (state->data_offset == 5 && buff[i] == 1) { // Excel 4.0 macro sheet cli_dbgmsg("[scan_biff_for_xlm_macros_and_images] Found XLM macro sheet\n"); -#if HAVE_JSON + if (SCAN_COLLECT_METADATA && (ctx->wrkproperty != NULL)) { cli_jsonbool(ctx->wrkproperty, "HasMacros", 1); json_object *macro_languages = cli_jsonarray(ctx->wrkproperty, "MacroLanguages"); @@ -1106,7 +1098,7 @@ static cl_error_t scan_biff_for_xlm_macros_and_images( } } } -#endif + *found_macro = true; } break; @@ -1244,11 +1236,12 @@ static cl_error_t handler_enum(ole2_header_t *hdr, property_t *prop, const char char *name = NULL; unsigned char *hwp_check = NULL; int32_t offset = 0; -#if HAVE_JSON + json_object *arrobj = NULL; json_object *strmobj = NULL; UNUSEDPARAM(handler_ctx); + UNUSEDPARAM(dir); name = cli_ole2_get_property_name2(prop->name, prop->name_size); if (name) { @@ -1272,10 +1265,6 @@ static cl_error_t handler_enum(ole2_header_t *hdr, property_t *prop, const char } } } -#else - UNUSEDPARAM(ctx); -#endif - UNUSEDPARAM(dir); if (!hdr->has_vba) { if (!name) @@ -1327,9 +1316,9 @@ static cl_error_t handler_enum(ole2_header_t *hdr, property_t *prop, const char /* compare against HWP signature; we could add the 15 padding NULLs too */ if (!memcmp(hwp_check + offset, "HWP Document File", 17)) { hwp5_header_t *hwp_new; -#if HAVE_JSON + cli_jsonstr(ctx->wrkproperty, "FileType", "CL_TYPE_HWP5"); -#endif + CLI_CALLOC_OR_GOTO_DONE(hwp_new, 1, sizeof(hwp5_header_t), status = CL_EMEM); /* @@ -1645,7 +1634,6 @@ static cl_error_t handler_otf(ole2_header_t *hdr, property_t *prop, const char * goto done; } -#if HAVE_JSON /* JSON Output Summary Information */ if (SCAN_COLLECT_METADATA && (ctx->properties != NULL)) { if (!name) { @@ -1671,7 +1659,6 @@ static cl_error_t handler_otf(ole2_header_t *hdr, property_t *prop, const char * } } } -#endif if (hdr->is_hwp) { if (!name) { @@ -1887,8 +1874,6 @@ static cl_error_t handler_otf_encrypted(ole2_header_t *hdr, property_t *prop, co goto done; } -#if HAVE_JSON - /* JSON Output Summary Information */ if (SCAN_COLLECT_METADATA && (ctx->properties != NULL)) { if (!name) { @@ -1915,8 +1900,6 @@ static cl_error_t handler_otf_encrypted(ole2_header_t *hdr, property_t *prop, co } } -#endif - if (hdr->is_hwp) { if (!name) { name = cli_ole2_get_property_name2(prop->name, prop->name_size); @@ -2592,11 +2575,9 @@ cl_error_t cli_ole2_extract(const char *dirname, cli_ctx *ctx, struct uniq **fil cli_dbgmsg("Encrypted with VelvetSweatshop: %d\n", bEncrypted); -#if HAVE_JSON if (ctx->wrkproperty == ctx->properties) { cli_jsonint(ctx->wrkproperty, "EncryptedWithVelvetSweatshop", bEncrypted); } -#endif /* HAVE_JSON */ } /* 8 SBAT blocks per file block */ diff --git a/libclamav/ooxml.c b/libclamav/ooxml.c index 4b58ffa0f7..ab9df48d0b 100644 --- a/libclamav/ooxml.c +++ b/libclamav/ooxml.c @@ -23,13 +23,9 @@ #include "clamav-config.h" #endif -#if HAVE_JSON #include "json.h" -#endif -#if HAVE_LIBXML2 #include -#endif #include "clamav.h" #include "filetypes.h" @@ -39,8 +35,6 @@ #include "msxml_parser.h" #include "ooxml.h" -#if HAVE_LIBXML2 && HAVE_JSON - // clang-format off /*** OOXML MSDOC ***/ @@ -386,8 +380,6 @@ static cl_error_t ooxml_hwp_cb(int fd, const char *filepath, cli_ctx *ctx, const return ret; } -#endif /* HAVE_LIBXML2 && HAVE_JSON */ - cli_file_t cli_ooxml_filetype(cli_ctx *ctx, fmap_t *map) { struct zip_requests requests; @@ -428,7 +420,6 @@ cli_file_t cli_ooxml_filetype(cli_ctx *ctx, fmap_t *map) cl_error_t cli_process_ooxml(cli_ctx *ctx, int type) { -#if HAVE_LIBXML2 && HAVE_JSON uint32_t loff = 0; cl_error_t ret = CL_SUCCESS; @@ -485,15 +476,4 @@ cl_error_t cli_process_ooxml(cli_ctx *ctx, int type) } return ret; -#else - UNUSEDPARAM(ctx); - cli_dbgmsg("in cli_process_ooxml\n"); -#if !HAVE_LIBXML2 - cli_dbgmsg("cli_process_ooxml: libxml2 needs to enabled!\n"); -#endif -#if !HAVE_JSON - cli_dbgmsg("cli_process_ooxml: libjson needs to enabled!\n"); -#endif - return CL_SUCCESS; -#endif } diff --git a/libclamav/openioc.c b/libclamav/openioc.c index 7192abc853..e7a24c71ca 100644 --- a/libclamav/openioc.c +++ b/libclamav/openioc.c @@ -34,7 +34,6 @@ #include "others.h" #include "openioc.h" -#ifdef HAVE_LIBXML2 #include struct openioc_hash { @@ -334,10 +333,3 @@ int openioc_parse(const char *fname, int fd, struct cl_engine *engine, unsigned return CL_SUCCESS; } -#else -int openioc_parse(const char *fname, int fd, struct cl_engine *engine, unsigned int options) -{ - cli_dbgmsg("openioc_parse: libxml2 support is compiled out and is needed for OpenIOC support.\n"); - return CL_SUCCESS; -} -#endif diff --git a/libclamav/others.c b/libclamav/others.c index 9e6f9cecdd..2b9fc6f1c7 100644 --- a/libclamav/others.c +++ b/libclamav/others.c @@ -58,9 +58,7 @@ #include #endif -#ifdef HAVE_LIBXML2 #include -#endif #ifndef _WIN32 #include @@ -442,9 +440,9 @@ cl_error_t cl_init(unsigned int initoptions) rc = bytecode_init(); if (rc) return rc; -#ifdef HAVE_LIBXML2 + xmlInitParser(); -#endif + return CL_SUCCESS; } @@ -581,9 +579,6 @@ struct cl_engine *cl_engine_new(void) new->maxrechwp3 = CLI_DEFAULT_MAXRECHWP3; /* PCRE matching limitations */ -#if HAVE_PCRE - cli_pcre_init(); -#endif new->pcre_match_limit = CLI_DEFAULT_PCRE_MATCH_LIMIT; new->pcre_recmatch_limit = CLI_DEFAULT_PCRE_RECMATCH_LIMIT; new->pcre_max_filesize = CLI_DEFAULT_PCRE_MAX_FILESIZE; @@ -1123,12 +1118,10 @@ void cli_append_potentially_unwanted_if_heur_exceedsmax(cli_ctx *ctx, char *vnam cli_dbgmsg("%s: scanning may be incomplete and additional analysis needed for this file.\n", vname); } -#if HAVE_JSON /* Also record the event in the scan metadata, under "ParseErrors" */ if (SCAN_COLLECT_METADATA && ctx->wrkproperty) { cli_json_parse_error(ctx->wrkproperty, vname); } -#endif } } @@ -1396,7 +1389,6 @@ static cl_error_t append_virus(cli_ctx *ctx, const char *virname, IndicatorType cli_virus_found_cb(ctx, virname); } -#if HAVE_JSON if (SCAN_COLLECT_METADATA && ctx->wrkproperty) { json_object *arrobj, *virobj; if (!json_object_object_get_ex(ctx->wrkproperty, "Viruses", &arrobj)) { @@ -1416,7 +1408,6 @@ static cl_error_t append_virus(cli_ctx *ctx, const char *virname, IndicatorType } json_object_array_add(arrobj, virobj); } -#endif if (SCAN_ALLMATCHES) { // Never break. diff --git a/libclamav/others.h b/libclamav/others.h index bd852326f4..b2a78b1006 100644 --- a/libclamav/others.h +++ b/libclamav/others.h @@ -40,9 +40,7 @@ #include #include -#ifdef HAVE_JSON #include -#endif #include "clamav.h" #include "dconf.h" @@ -60,9 +58,7 @@ #include "yara_clam.h" #endif -#if HAVE_LIBXML2 #define CLAMAV_MIN_XMLREADER_FLAGS (XML_PARSE_NOERROR | XML_PARSE_NONET) -#endif /* * CL_FLEVEL is the signature f-level specific to the current code and @@ -218,10 +214,8 @@ typedef struct cli_ctx_tag { #ifdef HAVE__INTERNAL__SHA_COLLECT int sha_collect; #endif -#ifdef HAVE_JSON struct json_object *properties; struct json_object *wrkproperty; -#endif struct timeval time_limit; bool limit_exceeded; /* To guard against alerting on limits exceeded more than once, or storing that in the JSON metadata more than once. */ bool abort_scan; /* So we can guarantee a scan is aborted, even if CL_ETIMEOUT/etc. status is lost in the scan recursion stack. */ diff --git a/libclamav/pdf.c b/libclamav/pdf.c index 49a1586c7d..a5dd159e8a 100644 --- a/libclamav/pdf.c +++ b/libclamav/pdf.c @@ -83,7 +83,6 @@ static const char *pdf_nextobject(const char *ptr, size_t len); /* PDF statistics callbacks and related */ struct pdfname_action; -#if HAVE_JSON static void pdf_export_json(struct pdf_struct *); static void ASCIIHexDecode_cb(struct pdf_struct *, struct pdf_obj *, struct pdfname_action *); @@ -117,7 +116,7 @@ static void Colors_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfnam static void RichMedia_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act); static void AcroForm_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act); static void XFA_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act); -#endif + /* End PDF statistics callbacks and related */ static int pdf_readint(const char *q0, int len, const char *key); @@ -1757,7 +1756,6 @@ cl_error_t pdf_extract_obj(struct pdf_struct *pdf, struct pdf_obj *obj, uint32_t } } -#if HAVE_JSON if ((pdf->ctx->options->general & CL_SCAN_GENERAL_COLLECT_METADATA) && pdf->ctx->wrkproperty != NULL) { struct json_object *pdfobj, *jbig2arr; @@ -1769,7 +1767,7 @@ cl_error_t pdf_extract_obj(struct pdf_struct *pdf, struct pdf_obj *obj, uint32_t cli_jsonint_array(jbig2arr, obj->id >> 8); } } -#endif + pdf->stats.njs++; if (filter_writen(pdf, obj, fout, out, js_len, (size_t *)&sum) != js_len) { @@ -1889,12 +1887,9 @@ struct pdfname_action { enum objstate from_state; /* STATE_NONE is noop */ enum objstate to_state; uint32_t nameflags; -#if HAVE_JSON void (*pdf_stats_cb)(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act); -#endif }; -#if HAVE_JSON static struct pdfname_action pdfname_actions[] = { {"ASCIIHexDecode", OBJ_FILTER_AH, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC, ASCIIHexDecode_cb}, {"ASCII85Decode", OBJ_FILTER_A85, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC, ASCII85Decode_cb}, @@ -1942,42 +1937,6 @@ static struct pdfname_action pdfname_actions[] = { {"RichMedia", OBJ_DICT, STATE_NONE, STATE_NONE, NAMEFLAG_NONE, RichMedia_cb}, {"AcroForm", OBJ_DICT, STATE_NONE, STATE_NONE, NAMEFLAG_NONE, AcroForm_cb}, {"XFA", OBJ_DICT, STATE_NONE, STATE_NONE, NAMEFLAG_NONE, XFA_cb}}; -#else -static struct pdfname_action pdfname_actions[] = { - {"ASCIIHexDecode", OBJ_FILTER_AH, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"ASCII85Decode", OBJ_FILTER_A85, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"A85", OBJ_FILTER_A85, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"AHx", OBJ_FILTER_AH, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"EmbeddedFile", OBJ_EMBEDDED_FILE, STATE_NONE, STATE_NONE, NAMEFLAG_HEURISTIC}, - {"FlateDecode", OBJ_FILTER_FLATE, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"Fl", OBJ_FILTER_FLATE, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"Image", OBJ_IMAGE, STATE_NONE, STATE_NONE, NAMEFLAG_HEURISTIC}, - {"LZWDecode", OBJ_FILTER_LZW, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"LZW", OBJ_FILTER_LZW, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"RunLengthDecode", OBJ_FILTER_RL, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"RL", OBJ_FILTER_RL, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"CCITTFaxDecode", OBJ_FILTER_FAX, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"CCF", OBJ_FILTER_FAX, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"JBIG2Decode", OBJ_FILTER_DCT, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"DCTDecode", OBJ_FILTER_DCT, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"DCT", OBJ_FILTER_DCT, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"JPXDecode", OBJ_FILTER_JPX, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"Crypt", OBJ_FILTER_CRYPT, STATE_FILTER, STATE_NONE, NAMEFLAG_HEURISTIC}, - {"Standard", OBJ_FILTER_STANDARD, STATE_FILTER, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"Sig", OBJ_SIGNED, STATE_ANY, STATE_NONE, NAMEFLAG_HEURISTIC}, - {"V", OBJ_SIGNED, STATE_ANY, STATE_NONE, NAMEFLAG_HEURISTIC}, - {"R", OBJ_SIGNED, STATE_ANY, STATE_NONE, NAMEFLAG_HEURISTIC}, - {"Linearized", OBJ_DICT, STATE_NONE, STATE_LINEARIZED, NAMEFLAG_HEURISTIC}, - {"Filter", OBJ_HASFILTERS, STATE_ANY, STATE_FILTER, NAMEFLAG_HEURISTIC}, - {"JavaScript", OBJ_JAVASCRIPT, STATE_S, STATE_JAVASCRIPT, NAMEFLAG_HEURISTIC}, - {"Length", OBJ_DICT, STATE_FILTER, STATE_NONE, NAMEFLAG_HEURISTIC}, - {"S", OBJ_DICT, STATE_NONE, STATE_S, NAMEFLAG_HEURISTIC}, - {"Type", OBJ_DICT, STATE_NONE, STATE_NONE, NAMEFLAG_HEURISTIC}, - {"OpenAction", OBJ_OPENACTION, STATE_ANY, STATE_OPENACTION, NAMEFLAG_HEURISTIC}, - {"Launch", OBJ_LAUNCHACTION, STATE_ANY, STATE_LAUNCHACTION, NAMEFLAG_HEURISTIC}, - {"Page", OBJ_PAGE, STATE_NONE, STATE_NONE, NAMEFLAG_HEURISTIC}, - {"Contents", OBJ_CONTENTS, STATE_NONE, STATE_CONTENTS, NAMEFLAG_HEURISTIC}}; -#endif #define KNOWN_FILTERS ((1 << OBJ_FILTER_AH) | (1 << OBJ_FILTER_RL) | (1 << OBJ_FILTER_A85) | (1 << OBJ_FILTER_FLATE) | (1 << OBJ_FILTER_LZW) | (1 << OBJ_FILTER_FAX) | (1 << OBJ_FILTER_DCT) | (1 << OBJ_FILTER_JPX) | (1 << OBJ_FILTER_CRYPT)) @@ -2017,10 +1976,8 @@ static void handle_pdfname(struct pdf_struct *pdf, struct pdf_obj *obj, const ch pdfobj_flag(pdf, obj, ESCAPED_COMMON_PDFNAME); } -#if HAVE_JSON if ((act->pdf_stats_cb)) act->pdf_stats_cb(pdf, obj, act); -#endif if (act->from_state == *state || act->from_state == STATE_ANY) { *state = act->to_state; @@ -2135,9 +2092,8 @@ void pdf_parseobj(struct pdf_struct *pdf, struct pdf_obj *obj) size_t i = 0; unsigned filters = 0, blockopens = 0; enum objstate objstate = STATE_NONE; -#if HAVE_JSON + json_object *pdfobj = NULL, *jsonobj = NULL; -#endif if (NULL == pdf || NULL == obj) { cli_warnmsg("pdf_parseobj: invalid arguments\n"); @@ -2204,7 +2160,7 @@ void pdf_parseobj(struct pdf_struct *pdf, struct pdf_obj *obj) if (!nextobj || bytesleft < 0) { cli_dbgmsg("pdf_parseobj: %u %u obj: no dictionary\n", obj->id >> 8, obj->id & 0xff); -#if HAVE_JSON + if (!(pdfobj) && pdf->ctx->wrkproperty != NULL) { pdfobj = cli_jsonobj(pdf->ctx->wrkproperty, "PDFStats"); if (!(pdfobj)) @@ -2217,7 +2173,7 @@ void pdf_parseobj(struct pdf_struct *pdf, struct pdf_obj *obj) if (jsonobj) cli_jsonint_array(jsonobj, obj->id >> 8); } -#endif + return; } @@ -2251,7 +2207,7 @@ void pdf_parseobj(struct pdf_struct *pdf, struct pdf_obj *obj) /* find end of dictionary block */ if (bytesleft < 0) { cli_dbgmsg("pdf_parseobj: %u %u obj: broken dictionary\n", obj->id >> 8, obj->id & 0xff); -#if HAVE_JSON + if (!(pdfobj) && pdf->ctx->wrkproperty != NULL) { pdfobj = cli_jsonobj(pdf->ctx->wrkproperty, "PDFStats"); if (!(pdfobj)) @@ -2264,7 +2220,7 @@ void pdf_parseobj(struct pdf_struct *pdf, struct pdf_obj *obj) if (jsonobj) cli_jsonint_array(jsonobj, obj->id >> 8); } -#endif + return; } @@ -2300,7 +2256,7 @@ void pdf_parseobj(struct pdf_struct *pdf, struct pdf_obj *obj) if (blockopens) { /* probably truncated */ cli_dbgmsg("pdf_parseobj: %u %u obj broken dictionary\n", obj->id >> 8, obj->id & 0xff); -#if HAVE_JSON + if (!(pdfobj) && pdf->ctx->wrkproperty != NULL) { pdfobj = cli_jsonobj(pdf->ctx->wrkproperty, "PDFStats"); if (!(pdfobj)) @@ -2313,7 +2269,7 @@ void pdf_parseobj(struct pdf_struct *pdf, struct pdf_obj *obj) if (jsonobj) cli_jsonint_array(jsonobj, obj->id >> 8); } -#endif + return; } @@ -3703,10 +3659,9 @@ cl_error_t cli_pdf(const char *dir, cli_ctx *ctx, off_t offset) const char *pdfver, *tmp, *start, *eofmap, *q, *eof; unsigned i; unsigned int objs_found = 0; -#if HAVE_JSON + json_object *pdfobj = NULL; char *begin, *end, *p1; -#endif cli_dbgmsg("in cli_pdf(%s)\n", dir); memset(&pdf, 0, sizeof(pdf)); @@ -3723,10 +3678,8 @@ cl_error_t cli_pdf(const char *dir, cli_ctx *ctx, off_t offset) goto done; } -#if HAVE_JSON if (ctx->wrkproperty) pdfobj = cli_jsonobj(ctx->wrkproperty, "PDFStats"); -#endif /* offset is 0 when coming from filetype2 */ tmp = cli_memstr(pdfver, versize, "%PDF-", 5); @@ -3751,12 +3704,10 @@ cl_error_t cli_pdf(const char *dir, cli_ctx *ctx, off_t offset) pdfver[7] < '1' || pdfver[7] > '9') { pdf.flags |= 1 << BAD_PDF_VERSION; cli_dbgmsg("cli_pdf: bad pdf version: %.8s\n", pdfver); -#if HAVE_JSON + if (pdfobj) cli_jsonbool(pdfobj, "BadVersion", 1); -#endif } else { -#if HAVE_JSON if (pdfobj) { begin = (char *)(pdfver + 5); end = begin + 2; @@ -3769,16 +3720,14 @@ cl_error_t cli_pdf(const char *dir, cli_ctx *ctx, off_t offset) free(p1); } } -#endif } if (pdfver != start || offset) { pdf.flags |= 1 << BAD_PDF_HEADERPOS; cli_dbgmsg("cli_pdf: PDF header is not at position 0: %lld\n", (long long)(pdfver - start + offset)); -#if HAVE_JSON + if (pdfobj) cli_jsonbool(pdfobj, "BadVersionLocation", 1); -#endif } offset += pdfver - start; @@ -3807,10 +3756,9 @@ cl_error_t cli_pdf(const char *dir, cli_ctx *ctx, off_t offset) if (q <= eofmap) { pdf.flags |= 1 << BAD_PDF_TRAILER; cli_dbgmsg("cli_pdf: %%%%EOF not found\n"); -#if HAVE_JSON + if (pdfobj) cli_jsonbool(pdfobj, "NoEOF", 1); -#endif } else { const char *t; @@ -3824,10 +3772,9 @@ cl_error_t cli_pdf(const char *dir, cli_ctx *ctx, off_t offset) if (q <= eofmap) { pdf.flags |= 1 << BAD_PDF_TRAILER; cli_dbgmsg("cli_pdf: startxref not found\n"); -#if HAVE_JSON + if (pdfobj) cli_jsonbool(pdfobj, "NoXREF", 1); -#endif } else { for (t = q; t > eofmap; t--) { if (memcmp(t, "trailer", 7) == 0) @@ -3933,9 +3880,7 @@ cl_error_t cli_pdf(const char *dir, cli_ctx *ctx, off_t offset) err: -#if HAVE_JSON pdf_export_json(&pdf); -#endif if (pdf.objstms) { for (i = 0; i < pdf.nobjstms; i++) { @@ -4075,7 +4020,6 @@ pdf_nextobject(const char *ptr, size_t len) } /* PDF statistics */ -#if HAVE_JSON static void ASCIIHexDecode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4086,9 +4030,7 @@ static void ASCIIHexDecode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struc pdf->stats.nasciihexdecode++; } -#endif -#if HAVE_JSON static void ASCII85Decode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4099,9 +4041,7 @@ static void ASCII85Decode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf->stats.nascii85decode++; } -#endif -#if HAVE_JSON static void EmbeddedFile_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4112,9 +4052,7 @@ static void EmbeddedFile_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf->stats.nembeddedfile++; } -#endif -#if HAVE_JSON static void FlateDecode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4125,9 +4063,7 @@ static void FlateDecode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct p pdf->stats.nflate++; } -#endif -#if HAVE_JSON static void Image_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4138,9 +4074,7 @@ static void Image_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname pdf->stats.nimage++; } -#endif -#if HAVE_JSON static void LZWDecode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4151,9 +4085,7 @@ static void LZWDecode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf pdf->stats.nlzw++; } -#endif -#if HAVE_JSON static void RunLengthDecode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4164,9 +4096,7 @@ static void RunLengthDecode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, stru pdf->stats.nrunlengthdecode++; } -#endif -#if HAVE_JSON static void CCITTFaxDecode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4177,9 +4107,7 @@ static void CCITTFaxDecode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struc pdf->stats.nfaxdecode++; } -#endif -#if HAVE_JSON static void JBIG2Decode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { cli_ctx *ctx = NULL; @@ -4211,9 +4139,7 @@ static void JBIG2Decode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct p pdf->stats.njbig2decode++; } -#endif -#if HAVE_JSON static void DCTDecode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4224,9 +4150,7 @@ static void DCTDecode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf pdf->stats.ndctdecode++; } -#endif -#if HAVE_JSON static void JPXDecode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4237,9 +4161,7 @@ static void JPXDecode_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf pdf->stats.njpxdecode++; } -#endif -#if HAVE_JSON static void Crypt_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4250,9 +4172,7 @@ static void Crypt_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname pdf->stats.ncrypt++; } -#endif -#if HAVE_JSON static void Standard_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4263,9 +4183,7 @@ static void Standard_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfn pdf->stats.nstandard++; } -#endif -#if HAVE_JSON static void Sig_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4276,9 +4194,7 @@ static void Sig_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_a pdf->stats.nsigned++; } -#endif -#if HAVE_JSON static void JavaScript_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(pdf); @@ -4292,9 +4208,7 @@ static void JavaScript_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pd * actually have any content. */ } -#endif -#if HAVE_JSON static void OpenAction_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4305,9 +4219,7 @@ static void OpenAction_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pd pdf->stats.nopenaction++; } -#endif -#if HAVE_JSON static void Launch_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4318,9 +4230,7 @@ static void Launch_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfnam pdf->stats.nlaunch++; } -#endif -#if HAVE_JSON static void Page_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4331,9 +4241,7 @@ static void Page_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_ pdf->stats.npage++; } -#endif -#if HAVE_JSON static void Author_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { cli_ctx *ctx = NULL; @@ -4361,9 +4269,7 @@ static void Author_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfnam pdf->parse_recursion_depth--; } } -#endif -#if HAVE_JSON static void Creator_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { cli_ctx *ctx = NULL; @@ -4391,9 +4297,7 @@ static void Creator_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfna pdf->parse_recursion_depth--; } } -#endif -#if HAVE_JSON static void ModificationDate_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { cli_ctx *ctx = NULL; @@ -4421,9 +4325,7 @@ static void ModificationDate_cb(struct pdf_struct *pdf, struct pdf_obj *obj, str pdf->parse_recursion_depth--; } } -#endif -#if HAVE_JSON static void CreationDate_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { cli_ctx *ctx = NULL; @@ -4451,9 +4353,7 @@ static void CreationDate_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf->parse_recursion_depth--; } } -#endif -#if HAVE_JSON static void Producer_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { cli_ctx *ctx = NULL; @@ -4481,9 +4381,7 @@ static void Producer_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfn pdf->parse_recursion_depth--; } } -#endif -#if HAVE_JSON static void Title_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { cli_ctx *ctx = NULL; @@ -4511,9 +4409,7 @@ static void Title_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname pdf->parse_recursion_depth--; } } -#endif -#if HAVE_JSON static void Keywords_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { cli_ctx *ctx = NULL; @@ -4541,9 +4437,7 @@ static void Keywords_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfn pdf->parse_recursion_depth--; } } -#endif -#if HAVE_JSON static void Subject_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { cli_ctx *ctx = NULL; @@ -4571,9 +4465,7 @@ static void Subject_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfna pdf->parse_recursion_depth--; } } -#endif -#if HAVE_JSON static void RichMedia_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4584,9 +4476,7 @@ static void RichMedia_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdf pdf->stats.nrichmedia++; } -#endif -#if HAVE_JSON static void AcroForm_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4597,9 +4487,7 @@ static void AcroForm_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfn pdf->stats.nacroform++; } -#endif -#if HAVE_JSON static void XFA_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { UNUSEDPARAM(obj); @@ -4610,9 +4498,7 @@ static void XFA_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_a pdf->stats.nxfa++; } -#endif -#if HAVE_JSON static void Pages_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { cli_ctx *ctx = NULL; @@ -4691,9 +4577,7 @@ static void Pages_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname cleanup: pdf_free_array(array); } -#endif -#if HAVE_JSON static void Colors_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfname_action *act) { cli_ctx *ctx = NULL; @@ -4751,9 +4635,7 @@ static void Colors_cb(struct pdf_struct *pdf, struct pdf_obj *obj, struct pdfnam cli_jsonint_array(colorsobj, obj->id >> 8); } -#endif -#if HAVE_JSON static void pdf_free_stats(struct pdf_struct *pdf) { @@ -4817,9 +4699,7 @@ static void pdf_free_stats(struct pdf_struct *pdf) pdf->stats.keywords = NULL; } } -#endif -#if HAVE_JSON static void pdf_export_json(struct pdf_struct *pdf) { cli_ctx *ctx = NULL; @@ -5101,4 +4981,3 @@ static void pdf_export_json(struct pdf_struct *pdf) cleanup: pdf_free_stats(pdf); } -#endif \ No newline at end of file diff --git a/libclamav/pe.c b/libclamav/pe.c index 681a41a4d0..23f4c4ae0d 100644 --- a/libclamav/pe.c +++ b/libclamav/pe.c @@ -2247,11 +2247,7 @@ static inline int hash_impfns(cli_ctx *ctx, void **hashctx, uint32_t *impsz, str int num_fns = 0, ret = CL_SUCCESS; const char *buffer; cli_hash_type_t type; -#if HAVE_JSON json_object *imptbl = NULL; -#else - void *imptbl = NULL; -#endif if (image->u.OriginalFirstThunk) thuoff = cli_rawaddr(image->u.OriginalFirstThunk, peinfo->sections, peinfo->nsections, &err, fsize, peinfo->hdr_size); @@ -2262,7 +2258,6 @@ static inline int hash_impfns(cli_ctx *ctx, void **hashctx, uint32_t *impsz, str return CL_EFORMAT; } -#if HAVE_JSON if (ctx->wrkproperty) { imptbl = cli_jsonarray(ctx->wrkproperty, "ImportTable"); if (!imptbl) { @@ -2270,7 +2265,6 @@ static inline int hash_impfns(cli_ctx *ctx, void **hashctx, uint32_t *impsz, str return CL_EMEM; } } -#endif #define UPDATE_IMPHASH() \ do { \ @@ -2601,11 +2595,7 @@ static cl_error_t scan_pe_imp(cli_ctx *ctx, struct cli_exe_info *peinfo) } /* Force md5 hash generation for debug and preclass */ -#if HAVE_JSON if ((cli_debug_flag || ctx->wrkproperty) && !genhash[CLI_HASH_MD5]) { -#else - if (cli_debug_flag && !genhash[CLI_HASH_MD5]) { -#endif genhash[CLI_HASH_MD5] = 1; hashset[CLI_HASH_MD5] = calloc(hashlen[CLI_HASH_MD5], sizeof(char)); if (!hashset[CLI_HASH_MD5]) { @@ -2629,17 +2619,13 @@ static cl_error_t scan_pe_imp(cli_ctx *ctx, struct cli_exe_info *peinfo) } /* Print hash */ -#if HAVE_JSON if (cli_debug_flag || ctx->wrkproperty) { -#else - if (cli_debug_flag) { -#endif char *dstr = cli_str2hex((char *)hashset[CLI_HASH_MD5], hashlen[CLI_HASH_MD5]); cli_dbgmsg("IMP: %s:%u\n", dstr ? (char *)dstr : "(NULL)", impsz); -#if HAVE_JSON + if (ctx->wrkproperty) cli_jsonstr(ctx->wrkproperty, "Imphash", dstr ? dstr : "(NULL)"); -#endif + if (dstr) free(dstr); } @@ -2665,7 +2651,6 @@ static cl_error_t scan_pe_imp(cli_ctx *ctx, struct cli_exe_info *peinfo) return ret; } -#if HAVE_JSON static struct json_object *get_pe_property(cli_ctx *ctx) { struct json_object *pe; @@ -2776,7 +2761,6 @@ static void add_section_info(cli_ctx *ctx, struct cli_exe_section *s) json_object_array_add(sections, section); } -#endif int cli_scanpe(cli_ctx *ctx) { @@ -2800,17 +2784,14 @@ int cli_scanpe(cli_ctx *ctx) #ifdef HAVE__INTERNAL__SHA_COLLECT int sha_collect = ctx->sha_collect; #endif -#if HAVE_JSON int toval = 0; struct json_object *pe_json = NULL; -#endif if (!ctx) { cli_errmsg("cli_scanpe: ctx == NULL\n"); return CL_ENULLARG; } -#if HAVE_JSON if (cli_json_timeout_cycle_check(ctx, &toval) != CL_SUCCESS) { return CL_ETIMEOUT; } @@ -2818,7 +2799,7 @@ int cli_scanpe(cli_ctx *ctx) if (SCAN_COLLECT_METADATA) { pe_json = get_pe_property(ctx); } -#endif + map = ctx->fmap; fsize = map->len; @@ -2827,11 +2808,9 @@ int cli_scanpe(cli_ctx *ctx) uint32_t opts = CLI_PEHEADER_OPT_DBG_PRINT_INFO | CLI_PEHEADER_OPT_REMOVE_MISSING_SECTIONS; -#if HAVE_JSON if (SCAN_COLLECT_METADATA) { opts |= CLI_PEHEADER_OPT_COLLECT_JSON; } -#endif if (DETECT_BROKEN_PE) { opts |= CLI_PEHEADER_OPT_STRICT_ON_PE_ERRORS; @@ -2983,11 +2962,7 @@ int cli_scanpe(cli_ctx *ctx) /* Attempt to run scans on import table */ /* Run if there are existing signatures and/or preclassing */ -#if HAVE_JSON if (DCONF & PE_CONF_IMPTBL && (ctx->engine->hm_imp || ctx->wrkproperty)) { -#else - if (DCONF & PE_CONF_IMPTBL && ctx->engine->hm_imp) { -#endif ret = scan_pe_imp(ctx, peinfo); switch (ret) { case CL_SUCCESS: @@ -3301,10 +3276,10 @@ int cli_scanpe(cli_ctx *ctx) if (!peinfo->sections[i].rsz && peinfo->sections[i].vsz && peinfo->sections[i + 1].rsz && peinfo->sections[i + 1].vsz) { found = 1; cli_dbgmsg("cli_scanpe: UPX/FSG/MEW: empty section found - assuming compression\n"); -#if HAVE_JSON + if (pe_json != NULL) cli_jsonbool(pe_json, "HasEmptySection", 1); -#endif + break; } } @@ -3401,10 +3376,8 @@ int cli_scanpe(cli_ctx *ctx) uselzma = 0; } -#if HAVE_JSON if (pe_json != NULL) cli_jsonstr(pe_json, "Packer", "MEW"); -#endif CLI_UNPTEMP("cli_scanpe: MEW", (src, 0)); CLI_UNPRESULTS("cli_scanpe: MEW", (unmew11(src, offdiff, ssize, dsize, EC32(peinfo->pe_opt.opt32.ImageBase), peinfo->sections[0].rva, uselzma, ndesc)), 1, (src, 0)); @@ -3509,10 +3482,8 @@ int cli_scanpe(cli_ctx *ctx) break; } -#if HAVE_JSON if (pe_json != NULL) cli_jsonstr(pe_json, "Packer", "Upack"); -#endif CLI_UNPTEMP("cli_scanpe: Upack", (dest, 0)); CLI_UNPRESULTS("cli_scanpe: Upack", (unupack(upack, dest, dsize, epbuff, vma, peinfo->ep, EC32(peinfo->pe_opt.opt32.ImageBase), peinfo->sections[0].rva, ndesc)), 1, (dest, 0)); @@ -3596,10 +3567,8 @@ int cli_scanpe(cli_ctx *ctx) return CL_EMEM; } -#if HAVE_JSON if (pe_json != NULL) cli_jsonstr(pe_json, "Packer", "FSG"); -#endif CLI_UNPTEMP("cli_scanpe: FSG", (dest, 0)); CLI_UNPRESULTSFSG2("cli_scanpe: FSG", (unfsg_200(newesi - peinfo->sections[i + 1].rva + src, dest, ssize + peinfo->sections[i + 1].rva - newesi, dsize, newedi, EC32(peinfo->pe_opt.opt32.ImageBase), newedx, ndesc)), 1, (dest, 0)); @@ -3703,10 +3672,8 @@ int cli_scanpe(cli_ctx *ctx) oldep = peinfo->vep + 161 + 6 + cli_readint32(epbuff + 163); cli_dbgmsg("cli_scanpe: FSG: found old EP @%x\n", oldep); -#if HAVE_JSON if (pe_json != NULL) cli_jsonstr(pe_json, "Packer", "FSG"); -#endif CLI_UNPTEMP("cli_scanpe: FSG", (dest, sections, 0)); CLI_UNPRESULTSFSG1("cli_scanpe: FSG", (unfsg_133(src + newesi - peinfo->sections[i + 1].rva, dest, ssize + peinfo->sections[i + 1].rva - newesi, dsize, sections, sectcnt, EC32(peinfo->pe_opt.opt32.ImageBase), oldep, ndesc)), 1, (dest, sections, 0)); @@ -3806,10 +3773,8 @@ int cli_scanpe(cli_ctx *ctx) oldep = peinfo->vep + gp + 6 + cli_readint32(src + gp + 2 + oldep); cli_dbgmsg("cli_scanpe: FSG: found old EP @%x\n", oldep); -#if HAVE_JSON if (pe_json != NULL) cli_jsonstr(pe_json, "Packer", "FSG"); -#endif CLI_UNPTEMP("cli_scanpe: FSG", (dest, sections, 0)); CLI_UNPRESULTSFSG1("cli_scanpe: FSG", (unfsg_133(src + newesi - peinfo->sections[i + 1].rva, dest, ssize + peinfo->sections[i + 1].rva - newesi, dsize, sections, sectcnt, EC32(peinfo->pe_opt.opt32.ImageBase), oldep, ndesc)), 1, (dest, sections, 0)); @@ -3951,10 +3916,9 @@ int cli_scanpe(cli_ctx *ctx) cli_exe_info_destroy(peinfo); CLI_UNPTEMP("cli_scanpe: UPX/FSG", (dest, 0)); -#if HAVE_JSON + if (pe_json != NULL) cli_jsonstr(pe_json, "Packer", "UPX"); -#endif if ((unsigned int)write(ndesc, dest, dsize) != dsize) { cli_dbgmsg("cli_scanpe: UPX/FSG: Can't write %d bytes\n", dsize); @@ -4051,10 +4015,8 @@ int cli_scanpe(cli_ctx *ctx) } } -#if HAVE_JSON if (pe_json != NULL) cli_jsonstr(pe_json, "Packer", "Petite"); -#endif CLI_UNPTEMP("cli_scanpe: Petite", (dest, 0)); CLI_UNPRESULTS("Petite", (petite_inflate2x_1to9(dest, peinfo->min, peinfo->max - peinfo->min, peinfo->sections, peinfo->nsections - (found == 1 ? 1 : 0), EC32(peinfo->pe_opt.opt32.ImageBase), peinfo->vep, ndesc, found, peinfo->dirs[2].VirtualAddress, peinfo->dirs[2].Size)), 0, (dest, 0)); @@ -4086,10 +4048,8 @@ int cli_scanpe(cli_ctx *ctx) return CL_EREAD; } -#if HAVE_JSON if (pe_json != NULL) cli_jsonstr(pe_json, "Packer", "PEspin"); -#endif CLI_UNPTEMP("cli_scanpe: PESpin", (spinned, 0)); CLI_UNPRESULTS_("cli_scanpe: PEspin", SPINCASE(), (unspin(spinned, fsize, peinfo->sections, peinfo->nsections - 1, peinfo->vep, ndesc, ctx)), 0, (spinned, 0)); @@ -4155,10 +4115,8 @@ int cli_scanpe(cli_ctx *ctx) return CL_EREAD; } -#if HAVE_JSON if (pe_json != NULL) cli_jsonstr(pe_json, "Packer", "yC"); -#endif // record number of alerts before unpacking and scanning num_alerts = evidence_num_alerts(ctx->evidence); @@ -4250,10 +4208,8 @@ int cli_scanpe(cli_ctx *ctx) return CL_EREAD; } -#if HAVE_JSON if (pe_json != NULL) cli_jsonstr(pe_json, "Packer", "WWPack"); -#endif CLI_UNPTEMP("cli_scanpe: WWPack", (src, packer, 0)); CLI_UNPRESULTS("cli_scanpe: WWPack", (wwunpack((uint8_t *)src, ssize, packer, peinfo->sections, peinfo->nsections - 1, peinfo->e_lfanew, ndesc)), 0, (src, packer, 0)); @@ -4312,10 +4268,8 @@ int cli_scanpe(cli_ctx *ctx) break; } -#if HAVE_JSON if (pe_json != NULL) cli_jsonstr(pe_json, "Packer", "Aspack"); -#endif CLI_UNPTEMP("cli_scanpe: Aspack", (src, 0)); CLI_UNPRESULTS("cli_scanpe: Aspack", (unaspack((uint8_t *)src, ssize, peinfo->sections, peinfo->nsections, peinfo->vep - 1, EC32(peinfo->pe_opt.opt32.ImageBase), ndesc, aspack_ver)), 1, (src, 0)); @@ -4396,10 +4350,8 @@ int cli_scanpe(cli_ctx *ctx) eprva = eprva + 5 + cli_readint32(nbuff + 1); cli_dbgmsg("cli_scanpe: NsPack: OEP = %08x\n", eprva); -#if HAVE_JSON if (pe_json != NULL) cli_jsonstr(pe_json, "Packer", "NsPack"); -#endif CLI_UNPTEMP("cli_scanpe: NsPack", (dest, 0)); CLI_UNPRESULTS("cli_scanpe: NsPack", (unspack(src, dest, ctx, peinfo->sections[0].rva, EC32(peinfo->pe_opt.opt32.ImageBase), eprva, ndesc)), 0, (dest, 0)); @@ -4441,10 +4393,8 @@ int cli_scanpe(cli_ctx *ctx) cli_exe_info_destroy(peinfo); -#if HAVE_JSON if (cli_json_timeout_cycle_check(ctx, &toval) != CL_SUCCESS) return CL_ETIMEOUT; -#endif return CL_SUCCESS; } @@ -4537,11 +4487,9 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, size_t read; uint32_t temp; -#if HAVE_JSON int toval = 0; struct json_object *pe_json = NULL; char jsonbuf[128]; -#endif if (ctx == NULL && (opts & CLI_PEHEADER_OPT_COLLECT_JSON || @@ -4550,11 +4498,9 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, goto done; } -#if HAVE_JSON if (opts & CLI_PEHEADER_OPT_COLLECT_JSON) { pe_json = get_pe_property(ctx); } -#endif fsize = map->len - peinfo->offset; if (fmap_readn(map, &e_magic, peinfo->offset, sizeof(e_magic)) != sizeof(e_magic)) { @@ -4599,10 +4545,9 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, if (EC16(file_hdr->Characteristics) & 0x2000) { -#if HAVE_JSON if (opts & CLI_PEHEADER_OPT_COLLECT_JSON) cli_jsonstr(pe_json, "Type", "DLL"); -#endif + if (opts & CLI_PEHEADER_OPT_DBG_PRINT_INFO) { cli_dbgmsg("File type: DLL\n"); } @@ -4610,10 +4555,9 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, is_dll = 1; } else if (EC16(file_hdr->Characteristics) & 0x0002) { -#if HAVE_JSON if (opts & CLI_PEHEADER_OPT_COLLECT_JSON) cli_jsonstr(pe_json, "Type", "EXE"); -#endif + if (opts & CLI_PEHEADER_OPT_DBG_PRINT_INFO) { cli_dbgmsg("File type: Executable\n"); } @@ -4744,20 +4688,17 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, if (opts & CLI_PEHEADER_OPT_DBG_PRINT_INFO) cli_dbgmsg("Machine type: %s\n", archtype); -#if HAVE_JSON if (opts & CLI_PEHEADER_OPT_COLLECT_JSON) cli_jsonstr(pe_json, "ArchType", archtype); -#endif } peinfo->nsections = EC16(file_hdr->NumberOfSections); if (peinfo->nsections == 0) { -#if HAVE_JSON if (opts & CLI_PEHEADER_OPT_COLLECT_JSON) { pe_add_heuristic_property(ctx, "BadNumberOfSections"); } -#endif + // TODO Investigate how corrupted_input is set and whether this // check is needed if (opts & CLI_PEHEADER_OPT_DBG_PRINT_INFO && @@ -4779,14 +4720,12 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, cli_dbgmsg("SizeOfOptionalHeader: 0x%x\n", opt_hdr_size); } -#if HAVE_JSON if (opts & CLI_PEHEADER_OPT_COLLECT_JSON) { cli_jsonint(pe_json, "NumberOfSections", peinfo->nsections); /* NOTE: the TimeDateStamp value will look like "Wed Dec 31 19:00:00 1969\n" */ cli_jsonstr(pe_json, "TimeDateStamp", cli_ctime(×tamp, timestr, sizeof(timestr))); cli_jsonint(pe_json, "SizeOfOptionalHeader", opt_hdr_size); } -#endif // Ensure there are enough bytes to cover the full optional header, // not including the data directory entries (which aren't all guaranteed @@ -4794,11 +4733,10 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, if (opt_hdr_size < sizeof(struct pe_image_optional_hdr32)) { cli_dbgmsg("cli_peheader: SizeOfOptionalHeader too small\n"); -#if HAVE_JSON if (opts & CLI_PEHEADER_OPT_COLLECT_JSON) { pe_add_heuristic_property(ctx, "BadOptionalHeaderSize"); } -#endif + ret = CL_EFORMAT; goto done; } @@ -4820,11 +4758,11 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, if (opt_hdr_size < sizeof(struct pe_image_optional_hdr64)) { cli_dbgmsg("cli_peheader: Incorrect SizeOfOptionalHeader for PE32+\n"); -#if HAVE_JSON + if (opts & CLI_PEHEADER_OPT_COLLECT_JSON) { pe_add_heuristic_property(ctx, "BadOptionalHeaderSizePE32Plus"); } -#endif + ret = CL_EFORMAT; goto done; } @@ -4863,7 +4801,6 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, cli_dbgmsg("NumberOfRvaAndSizes: %u\n", peinfo->ndatadirs); } -#if HAVE_JSON if (opts & CLI_PEHEADER_OPT_COLLECT_JSON) { cli_jsonint(pe_json, "MajorLinkerVersion", opt64->MajorLinkerVersion); cli_jsonint(pe_json, "MinorLinkerVersion", opt64->MinorLinkerVersion); @@ -4892,7 +4829,6 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, snprintf(jsonbuf, sizeof(jsonbuf), "0x%x", peinfo->hdr_size); cli_jsonstr(pe_json, "SizeOfHeaders", jsonbuf); } -#endif } else { /* PE */ peinfo->is_pe32plus = 0; @@ -4918,7 +4854,6 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, cli_dbgmsg("NumberOfRvaAndSizes: %u\n", peinfo->ndatadirs); } -#if HAVE_JSON if (opts & CLI_PEHEADER_OPT_COLLECT_JSON) { cli_jsonint(pe_json, "MajorLinkerVersion", opt32->MajorLinkerVersion); cli_jsonint(pe_json, "MinorLinkerVersion", opt32->MinorLinkerVersion); @@ -4947,7 +4882,6 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, snprintf(jsonbuf, sizeof(jsonbuf), "0x%x", peinfo->hdr_size); cli_jsonstr(pe_json, "SizeOfHeaders", jsonbuf); } -#endif } salign = (peinfo->is_pe32plus && opt64 != NULL) ? EC32(opt64->SectionAlignment) : EC32(opt32->SectionAlignment); @@ -5006,10 +4940,8 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, cli_dbgmsg("------------------------------------\n"); } -#if HAVE_JSON if (opts & CLI_PEHEADER_OPT_COLLECT_JSON) cli_jsonstr(pe_json, "Subsystem", subsystem); -#endif if (!native && (!salign || (salign % 0x1000))) { cli_dbgmsg("cli_peheader: Bad section alignment\n"); @@ -5199,7 +5131,6 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, strncpy(sname, (char *)section_hdr->Name, 8); sname[8] = '\0'; -#if HAVE_JSON if (opts & CLI_PEHEADER_OPT_COLLECT_JSON) { add_section_info(ctx, &peinfo->sections[i]); @@ -5208,7 +5139,6 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, goto done; } } -#endif // TODO Why do we do this // TODO Should this be done before we dump the json @@ -5307,7 +5237,6 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, goto done; } -#if HAVE_JSON if (opts & CLI_PEHEADER_OPT_COLLECT_JSON) { cli_jsonint(pe_json, "EntryPointOffset", peinfo->ep); @@ -5316,7 +5245,6 @@ cl_error_t cli_peheader(fmap_t *map, struct cli_exe_info *peinfo, uint32_t opts, goto done; } } -#endif if (opts & CLI_PEHEADER_OPT_DBG_PRINT_INFO) { cli_dbgmsg("EntryPoint offset: 0x%x (%d)\n", peinfo->ep, peinfo->ep); diff --git a/libclamav/readdb.c b/libclamav/readdb.c index 29c4782a3b..46fb55abf9 100644 --- a/libclamav/readdb.c +++ b/libclamav/readdb.c @@ -2121,18 +2121,6 @@ static cl_error_t load_oneldb(char *buffer, int chkpua, struct cl_engine *engine goto done; } -#if !HAVE_PCRE - /* Regex Usage and Support Check */ - for (i = 0; i < subsigs; ++i) { - char *slash = strchr(tokens[i + 3], '/'); - if (slash && strchr(slash + 1, '/')) { - cli_warnmsg("cli_loadldb: logical signature for %s uses PCREs but support is disabled, skipping\n", virname); - status = CL_BREAK; - goto done; - } - } -#endif - /* enforce MAX_LDB_SUBSIGS subsig cap */ if (subsigs > MAX_LDB_SUBSIGS) { cli_errmsg("cli_loadldb: Broken logical expression or too many subsignatures\n"); @@ -4027,7 +4015,6 @@ static int load_oneyara(YR_RULE *rule, int chkpua, struct cl_engine *engine, uns free(substr); } else if (STRING_IS_REGEXP(string)) { /* TODO - rewrite to NOT use PCRE_BYPASS */ -#if HAVE_PCRE size_t length = strlen(PCRE_BYPASS) + string->length + 3; substr = calloc(length, sizeof(char)); @@ -4044,12 +4031,6 @@ static int load_oneyara(YR_RULE *rule, int chkpua, struct cl_engine *engine, uns ytable_add_string(&ytable, substr); free(substr); -#else - cli_warnmsg("cli_loadyara: %s uses PCREs but support is disabled\n", newident); - str_error++; - ret = CL_SUCCESS; - break; -#endif } else { /* TODO - extract the string length to handle NULL hex-escaped characters * For now, we'll just use the strlen we get which crudely finds the length @@ -5634,9 +5615,9 @@ cl_error_t cl_engine_free(struct cl_engine *engine) tasks_to_do += root->ac_lsigs / 1000; // every 1000 logical sigs tasks_to_do += 1; // ac lsig table } -#if HAVE_PCRE + tasks_to_do += 1; // pcre table -#endif + tasks_to_do += 1; // root mempool } } @@ -5665,9 +5646,9 @@ cl_error_t cl_engine_free(struct cl_engine *engine) tasks_to_do += root->ac_lsigs / 1000; // every 1000 logical sigs tasks_to_do += 1; // ac lsig table } -#if HAVE_PCRE + tasks_to_do += 1; // pcre table -#endif + tasks_to_do += 1; // fuzzy hashmap tasks_to_do += 1; // engine root mempool @@ -5718,10 +5699,10 @@ cl_error_t cl_engine_free(struct cl_engine *engine) MPOOL_FREE(engine->mempool, root->ac_lsigtable); TASK_COMPLETE(); } -#if HAVE_PCRE + cli_pcre_freetable(root); TASK_COMPLETE(); -#endif /* HAVE_PCRE */ + fuzzy_hash_free_hashmap(root->fuzzy_hashmap); TASK_COMPLETE(); @@ -5889,10 +5870,9 @@ cl_error_t cl_engine_free(struct cl_engine *engine) MPOOL_FREE(engine->mempool, root->ac_lsigtable); TASK_COMPLETE(); } -#if HAVE_PCRE cli_pcre_freetable(root); TASK_COMPLETE(); -#endif /* HAVE_PCRE */ + MPOOL_FREE(engine->mempool, root); TASK_COMPLETE(); } @@ -5938,9 +5918,7 @@ cl_error_t cl_engine_compile(struct cl_engine *engine) for (i = 0; i < CLI_MTARGETS; i++) { if ((root = engine->root[i])) { tasks_to_do += 1; // build ac trie -#if HAVE_PCRE tasks_to_do += 1; // compile pcre regex -#endif } } tasks_to_do += 1; // flush hdb @@ -6000,15 +5978,12 @@ cl_error_t cl_engine_compile(struct cl_engine *engine) if ((ret = cli_ac_buildtrie(root))) return ret; TASK_COMPLETE(); -#if HAVE_PCRE + if ((ret = cli_pcre_build(root, engine->pcre_match_limit, engine->pcre_recmatch_limit, engine->dconf))) return ret; TASK_COMPLETE(); cli_dbgmsg("Matcher[%u]: %s: AC sigs: %u (reloff: %u, absoff: %u) BM sigs: %u (reloff: %u, absoff: %u) PCREs: %u (reloff: %u, absoff: %u) maxpatlen %u %s\n", i, cli_mtargets[i].name, root->ac_patterns, root->ac_reloff_num, root->ac_absoff_num, root->bm_patterns, root->bm_reloff_num, root->bm_absoff_num, root->pcre_metas, root->pcre_reloff_num, root->pcre_absoff_num, root->maxpatlen, root->ac_only ? "(ac_only mode)" : ""); -#else - cli_dbgmsg("Matcher[%u]: %s: AC sigs: %u (reloff: %u, absoff: %u) BM sigs: %u (reloff: %u, absoff: %u) maxpatlen %u PCREs: 0 (disabled) %s\n", i, cli_mtargets[i].name, root->ac_patterns, root->ac_reloff_num, root->ac_absoff_num, root->bm_patterns, root->bm_reloff_num, root->bm_absoff_num, root->maxpatlen, root->ac_only ? "(ac_only mode)" : ""); -#endif } } @@ -6061,9 +6036,9 @@ cl_error_t cl_engine_compile(struct cl_engine *engine) } MPOOL_FREE(engine->mempool, root->ac_lsigtable); } -#if HAVE_PCRE + cli_pcre_freetable(root); -#endif /* HAVE_PCRE */ + MPOOL_FREE(engine->mempool, root); engine->test_root = NULL; TASK_COMPLETE(); diff --git a/libclamav/regex_pcre.c b/libclamav/regex_pcre.c index 9c0e2c0819..a7b3d944c0 100644 --- a/libclamav/regex_pcre.c +++ b/libclamav/regex_pcre.c @@ -25,19 +25,13 @@ #include "clamav-config.h" #endif -#if HAVE_PCRE -#if USING_PCRE2 #define PCRE2_CODE_UNIT_WIDTH 8 #include -#else -#include -#endif #include "clamav.h" #include "others.h" #include "regex_pcre.h" -#if USING_PCRE2 /* NOTE: pcre2 could use mpool through ext */ void *cli_pcre_malloc(size_t size, void *ext) { @@ -50,20 +44,6 @@ void cli_pcre_free(void *ptr, void *ext) UNUSEDPARAM(ext); free(ptr); } -#endif - -/* cli_pcre_init_internal: redefine pcre_malloc and pcre_free; pcre2 does this during compile */ -cl_error_t cli_pcre_init_internal() -{ -#if !USING_PCRE2 - pcre_malloc = cli_max_malloc; - pcre_free = free; - pcre_stack_malloc = cli_max_malloc; - pcre_stack_free = free; -#endif - - return CL_SUCCESS; -} cl_error_t cli_pcre_addoptions(struct cli_pcre_data *pd, const char **opt, int errout) { @@ -72,7 +52,6 @@ cl_error_t cli_pcre_addoptions(struct cli_pcre_data *pd, const char **opt, int e while (**opt != '\0') { switch (**opt) { -#if USING_PCRE2 case 'i': pd->options |= PCRE2_CASELESS; break; @@ -96,31 +75,6 @@ cl_error_t cli_pcre_addoptions(struct cli_pcre_data *pd, const char **opt, int e case 'U': pd->options |= PCRE2_UNGREEDY; break; -#else - case 'i': - pd->options |= PCRE_CASELESS; - break; - case 's': - pd->options |= PCRE_DOTALL; - break; - case 'm': - pd->options |= PCRE_MULTILINE; - break; - case 'x': - pd->options |= PCRE_EXTENDED; - break; - - /* these are pcre specific... don't work with perl */ - case 'A': - pd->options |= PCRE_ANCHORED; - break; - case 'E': - pd->options |= PCRE_DOLLAR_ENDONLY; - break; - case 'U': - pd->options |= PCRE_UNGREEDY; - break; -#endif default: if (errout) { cli_errmsg("cli_pcre_addoptions: unknown/extra pcre option encountered %c\n", **opt); @@ -134,7 +88,6 @@ cl_error_t cli_pcre_addoptions(struct cli_pcre_data *pd, const char **opt, int e return CL_SUCCESS; } -#if USING_PCRE2 cl_error_t cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_limit, long long unsigned match_limit_recursion, unsigned int options, int opt_override) { int errornum; @@ -192,78 +145,20 @@ cl_error_t cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_l pcre2_general_context_free(gctx); return CL_SUCCESS; } -#else -cl_error_t cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_limit, long long unsigned match_limit_recursion, unsigned int options, int opt_override) -{ - const char *error; - int erroffset; - - if (!pd || !pd->expression) { - cli_errmsg("cli_pcre_compile: NULL pd or NULL pd->expression\n"); - return CL_ENULLARG; - } - - /* compile the pcre regex last arg is charset, allow for options override */ - if (opt_override) - pd->re = pcre_compile(pd->expression, options, &error, &erroffset, NULL); /* pd->re handled by pcre -> call pcre_free() -> calls free() */ - else - pd->re = pcre_compile(pd->expression, pd->options, &error, &erroffset, NULL); /* pd->re handled by pcre -> call pcre_free() -> calls free() */ - if (pd->re == NULL) { - cli_errmsg("cli_pcre_compile: PCRE compilation failed at offset %d: %s\n", erroffset, error); - return CL_EMALFDB; - } - - /* now study it... (section totally not from snort) */ - pd->ex = pcre_study(pd->re, 0, &error); - if (!(pd->ex)) { - pd->ex = (pcre_extra *)calloc(1, sizeof(*(pd->ex))); - if (!(pd->ex)) { - cli_errmsg("cli_pcre_compile: Unable to allocate memory for extra data\n"); - return CL_EMEM; - } - } - - /* set the match limits */ - if (pd->ex->flags & PCRE_EXTRA_MATCH_LIMIT) { - pd->ex->match_limit = match_limit; - } else { - pd->ex->flags |= PCRE_EXTRA_MATCH_LIMIT; - pd->ex->match_limit = match_limit; - } - - /* set the recursion match limits */ -#ifdef PCRE_EXTRA_MATCH_LIMIT_RECURSION - if (pd->ex->flags & PCRE_EXTRA_MATCH_LIMIT_RECURSION) { - pd->ex->match_limit_recursion = match_limit_recursion; - } else { - pd->ex->flags |= PCRE_EXTRA_MATCH_LIMIT_RECURSION; - pd->ex->match_limit_recursion = match_limit_recursion; - } -#endif /* PCRE_EXTRA_MATCH_LIMIT_RECURSION */ - - /* non-dynamic allocated fields set by caller */ - return CL_SUCCESS; -} -#endif int cli_pcre_match(struct cli_pcre_data *pd, const unsigned char *buffer, size_t buflen, size_t override_offset, int options, struct cli_pcre_results *results) { int rc; -#if USING_PCRE2 PCRE2_SIZE *ovector; size_t startoffset; -#else - int startoffset; -#endif /* set the startoffset, override if a value is specified */ startoffset = pd->search_offset; if (override_offset != pd->search_offset) startoffset = override_offset; - /* execute the pcre and return */ -#if USING_PCRE2 + /* execute the pcre and return */ rc = pcre2_match(pd->re, buffer, buflen, startoffset, options, results->match_data, pd->mctx); if (rc < 0 && rc != PCRE2_ERROR_NOMATCH) { switch (rc) { @@ -291,33 +186,7 @@ int cli_pcre_match(struct cli_pcre_data *pd, const unsigned char *buffer, size_t } else { results->match[0] = results->match[1] = 0; } -#else - rc = pcre_exec(pd->re, pd->ex, (const char *)buffer, (int)buflen, (int)startoffset, options, results->ovector, OVECCOUNT); - if (rc < 0 && rc != PCRE_ERROR_NOMATCH) { - switch (rc) { - case PCRE_ERROR_CALLOUT: - break; - case PCRE_ERROR_NOMEMORY: - cli_errmsg("cli_pcre_match: pcre_exec: out of memory\n"); - results->err = CL_EMEM; - break; - case PCRE_ERROR_MATCHLIMIT: - cli_dbgmsg("cli_pcre_match: pcre_exec: match limit exceeded\n"); - break; - case PCRE_ERROR_RECURSIONLIMIT: - cli_dbgmsg("cli_pcre_match: pcre_exec: recursive limit exceeded\n"); - break; - default: - cli_errmsg("cli_pcre_match: pcre_exec: returned error %d\n", rc); - results->err = CL_BREAK; - } - } else if (rc > 0) { - results->match[0] = results->ovector[0]; - results->match[1] = results->ovector[1]; - } else { - results->match[0] = results->match[1] = 0; - } -#endif + return rc; } @@ -325,19 +194,11 @@ int cli_pcre_match(struct cli_pcre_data *pd, const unsigned char *buffer, size_t #define MATCH_MAXLEN 1028 /*because lolz*/ /* TODO: audit this function */ -#if USING_PCRE2 static void named_substr_print(const struct cli_pcre_data *pd, const unsigned char *buffer, PCRE2_SIZE *ovector) -#else -static void named_substr_print(const struct cli_pcre_data *pd, const unsigned char *buffer, int *ovector) -#endif { int i, namecount, trunc; -#if USING_PCRE2 PCRE2_SIZE length, j; -#else - int length, j; -#endif unsigned char *tabptr; int name_entry_size; @@ -346,24 +207,16 @@ static void named_substr_print(const struct cli_pcre_data *pd, const unsigned ch char outstr[2 * MATCH_MAXLEN + 1]; /* determine if there are named substrings */ -#if USING_PCRE2 (void)pcre2_pattern_info(pd->re, PCRE2_INFO_NAMECOUNT, &namecount); -#else - (void)pcre_fullinfo(pd->re, pd->ex, PCRE_INFO_NAMECOUNT, &namecount); -#endif + if (namecount <= 0) { cli_dbgmsg("cli_pcre_report: no named substrings\n"); } else { cli_dbgmsg("cli_pcre_report: named substrings\n"); /* extract named substring translation table */ -#if USING_PCRE2 (void)pcre2_pattern_info(pd->re, PCRE2_INFO_NAMETABLE, &name_table); (void)pcre2_pattern_info(pd->re, PCRE2_INFO_NAMEENTRYSIZE, &name_entry_size); -#else - (void)pcre_fullinfo(pd->re, pd->ex, PCRE_INFO_NAMETABLE, &name_table); - (void)pcre_fullinfo(pd->re, pd->ex, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size); -#endif /* print named substring information */ tabptr = name_table; @@ -398,42 +251,27 @@ void cli_pcre_report(const struct cli_pcre_data *pd, const unsigned char *buffer { int i, trunc; -#if USING_PCRE2 PCRE2_SIZE length, j; -#else - int length, j; -#endif const char *start; char outstr[2 * MATCH_MAXLEN + 1]; -#if USING_PCRE2 PCRE2_SIZE *ovector; ovector = pcre2_get_ovector_pointer(results->match_data); -#else - int *ovector = results->ovector; -#endif /* print out additional diagnostics if cli_debug_flag is set */ if (!DISABLE_PCRE_REPORT) { cli_dbgmsg("\n"); -#if USING_PCRE2 cli_dbgmsg("cli_pcre_report: PCRE2 Execution Report:\n"); -#else - cli_dbgmsg("cli_pcre_report: PCRE Execution Report:\n"); -#endif cli_dbgmsg("cli_pcre_report: running regex /%s/ returns %d\n", pd->expression, rc); + if (rc > 0) { /* print out full-match and capture groups */ for (i = 0; i < rc; ++i) { start = (const char *)buffer + ovector[2 * i]; length = ovector[2 * i + 1] - ovector[2 * i]; -#ifdef USING_PCRE2 if (ovector[2 * i + 1] > buflen) { -#else - if (ovector[2 * i + 1] > (int)buflen) { -#endif cli_warnmsg("cli_pcre_report: reported match goes outside buffer\n"); continue; } @@ -452,12 +290,7 @@ void cli_pcre_report(const struct cli_pcre_data *pd, const unsigned char *buffer } named_substr_print(pd, buffer, ovector); - } -#if USING_PCRE2 - else if (rc == 0 || rc == PCRE2_ERROR_NOMATCH) { -#else - else if (rc == 0 || rc == PCRE_ERROR_NOMATCH) { -#endif + } else if (rc == 0 || rc == PCRE2_ERROR_NOMATCH) { cli_dbgmsg("cli_pcre_report: no match found\n"); } else { cli_dbgmsg("cli_pcre_report: error occurred in pcre_match: %d\n", rc); @@ -472,30 +305,25 @@ cl_error_t cli_pcre_results_reset(struct cli_pcre_results *results, const struct { results->err = CL_SUCCESS; results->match[0] = results->match[1] = 0; -#if USING_PCRE2 + if (results->match_data) pcre2_match_data_free(results->match_data); results->match_data = pcre2_match_data_create_from_pattern(pd->re, NULL); if (!results->match_data) return CL_EMEM; -#else - memset(results->ovector, 0, OVECCOUNT); -#endif + return CL_SUCCESS; } void cli_pcre_results_free(struct cli_pcre_results *results) { -#if USING_PCRE2 if (results->match_data) pcre2_match_data_free(results->match_data); -#endif } void cli_pcre_free_single(struct cli_pcre_data *pd) { -#if USING_PCRE2 if (pd->re) { pcre2_code_free(pd->re); pd->re = NULL; @@ -505,19 +333,9 @@ void cli_pcre_free_single(struct cli_pcre_data *pd) pcre2_match_context_free(pd->mctx); pd->mctx = NULL; } -#else - if (pd->re) { - pcre_free(pd->re); - pd->re = NULL; - } - if (pd->ex) { - free(pd->ex); - pd->ex = NULL; - } -#endif + if (pd->expression) { free(pd->expression); pd->expression = NULL; } } -#endif /* HAVE_PCRE */ diff --git a/libclamav/regex_pcre.h b/libclamav/regex_pcre.h index 5a0f0f6295..4f3549b5ed 100644 --- a/libclamav/regex_pcre.h +++ b/libclamav/regex_pcre.h @@ -27,14 +27,9 @@ #if HAVE_CONFIG_H #include "clamav-config.h" #endif -#if HAVE_PCRE -#if USING_PCRE2 #define PCRE2_CODE_UNIT_WIDTH 8 #include -#else -#include -#endif #include "clamav-types.h" #include "mpool.h" @@ -44,7 +39,6 @@ /* must be multiple of 3 */ #define OVECCOUNT 300 -#if USING_PCRE2 struct cli_pcre_data { pcre2_code *re; /* compiled pcre regex */ pcre2_match_context *mctx; /* match context */ @@ -59,22 +53,6 @@ struct cli_pcre_results { pcre2_match_data *match_data; }; -#else -struct cli_pcre_data { - pcre *re; /* compiled pcre regex */ - pcre_extra *ex; /* pcre extra data - limits */ - int options; /* pcre options */ - char *expression; /* copied regular expression */ - uint32_t search_offset; /* start offset to search at for pcre_exec */ -}; - -struct cli_pcre_results { - cl_error_t err; - uint32_t match[2]; /* populated by cli_pcre_match to be start (0) and end (1) offset of match */ - - int ovector[OVECCOUNT]; -}; -#endif cl_error_t cli_pcre_init_internal(void); cl_error_t cli_pcre_addoptions(struct cli_pcre_data *pd, const char **opt, int errout); @@ -97,5 +75,5 @@ void cli_pcre_report(const struct cli_pcre_data *pd, const unsigned char *buffer cl_error_t cli_pcre_results_reset(struct cli_pcre_results *results, const struct cli_pcre_data *pd); void cli_pcre_results_free(struct cli_pcre_results *results); void cli_pcre_free_single(struct cli_pcre_data *pd); -#endif /* HAVE_PCRE */ + #endif /*_REGEX_PCRE_H_*/ diff --git a/libclamav/scanners.c b/libclamav/scanners.c index 34544323b3..832f0dc670 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) { @@ -1659,7 +1647,6 @@ static cl_error_t cli_ole2_tempdir_scan_vba_new(const char *dir, cli_ctx *ctx, s continue; } -#if HAVE_JSON if (*has_macros && SCAN_COLLECT_METADATA && (ctx->wrkproperty != NULL)) { cli_jsonbool(ctx->wrkproperty, "HasMacros", 1); json_object *macro_languages = cli_jsonarray(ctx->wrkproperty, "MacroLanguages"); @@ -1669,7 +1656,7 @@ static cl_error_t cli_ole2_tempdir_scan_vba_new(const char *dir, cli_ctx *ctx, s cli_dbgmsg("[cli_ole2_tempdir_scan_vba_new] Failed to add \"VBA\" entry to MacroLanguages JSON array\n"); } } -#endif + if (SCAN_HEURISTIC_MACROS && *has_macros) { ret = cli_append_potentially_unwanted(ctx, "Heuristics.OLE2.ContainsMacros.VBA"); if (ret == CL_VIRUS) { @@ -1739,7 +1726,6 @@ static cl_error_t cli_ole2_tempdir_scan_summary(const char *dir, cli_ctx *ctx, s char *hash; uint32_t hashcnt = 0; -#if HAVE_JSON if (CL_SUCCESS != (ret = uniq_get(U, "_5_summaryinformation", 21, &hash, &hashcnt))) { cli_dbgmsg("cli_ole2_tempdir_scan_summary: uniq_get('_5_summaryinformation') failed with ret code (%d)!\n", ret); status = ret; @@ -1781,7 +1767,6 @@ static cl_error_t cli_ole2_tempdir_scan_summary(const char *dir, cli_ctx *ctx, s } hashcnt--; } -#endif done: @@ -2022,7 +2007,6 @@ static cl_error_t cli_ole2_tempdir_scan_vba(const char *dir, cli_ctx *ctx, struc done: if (*has_macros) { -#if HAVE_JSON if (SCAN_COLLECT_METADATA && (ctx->wrkproperty != NULL)) { cli_jsonbool(ctx->wrkproperty, "HasMacros", 1); json_object *macro_languages = cli_jsonarray(ctx->wrkproperty, "MacroLanguages"); @@ -2032,7 +2016,6 @@ static cl_error_t cli_ole2_tempdir_scan_vba(const char *dir, cli_ctx *ctx, struc cli_dbgmsg("cli_ole2_tempdir_scan_vba: Failed to add \"VBA\" entry to MacroLanguages JSON array\n"); } } -#endif if (SCAN_HEURISTIC_MACROS) { ret = cli_append_potentially_unwanted(ctx, "Heuristics.OLE2.ContainsMacros.VBA"); @@ -3289,11 +3272,7 @@ static cl_error_t scanraw(cli_ctx *ctx, cli_file_t type, uint8_t typercg, cli_fi cli_file_t found_type; -#if HAVE_JSON struct json_object *parent_property = NULL; -#else - void *parent_property = NULL; -#endif if ((typercg) && // We should also omit bzips, but DMG's may be detected in bzips. (type != CL_TYPE_BZ) && /* Omit BZ files because they can contain portions of original files like zip file entries that cause invalid extractions and lots of warnings. Decompress first, then scan! */ @@ -3332,7 +3311,6 @@ static cl_error_t scanraw(cli_ctx *ctx, cli_file_t type, uint8_t typercg, cli_fi if (fpt->offset > 0) { bool type_has_been_handled = true; -#if HAVE_JSON /* * Add embedded file to metadata JSON. */ @@ -3371,7 +3349,7 @@ static cl_error_t scanraw(cli_ctx *ctx, cli_file_t type, uint8_t typercg, cli_fi break; } } -#endif + /* * First, use "embedded type recognition" to identify a file's actual type. * (a.k.a. not embedded files, but file type detection corrections) @@ -3886,12 +3864,10 @@ static cl_error_t scanraw(cli_ctx *ctx, cli_file_t type, uint8_t typercg, cli_fi fpt = fpt->next; -#if HAVE_JSON if (NULL != parent_property) { ctx->wrkproperty = (struct json_object *)(parent_property); parent_property = NULL; } -#endif } // end while (fpt) loop if (!((nret == CL_EMEM) || (ctx->abort_scan))) { @@ -3931,11 +3907,9 @@ static cl_error_t scanraw(cli_ctx *ctx, cli_file_t type, uint8_t typercg, cli_fi ret = nret; } // end if (ret >= CL_TYPENO) -#if HAVE_JSON if (NULL != parent_property) { ctx->wrkproperty = (struct json_object *)(parent_property); } -#endif while (ftoffset) { fpt = ftoffset; @@ -4248,11 +4222,7 @@ cl_error_t cli_magic_scan(cli_ctx *ctx, cli_file_t type) bitset_t *old_hook_lsig_matches = NULL; const char *filetype; -#if HAVE_JSON struct json_object *parent_property = NULL; -#else - void *parent_property = NULL; -#endif char *old_temp_path = NULL; char *new_temp_path = NULL; @@ -4344,7 +4314,6 @@ cl_error_t cli_magic_scan(cli_ctx *ctx, cli_file_t type) /* set current layer to the type we found */ cli_recursion_stack_change_type(ctx, type); -#if HAVE_JSON if (SCAN_COLLECT_METADATA) { /* * Create JSON object to record metadata during the scan. @@ -4419,7 +4388,6 @@ cl_error_t cli_magic_scan(cli_ctx *ctx, cli_file_t type) goto early_ret; } } -#endif /* * Run the pre_scan callback. @@ -4459,7 +4427,6 @@ cl_error_t cli_magic_scan(cli_ctx *ctx, cli_file_t type) cache_check_result = clean_cache_check(hash, hashed_size, ctx); perf_stop(ctx, PERFT_CACHE); -#if HAVE_JSON if (SCAN_COLLECT_METADATA) { char hashstr[CLI_HASHLEN_MD5 * 2 + 1]; snprintf(hashstr, CLI_HASHLEN_MD5 * 2 + 1, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", @@ -4475,7 +4442,6 @@ cl_error_t cli_magic_scan(cli_ctx *ctx, cli_file_t type) goto early_ret; } } -#endif if (cache_check_result != CL_VIRUS) { cli_dbgmsg("cli_magic_scan: returning %d %s (no post, no cache)\n", ret, __AT__); @@ -4594,7 +4560,6 @@ cl_error_t cli_magic_scan(cli_ctx *ctx, cli_file_t type) case CL_TYPE_OOXML_PPT: case CL_TYPE_OOXML_XL: case CL_TYPE_OOXML_HWP: -#if HAVE_JSON if (SCAN_PARSE_XMLDOCS && (DCONF_DOC & DOC_CONF_OOXML)) { if (SCAN_COLLECT_METADATA && (ctx->wrkproperty != NULL)) { ret = cli_process_ooxml(ctx, type); @@ -4613,7 +4578,6 @@ cl_error_t cli_magic_scan(cli_ctx *ctx, cli_file_t type) } } } -#endif /* fall-through */ case CL_TYPE_ZIP: if (SCAN_PARSE_ARCHIVE && (DCONF_ARCH & ARCH_CONF_ZIP)) @@ -5040,9 +5004,7 @@ cl_error_t cli_magic_scan(cli_ctx *ctx, cli_file_t type) ctx->hook_lsig_matches = old_hook_lsig_matches; } -#if HAVE_JSON ctx->wrkproperty = (struct json_object *)(parent_property); -#endif /* * Determine if there was an alert for this layer (or its children). @@ -5118,11 +5080,9 @@ cl_error_t cli_magic_scan(cli_ctx *ctx, cli_file_t type) ctx->sub_tmpdir = old_temp_path; } -#if HAVE_JSON if (NULL != parent_property) { ctx->wrkproperty = (struct json_object *)(parent_property); } -#endif return ret; } @@ -5525,7 +5485,6 @@ static cl_error_t scan_common(cl_fmap_t *map, const char *filepath, const char * status = cli_magic_scan(&ctx, CL_TYPE_ANY); -#if HAVE_JSON if (ctx.options->general & CL_SCAN_GENERAL_COLLECT_METADATA && (ctx.properties != NULL)) { json_object *jobj; const char *jstring; @@ -5573,11 +5532,7 @@ static cl_error_t scan_common(cl_fmap_t *map, const char *filepath, const char * } /* backwards compatibility: scan the json string unless a virus was detected */ - if (status != CL_VIRUS && (iroot->ac_lsigs || iroot->ac_patterns -#ifdef HAVE_PCRE - || iroot->pcre_metas -#endif // HAVE_PCRE - )) { + if (status != CL_VIRUS && (iroot->ac_lsigs || iroot->ac_patterns || iroot->pcre_metas)) { cli_dbgmsg("scan_common: running deprecated preclass bytecodes for target type 13\n"); ctx.options->general &= ~CL_SCAN_GENERAL_COLLECT_METADATA; status = cli_magic_scan_buff(jstring, strlen(jstring), &ctx, NULL, LAYER_ATTRIBUTES_NONE); @@ -5618,7 +5573,6 @@ static cl_error_t scan_common(cl_fmap_t *map, const char *filepath, const char * } } } -#endif // HAVE_JSON // If any alerts occurred, set the output pointer to the "latest" alert signature name. if (0 < evidence_num_alerts(ctx.evidence)) { diff --git a/libclamav/unzip.c b/libclamav/unzip.c index 74fe0c120e..93be93fb6d 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: @@ -1181,9 +1175,7 @@ cl_error_t cli_unzip(cli_ctx *ctx) fmap_t *map = ctx->fmap; char *tmpd = NULL; const char *ptr; -#if HAVE_JSON - int toval = 0; -#endif + int toval = 0; struct zip_record *zip_catalogue = NULL; size_t records_count = 0; size_t i; @@ -1294,11 +1286,10 @@ cl_error_t cli_unzip(cli_ctx *ctx) goto done; } -#if HAVE_JSON if (cli_json_timeout_cycle_check(ctx, &toval) != CL_SUCCESS) { ret = CL_ETIMEOUT; } -#endif + if (ret != CL_SUCCESS) { break; } @@ -1343,11 +1334,10 @@ cl_error_t cli_unzip(cli_ctx *ctx) cli_append_potentially_unwanted_if_heur_exceedsmax(ctx, "Heuristics.Limits.Exceeded.MaxFiles"); ret = CL_EMAXFILES; } -#if HAVE_JSON + if (cli_json_timeout_cycle_check(ctx, &toval) != CL_SUCCESS) { ret = CL_ETIMEOUT; } -#endif } } @@ -1444,9 +1434,8 @@ cl_error_t unzip_search(cli_ctx *ctx, fmap_t *map, struct zip_requests *requests uint32_t coff = 0; const char *ptr; cl_error_t ret = CL_CLEAN; -#if HAVE_JSON uint32_t toval = 0; -#endif + cli_dbgmsg("in unzip_search\n"); if ((!ctx && !map) || !requests) { @@ -1501,11 +1490,10 @@ cl_error_t unzip_search(cli_ctx *ctx, fmap_t *map, struct zip_requests *requests cli_append_potentially_unwanted_if_heur_exceedsmax(ctx, "Heuristics.Limits.Exceeded.MaxFiles"); ret = CL_EMAXFILES; } -#if HAVE_JSON + if (ctx && cli_json_timeout_cycle_check(ctx, (int *)(&toval)) != CL_SUCCESS) { ret = CL_ETIMEOUT; } -#endif } } else { cli_dbgmsg("unzip_search: cannot locate central directory\n"); diff --git a/libclamav/vba_extract.c b/libclamav/vba_extract.c index c810c3d8c4..88b2daa1c3 100644 --- a/libclamav/vba_extract.c +++ b/libclamav/vba_extract.c @@ -35,9 +35,7 @@ #include #include -#ifdef HAVE_JSON #include -#endif #include "clamav.h" diff --git a/libclamav/xar.c b/libclamav/xar.c index 7d195ab098..12f911551e 100644 --- a/libclamav/xar.c +++ b/libclamav/xar.c @@ -27,7 +27,6 @@ #include "xar.h" #include "fmap.h" -#if HAVE_LIBXML2 #include #include "clamav.h" #include "str.h" @@ -409,8 +408,6 @@ static int xar_hash_check(int hash, const void *result, const void *expected) return memcmp(result, expected, len); } -#endif - /* cli_scanxar - scan an xar archive. Parameters: @@ -423,7 +420,7 @@ int cli_scanxar(cli_ctx *ctx) int rc = CL_SUCCESS; unsigned int cksum_fails = 0; unsigned int extract_errors = 0; -#if HAVE_LIBXML2 + int fd = -1; struct xar_header hdr; fmap_t *map = ctx->fmap; @@ -878,9 +875,7 @@ int cli_scanxar(cli_ctx *ctx) free(toc); if (rc == CL_BREAK) rc = CL_SUCCESS; -#else - cli_dbgmsg("cli_scanxar: can't scan xar files, need libxml2.\n"); -#endif + if (cksum_fails + extract_errors != 0) { cli_dbgmsg("cli_scanxar: %u checksum errors and %u extraction errors.\n", cksum_fails, extract_errors); diff --git a/libclamav/xdp.c b/libclamav/xdp.c index 97eeecfc35..11bbcac14d 100644 --- a/libclamav/xdp.c +++ b/libclamav/xdp.c @@ -42,11 +42,12 @@ #include #endif #include + #include "xar.h" #include "fmap.h" -#if HAVE_LIBXML2 + #include -#endif + #include "clamav.h" #include "str.h" #include "scanners.h" @@ -91,7 +92,6 @@ static char *dump_xdp(cli_ctx *ctx, const char *start, size_t sz) cl_error_t cli_scanxdp(cli_ctx *ctx) { -#if HAVE_LIBXML2 xmlTextReaderPtr reader = NULL; const char *buf; const xmlChar *name, *value; @@ -174,7 +174,4 @@ cl_error_t cli_scanxdp(cli_ctx *ctx) xmlFreeTextReader(reader); return rc; -#else - return CL_SUCCESS; -#endif } diff --git a/libfreshclam/libfreshclam.c b/libfreshclam/libfreshclam.c index 6358bd2ccd..400f44694c 100644 --- a/libfreshclam/libfreshclam.c +++ b/libfreshclam/libfreshclam.c @@ -932,7 +932,6 @@ fc_error_t fc_download_url_database( logg(LOGG_INFO, " https://github.com/Cisco-Talos/clamav/issues\n"); logg(LOGG_INFO, " and we will investigate why your network is blocked.\n"); if (0 != g_lastRay[0]) { - size_t i; logg(LOGG_INFO, " Please provide the following cf-ray id with your ticket: %s\n", g_lastRay); logg(LOGG_INFO, "\n"); } diff --git a/sigtool/sigtool.c b/sigtool/sigtool.c index c3720740f6..8e36a4684b 100644 --- a/sigtool/sigtool.c +++ b/sigtool/sigtool.c @@ -2795,12 +2795,8 @@ static int decodehex(const char *hexsig) free(regex); if (cflags) free(cflags); -#if HAVE_PCRE + return 0; -#else - mprintf(LOGG_ERROR, "PCRE subsig cannot be loaded without PCRE support\n"); - return -1; -#endif } else if (strchr(hexsig, '{') || strchr(hexsig, '[')) { if (!(hexcpy = strdup(hexsig))) return -1; diff --git a/unit_tests/check_clamav.c b/unit_tests/check_clamav.c index 1e341e7ddd..1d55f1763c 100644 --- a/unit_tests/check_clamav.c +++ b/unit_tests/check_clamav.c @@ -15,9 +15,7 @@ #include #endif -#if HAVE_LIBXML2 #include -#endif #include "platform.h" @@ -545,18 +543,6 @@ static unsigned skip_files(void) skipped += 2; } - /* skip .bz2 files if bzip is disabled */ -#if HAVE_BZLIB_H -#else - skipped += 2; -#endif - - /* skip [placeholder] files if xml is disabled */ -#if HAVE_LIBXML2 -#else - skipped += 0; -#endif - #if HAVE_UNRAR #else skipped += 2; @@ -2070,9 +2056,7 @@ int main(int argc, char **argv) printf("NOTICE: Use the 'T' environment variable to adjust testcase timeout\n"); srunner_free(sr); -#if HAVE_LIBXML2 xmlCleanupParser(); -#endif return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/unit_tests/check_matchers.c b/unit_tests/check_matchers.c index ec27cceb9d..d615bd3eeb 100644 --- a/unit_tests/check_matchers.c +++ b/unit_tests/check_matchers.c @@ -125,8 +125,6 @@ static const struct ac_sigopts_testdata_s { {NULL, 0, NULL, NULL, ACPATT_OPTION_NOOPTS, NULL, CL_CLEAN}}; -#if HAVE_PCRE - static const struct pcre_testdata_s { const char *data; const char *hexsig; @@ -152,8 +150,6 @@ static const struct pcre_testdata_s { {NULL, NULL, NULL, ACPATT_OPTION_NOOPTS, NULL, CL_CLEAN}}; -#endif /* HAVE_PCRE */ - static cli_ctx ctx; static struct cl_scan_options options; @@ -456,8 +452,6 @@ START_TEST(test_bm_scanbuff_allscan) } END_TEST -#if HAVE_PCRE - START_TEST(test_pcre_scanbuff) { struct cli_ac_data mdata; @@ -472,9 +466,6 @@ START_TEST(test_pcre_scanbuff) #ifdef USE_MPOOL root->mempool = mpool_create(); #endif - ret = cli_pcre_init(); - ck_assert_msg(ret == CL_SUCCESS, "[pcre] cli_pcre_init() failed"); - for (i = 0; pcre_testdata[i].data; i++) { hexlen = strlen(PCRE_BYPASS) + strlen(pcre_testdata[i].hexsig) + 1; @@ -526,8 +517,6 @@ START_TEST(test_pcre_scanbuff_allscan) #ifdef USE_MPOOL root->mempool = mpool_create(); #endif - ret = cli_pcre_init(); - ck_assert_msg(ret == CL_SUCCESS, "[pcre] cli_pcre_init() failed"); for (i = 0; pcre_testdata[i].data; i++) { hexlen = strlen(PCRE_BYPASS) + strlen(pcre_testdata[i].hexsig) + 1; @@ -581,8 +570,6 @@ START_TEST(test_pcre_scanbuff_allscan) } END_TEST -#endif /* HAVE_PCRE */ - Suite *test_matchers_suite(void) { Suite *s = suite_create("matchers"); @@ -593,14 +580,10 @@ Suite *test_matchers_suite(void) tcase_add_test(tc_matchers, test_ac_scanbuff); tcase_add_test(tc_matchers, test_ac_scanbuff_ex); tcase_add_test(tc_matchers, test_bm_scanbuff); -#if HAVE_PCRE tcase_add_test(tc_matchers, test_pcre_scanbuff); -#endif tcase_add_test(tc_matchers, test_ac_scanbuff_allscan); tcase_add_test(tc_matchers, test_ac_scanbuff_allscan_ex); tcase_add_test(tc_matchers, test_bm_scanbuff_allscan); -#if HAVE_PCRE tcase_add_test(tc_matchers, test_pcre_scanbuff_allscan); -#endif return s; }