Remove libxml2 dead code

As of ClamAV 0.105, libxml2 is required.
There is also no option to disable PCRE support.

This commit removes the dead code associated with the old build
option.
pull/1241/head
Micah Snyder 1 year ago committed by Micah Snyder
parent a729aafc38
commit 71ff5c579c
  1. 3
      CMakeLists.txt
  2. 3
      clamav-config.h.cmake.in
  3. 3
      clamconf/clamconf.c
  4. 17
      libclamav/dmg.c
  5. 11
      libclamav/hwp.c
  6. 23
      libclamav/mbox.c
  7. 10
      libclamav/msxml.c
  8. 3
      libclamav/msxml_parser.c
  9. 4
      libclamav/msxml_parser.h
  10. 11
      libclamav/ooxml.c
  11. 8
      libclamav/openioc.c
  12. 6
      libclamav/others.c
  13. 2
      libclamav/others.h
  14. 9
      libclamav/xar.c
  15. 9
      libclamav/xdp.c
  16. 1
      libfreshclam/libfreshclam.c
  17. 10
      unit_tests/check_clamav.c

@ -477,9 +477,6 @@ 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})

@ -196,9 +196,6 @@
/* 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

@ -466,9 +466,6 @@ int main(int argc, char **argv)
printf("BZIP2 ");
#endif
#ifdef HAVE_LIBXML2
printf("LIBXML2 ");
#endif
#ifdef HAVE_ICONV
printf("ICONV ");
#endif

@ -46,9 +46,7 @@
#endif
#endif
#if HAVE_LIBXML2
#include <libxml/xmlreader.h>
#endif
#include "clamav.h"
#include "others.h"
@ -85,9 +83,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 +100,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 +198,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 +425,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 +450,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 +519,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)

@ -23,10 +23,7 @@
#include "clamav-config.h"
#endif
#if HAVE_LIBXML2
#include <libxml/xmlreader.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@ -1928,7 +1925,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 +2098,11 @@ hwpml_end:
}
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;
@ -2137,11 +2131,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;
}

@ -77,12 +77,10 @@
#include "json_api.h"
#include "msxml_parser.h"
#if HAVE_LIBXML2
#include <libxml/xmlversion.h>
#include <libxml/HTMLtree.h>
#include <libxml/HTMLparser.h>
#include <libxml/xmlreader.h>
#endif
#define DCONF_PHISHING mctx->ctx->dconf->phishing
@ -1402,7 +1400,6 @@ done:
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 +1432,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 +1443,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;
@ -1483,15 +1478,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 +1491,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;
@ -1608,14 +1593,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 */
}
/*

@ -35,7 +35,6 @@
#include "msxml.h"
#include "msxml_parser.h"
#if HAVE_LIBXML2
#include <libxml/xmlreader.h>
#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;
@ -255,11 +252,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
}

@ -35,7 +35,6 @@
#include "json_api.h"
#include "msxml_parser.h"
#if HAVE_LIBXML2
#include <libxml/xmlreader.h>
#define MSXML_VERBIOSE 0
@ -664,5 +663,3 @@ cl_error_t cli_msxml_parse_document(cli_ctx *ctx, xmlTextReaderPtr reader, const
return ret;
}
#endif /* HAVE_LIBXML2 */

@ -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 */

@ -27,9 +27,7 @@
#include "json.h"
#endif
#if HAVE_LIBXML2
#include <libxml/xmlreader.h>
#endif
#include "clamav.h"
#include "filetypes.h"
@ -39,7 +37,7 @@
#include "msxml_parser.h"
#include "ooxml.h"
#if HAVE_LIBXML2 && HAVE_JSON
#if HAVE_JSON
// clang-format off
@ -386,7 +384,7 @@ static cl_error_t ooxml_hwp_cb(int fd, const char *filepath, cli_ctx *ctx, const
return ret;
}
#endif /* HAVE_LIBXML2 && HAVE_JSON */
#endif /* HAVE_JSON */
cli_file_t cli_ooxml_filetype(cli_ctx *ctx, fmap_t *map)
{
@ -428,7 +426,7 @@ 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
#if HAVE_JSON
uint32_t loff = 0;
cl_error_t ret = CL_SUCCESS;
@ -488,9 +486,6 @@ cl_error_t cli_process_ooxml(cli_ctx *ctx, int type)
#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

@ -34,7 +34,6 @@
#include "others.h"
#include "openioc.h"
#ifdef HAVE_LIBXML2
#include <libxml/xmlreader.h>
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

@ -58,9 +58,7 @@
#include <pthread.h>
#endif
#ifdef HAVE_LIBXML2
#include <libxml/parser.h>
#endif
#ifndef _WIN32
#include <dlfcn.h>
@ -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;
}

@ -60,9 +60,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

@ -27,7 +27,6 @@
#include "xar.h"
#include "fmap.h"
#if HAVE_LIBXML2
#include <libxml/xmlreader.h>
#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 @@ exit_toc:
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);

@ -42,11 +42,12 @@
#include <unistd.h>
#endif
#include <errno.h>
#include "xar.h"
#include "fmap.h"
#if HAVE_LIBXML2
#include <libxml/xmlreader.h>
#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
}

@ -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");
}

@ -15,9 +15,7 @@
#include <sys/mman.h>
#endif
#if HAVE_LIBXML2
#include <libxml/parser.h>
#endif
#include "platform.h"
@ -551,12 +549,6 @@ static unsigned skip_files(void)
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 +2062,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;
}

Loading…
Cancel
Save