diff options
author | Haibo Huang <hhb@google.com> | 2021-02-25 01:53:32 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-02-25 01:53:32 +0000 |
commit | 535169300fb4cc18e3858790ad27ecf1da36a114 (patch) | |
tree | 88d5b4ca5dee4aa18ac4e2376334dcde471370d7 | |
parent | 08e833e9066a090ebf42a3c0cc7ec2e494a0aef2 (diff) | |
parent | d015330e25f95212f64203ba003776dbc6f45657 (diff) | |
download | libxml2-535169300fb4cc18e3858790ad27ecf1da36a114.tar.gz |
Merge "Upgrade libxml2 to ce2fbaa89da627a6c6cd6344d5339a76feba94b5" am: ef24f15415 am: c92b3ec2db am: 2daea33a69 am: d015330e25
Original change: https://android-review.googlesource.com/c/platform/external/libxml2/+/1604821
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: If686a987fd138c21f350082d203de8a85c3372d4
-rw-r--r-- | .gitlab-ci.yml | 41 | ||||
-rw-r--r-- | CMakeLists.txt | 36 | ||||
-rw-r--r-- | HTMLparser.c | 18 | ||||
-rw-r--r-- | METADATA | 9 | ||||
-rw-r--r-- | encoding.c | 5 | ||||
-rw-r--r-- | fuzz/fuzz.h | 21 | ||||
-rw-r--r-- | fuzz/genSeed.c | 26 | ||||
-rw-r--r-- | fuzz/html.c | 5 | ||||
-rw-r--r-- | fuzz/html.dict | 13 | ||||
-rw-r--r-- | fuzz/regexp.c | 1 | ||||
-rw-r--r-- | fuzz/schema.c | 5 | ||||
-rw-r--r-- | fuzz/testFuzzer.c | 98 | ||||
-rw-r--r-- | fuzz/xml.c | 5 | ||||
-rw-r--r-- | fuzz/xml.dict | 13 | ||||
-rw-r--r-- | fuzz/xpath.c | 1 | ||||
-rw-r--r-- | libxml.m4 | 12 | ||||
-rw-r--r-- | parserInternals.c | 5 | ||||
-rw-r--r-- | xmllint.c | 25 |
18 files changed, 269 insertions, 70 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fd2ac6e3..e58ebd00 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,6 +30,8 @@ gcc: gcc:python3: extends: .test + only: + - schedules variables: CONFIG: "--with-python=/usr/bin/python3" CFLAGS: "-O2" @@ -46,6 +48,8 @@ clang:asan: clang:msan: extends: .test + only: + - schedules variables: CONFIG: "--without-python --without-zlib --without-lzma" CC: clang @@ -70,6 +74,8 @@ clang:msan: cmake:linux:gcc:shared: extends: .cmake:linux + only: + - schedules variables: BUILD_SHARED_LIBS: "ON" CC: gcc @@ -77,6 +83,8 @@ cmake:linux:gcc:shared: cmake:linux:gcc:static: extends: .cmake:linux + only: + - schedules variables: BUILD_SHARED_LIBS: "OFF" CC: gcc @@ -84,6 +92,8 @@ cmake:linux:gcc:static: cmake:linux:clang:shared: extends: .cmake:linux + only: + - schedules variables: BUILD_SHARED_LIBS: "ON" CC: clang @@ -91,6 +101,8 @@ cmake:linux:clang:shared: cmake:linux:clang:static: extends: .cmake:linux + only: + - schedules variables: BUILD_SHARED_LIBS: "OFF" CC: clang @@ -140,6 +152,8 @@ cmake:linux:clang:static: cmake:mingw:w64-i686:shared: extends: .cmake:mingw + only: + - schedules variables: BUILD_SHARED_LIBS: "ON" MINGW_PACKAGE_PREFIX: mingw-w64-i686 @@ -148,6 +162,8 @@ cmake:mingw:w64-i686:shared: cmake:mingw:w64-i686:static: extends: .cmake:mingw + only: + - schedules variables: BUILD_SHARED_LIBS: "OFF" MINGW_PACKAGE_PREFIX: mingw-w64-i686 @@ -164,6 +180,8 @@ cmake:mingw:w64-x86_64:shared: cmake:mingw:w64-x86_64:static: extends: .cmake:mingw + only: + - schedules variables: BUILD_SHARED_LIBS: "OFF" MINGW_PACKAGE_PREFIX: mingw-w64-x86_64 @@ -231,6 +249,29 @@ cmake:msvc:v141:x64:shared: cmake:msvc:v141:x64:static: extends: .cmake:msvc:v141:x64 + only: + - schedules + variables: + BUILD_SHARED_LIBS: "OFF" + SUFFIX: static + +.cmake:msvc:v141:x86: + extends: .cmake:msvc:v141 + only: + - schedules + variables: + CMAKE_GENERATOR_PLATFORM: Win32 + +cmake:msvc:v141:x86:shared: + extends: .cmake:msvc:v141:x86 + only: + - schedules + variables: + BUILD_SHARED_LIBS: "ON" + SUFFIX: shared + +cmake:msvc:v141:x86:static: + extends: .cmake:msvc:v141:x86 variables: BUILD_SHARED_LIBS: "OFF" SUFFIX: static diff --git a/CMakeLists.txt b/CMakeLists.txt index da0e5a91..d6ee9ec7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.15) -project(libxml2 C) +project(libxml2 VERSION 2.9.10 LANGUAGES C) include(CheckCSourceCompiles) include(CheckFunctionExists) @@ -11,16 +11,6 @@ include(CheckSymbolExists) include(CMakePackageConfigHelpers) include(GNUInstallDirs) -set(LIBXML_MAJOR_VERSION 2) -set(LIBXML_MINOR_VERSION 9) -set(LIBXML_MICRO_VERSION 10) - -set(VERSION "${LIBXML_MAJOR_VERSION}.${LIBXML_MINOR_VERSION}.${LIBXML_MICRO_VERSION}") -set(LIBXML_VERSION ${LIBXML_MAJOR_VERSION}0${LIBXML_MINOR_VERSION}0${LIBXML_MICRO_VERSION}) -set(LIBXML_VERSION_STRING "${LIBXML_VERSION}") -set(LIBXML_VERSION_EXTRA "") -set(LIBXML_VERSION_NUMBER ${LIBXML_VERSION}) - option(BUILD_SHARED_LIBS "Build shared libraries" ON) set(LIBXML2_WITH_AUTOMATA ON) option(LIBXML2_WITH_C14N "Add the Canonicalization support" ON) @@ -105,6 +95,16 @@ foreach(VARIABLE IN ITEMS WITH_AUTOMATA WITH_C14N WITH_CATALOG WITH_DEBUG WITH_D endif() endforeach() +set(LIBXML_MAJOR_VERSION ${PROJECT_VERSION_MAJOR}) +set(LIBXML_MINOR_VERSION ${PROJECT_VERSION_MINOR}) +set(LIBXML_MICRO_VERSION ${PROJECT_VERSION_PATCH}) + +set(VERSION "${LIBXML_MAJOR_VERSION}.${LIBXML_MINOR_VERSION}.${LIBXML_MICRO_VERSION}") +set(LIBXML_VERSION ${LIBXML_MAJOR_VERSION}0${LIBXML_MINOR_VERSION}0${LIBXML_MICRO_VERSION}) +set(LIBXML_VERSION_STRING "${LIBXML_VERSION}") +set(LIBXML_VERSION_EXTRA "") +set(LIBXML_VERSION_NUMBER ${LIBXML_VERSION}) + set(MODULE_EXTENSION "${CMAKE_SHARED_LIBRARY_SUFFIX}") set(PACKAGE "libxml2") @@ -493,7 +493,7 @@ set_target_properties( OUTPUT_NAME xml2 POSITION_INDEPENDENT_CODE ON PREFIX lib - VERSION ${VERSION} + VERSION ${PROJECT_VERSION} ) if(WIN32) @@ -637,7 +637,7 @@ if(LIBXML2_WITH_PYTHON) IMPORT_PREFIX lib OUTPUT_NAME xml2mod PREFIX lib - VERSION ${VERSION} + VERSION ${PROJECT_VERSION} ) install( TARGETS LibXml2Mod @@ -659,30 +659,30 @@ install(DIRECTORY doc/ DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/libxml2 COMPONEN configure_package_config_file( libxml2-config.cmake.cmake.in libxml2-config.cmake - INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${VERSION} + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION} ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${VERSION} + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION} COMPONENT development ) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-version.cmake - VERSION ${VERSION} + VERSION ${PROJECT_VERSION} COMPATIBILITY ExactVersion ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-version.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${VERSION} + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION} COMPONENT development ) install( EXPORT LibXml2 - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${VERSION} + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION} NAMESPACE LibXml2:: FILE libxml2-export.cmake COMPONENT development diff --git a/HTMLparser.c b/HTMLparser.c index 14cc56fa..c9a64c78 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -457,7 +457,12 @@ htmlCurrentChar(xmlParserCtxtPtr ctxt, int *len) { ctxt->input->encoding = guess; handler = xmlFindCharEncodingHandler((const char *) guess); if (handler != NULL) { - xmlSwitchToEncoding(ctxt, handler); + /* + * Don't use UTF-8 encoder which isn't required and + * can produce invalid UTF-8. + */ + if (!xmlStrEqual(BAD_CAST handler->name, BAD_CAST "UTF-8")) + xmlSwitchToEncoding(ctxt, handler); } else { htmlParseErr(ctxt, XML_ERR_INVALID_ENCODING, "Unsupported encoding %s", guess, NULL); @@ -570,7 +575,16 @@ encoding_error: BAD_CAST buffer, NULL); } - ctxt->charset = XML_CHAR_ENCODING_8859_1; + /* + * Don't switch encodings twice. Note that if there's an encoder, we + * shouldn't receive invalid UTF-8 anyway. + * + * Note that if ctxt->input->buf == NULL, switching encodings is + * impossible, see Gitlab issue #34. + */ + if ((ctxt->input->buf != NULL) && + (ctxt->input->buf->encoder == NULL)) + xmlSwitchEncoding(ctxt, XML_CHAR_ENCODING_8859_1); *len = 1; return((int) *ctxt->input->cur); } @@ -1,3 +1,6 @@ +# *** THIS PACKAGE HAS SPECIAL LICENSING CONDITIONS. PLEASE +# CONSULT THE OWNERS AND opensource-licensing@google.com BEFORE +# DEPENDING ON IT IN YOUR PROJECT. *** name: "libxml2" description: "Libxml2 is the XML C parser and toolkit developed for the Gnome project (but usable outside of the Gnome platform), it is free software available under the MIT License." third_party { @@ -7,13 +10,13 @@ third_party { } url { type: ARCHIVE - value: "https://github.com/GNOME/libxml2/archive/cbe1212db6e22fa92c33242c3ce089476585f872.zip" + value: "https://github.com/GNOME/libxml2/archive/ce2fbaa89da627a6c6cd6344d5339a76feba94b5.zip" } - version: "cbe1212db6e22fa92c33242c3ce089476585f872" + version: "ce2fbaa89da627a6c6cd6344d5339a76feba94b5" license_type: BY_EXCEPTION_ONLY last_upgrade_date { year: 2021 month: 2 - day: 9 + day: 23 } } @@ -373,6 +373,11 @@ UTF8ToUTF8(unsigned char* out, int *outlen, if (len < 0) return(-1); + /* + * FIXME: Conversion functions must assure valid UTF-8, so we have + * to check for UTF-8 validity. Preferably, this converter shouldn't + * be used at all. + */ memcpy(out, inb, len); *outlen = len; diff --git a/fuzz/fuzz.h b/fuzz/fuzz.h index 8716af93..a51b3987 100644 --- a/fuzz/fuzz.h +++ b/fuzz/fuzz.h @@ -15,6 +15,27 @@ extern "C" { #endif +#if defined(LIBXML_HTML_ENABLED) && defined(LIBXML_OUTPUT_ENABLED) + #define HAVE_HTML_FUZZER +#endif +#if defined(LIBXML_REGEXP_ENABLED) + #define HAVE_REGEXP_FUZZER +#endif +#if defined(LIBXML_SCHEMAS_ENABLED) + #define HAVE_SCHEMA_FUZZER +#endif +#if 1 + #define HAVE_URI_FUZZER +#endif +#if defined(LIBXML_OUTPUT_ENABLED) && \ + defined(LIBXML_READER_ENABLED) && \ + defined(LIBXML_XINCLUDE_ENABLED) + #define HAVE_XML_FUZZER +#endif +#if defined(LIBXML_XPATH_ENABLED) + #define HAVE_XPATH_FUZZER +#endif + int LLVMFuzzerInitialize(int *argc, char ***argv); diff --git a/fuzz/genSeed.c b/fuzz/genSeed.c index 68fb87a1..2f038027 100644 --- a/fuzz/genSeed.c +++ b/fuzz/genSeed.c @@ -102,6 +102,7 @@ fuzzRecorderCleanup() { globalData.oldLoader = NULL; } +#ifdef HAVE_XML_FUZZER static int processXml(const char *docFile, FILE *out) { int opts = XML_PARSE_NOENT | XML_PARSE_DTDLOAD; @@ -119,7 +120,9 @@ processXml(const char *docFile, FILE *out) { return(0); } +#endif +#ifdef HAVE_HTML_FUZZER static int processHtml(const char *docFile, FILE *out) { char buf[SEED_BUF_SIZE]; @@ -144,7 +147,9 @@ processHtml(const char *docFile, FILE *out) { return(0); } +#endif +#ifdef HAVE_SCHEMA_FUZZER static int processSchema(const char *docFile, FILE *out) { xmlSchemaPtr schema; @@ -162,6 +167,7 @@ processSchema(const char *docFile, FILE *out) { return(0); } +#endif static int processPattern(const char *pattern) { @@ -240,6 +246,7 @@ error: return(ret); } +#ifdef HAVE_XPATH_FUZZER static int processXPath(const char *testDir, const char *prefix, const char *name, const char *data, const char *subdir, int xptr) { @@ -363,10 +370,11 @@ processXPathDir(const char *testDir) { return(ret); } +#endif int main(int argc, const char **argv) { - mainFunc processArg = processPattern; + mainFunc processArg = NULL; const char *fuzzer; int ret = 0; int xpath = 0; @@ -381,13 +389,24 @@ main(int argc, const char **argv) { fuzzer = argv[1]; if (strcmp(fuzzer, "html") == 0) { +#ifdef HAVE_HTML_FUZZER + processArg = processPattern; globalData.processFile = processHtml; +#endif } else if (strcmp(fuzzer, "schema") == 0) { +#ifdef HAVE_SCHEMA_FUZZER + processArg = processPattern; globalData.processFile = processSchema; +#endif } else if (strcmp(fuzzer, "xml") == 0) { +#ifdef HAVE_XML_FUZZER + processArg = processPattern; globalData.processFile = processXml; +#endif } else if (strcmp(fuzzer, "xpath") == 0) { +#ifdef HAVE_XPATH_FUZZER processArg = processXPathDir; +#endif } else { fprintf(stderr, "unknown fuzzer %s\n", fuzzer); return(1); @@ -399,8 +418,9 @@ main(int argc, const char **argv) { return(1); } - for (i = 2; i < argc; i++) - processArg(argv[i]); + if (processArg != NULL) + for (i = 2; i < argc; i++) + processArg(argv[i]); return(ret); } diff --git a/fuzz/html.c b/fuzz/html.c index 449a9d49..116b3df3 100644 --- a/fuzz/html.c +++ b/fuzz/html.c @@ -6,12 +6,16 @@ #include <libxml/HTMLparser.h> #include <libxml/HTMLtree.h> +#include <libxml/catalog.h> #include "fuzz.h" int LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED, char ***argv ATTRIBUTE_UNUSED) { xmlInitParser(); +#ifdef LIBXML_CATALOG_ENABLED + xmlInitializeCatalog(); +#endif xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc); return 0; @@ -71,6 +75,7 @@ LLVMFuzzerTestOneInput(const char *data, size_t size) { /* Cleanup */ xmlFuzzDataCleanup(); + xmlResetLastError(); return(0); } diff --git a/fuzz/html.dict b/fuzz/html.dict index 801b7bb5..80444c26 100644 --- a/fuzz/html.dict +++ b/fuzz/html.dict @@ -109,3 +109,16 @@ ref_apos="'" ref_quot=""" ref_dec="	" ref_hex="
" + +cs_utf8="UTF-8" +cs_utf16="UTF-16" +cs_utf16le="UTF-16LE" +cs_utf16be="UTF-16BE" +cs_ucs2="UCS-2" +cs_ucs4="UCS-4" +cs_latin1="ISO-8859-1" +cs_ascii="ASCII" +cs_ebcdic="EBCDIC" +cs_iso2022jp="ISO-2022-JP" +cs_shift_jis="SHIFT_JIS" +cs_euc_jp="EUC-JP" diff --git a/fuzz/regexp.c b/fuzz/regexp.c index cfffedd9..af1210aa 100644 --- a/fuzz/regexp.c +++ b/fuzz/regexp.c @@ -40,6 +40,7 @@ LLVMFuzzerTestOneInput(const char *data, size_t size) { xmlFree(str[0]); xmlFree(str[1]); + xmlResetLastError(); return 0; } diff --git a/fuzz/schema.c b/fuzz/schema.c index 7b034eca..689bffe3 100644 --- a/fuzz/schema.c +++ b/fuzz/schema.c @@ -4,6 +4,7 @@ * See Copyright for the status of this software. */ +#include <libxml/catalog.h> #include <libxml/xmlschemas.h> #include "fuzz.h" @@ -11,6 +12,9 @@ int LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED, char ***argv ATTRIBUTE_UNUSED) { xmlInitParser(); +#ifdef LIBXML_CATALOG_ENABLED + xmlInitializeCatalog(); +#endif xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc); xmlSetExternalEntityLoader(xmlFuzzEntityLoader); @@ -33,6 +37,7 @@ LLVMFuzzerTestOneInput(const char *data, size_t size) { xmlSchemaFreeParserCtxt(pctxt); xmlFuzzDataCleanup(); + xmlResetLastError(); return(0); } diff --git a/fuzz/testFuzzer.c b/fuzz/testFuzzer.c index 678f3243..b0c7ffbc 100644 --- a/fuzz/testFuzzer.c +++ b/fuzz/testFuzzer.c @@ -12,41 +12,53 @@ #include <libxml/xmlstring.h> #include "fuzz.h" -#define LLVMFuzzerInitialize fuzzHtmlInit -#define LLVMFuzzerTestOneInput fuzzHtml -#include "html.c" -#undef LLVMFuzzerInitialize -#undef LLVMFuzzerTestOneInput - -#define LLVMFuzzerInitialize fuzzRegexpInit -#define LLVMFuzzerTestOneInput fuzzRegexp -#include "regexp.c" -#undef LLVMFuzzerInitialize -#undef LLVMFuzzerTestOneInput - -#define LLVMFuzzerInitialize fuzzSchemaInit -#define LLVMFuzzerTestOneInput fuzzSchema -#include "schema.c" -#undef LLVMFuzzerInitialize -#undef LLVMFuzzerTestOneInput - -#define LLVMFuzzerInitialize fuzzUriInit -#define LLVMFuzzerTestOneInput fuzzUri -#include "uri.c" -#undef LLVMFuzzerInitialize -#undef LLVMFuzzerTestOneInput - -#define LLVMFuzzerInitialize fuzzXmlInit -#define LLVMFuzzerTestOneInput fuzzXml -#include "xml.c" -#undef LLVMFuzzerInitialize -#undef LLVMFuzzerTestOneInput - -#define LLVMFuzzerInitialize fuzzXPathInit -#define LLVMFuzzerTestOneInput fuzzXPath -#include "xpath.c" -#undef LLVMFuzzerInitialize -#undef LLVMFuzzerTestOneInput +#ifdef HAVE_HTML_FUZZER + #define LLVMFuzzerInitialize fuzzHtmlInit + #define LLVMFuzzerTestOneInput fuzzHtml + #include "html.c" + #undef LLVMFuzzerInitialize + #undef LLVMFuzzerTestOneInput +#endif + +#ifdef HAVE_REGEXP_FUZZER + #define LLVMFuzzerInitialize fuzzRegexpInit + #define LLVMFuzzerTestOneInput fuzzRegexp + #include "regexp.c" + #undef LLVMFuzzerInitialize + #undef LLVMFuzzerTestOneInput +#endif + +#ifdef HAVE_SCHEMA_FUZZER + #define LLVMFuzzerInitialize fuzzSchemaInit + #define LLVMFuzzerTestOneInput fuzzSchema + #include "schema.c" + #undef LLVMFuzzerInitialize + #undef LLVMFuzzerTestOneInput +#endif + +#ifdef HAVE_URI_FUZZER + #define LLVMFuzzerInitialize fuzzUriInit + #define LLVMFuzzerTestOneInput fuzzUri + #include "uri.c" + #undef LLVMFuzzerInitialize + #undef LLVMFuzzerTestOneInput +#endif + +#ifdef HAVE_XML_FUZZER + #define LLVMFuzzerInitialize fuzzXmlInit + #define LLVMFuzzerTestOneInput fuzzXml + #include "xml.c" + #undef LLVMFuzzerInitialize + #undef LLVMFuzzerTestOneInput +#endif + +#ifdef HAVE_XPATH_FUZZER + #define LLVMFuzzerInitialize fuzzXPathInit + #define LLVMFuzzerTestOneInput fuzzXPath + #include "xpath.c" + #undef LLVMFuzzerInitialize + #undef LLVMFuzzerTestOneInput +#endif typedef int (*initFunc)(int *argc, char ***argv); @@ -91,6 +103,7 @@ error: return(ret); } +#ifdef HAVE_XML_FUZZER static int testEntityLoader() { static const char data[] = @@ -132,25 +145,40 @@ testEntityLoader() { return(ret); } +#endif int main() { int ret = 0; +#ifdef HAVE_XML_FUZZER if (testEntityLoader() != 0) ret = 1; +#endif +#ifdef HAVE_HTML_FUZZER if (testFuzzer(fuzzHtmlInit, fuzzHtml, "seed/html/*") != 0) ret = 1; +#endif +#ifdef HAVE_REGEXP_FUZZER if (testFuzzer(fuzzRegexpInit, fuzzRegexp, "seed/regexp/*") != 0) ret = 1; +#endif +#ifdef HAVE_SCHEMA_FUZZER if (testFuzzer(fuzzSchemaInit, fuzzSchema, "seed/schema/*") != 0) ret = 1; +#endif +#ifdef HAVE_URI_FUZZER if (testFuzzer(NULL, fuzzUri, "seed/uri/*") != 0) ret = 1; +#endif +#ifdef HAVE_XML_FUZZER if (testFuzzer(fuzzXmlInit, fuzzXml, "seed/xml/*") != 0) ret = 1; +#endif +#ifdef HAVE_XPATH_FUZZER if (testFuzzer(fuzzXPathInit, fuzzXPath, "seed/xpath/*") != 0) ret = 1; +#endif if (ret == 0) printf("Successfully tested %d inputs\n", numInputs); @@ -4,6 +4,7 @@ * See Copyright for the status of this software. */ +#include <libxml/catalog.h> #include <libxml/parser.h> #include <libxml/tree.h> #include <libxml/xmlerror.h> @@ -15,6 +16,9 @@ int LLVMFuzzerInitialize(int *argc ATTRIBUTE_UNUSED, char ***argv ATTRIBUTE_UNUSED) { xmlInitParser(); +#ifdef LIBXML_CATALOG_ENABLED + xmlInitializeCatalog(); +#endif xmlSetGenericErrorFunc(NULL, xmlFuzzErrorFunc); xmlSetExternalEntityLoader(xmlFuzzEntityLoader); @@ -94,6 +98,7 @@ LLVMFuzzerTestOneInput(const char *data, size_t size) { exit: xmlFuzzDataCleanup(); + xmlResetLastError(); return(0); } diff --git a/fuzz/xml.dict b/fuzz/xml.dict index 2573aea6..a539e6ad 100644 --- a/fuzz/xml.dict +++ b/fuzz/xml.dict @@ -74,3 +74,16 @@ pe_ref_quoted="%a;" notation_decl_public="<!NOTATION a PUBLIC 'a'>" notation_decl_system="<!NOTATION a SYSTEM 'a'>" + +cs_utf8="UTF-8" +cs_utf16="UTF-16" +cs_utf16le="UTF-16LE" +cs_utf16be="UTF-16BE" +cs_ucs2="UCS-2" +cs_ucs4="UCS-4" +cs_latin1="ISO-8859-1" +cs_ascii="ASCII" +cs_ebcdic="EBCDIC" +cs_iso2022jp="ISO-2022-JP" +cs_shift_jis="SHIFT_JIS" +cs_euc_jp="EUC-JP" diff --git a/fuzz/xpath.c b/fuzz/xpath.c index 4cb29f67..47652bd5 100644 --- a/fuzz/xpath.c +++ b/fuzz/xpath.c @@ -45,6 +45,7 @@ LLVMFuzzerTestOneInput(const char *data, size_t size) { xmlFreeDoc(doc); xmlFuzzDataCleanup(); + xmlResetLastError(); return(0); } @@ -1,4 +1,6 @@ # Configure paths for LIBXML2 +# Simon Josefsson 2020-02-12 +# Fix autoconf 2.70+ warnings # Mike Hommey 2004-06-19 # use CPPFLAGS instead of CFLAGS # Toshio Kuratomi 2001-04-21 @@ -58,7 +60,8 @@ dnl Now check if the installed libxml is sufficiently new. dnl (Also sanity checks the results of xml2-config to some extent) dnl rm -f conf.xmltest - AC_TRY_RUN([ + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ #include <stdlib.h> #include <stdio.h> #include <string.h> @@ -133,7 +136,7 @@ main() } return 1; } -],, no_xml=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) +]])],, no_xml=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) CPPFLAGS="$ac_save_CPPFLAGS" LIBS="$ac_save_LIBS" fi @@ -156,10 +159,11 @@ main() echo "*** Could not run libxml test program, checking why..." CPPFLAGS="$CPPFLAGS $XML_CPPFLAGS" LIBS="$LIBS $XML_LIBS" - AC_TRY_LINK([ + AC_LINK_IFELSE( + [AC_LANG_PROGRAM([[ #include <libxml/xmlversion.h> #include <stdio.h> -], [ LIBXML_TEST_VERSION; return 0;], +]], [[ LIBXML_TEST_VERSION; return 0;]])], [ echo "*** The test program compiled, but did not run. This usually means" echo "*** that the run-time linker is not finding LIBXML or finding the wrong" echo "*** version of LIBXML. If it is not finding LIBXML, you'll need to set your" diff --git a/parserInternals.c b/parserInternals.c index b0629ef3..cbcfde0e 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -1153,6 +1153,11 @@ xmlSwitchInputEncodingInt(xmlParserCtxtPtr ctxt, xmlParserInputPtr input, * Note: this is a bit dangerous, but that's what it * takes to use nearly compatible signature for different * encodings. + * + * FIXME: Encoders might buffer partial byte sequences, so + * this probably can't work. We should return an error and + * make sure that callers never try to switch the encoding + * twice. */ xmlCharEncCloseFunc(input->buf->encoder); input->buf->encoder = handler; @@ -165,6 +165,7 @@ static int xinclude = 0; static int dtdattrs = 0; static int loaddtd = 0; static xmllintReturnCode progresult = XMLLINT_RETURN_OK; +static int quiet = 0; static int timing = 0; static int generate = 0; static int dropdtd = 0; @@ -1665,7 +1666,9 @@ testSAX(const char *filename) { (void *)user_data); if (repeat == 0) { if (ret == 0) { - fprintf(stderr, "%s validates\n", filename); + if (!quiet) { + fprintf(stderr, "%s validates\n", filename); + } } else if (ret > 0) { fprintf(stderr, "%s fails to validate\n", filename); progresult = XMLLINT_ERR_VALID; @@ -1948,7 +1951,9 @@ static void streamFile(char *filename) { fprintf(stderr, "%s fails to validate\n", filename); progresult = XMLLINT_ERR_VALID; } else { - fprintf(stderr, "%s validates\n", filename); + if (!quiet) { + fprintf(stderr, "%s validates\n", filename); + } } } #endif @@ -2840,7 +2845,9 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { #endif ret = xmlSchematronValidateDoc(ctxt, doc); if (ret == 0) { - fprintf(stderr, "%s validates\n", filename); + if (!quiet) { + fprintf(stderr, "%s validates\n", filename); + } } else if (ret > 0) { fprintf(stderr, "%s fails to validate\n", filename); progresult = XMLLINT_ERR_VALID; @@ -2868,7 +2875,9 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { xmlRelaxNGSetValidErrors(ctxt, xmlGenericError, xmlGenericError, NULL); ret = xmlRelaxNGValidateDoc(ctxt, doc); if (ret == 0) { - fprintf(stderr, "%s validates\n", filename); + if (!quiet) { + fprintf(stderr, "%s validates\n", filename); + } } else if (ret > 0) { fprintf(stderr, "%s fails to validate\n", filename); progresult = XMLLINT_ERR_VALID; @@ -2893,7 +2902,9 @@ static void parseAndPrintFile(char *filename, xmlParserCtxtPtr rectxt) { xmlSchemaSetValidErrors(ctxt, xmlGenericError, xmlGenericError, NULL); ret = xmlSchemaValidateDoc(ctxt, doc); if (ret == 0) { - fprintf(stderr, "%s validates\n", filename); + if (!quiet) { + fprintf(stderr, "%s validates\n", filename); + } } else if (ret > 0) { fprintf(stderr, "%s fails to validate\n", filename); progresult = XMLLINT_ERR_VALID; @@ -3010,6 +3021,7 @@ static void usage(FILE *f, const char *name) { fprintf(f, "\t--dtdvalid URL : do a posteriori validation against a given DTD\n"); fprintf(f, "\t--dtdvalidfpi FPI : same but name the DTD with a Public Identifier\n"); #endif /* LIBXML_VALID_ENABLED */ + fprintf(f, "\t--quiet : be quiet when succeeded\n"); fprintf(f, "\t--timing : print some timings\n"); fprintf(f, "\t--output file or -o file: save to a given file\n"); fprintf(f, "\t--repeat : repeat 100 times, for timing or profiling\n"); @@ -3244,6 +3256,9 @@ main(int argc, char **argv) { else if ((!strcmp(argv[i], "-insert")) || (!strcmp(argv[i], "--insert"))) insert++; + else if ((!strcmp(argv[i], "-quiet")) || + (!strcmp(argv[i], "--quiet"))) + quiet++; else if ((!strcmp(argv[i], "-timing")) || (!strcmp(argv[i], "--timing"))) timing++; |