diff options
Diffstat (limited to '3rdparty/expat')
155 files changed, 31630 insertions, 18813 deletions
diff --git a/3rdparty/expat/CMake.README b/3rdparty/expat/CMake.README index aa098b4f942..86e1eb98918 100644 --- a/3rdparty/expat/CMake.README +++ b/3rdparty/expat/CMake.README @@ -3,25 +3,25 @@ The cmake based buildsystem for expat works on Windows (cygwin, mingw, Visual Studio) and should work on all other platform cmake supports. -Assuming ~/expat-2.2.10 is the source directory of expat, add a subdirectory +Assuming ~/expat-2.6.4 is the source directory of expat, add a subdirectory build and change into that directory: -~/expat-2.2.10$ mkdir build && cd build -~/expat-2.2.10/build$ +~/expat-2.6.4$ mkdir build && cd build +~/expat-2.6.4/build$ From that directory, call cmake first, then call make, make test and make install in the usual way: -~/expat-2.2.10/build$ cmake .. +~/expat-2.6.4/build$ cmake .. -- The C compiler identification is GNU -- The CXX compiler identification is GNU .... -- Configuring done -- Generating done --- Build files have been written to: /home/patrick/expat-2.2.10/build +-- Build files have been written to: /home/patrick/expat-2.6.4/build If you want to specify the install location for your files, append -DCMAKE_INSTALL_PREFIX=/your/install/path to the cmake call. -~/expat-2.2.10/build$ make && make test && make install +~/expat-2.6.4/build$ make && make test && make install Scanning dependencies of target expat [ 5%] Building C object CMakeFiles/expat.dir/lib/xmlparse.c.o [ 11%] Building C object CMakeFiles/expat.dir/lib/xmlrole.c.o @@ -36,7 +36,7 @@ Visual Studio Command Prompt or when using mingw, you must open a cmd.exe and make sure that gcc can be called. On Windows, you also might want to specify a special Generator for CMake: for Visual Studio builds do: -cmake .. -G "Visual Studio 15 2017" && msbuild /m expat.sln +cmake .. -G "Visual Studio 16 2019" && msbuild /m expat.sln for mingw builds do: cmake .. -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=D:\expat-install && gmake && gmake install diff --git a/3rdparty/expat/CMakeLists.txt b/3rdparty/expat/CMakeLists.txt index dfbd0c5943b..1f650339062 100644 --- a/3rdparty/expat/CMakeLists.txt +++ b/3rdparty/expat/CMakeLists.txt @@ -1,44 +1,52 @@ -# This file is copyrighted under the BSD-license for buildsystem files of KDE -# copyright 2010, Patrick Spendrin <ps_ml@gmx.de> - -cmake_minimum_required(VERSION 3.1.3) - -# This allows controlling documented build time switches -# when Expat is pulled in using the add_subdirectory function, e.g. -# -# set(EXPAT_BUILD_DOCS OFF) -# set(EXPAT_BUILD_TOOLS OFF) -# add_subdirectory(${expat_SOURCE_DIR}/expat ${expat_BINARY_DIR}) -# -# would disable compilation of the xmlwf CLI and its man page. -# Without activating behaviour NEW for policy CMP0077 here, -# a user with -Wdev enabled would see warning -# -# Policy CMP0077 is not set: option() honors normal variables. Run "cmake -# --help-policy CMP0077" for policy details. Use the cmake_policy command to -# set the policy and suppress this warning. -# -# For compatibility with older versions of CMake, option is clearing the -# normal variable 'EXPAT_BUILD_DOCS'. -# -# and effectively not be able to adjust option EXPAT_BUILD_DOCS. -# -# For more details please see: -# - https://cmake.org/cmake/help/latest/policy/CMP0077.html -# - https://github.com/libexpat/libexpat/pull/419 -# -if(POLICY CMP0077) - cmake_policy(SET CMP0077 NEW) -endif() +# __ __ _ +# ___\ \/ /_ __ __ _| |_ +# / _ \\ /| '_ \ / _` | __| +# | __// \| |_) | (_| | |_ +# \___/_/\_\ .__/ \__,_|\__| +# |_| XML parser +# +# Copyright (c) 2010 Patrick Spendrin <ps_ml@gmx.de> +# Copyright (c) 2012 Karl Waclawek <karl@waclawek.net> +# Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2016 Sergei Nikulov <sergey.nikulov@gmail.com> +# Copyright (c) 2016 Björn Lindahl <bjorn.lindahl@foi.se> +# Copyright (c) 2016 Tobias Taschner <github@tc84.de> +# Copyright (c) 2016 Ben Boeckel <ben.boeckel@kitware.com> +# Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> +# Copyright (c) 2017 Rolf Eike Beer <eike@sf-mail.de> +# Copyright (c) 2017 Stephen Groat <stephen@groat.us> +# Copyright (c) 2017 Franek Korta <fkorta@gmail.com> +# Copyright (c) 2018 pedro-vicente <pedro.vicente@space-research.org> +# Copyright (c) 2018 Frank Rast <frank.rast@gefeg.com> +# Copyright (c) 2018 userwithuid <userwithuid@gmail.com> +# Copyright (c) 2018 Yury Gribov <tetra2005@gmail.com> +# Copyright (c) 2019 Kishore Kunche <kishore.kunche@intel.com> +# Copyright (c) 2019 xantares <xantares09@hotmail.com> +# Copyright (c) 2019 Mohammed Khajapasha <mohammed.khajapasha@intel.com> +# Copyright (c) 2019 David Loffredo <loffredo@steptools.com> +# Copyright (c) 2019 Bhargava Shastry <bhargava.shastry@ethereum.org> +# Copyright (c) 2020 Maciej SroczyÅ„ski <macieksroczynski@poczta.fm> +# Copyright (c) 2020 Gulliver <gulliver@traumkristalle.net> +# Copyright (c) 2020 Thomas Beutlich <tc@tbeu.de> +# Copyright (c) 2021 Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> +# Copyright (c) 2022 Johnny Jazeix <jazeix@gmail.com> +# Copyright (c) 2022 David Faure <david.faure@kdab.com> +# Unlike most of Expat, +# this file is copyrighted under the BSD-license for buildsystem files of KDE. + +cmake_minimum_required(VERSION 3.5.0) project(expat VERSION - 2.2.10 + 2.6.4 LANGUAGES C ) +set(CMAKE_C_STANDARD 99) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS OFF) # i.e. -std=c99 rather than default -std=gnu99 -set(PACKAGE_BUGREPORT "expat-bugs@libexpat.org") +set(PACKAGE_BUGREPORT "https://github.com/libexpat/libexpat/issues") set(PACKAGE_NAME "expat") set(PACKAGE_VERSION "${PROJECT_VERSION}") set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") @@ -48,11 +56,6 @@ include(CMakePackageConfigHelpers) include(GNUInstallDirs) # -# Detect use by means of add_subdirectory -# -get_directory_property(_EXPAT_PARENT_DIRECTORY PARENT_DIRECTORY) - -# # Configuration defaults # if(WINCE) @@ -75,51 +78,114 @@ if(MSVC) else() set(_EXPAT_BUILD_PKGCONFIG_DEFAULT ON) endif() +if(DEFINED BUILD_SHARED_LIBS) + set(_EXPAT_SHARED_LIBS_DEFAULT ${BUILD_SHARED_LIBS}) +else() + set(_EXPAT_SHARED_LIBS_DEFAULT ON) +endif() +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE NoConfig) # so that accessing EXPAT_*_POSTFIX will be waterproof +endif() +string(TOUPPER "${CMAKE_BUILD_TYPE}" _EXPAT_BUILD_TYPE_UPPER) # # Configuration # -option(EXPAT_BUILD_TOOLS "build the xmlwf tool for expat library" ${_EXPAT_BUILD_TOOLS_DEFAULT}) -option(EXPAT_BUILD_EXAMPLES "build the examples for expat library" ON) -option(EXPAT_BUILD_TESTS "build the tests for expat library" ON) -option(EXPAT_SHARED_LIBS "build a shared expat library" ON) -option(EXPAT_BUILD_DOCS "build man page for xmlwf" ${_EXPAT_BUILD_DOCS_DEFAULT}) -option(EXPAT_BUILD_FUZZERS "build fuzzers for the expat library" OFF) -option(EXPAT_BUILD_PKGCONFIG "build pkg-config file" ${_EXPAT_BUILD_PKGCONFIG_DEFAULT}) -option(EXPAT_OSSFUZZ_BUILD "build fuzzers via ossfuzz for the expat library" OFF) + +macro(expat_shy_set var default cache type desc) + # Macro expat_shy_set came into life because: + # - Expat was previously using an inconsistent mix of CMake's native set() + # and option() to define public build time options. + # - option() is more friendly than set() with regard to configuring an + # external project that is pulled in by means of add_subdirectory() -- + # see comments in issue #597 -- so we wanted to get away from set(). + # - option() auto-converts non-bool values to bool when writing to the CMake + # cache, so we needed something that supports non-bool better and hence + # wanted to get away from plain option(), too. + # + # As a result, this function serves as a hybrid between CMake's regular set() + # and option(): from set() it takes support for non-bool types and the function + # name and signature whereas from option() (with policy CMP0077 mode NEW) it + # takes being shy when a value has previously been defined for that variable. + # + # So that resolves all need for set(.. FORCE) when pulling in Expat by means of + # add_subdirectory(). + # + if(NOT ${cache} STREQUAL "CACHE") + message(SEND_ERROR "Macro usage is: expat_shy_set(var default CACHE type desc)") + endif() + + if(DEFINED ${var}) + # NOTE: The idea is to (ideally) only add to the cache if + # there is no cache entry, yet. "if(DEFINED CACHE{var})" + # requires CMake >=3.14. + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.14" AND NOT DEFINED "CACHE{${var}}") + set("${var}" "${${var}}" CACHE "${type}" "${desc}") + endif() + else() + set("${var}" "${default}" CACHE "${type}" "${desc}") + endif() +endmacro() + +expat_shy_set(EXPAT_BUILD_TOOLS ${_EXPAT_BUILD_TOOLS_DEFAULT} CACHE BOOL "Build the xmlwf tool for expat library") +expat_shy_set(EXPAT_BUILD_EXAMPLES ON CACHE BOOL "Build the examples for expat library") +expat_shy_set(EXPAT_BUILD_TESTS ON CACHE BOOL "Build the tests for expat library") +expat_shy_set(EXPAT_SHARED_LIBS ${_EXPAT_SHARED_LIBS_DEFAULT} CACHE BOOL "Build a shared expat library") +expat_shy_set(EXPAT_BUILD_DOCS ${_EXPAT_BUILD_DOCS_DEFAULT} CACHE BOOL "Build man page for xmlwf") +expat_shy_set(EXPAT_BUILD_FUZZERS OFF CACHE BOOL "Build fuzzers for the expat library") +expat_shy_set(EXPAT_BUILD_PKGCONFIG ${_EXPAT_BUILD_PKGCONFIG_DEFAULT} CACHE BOOL "Build pkg-config file") +expat_shy_set(EXPAT_OSSFUZZ_BUILD OFF CACHE BOOL "Build fuzzers via ossfuzz for the expat library") if(UNIX OR _EXPAT_HELP) - option(EXPAT_WITH_LIBBSD "utilize libbsd (for arc4random_buf)" OFF) + expat_shy_set(EXPAT_WITH_LIBBSD OFF CACHE BOOL "Utilize libbsd (for arc4random_buf)") endif() -option(EXPAT_ENABLE_INSTALL "install expat files in cmake install target" ON) -set(EXPAT_CONTEXT_BYTES 1024 CACHE STRING "Define to specify how much context to retain around the current parse point") +expat_shy_set(EXPAT_ENABLE_INSTALL ON CACHE BOOL "Install expat files in cmake install target") +expat_shy_set(EXPAT_CONTEXT_BYTES 1024 CACHE STRING "Define to specify how much context to retain around the current parse point, 0 to disable") mark_as_advanced(EXPAT_CONTEXT_BYTES) -option(EXPAT_DTD "Define to make parameter entity parsing functionality available" ON) +expat_shy_set(EXPAT_DTD ON CACHE BOOL "Define to make parameter entity parsing functionality available") mark_as_advanced(EXPAT_DTD) -option(EXPAT_NS "Define to make XML Namespaces functionality available" ON) +expat_shy_set(EXPAT_GE ON CACHE BOOL "Define to make general entity parsing functionality available") +mark_as_advanced(EXPAT_GE) +expat_shy_set(EXPAT_NS ON CACHE BOOL "Define to make XML Namespaces functionality available") mark_as_advanced(EXPAT_NS) -option(EXPAT_WARNINGS_AS_ERRORS "Treat all compiler warnings as errors" OFF) +expat_shy_set(EXPAT_WARNINGS_AS_ERRORS OFF CACHE BOOL "Treat all compiler warnings as errors") if(UNIX OR _EXPAT_HELP) - option(EXPAT_DEV_URANDOM "Define to include code reading entropy from `/dev/urandom'." ON) - set(EXPAT_WITH_GETRANDOM "AUTO" CACHE STRING - "Make use of getrandom function (ON|OFF|AUTO) [default=AUTO]") - set(EXPAT_WITH_SYS_GETRANDOM "AUTO" CACHE STRING - "Make use of syscall SYS_getrandom (ON|OFF|AUTO) [default=AUTO]") + expat_shy_set(EXPAT_DEV_URANDOM ON CACHE BOOL "Define to include code reading entropy from `/dev/urandom'.") + expat_shy_set(EXPAT_WITH_GETRANDOM "AUTO" CACHE STRING "Make use of getrandom function (ON|OFF|AUTO) [default=AUTO]") + expat_shy_set(EXPAT_WITH_SYS_GETRANDOM "AUTO" CACHE STRING "Make use of syscall SYS_getrandom (ON|OFF|AUTO) [default=AUTO]") mark_as_advanced(EXPAT_DEV_URANDOM) endif() -set(EXPAT_CHAR_TYPE "char" CACHE STRING "Character type to use (char|ushort|wchar_t) [default=char]") -option(EXPAT_ATTR_INFO "Define to allow retrieving the byte offsets for attribute names and values" OFF) +expat_shy_set(EXPAT_CHAR_TYPE "char" CACHE STRING "Character type to use (char|ushort|wchar_t) [default=char]") +expat_shy_set(EXPAT_ATTR_INFO OFF CACHE BOOL "Define to allow retrieving the byte offsets for attribute names and values") mark_as_advanced(EXPAT_ATTR_INFO) -option(EXPAT_LARGE_SIZE "Make XML_GetCurrent* functions return <(unsigned) long long> rather than <(unsigned) long>" OFF) +expat_shy_set(EXPAT_LARGE_SIZE OFF CACHE BOOL "Make XML_GetCurrent* functions return <(unsigned) long long> rather than <(unsigned) long>") mark_as_advanced(EXPAT_LARGE_SIZE) -option(EXPAT_MIN_SIZE "Get a smaller (but slower) parser (in particular avoid multiple copies of the tokenizer)" OFF) +expat_shy_set(EXPAT_MIN_SIZE OFF CACHE BOOL "Get a smaller (but slower) parser (in particular avoid multiple copies of the tokenizer)") mark_as_advanced(EXPAT_MIN_SIZE) if(MSVC OR _EXPAT_HELP) - set(EXPAT_MSVC_STATIC_CRT OFF CACHE BOOL "Use /MT flag (static CRT) when compiling in MSVC") + expat_shy_set(EXPAT_MSVC_STATIC_CRT OFF CACHE BOOL "Use /MT flag (static CRT) when compiling in MSVC") +endif() +if(NOT _EXPAT_HELP) + expat_shy_set(_EXPAT_M32 OFF CACHE BOOL "(Unofficial!) Produce 32bit code with -m32") + mark_as_advanced(_EXPAT_M32) +endif() + +if(EXPAT_BUILD_TESTS) + # We have to call enable_language() before modifying any CMAKE_CXX_* variables + enable_language(CXX) + + set(CMAKE_CXX_STANDARD 11) + set(CMAKE_CXX_STANDARD_REQUIRED ON) + set(CMAKE_CXX_EXTENSIONS OFF) # i.e. -std=c++11 rather than default -std=gnu++11 endif() # # Environment checks # +if(EXPAT_DTD AND NOT EXPAT_GE) + message(SEND_ERROR "Option EXPAT_DTD requires that EXPAT_GE is also enabled.") + message(SEND_ERROR "Please either enable option EXPAT_GE (recommended) or disable EXPAT_DTD also.") +endif() + if(EXPAT_WITH_LIBBSD) find_library(LIB_BSD NAMES bsd) if(NOT LIB_BSD) @@ -129,6 +195,26 @@ if(EXPAT_WITH_LIBBSD) endif() endif() +if(MSVC) + # For the three types of MSVC version values, please see: + # - https://cmake.org/cmake/help/latest/variable/MSVC_VERSION.html + # - https://sourceforge.net/p/predef/wiki/Compilers/ + # - https://en.wikipedia.org/wiki/Microsoft_Visual_Studio#History + set(_EXPAT_MSVC_REQUIRED_INT 1800) # i.e. 12.0/2013/1800; see PR #426 + set(_EXPAT_MSVC_SUPPORTED_INT 1920) + set(_EXPAT_MSVC_SUPPORTED_DISPLAY "Visual Studio 16.0/2019/${_EXPAT_MSVC_SUPPORTED_INT}") + + if(MSVC_VERSION VERSION_LESS ${_EXPAT_MSVC_SUPPORTED_INT}) + if(MSVC_VERSION VERSION_LESS ${_EXPAT_MSVC_REQUIRED_INT}) + message(SEND_ERROR "MSVC_VERSION ${MSVC_VERSION} is TOO OLD to compile Expat without errors.") + message(SEND_ERROR "Please use officially supported ${_EXPAT_MSVC_SUPPORTED_DISPLAY} or later. Thank you!") + else() + message(WARNING "MSVC_VERSION ${MSVC_VERSION} is NOT OFFICIALLY SUPPORTED by Expat.") + message(WARNING "Please use ${_EXPAT_MSVC_SUPPORTED_DISPLAY} or later. Thank you!") + endif() + endif() +endif() + macro(_expat_copy_bool_int source_ref dest_ref) if(${source_ref}) set(${dest_ref} 1) @@ -202,12 +288,16 @@ endif() _expat_copy_bool_int(EXPAT_ATTR_INFO XML_ATTR_INFO) _expat_copy_bool_int(EXPAT_DTD XML_DTD) +_expat_copy_bool_int(EXPAT_GE XML_GE) _expat_copy_bool_int(EXPAT_LARGE_SIZE XML_LARGE_SIZE) _expat_copy_bool_int(EXPAT_MIN_SIZE XML_MIN_SIZE) _expat_copy_bool_int(EXPAT_NS XML_NS) if(NOT WIN32) _expat_copy_bool_int(EXPAT_DEV_URANDOM XML_DEV_URANDOM) endif() +if(NOT EXPAT_CONTEXT_BYTES GREATER 0) # in particular with -DEXPAT_CONTEXT_BYTES=OFF + set(EXPAT_CONTEXT_BYTES 0) +endif() set(XML_CONTEXT_BYTES ${EXPAT_CONTEXT_BYTES}) macro(expat_install) @@ -217,7 +307,6 @@ macro(expat_install) endmacro() configure_file(expat_config.h.cmake "${CMAKE_CURRENT_BINARY_DIR}/expat_config.h") -add_definitions(-DHAVE_EXPAT_CONFIG_H) expat_install(FILES "${CMAKE_CURRENT_BINARY_DIR}/expat_config.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) @@ -226,14 +315,24 @@ if(FLAG_NO_STRICT_ALIASING) set(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -fno-strict-aliasing") endif() if(FLAG_VISIBILITY) - add_definitions(-DXML_ENABLE_VISIBILITY=1) + if(EXPAT_SHARED_LIBS) + add_definitions(-DXML_ENABLE_VISIBILITY=1) + endif() set(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -fvisibility=hidden") endif() +if(MINGW) + # Without __USE_MINGW_ANSI_STDIO the compiler produces a false positive + set(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -Wno-pedantic-ms-format") +endif() if (EXPAT_WARNINGS_AS_ERRORS) if(MSVC) add_definitions(/WX) else() set(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -Werror") + if(MINGW) + # To avoid "error: unknown conversion type character ‘l’ in format [-Werror=format=]" + set(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -Wno-format") + endif() endif() endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_COMPILE_FLAGS}") @@ -243,10 +342,12 @@ if (MSVC) if (EXPAT_MSVC_STATIC_CRT) message("-- Using static CRT ${EXPAT_MSVC_STATIC_CRT}") foreach(flag_var + CMAKE_CXX_FLAGS_${_EXPAT_BUILD_TYPE_UPPER} CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO + CMAKE_C_FLAGS_${_EXPAT_BUILD_TYPE_UPPER} CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL @@ -257,43 +358,32 @@ if (MSVC) endif() endif() +if(_EXPAT_M32 AND NOT MSVC) + foreach(flag_var + CMAKE_CXX_FLAGS_${_EXPAT_BUILD_TYPE_UPPER} + CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_MINSIZEREL + CMAKE_CXX_FLAGS_RELWITHDEBINFO + CMAKE_C_FLAGS_${_EXPAT_BUILD_TYPE_UPPER} + CMAKE_C_FLAGS_DEBUG + CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_MINSIZEREL + CMAKE_C_FLAGS_RELWITHDEBINFO + ) + set(${flag_var} "${${flag_var}} -m32") + endforeach() +endif() + include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/lib) if(MSVC) add_definitions(-D_CRT_SECURE_NO_WARNINGS -wd4996) endif() -if(WIN32) - if(_EXPAT_UNICODE_WCHAR_T) - set(_POSTFIX_WIDE "w") - endif() - - if(MSVC AND NOT EXPAT_SHARED_LIBS) - if(EXPAT_MSVC_STATIC_CRT) - set(_POSTFIX_CRT "MT") - else() - set(_POSTFIX_CRT "MD") - endif() - endif() - - foreach(postfix_var - CMAKE_DEBUG_POSTFIX - CMAKE_RELEASE_POSTFIX - CMAKE_MINSIZEREL_POSTFIX - CMAKE_RELWITHDEBINFO_POSTFIX - ) - if(postfix_var STREQUAL "CMAKE_DEBUG_POSTFIX") - set(_POSTFIX_DEBUG "d") - else() - set(_POSTFIX_DEBUG "") - endif() - - set(${postfix_var} "${_POSTFIX_WIDE}${_POSTFIX_DEBUG}${_POSTFIX_CRT}" CACHE STRING "Windows binary postfix, e.g. libexpat<postfix=[w][d][MD|MT]>.lib") - endforeach() -endif() # # C library # -set(expat_SRCS +set(_EXPAT_C_SOURCES lib/xmlparse.c lib/xmlrole.c lib/xmltok.c @@ -304,39 +394,116 @@ set(expat_SRCS if(EXPAT_SHARED_LIBS) set(_SHARED SHARED) - if(MSVC) - set(expat_SRCS ${expat_SRCS} lib/libexpat.def) + if(WIN32) + macro(_expat_def_file_toggle source_var target_var) + if(${source_var}) + set(${target_var} " ") # i.e. not commented out, a single space + else() + set(${target_var} ";") # i.e. commented out + endif() + endmacro() + + if(EXPAT_DTD OR EXPAT_GE) + set(_EXPAT_DTD_OR_GE TRUE) + else() + set(_EXPAT_DTD_OR_GE FALSE) + endif() + + _expat_def_file_toggle(_EXPAT_DTD_OR_GE _EXPAT_COMMENT_DTD_OR_GE) + _expat_def_file_toggle(EXPAT_ATTR_INFO _EXPAT_COMMENT_ATTR_INFO) + + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lib/libexpat.def.cmake" "${CMAKE_CURRENT_BINARY_DIR}/lib/libexpat.def") + set(_EXPAT_EXTRA_SOURCES ${_EXPAT_EXTRA_SOURCES} "${CMAKE_CURRENT_BINARY_DIR}/lib/libexpat.def") + + # Add DLL version + string(REPLACE "." "," _EXPAT_DLL_VERSION ${PROJECT_VERSION}.0) + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/win32/version.rc.cmake" "${CMAKE_CURRENT_BINARY_DIR}/win32/version.rc") + set(_EXPAT_EXTRA_SOURCES ${_EXPAT_EXTRA_SOURCES} "${CMAKE_CURRENT_BINARY_DIR}/win32/version.rc") endif() else() set(_SHARED STATIC) endif() -# Avoid colliding with Expat.dll of Perl's XML::Parser::Expat -if(WIN32 AND NOT MINGW) - set(_EXPAT_OUTPUT_NAME libexpat) # CMAKE_*_POSTFIX applies, see above -else() - if(_EXPAT_UNICODE) - set(_EXPAT_OUTPUT_NAME expatw) - else() - set(_EXPAT_OUTPUT_NAME expat) - endif() +add_library(expat ${_SHARED} ${_EXPAT_C_SOURCES} ${_EXPAT_EXTRA_SOURCES}) +add_library(expat::expat ALIAS expat) +if(_EXPAT_LIBM_FOUND) + target_link_libraries(expat m) endif() - -add_library(expat ${_SHARED} ${expat_SRCS}) if(EXPAT_WITH_LIBBSD) target_link_libraries(expat ${LIB_BSD}) endif() -set(LIBCURRENT 7) # sync -set(LIBREVISION 12) # with -set(LIBAGE 6) # configure.ac! +# +# Library filename postfix +# +if(_EXPAT_UNICODE) + set(_POSTFIX_WIDE "w") +endif() + +if(MSVC AND NOT EXPAT_SHARED_LIBS) + if(EXPAT_MSVC_STATIC_CRT) + set(_POSTFIX_CRT "MT") + else() + set(_POSTFIX_CRT "MD") + endif() +endif() + +foreach(build_type_upper + ${_EXPAT_BUILD_TYPE_UPPER} + DEBUG + RELEASE + MINSIZEREL + RELWITHDEBINFO + ) + if(WIN32 AND build_type_upper STREQUAL "DEBUG") + set(_POSTFIX_DEBUG "d") + else() + set(_POSTFIX_DEBUG "") # needs a reset because of being looped + endif() + + expat_shy_set(EXPAT_${build_type_upper}_POSTFIX "${_POSTFIX_WIDE}${_POSTFIX_DEBUG}${_POSTFIX_CRT}" CACHE STRING "Library filename postfix for build type ${build_type_upper}; yields filenames libexpat<postfix=[w][d][MD|MT]>.(dll|dylib|lib|so)") + mark_as_advanced(EXPAT_${build_type_upper}_POSTFIX) + set_property(TARGET expat PROPERTY ${build_type_upper}_POSTFIX ${EXPAT_${build_type_upper}_POSTFIX}) +endforeach() + +set(LIBCURRENT 11) # sync +set(LIBREVISION 0) # with +set(LIBAGE 10) # configure.ac! math(EXPR LIBCURRENT_MINUS_AGE "${LIBCURRENT} - ${LIBAGE}") -set_property(TARGET expat PROPERTY OUTPUT_NAME "${_EXPAT_OUTPUT_NAME}") if(NOT WIN32) set_property(TARGET expat PROPERTY VERSION ${LIBCURRENT_MINUS_AGE}.${LIBAGE}.${LIBREVISION}) set_property(TARGET expat PROPERTY SOVERSION ${LIBCURRENT_MINUS_AGE}) set_property(TARGET expat PROPERTY NO_SONAME ${NO_SONAME}) + + if(APPLE) + if(NOT CMAKE_VERSION VERSION_GREATER_EQUAL 3.17) + message(FATAL_ERROR "Expat requires CMake >=3.17 on platform \"APPLE\".") + endif() + + # NOTE: This intends to talk CMake into compatibility with GNU Libtool + math(EXPR _EXPAT_MACHO_COMPATIBILITY_VERSION "${LIBCURRENT} + 1") + set(_EXPAT_MACHO_CURRENT_VERSION "${_EXPAT_MACHO_COMPATIBILITY_VERSION}.${LIBREVISION}") + set_property(TARGET expat PROPERTY MACHO_COMPATIBILITY_VERSION ${_EXPAT_MACHO_COMPATIBILITY_VERSION}) + set_property(TARGET expat PROPERTY MACHO_CURRENT_VERSION ${_EXPAT_MACHO_CURRENT_VERSION}) + endif() +endif() + +if(MINGW AND EXPAT_SHARED_LIBS) + set_target_properties(expat PROPERTIES SUFFIX "-${LIBCURRENT_MINUS_AGE}.dll") +endif() + +if(WIN32 AND NOT MINGW) + # NOTE: This avoids a name collision with Expat.dll of Perl's XML::Parser::Expat + # on Windows by resorting to filename libexpat.dll since Expat 1.95.3. + # Everything but MSVC is already adding prefix "lib", automatically. + # NOTE: "set_property(TARGET expat PROPERTY PREFIX lib)" would only affect *.dll + # files but not *.lib files, so we have to rely on property OUTPUT_NAME, instead. + # Target property <CONFIG>_POSTFIX still applies. + set(_EXPAT_OUTPUT_NAME libexpat) + set_property(TARGET expat PROPERTY OUTPUT_NAME ${_EXPAT_OUTPUT_NAME}) +else() + set(_EXPAT_OUTPUT_NAME expat) endif() target_include_directories(expat @@ -346,8 +513,8 @@ target_include_directories(expat $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> ) -if(NOT EXPAT_SHARED_LIBS AND WIN32) - target_compile_definitions(expat PUBLIC -DXML_STATIC) +if(WIN32 AND EXPAT_SHARED_LIBS) + target_compile_definitions(expat PRIVATE VER_FILEVERSION=${_EXPAT_DLL_VERSION}) endif() expat_install(TARGETS expat EXPORT expat @@ -361,12 +528,42 @@ expat_install(FILES lib/expat.h lib/expat_external.h DESTINATION ${CMAKE_INSTALL # pkg-config file # if(EXPAT_BUILD_PKGCONFIG) - set(prefix ${CMAKE_INSTALL_PREFIX}) - set(exec_prefix "\${prefix}") - set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") - set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") - configure_file(expat.pc.in ${CMAKE_CURRENT_BINARY_DIR}/expat.pc @ONLY) - expat_install(FILES ${CMAKE_CURRENT_BINARY_DIR}/expat.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + if(CMAKE_INSTALL_LIBDIR MATCHES "^/") + set(_expat_pkgconfig_libdir "${CMAKE_INSTALL_LIBDIR}") + else() + set(_expat_pkgconfig_libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") + endif() + + if(CMAKE_INSTALL_INCLUDEDIR MATCHES "^/") + set(_expat_pkgconfig_includedir "${CMAKE_INSTALL_INCLUDEDIR}") + else() + set(_expat_pkgconfig_includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") + endif() + + set_target_properties(expat PROPERTIES + pkgconfig_prefix "${CMAKE_INSTALL_PREFIX}" + pkgconfig_exec_prefix "\${prefix}" + pkgconfig_libdir "${_expat_pkgconfig_libdir}" + pkgconfig_includedir "${_expat_pkgconfig_includedir}" + pkgconfig_version "${PACKAGE_VERSION}") + + foreach(_build_type ${CMAKE_BUILD_TYPE} Debug Release RelWithDebInfo MinSizeRel) + string(TOLOWER "${_build_type}" _build_type_lower) + string(TOUPPER "${_build_type}" _build_type_upper) + set_property(TARGET expat PROPERTY "pkgconfig_${_build_type_lower}_name" "expat${EXPAT_${_build_type_upper}_POSTFIX}") + set_property(TARGET expat PROPERTY "pkgconfig_${_build_type_lower}_output_name" "${_EXPAT_OUTPUT_NAME}${EXPAT_${_build_type_upper}_POSTFIX}") + if(_EXPAT_LIBM_FOUND) + set_property(TARGET expat PROPERTY "pkgconfig_libm" "-lm") + else() + set_property(TARGET expat PROPERTY "pkgconfig_libm" "") + endif() + endforeach() + + file(GENERATE + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/expat.pc + INPUT ${PROJECT_SOURCE_DIR}/expat.pc.cmake) + + expat_install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/expat.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endif() # @@ -374,15 +571,18 @@ endif() # if(EXPAT_BUILD_TOOLS) set(xmlwf_SRCS - xmlwf/xmlwf.c - xmlwf/xmlfile.c xmlwf/codepage.c xmlwf/readfilemap.c + xmlwf/xmlfile.c + xmlwf/xmlwf.c ) add_executable(xmlwf ${xmlwf_SRCS}) set_property(TARGET xmlwf PROPERTY RUNTIME_OUTPUT_DIRECTORY xmlwf) target_link_libraries(xmlwf expat) + if(_EXPAT_LIBM_FOUND) + target_link_libraries(xmlwf m) + endif() expat_install(TARGETS xmlwf DESTINATION ${CMAKE_INSTALL_BINDIR}) if(MINGW AND _EXPAT_UNICODE_WCHAR_T) @@ -409,13 +609,11 @@ endif() # C code examples # if(EXPAT_BUILD_EXAMPLES) - add_executable(elements examples/elements.c) - set_property(TARGET elements PROPERTY RUNTIME_OUTPUT_DIRECTORY examples) - target_link_libraries(elements expat) - - add_executable(outline examples/outline.c) - set_property(TARGET outline PROPERTY RUNTIME_OUTPUT_DIRECTORY examples) - target_link_libraries(outline expat) + foreach(_target element_declarations elements outline) + add_executable(${_target} examples/${_target}.c) + set_property(TARGET ${_target} PROPERTY RUNTIME_OUTPUT_DIRECTORY examples) + target_link_libraries(${_target} expat) + endforeach() endif() # @@ -423,16 +621,8 @@ endif() # if(EXPAT_BUILD_TESTS) ## these are unittests that can be run on any platform - enable_language(CXX) enable_testing() - set(test_SRCS - tests/chardata.c - tests/memcheck.c - tests/minicheck.c - tests/structdata.c - ) - if(NOT MSVC) if(MINGW) set(host whatever-mingw32) # for nothing but run.sh @@ -448,17 +638,67 @@ if(EXPAT_BUILD_TESTS) endif() endfunction() - add_executable(runtests tests/runtests.c ${test_SRCS}) - set_property(TARGET runtests PROPERTY RUNTIME_OUTPUT_DIRECTORY tests) - target_link_libraries(runtests expat) - expat_add_test(runtests $<TARGET_FILE:runtests>) + set(_EXPAT_TEST_TARGETS runtests runtests_cxx) + + add_executable(runtests + tests/acc_tests.c + tests/alloc_tests.c + tests/basic_tests.c + tests/chardata.c + tests/common.c + tests/dummy.c + tests/handlers.c + tests/memcheck.c + tests/minicheck.c + tests/misc_tests.c + tests/ns_tests.c + tests/nsalloc_tests.c + tests/runtests.c + tests/structdata.c + ${_EXPAT_C_SOURCES} + ) + + add_executable(runtests_cxx + tests/acc_tests_cxx.cpp + tests/alloc_tests_cxx.cpp + tests/basic_tests_cxx.cpp + tests/chardata_cxx.cpp + tests/common_cxx.cpp + tests/dummy_cxx.cpp + tests/handlers_cxx.cpp + tests/memcheck_cxx.cpp + tests/minicheck_cxx.cpp + tests/misc_tests_cxx.cpp + tests/ns_tests_cxx.cpp + tests/nsalloc_tests_cxx.cpp + tests/runtests_cxx.cpp + tests/structdata_cxx.cpp + ${_EXPAT_C_SOURCES} + ) + + foreach(_target ${_EXPAT_TEST_TARGETS}) + target_compile_definitions(${_target} PRIVATE -DXML_TESTING) + + set_property(TARGET ${_target} PROPERTY RUNTIME_OUTPUT_DIRECTORY tests) + expat_add_test(${_target} $<TARGET_FILE:${_target}>) - add_executable(runtestspp tests/runtestspp.cpp ${test_SRCS}) - set_property(TARGET runtestspp PROPERTY RUNTIME_OUTPUT_DIRECTORY tests) - target_link_libraries(runtestspp expat) - expat_add_test(runtestspp $<TARGET_FILE:runtestspp>) + if(_EXPAT_LIBM_FOUND) + target_link_libraries(${_target} m) + endif() + + if(EXPAT_WITH_LIBBSD) + target_link_libraries(${_target} ${LIB_BSD}) + endif() + endforeach() + + add_executable(benchmark tests/benchmark/benchmark.c) + set_property(TARGET benchmark PROPERTY RUNTIME_OUTPUT_DIRECTORY tests/benchmark) + target_link_libraries(benchmark expat) endif() +# +# Fuzzers +# if(EXPAT_BUILD_FUZZERS) if(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") message(SEND_ERROR @@ -491,7 +731,7 @@ if(EXPAT_BUILD_FUZZERS) set(encoding_types UTF-16 UTF-8 ISO-8859-1 US-ASCII UTF-16BE UTF-16LE) set(fuzz_targets xml_parse_fuzzer xml_parsebuffer_fuzzer) - add_library(fuzzpat STATIC ${expat_SRCS}) + add_library(fuzzpat STATIC ${_EXPAT_C_SOURCES}) if(NOT EXPAT_OSSFUZZ_BUILD) target_compile_options(fuzzpat PRIVATE -fsanitize=fuzzer-no-link) endif() @@ -527,6 +767,23 @@ else() endif() # +# C/C++ config affecting multiple targets +# +if(WIN32) + set(_EXPAT_STATIC_TARGETS ${_EXPAT_TEST_TARGETS}) + if(NOT EXPAT_SHARED_LIBS) + list(APPEND _EXPAT_STATIC_TARGETS expat) + endif() + if(EXPAT_BUILD_FUZZERS) + list(APPEND _EXPAT_STATIC_TARGETS fuzzpat) + endif() + + foreach(_target ${_EXPAT_STATIC_TARGETS}) + target_compile_definitions(${_target} PUBLIC -DXML_STATIC) + endforeach() +endif() + +# # Custom target "run-xmltest" # if(EXPAT_BUILD_TOOLS AND NOT MSVC) @@ -656,20 +913,31 @@ elseif(EXPAT_CHAR_TYPE STREQUAL "wchar_t") else() set(_EXPAT_CHAR_TYPE_SUMMARY "ERROR") endif() -string(TOUPPER "${CMAKE_BUILD_TYPE}" _EXPAT_BUILD_TYPE_UPPER) +# NOTE: We're not accessing global property GENERATOR_IS_MULTI_CONFIG +# because that would require CMake >=3.9 +if(CMAKE_CONFIGURATION_TYPES) + set(_EXPAT_GENERATOR_IS_MULTI_CONFIG TRUE) +else() + set(_EXPAT_GENERATOR_IS_MULTI_CONFIG FALSE) +endif() message(STATUS "===========================================================================") message(STATUS "") message(STATUS "Configuration") +message(STATUS " Generator .................. ${CMAKE_GENERATOR}") +if(_EXPAT_GENERATOR_IS_MULTI_CONFIG) + message(STATUS " Build types ................ ${CMAKE_CONFIGURATION_TYPES}") +else() + message(STATUS " Build type ................. ${CMAKE_BUILD_TYPE}") +endif() message(STATUS " Prefix ..................... ${CMAKE_INSTALL_PREFIX}") -message(STATUS " Build type ................. ${CMAKE_BUILD_TYPE}") message(STATUS " Shared libraries ........... ${EXPAT_SHARED_LIBS}") if(MSVC) message(STATUS " Static CRT ................. ${EXPAT_MSVC_STATIC_CRT}") endif() message(STATUS " Character type ............. ${_EXPAT_CHAR_TYPE_SUMMARY}") -if(WIN32) - message(STATUS " Binary postfix ............. ${CMAKE_${_EXPAT_BUILD_TYPE_UPPER}_POSTFIX}") +if(NOT _EXPAT_GENERATOR_IS_MULTI_CONFIG) + message(STATUS " Library name postfix ....... ${EXPAT_${_EXPAT_BUILD_TYPE_UPPER}_POSTFIX}") endif() message(STATUS "") message(STATUS " Build documentation ........ ${EXPAT_BUILD_DOCS}") @@ -685,6 +953,7 @@ message(STATUS " // Advanced options, changes not advised") message(STATUS " Attributes info .......... ${EXPAT_ATTR_INFO}") message(STATUS " Context bytes ............ ${EXPAT_CONTEXT_BYTES}") message(STATUS " DTD support .............. ${EXPAT_DTD}") +message(STATUS " General entities ......... ${EXPAT_GE}") message(STATUS " Large size ............... ${EXPAT_LARGE_SIZE}") message(STATUS " Minimum size ............. ${EXPAT_MIN_SIZE}") message(STATUS " Namespace support ........ ${EXPAT_NS}") diff --git a/3rdparty/expat/COPYING b/3rdparty/expat/COPYING index 3c0142e71c8..ce9e5939291 100644 --- a/3rdparty/expat/COPYING +++ b/3rdparty/expat/COPYING @@ -1,5 +1,5 @@ Copyright (c) 1998-2000 Thai Open Source Software Center Ltd and Clark Cooper -Copyright (c) 2001-2019 Expat maintainers +Copyright (c) 2001-2022 Expat maintainers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/3rdparty/expat/Changes b/3rdparty/expat/Changes index b74a7c56a96..aa19f70ae21 100644 --- a/3rdparty/expat/Changes +++ b/3rdparty/expat/Changes @@ -1,6 +1,742 @@ -NOTE: We are looking for help with a few things: - https://github.com/libexpat/libexpat/labels/help%20wanted - If you can help, please get in touch. Thanks! + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +!! <blink>Expat is UNDERSTAFFED and WITHOUT FUNDING.</blink> !! +!! ~~~~~~~~~~~~ !! +!! The following topics need *additional skilled C developers* to progress !! +!! in a timely manner or at all (loosely ordered by descending priority): !! +!! !! +!! - <blink>fixing a complex non-public security issue</blink>, !! +!! - teaming up on researching and fixing future security reports and !! +!! ClusterFuzz findings with few-days-max response times in communication !! +!! in order to (1) have a sound fix ready before the end of a 90 days !! +!! grace period and (2) in a sustainable manner, !! +!! - implementing and auto-testing XML 1.0r5 support !! +!! (needs discussion before pull requests), !! +!! - smart ideas on fixing the Autotools CMake files generation issue !! +!! without breaking CI (needs discussion before pull requests), !! +!! - the Windows binaries topic (needs requirements engineering first), !! +!! - pushing migration from `int` to `size_t` further !! +!! including edge-cases test coverage (needs discussion before anything). !! +!! !! +!! For details, please reach out via e-mail to sebastian@pipping.org so we !! +!! can schedule a voice call on the topic, in English or German. !! +!! !! +!! THANK YOU! Sebastian Pipping -- Berlin, 2024-03-09 !! +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +Release 2.6.4 Wed November 6 2024 + Security fixes: + #915 CVE-2024-50602 -- Fix crash within function XML_ResumeParser + from a NULL pointer dereference by disallowing function + XML_StopParser to (stop or) suspend an unstarted parser. + A new error code XML_ERROR_NOT_STARTED was introduced to + properly communicate this situation. // CWE-476 CWE-754 + + Other changes: + #903 CMake: Add alias target "expat::expat" + #905 docs: Document use via CMake >=3.18 with FetchContent + and SOURCE_SUBDIR and its consequences + #902 tests: Reduce use of global parser instance + #904 tests: Resolve duplicate handler + #317 #918 tests: Improve tests on doctype closing (ex CVE-2019-15903) + #914 Fix signedness of format strings + #919 #920 Version info bumped from 10:3:9 (libexpat*.so.1.9.3) + to 11:0:10 (libexpat*.so.1.10.0); see https://verbump.de/ + for what these numbers do + + Infrastructure: + #907 CI: Upgrade Clang from 18 to 19 + #913 CI: Drop macos-12 and add macos-15 + #910 CI: Adapt to breaking changes in GitHub Actions + #898 Add missing entries to .gitignore + + Special thanks to: + Hanno Böck + José Eduardo Gutiérrez Conejo + José Ricardo Cardona Quesada + +Release 2.6.3 Wed September 4 2024 + Security fixes: + #887 #890 CVE-2024-45490 -- Calling function XML_ParseBuffer with + len < 0 without noticing and then calling XML_GetBuffer + will have XML_ParseBuffer fail to recognize the problem + and XML_GetBuffer corrupt memory. + With the fix, XML_ParseBuffer now complains with error + XML_ERROR_INVALID_ARGUMENT just like sibling XML_Parse + has been doing since Expat 2.2.1, and now documented. + Impact is denial of service to potentially artitrary code + execution. + #888 #891 CVE-2024-45491 -- Internal function dtdCopy can have an + integer overflow for nDefaultAtts on 32-bit platforms + (where UINT_MAX equals SIZE_MAX). + Impact is denial of service to potentially artitrary code + execution. + #889 #892 CVE-2024-45492 -- Internal function nextScaffoldPart can + have an integer overflow for m_groupSize on 32-bit + platforms (where UINT_MAX equals SIZE_MAX). + Impact is denial of service to potentially artitrary code + execution. + + Other changes: + #851 #879 Autotools: Sync CMake templates with CMake 3.28 + #853 Autotools: Always provide path to find(1) for portability + #861 Autotools: Ensure that the m4 directory always exists. + #870 Autotools: Simplify handling of SIZEOF_VOID_P + #869 Autotools: Support non-GNU sed + #856 Autotools|CMake: Fix main() to main(void) + #865 Autotools|CMake: Fix compile tests for HAVE_SYSCALL_GETRANDOM + #863 Autotools|CMake: Stop requiring dos2unix + #854 #855 CMake: Fix check for symbols size_t and off_t + #864 docs|tests: Convert README to Markdown and update + #741 Windows: Drop support for Visual Studio <=15.0/2017 + #886 Drop needless XML_DTD guards around is_param access + #885 Fix typo in a code comment + #894 #896 Version info bumped from 10:2:9 (libexpat*.so.1.9.2) + to 10:3:9 (libexpat*.so.1.9.3); see https://verbump.de/ + for what these numbers do + + Infrastructure: + #880 Readme: Promote the call for help + #868 CI: Fix various issues + #849 CI: Allow triggering GitHub Actions workflows manually + #851 #872 .. + #873 #879 CI: Adapt to breaking changes in GitHub Actions + + Special thanks to: + Alexander Bluhm + Berkay Eren Ürün + Dag-Erling Smørgrav + Ferenc Géczi + TaiYou + +Release 2.6.2 Wed March 13 2024 + Security fixes: + #839 #842 CVE-2024-28757 -- Prevent billion laughs attacks with + isolated use of external parsers. Please see the commit + message of commit 1d50b80cf31de87750103656f6eb693746854aa8 + for details. + + Bug fixes: + #839 #841 Reject direct parameter entity recursion + and avoid the related undefined behavior + + Other changes: + #847 Autotools: Fix build for DOCBOOK_TO_MAN containing spaces + #837 Add missing #821 and #824 to 2.6.1 change log + #838 #843 Version info bumped from 10:1:9 (libexpat*.so.1.9.1) + to 10:2:9 (libexpat*.so.1.9.2); see https://verbump.de/ + for what these numbers do + + Special thanks to: + Philippe Antoine + Tomas Korbar + and + Clang UndefinedBehaviorSanitizer + OSS-Fuzz / ClusterFuzz + +Release 2.6.1 Thu February 29 2024 + Bug fixes: + #817 Make tests independent of CPU speed, and thus more robust + #828 #836 Expose billion laughs API with XML_DTD defined and + XML_GE undefined, regression from 2.6.0 + + Other changes: + #829 Hide test-only code behind new internal macro + #833 Autotools: Reject expat_config.h.in defining SIZEOF_VOID_P + #821 #824 Autotools: Fix "make clean" for case: + ./configure --without-docbook && make clean all + #819 Address compiler warnings + #832 #834 Version info bumped from 10:0:9 (libexpat*.so.1.9.0) + to 10:1:9 (libexpat*.so.1.9.1); see https://verbump.de/ + for what these numbers do + + Infrastructure: + #818 CI: Adapt to breaking changes in clang-format + + Special thanks to: + David Hall + Snild Dolkow + +Release 2.6.0 Tue February 6 2024 + Security fixes: + #789 #814 CVE-2023-52425 -- Fix quadratic runtime issues with big tokens + that can cause denial of service, in partial where + dealing with compressed XML input. Applications + that parsed a document in one go -- a single call to + functions XML_Parse or XML_ParseBuffer -- were not affected. + The smaller the chunks/buffers you use for parsing + previously, the bigger the problem prior to the fix. + Backporters should be careful to no omit parts of + pull request #789 and to include earlier pull request #771, + in order to not break the fix. + #777 CVE-2023-52426 -- Fix billion laughs attacks for users + compiling *without* XML_DTD defined (which is not common). + Users with XML_DTD defined have been protected since + Expat >=2.4.0 (and that was CVE-2013-0340 back then). + + Bug fixes: + #753 Fix parse-size-dependent "invalid token" error for + external entities that start with a byte order mark + #780 Fix NULL pointer dereference in setContext via + XML_ExternalEntityParserCreate for compilation with + XML_DTD undefined + #812 #813 Protect against closing entities out of order + + Other changes: + #723 Improve support for arc4random/arc4random_buf + #771 #788 Improve buffer growth in XML_GetBuffer and XML_Parse + #761 #770 xmlwf: Support --help and --version + #759 #770 xmlwf: Support custom buffer size for XML_GetBuffer and read + #744 xmlwf: Improve language and URL clickability in help output + #673 examples: Add new example "element_declarations.c" + #764 Be stricter about macro XML_CONTEXT_BYTES at build time + #765 Make inclusion to expat_config.h consistent + #726 #727 Autotools: configure.ac: Support --disable-maintainer-mode + #678 #705 .. + #706 #733 #792 Autotools: Sync CMake templates with CMake 3.26 + #795 Autotools: Make installation of shipped man page doc/xmlwf.1 + independent of docbook2man availability + #815 Autotools|CMake: Add missing -DXML_STATIC to pkg-config file + section "Cflags.private" in order to fix compilation + against static libexpat using pkg-config on Windows + #724 #751 Autotools|CMake: Require a C99 compiler + (a de-facto requirement already since Expat 2.2.2 of 2017) + #793 Autotools|CMake: Fix PACKAGE_BUGREPORT variable + #750 #786 Autotools|CMake: Make test suite require a C++11 compiler + #749 CMake: Require CMake >=3.5.0 + #672 CMake: Lowercase off_t and size_t to help a bug in Meson + #746 CMake: Sort xmlwf sources alphabetically + #785 CMake|Windows: Fix generation of DLL file version info + #790 CMake: Build tests/benchmark/benchmark.c as well for + a build with -DEXPAT_BUILD_TESTS=ON + #745 #757 docs: Document the importance of isFinal + adjust tests + accordingly + #736 docs: Improve use of "NULL" and "null" + #713 docs: Be specific about version of XML (XML 1.0r4) + and version of C (C99); (XML 1.0r5 will need a sponsor.) + #762 docs: reference.html: Promote function XML_ParseBuffer more + #779 docs: reference.html: Add HTML anchors to XML_* macros + #760 docs: reference.html: Upgrade to OK.css 1.2.0 + #763 #739 docs: Fix typos + #696 docs|CI: Use HTTPS URLs instead of HTTP at various places + #669 #670 .. + #692 #703 .. + #733 #772 Address compiler warnings + #798 #800 Address clang-tidy warnings + #775 #776 Version info bumped from 9:10:8 (libexpat*.so.1.8.10) + to 10:0:9 (libexpat*.so.1.9.0); see https://verbump.de/ + for what these numbers do + + Infrastructure: + #700 #701 docs: Document security policy in file SECURITY.md + #766 docs: Improve parse buffer variables in-code documentation + #674 #738 .. + #740 #747 .. + #748 #781 #782 Refactor coverage and conformance tests + #714 #716 Refactor debug level variables to unsigned long + #671 Improve handling of empty environment variable value + in function getDebugLevel (without visible user effect) + #755 #774 .. + #758 #783 .. + #784 #787 tests: Improve test coverage with regard to parse chunk size + #660 #797 #801 Fuzzing: Improve fuzzing coverage + #367 #799 Fuzzing|CI: Start running OSS-Fuzz fuzzing regression tests + #698 #721 CI: Resolve some Travis CI leftovers + #669 CI: Be robust towards absence of Git tags + #693 #694 CI: Set permissions to "contents: read" for security + #709 CI: Pin all GitHub Actions to specific commits for security + #739 CI: Reject spelling errors using codespell + #798 CI: Enforce clang-tidy clean code + #773 #808 .. + #809 #810 CI: Upgrade Clang from 15 to 18 + #796 CI: Start using Clang's Control Flow Integrity sanitizer + #675 #720 #722 CI: Adapt to breaking changes in GitHub Actions Ubuntu images + #689 CI: Adapt to breaking changes in Clang/LLVM Debian packaging + #763 CI: Adapt to breaking changes in codespell + #803 CI: Adapt to breaking changes in Cppcheck + + Special thanks to: + Ivan Galkin + Joyce Brum + Philippe Antoine + Rhodri James + Snild Dolkow + spookyahell + Steven Garske + and + Clang AddressSanitizer + Clang UndefinedBehaviorSanitizer + codespell + GCC Farm Project + OSS-Fuzz + Sony Mobile + +Release 2.5.0 Tue October 25 2022 + Security fixes: + #616 #649 #650 CVE-2022-43680 -- Fix heap use-after-free after overeager + destruction of a shared DTD in function + XML_ExternalEntityParserCreate in out-of-memory situations. + Expected impact is denial of service or potentially + arbitrary code execution. + + Bug fixes: + #612 #645 Fix corruption from undefined entities + #613 #654 Fix case when parsing was suspended while processing nested + entities + #616 #652 #653 Stop leaking opening tag bindings after a closing tag + mismatch error where a parser is reset through + XML_ParserReset and then reused to parse + #656 CMake: Fix generation of pkg-config file + #658 MinGW|CMake: Fix static library name + + Other changes: + #663 Protect header expat_config.h from multiple inclusion + #666 examples: Make use of XML_GetBuffer and be more + consistent across examples + #648 Address compiler warnings + #667 #668 Version info bumped from 9:9:8 to 9:10:8; + see https://verbump.de/ for what these numbers do + + Special thanks to: + Jann Horn + Mark Brand + Osyotr + Rhodri James + and + Google Project Zero + +Release 2.4.9 Tue September 20 2022 + Security fixes: + #629 #640 CVE-2022-40674 -- Heap use-after-free vulnerability in + function doContent. Expected impact is denial of service + or potentially arbitrary code execution. + + Bug fixes: + #634 MinGW: Fix mis-compilation for -D__USE_MINGW_ANSI_STDIO=0 + #614 docs: Fix documentation on effect of switch XML_DTD on + symbol visibility in doc/reference.html + + Other changes: + #638 MinGW: Make fix-xmltest-log.sh drop more Wine bug output + #596 #625 Autotools: Sync CMake templates with CMake 3.22 + #608 CMake: Migrate from use of CMAKE_*_POSTFIX to + dedicated variables EXPAT_*_POSTFIX to stop affecting + other projects + #597 #599 Windows|CMake: Add missing -DXML_STATIC to test runners + and fuzzers + #512 #621 Windows|CMake: Render .def file from a template to fix + linking with -DEXPAT_DTD=OFF and/or -DEXPAT_ATTR_INFO=ON + #611 #621 MinGW|CMake: Apply MSVC .def file when linking + #622 #624 MinGW|CMake: Sync library name with GNU Autotools, + i.e. produce libexpat-1.dll rather than libexpat.dll + by default. Filename libexpat.dll.a is unaffected. + #632 MinGW|CMake: Set missing variable CMAKE_RC_COMPILER in + toolchain file "cmake/mingw-toolchain.cmake" to avoid + error "windres: Command not found" on e.g. Ubuntu 20.04 + #597 #627 CMake: Unify inconsistent use of set() and option() in + context of public build time options to take need for + set(.. FORCE) in projects using Expat by means of + add_subdirectory(..) off Expat's users' shoulders + #626 #641 Stop exporting API symbols when building a static library + #644 Resolve use of deprecated "fgrep" by "grep -F" + #620 CMake: Make documentation on variables a bit more consistent + #636 CMake: Drop leading whitespace from a #cmakedefine line in + file expat_config.h.cmake + #594 xmlwf: Fix harmless variable mix-up in function nsattcmp + #592 #593 #610 Address Cppcheck warnings + #643 Address Clang 15 compiler warnings + #642 #644 Version info bumped from 9:8:8 to 9:9:8; + see https://verbump.de/ for what these numbers do + + Infrastructure: + #597 #598 CI: Windows: Start covering MSVC 2022 + #619 CI: macOS: Migrate off deprecated macOS 10.15 + #632 CI: Linux: Make migration off deprecated Ubuntu 18.04 work + #643 CI: Upgrade Clang from 14 to 15 + #637 apply-clang-format.sh: Add support for BSD find + #633 coverage.sh: Exclude MinGW headers + #635 coverage.sh: Fix name collision for -funsigned-char + + Special thanks to: + David Faure + Felix Wilhelm + Frank Bergmann + Rhodri James + Rosen Penev + Thijs Schreijer + Vincent Torri + and + Google Project Zero + +Release 2.4.8 Mon March 28 2022 + Other changes: + #587 pkg-config: Move "-lm" to section "Libs.private" + #587 CMake|MSVC: Fix pkg-config section "Libs" + #55 #582 CMake|macOS: Start using linker arguments + "-compatibility_version <version>" and + "-current_version <version>" in a way compatible with + GNU Libtool + #590 #591 Version info bumped from 9:7:8 to 9:8:8; + see https://verbump.de/ for what these numbers do + + Infrastructure: + #589 CI: Upgrade Clang from 13 to 14 + + Special thanks to: + evpobr + Kai Pastor + Sam James + +Release 2.4.7 Fri March 4 2022 + Bug fixes: + #572 #577 Relax fix to CVE-2022-25236 (introduced with release 2.4.5) + with regard to all valid URI characters (RFC 3986), + i.e. the following set (excluding whitespace): + ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz + 0123456789 % -._~ :/?#[]@ !$&'()*+,;= + + Other changes: + #555 #570 #581 CMake|Windows: Store Expat version in the DLL + #577 Document consequences of namespace separator choices not just + in doc/reference.html but also in header <expat.h> + #577 Document Expat's lack of validation of namespace URIs against + RFC 3986, and that the XML 1.0r4 specification doesn't + require Expat to validate namespace URIs, and that Expat + may do more in that regard in future releases. + If you find need for strict RFC 3986 URI validation on + application level today, https://uriparser.github.io/ may + be of interest. + #579 Fix documentation of XML_EndDoctypeDeclHandler in <expat.h> + #575 Document that a call to XML_FreeContentModel can be done at + a later time from outside the element declaration handler + #574 Make hardcoded namespace URIs easier to find in code + #573 Update documentation on use of XML_POOR_ENTOPY on Solaris + #569 #571 tests: Resolve use of macros NAN and INFINITY for GNU G++ + 4.8.2 on Solaris. + #578 #580 Version info bumped from 9:6:8 to 9:7:8; + see https://verbump.de/ for what these numbers do + + Special thanks to: + Jeffrey Walton + Johnny Jazeix + Thijs Schreijer + +Release 2.4.6 Sun February 20 2022 + Bug fixes: + #566 Fix a regression introduced by the fix for CVE-2022-25313 + in release 2.4.5 that affects applications that (1) + call function XML_SetElementDeclHandler and (2) are + parsing XML that contains nested element declarations + (e.g. "<!ELEMENT junk ((bar|foo|xyz+), zebra*)>"). + + Other changes: + #567 #568 Version info bumped from 9:5:8 to 9:6:8; + see https://verbump.de/ for what these numbers do + + Special thanks to: + Matt Sergeant + Samanta Navarro + Sergei Trofimovich + and + NixOS + Perl XML::Parser + +Release 2.4.5 Fri February 18 2022 + Security fixes: + #562 CVE-2022-25235 -- Passing malformed 2- and 3-byte UTF-8 + sequences (e.g. from start tag names) to the XML + processing application on top of Expat can cause + arbitrary damage (e.g. code execution) depending + on how invalid UTF-8 is handled inside the XML + processor; validation was not their job but Expat's. + Exploits with code execution are known to exist. + #561 CVE-2022-25236 -- Passing (one or more) namespace separator + characters in "xmlns[:prefix]" attribute values + made Expat send malformed tag names to the XML + processor on top of Expat which can cause + arbitrary damage (e.g. code execution) depending + on such unexpectable cases are handled inside the XML + processor; validation was not their job but Expat's. + Exploits with code execution are known to exist. + #558 CVE-2022-25313 -- Fix stack exhaustion in doctype parsing + that could be triggered by e.g. a 2 megabytes + file with a large number of opening braces. + Expected impact is denial of service or potentially + arbitrary code execution. + #560 CVE-2022-25314 -- Fix integer overflow in function copyString; + only affects the encoding name parameter at parser creation + time which is often hardcoded (rather than user input), + takes a value in the gigabytes to trigger, and a 64-bit + machine. Expected impact is denial of service. + #559 CVE-2022-25315 -- Fix integer overflow in function storeRawNames; + needs input in the gigabytes and a 64-bit machine. + Expected impact is denial of service or potentially + arbitrary code execution. + + Other changes: + #557 #564 Version info bumped from 9:4:8 to 9:5:8; + see https://verbump.de/ for what these numbers do + + Special thanks to: + Ivan Fratric + Samanta Navarro + and + Google Project Zero + JetBrains + +Release 2.4.4 Sun January 30 2022 + Security fixes: + #550 CVE-2022-23852 -- Fix signed integer overflow + (undefined behavior) in function XML_GetBuffer + (that is also called by function XML_Parse internally) + for when XML_CONTEXT_BYTES is defined to >0 (which is both + common and default). + Impact is denial of service or more. + #551 CVE-2022-23990 -- Fix unsigned integer overflow in function + doProlog triggered by large content in element type + declarations when there is an element declaration handler + present (from a prior call to XML_SetElementDeclHandler). + Impact is denial of service or more. + + Bug fixes: + #544 #545 xmlwf: Fix a memory leak on output file opening error + + Other changes: + #546 Autotools: Fix broken CMake support under Cygwin + #554 Windows: Add missing files to the installer to fix + compilation with CMake from installed sources + #552 #554 Version info bumped from 9:3:8 to 9:4:8; + see https://verbump.de/ for what these numbers do + + Special thanks to: + Carlo Bramini + hwt0415 + Roland Illig + Samanta Navarro + and + Clang LeakSan and the Clang team + +Release 2.4.3 Sun January 16 2022 + Security fixes: + #531 #534 CVE-2021-45960 -- Fix issues with left shifts by >=29 places + resulting in + a) realloc acting as free + b) realloc allocating too few bytes + c) undefined behavior + depending on architecture and precise value + for XML documents with >=2^27+1 prefixed attributes + on a single XML tag a la + "<r xmlns:a='[..]' a:a123='[..]' [..] />" + where XML_ParserCreateNS is used to create the parser + (which needs argument "-n" when running xmlwf). + Impact is denial of service, or more. + #532 #538 CVE-2021-46143 (ZDI-CAN-16157) -- Fix integer overflow + on variable m_groupSize in function doProlog leading + to realloc acting as free. + Impact is denial of service or more. + #539 CVE-2022-22822 to CVE-2022-22827 -- Prevent integer overflows + near memory allocation at multiple places. Mitre assigned + a dedicated CVE for each involved internal C function: + - CVE-2022-22822 for function addBinding + - CVE-2022-22823 for function build_model + - CVE-2022-22824 for function defineAttribute + - CVE-2022-22825 for function lookup + - CVE-2022-22826 for function nextScaffoldPart + - CVE-2022-22827 for function storeAtts + Impact is denial of service or more. + + Other changes: + #535 CMake: Make call to file(GENERATE [..]) work for CMake <3.19 + #541 Autotools|CMake: MinGW: Make run.sh(.in) work for Cygwin + and MSYS2 by not going through Wine on these platforms + #527 #528 Address compiler warnings + #533 #543 Version info bumped from 9:2:8 to 9:3:8; + see https://verbump.de/ for what these numbers do + + Infrastructure: + #536 CI: Check for realistic minimum CMake version + #529 #539 CI: Cover compilation with -m32 + #529 CI: Store coverage reports as artifacts for download + #528 CI: Upgrade Clang from 11 to 13 + + Special thanks to: + An anonymous whitehat + Christopher Degawa + J. Peter Mugaas + Tyson Smith + and + GCC Farm Project + Trend Micro Zero Day Initiative + +Release 2.4.2 Sun December 19 2021 + Other changes: + #509 #510 Link againgst libm for function "isnan" + #513 #514 Include expat_config.h as early as possible + #498 Autotools: Include files with release archives: + - buildconf.sh + - fuzz/*.c + #507 #519 Autotools: Sync CMake templates with CMake 3.20 + #495 #524 CMake: MinGW: Fix pkg-config section "Libs" for + - non-release build types (e.g. -DCMAKE_BUILD_TYPE=Debug) + - multi-config CMake generators (e.g. Ninja Multi-Config) + #502 #503 docs: Document that function XML_GetBuffer may return NULL + when asking for a buffer of 0 (zero) bytes size + #522 #523 docs: Fix return value docs for both + XML_SetBillionLaughsAttackProtection* functions + #525 #526 Version info bumped from 9:1:8 to 9:2:8; + see https://verbump.de/ for what these numbers do + + Special thanks to: + Donghee Na + Joergen Ibsen + Kai Pastor + +Release 2.4.1 Sun May 23 2021 + Bug fixes: + #488 #490 Autotools: Fix installed header expat_config.h for multilib + systems; regression introduced in 2.4.0 by pull request #486 + + Other changes: + #491 #492 Version info bumped from 9:0:8 to 9:1:8; + see https://verbump.de/ for what these numbers do + + Special thanks to: + Gentoo's QA check "multilib_check_headers" + +Release 2.4.0 Sun May 23 2021 + Security fixes: + #34 #466 #484 CVE-2013-0340/CWE-776 -- Protect against billion laughs attacks + (denial-of-service; flavors targeting CPU time or RAM or both, + leveraging general entities or parameter entities or both) + by tracking and limiting the input amplification factor + (<amplification> := (<direct> + <indirect>) / <direct>). + By conservative default, amplification up to a factor of 100.0 + is tolerated and rejection only starts after 8 MiB of output bytes + (=<direct> + <indirect>) have been processed. + The fix adds the following to the API: + - A new error code XML_ERROR_AMPLIFICATION_LIMIT_BREACH to + signals this specific condition. + - Two new API functions .. + - XML_SetBillionLaughsAttackProtectionMaximumAmplification and + - XML_SetBillionLaughsAttackProtectionActivationThreshold + .. to further tighten billion laughs protection parameters + when desired. Please see file "doc/reference.html" for details. + If you ever need to increase the defaults for non-attack XML + payload, please file a bug report with libexpat. + - Two new XML_FEATURE_* constants .. + - that can be queried using the XML_GetFeatureList function, and + - that are shown in "xmlwf -v" output. + - Two new environment variable switches .. + - EXPAT_ACCOUNTING_DEBUG=(0|1|2|3) and + - EXPAT_ENTITY_DEBUG=(0|1) + .. for runtime debugging of accounting and entity processing. + Specific behavior of these values may change in the future. + - Two new command line arguments "-a FACTOR" and "-b BYTES" + for xmlwf to further tighten billion laughs protection + parameters when desired. + If you ever need to increase the defaults for non-attack XML + payload, please file a bug report with libexpat. + + Bug fixes: + #332 #470 For (non-default) compilation with -DEXPAT_MIN_SIZE=ON (CMake) + or CPPFLAGS=-DXML_MIN_SIZE (GNU Autotools): Fix segfault + for UTF-16 payloads containing CDATA sections. + #485 #486 Autotools: Fix generated CMake files for non-64bit and + non-Linux platforms (e.g. macOS and MinGW in particular) + that were introduced with release 2.3.0 + + Other changes: + #468 #469 xmlwf: Improve help output and the xmlwf man page + #463 xmlwf: Improve maintainability through some refactoring + #477 xmlwf: Fix man page DocBook validity + #456 Autotools: Sync CMake templates with CMake 3.18 + #458 #459 CMake: Support absolute paths for both CMAKE_INSTALL_LIBDIR + and CMAKE_INSTALL_INCLUDEDIR + #471 #481 CMake: Add support for standard variable BUILD_SHARED_LIBS + #457 Unexpose symbol _INTERNAL_trim_to_complete_utf8_characters + #467 Resolve macro HAVE_EXPAT_CONFIG_H + #472 Delete unused legacy helper file "conftools/PrintPath" + #473 #483 Improve attribution + #464 #465 #477 doc/reference.html: Fix XHTML validity + #475 #478 doc/reference.html: Replace the 90s look by OK.css + #479 Version info bumped from 8:0:7 to 9:0:8 + due to addition of new symbols and error codes; + see https://verbump.de/ for what these numbers do + + Infrastructure: + #456 CI: Enable periodic runs + #457 CI: Start covering the list of exported symbols + #474 CI: Isolate coverage task + #476 #482 CI: Adapt to breaking changes in image "ubuntu-18.04" + #477 CI: Cover well-formedness and DocBook/XHTML validity + of doc/reference.html and doc/xmlwf.xml + + Special thanks to: + Dimitry Andric + Eero Helenius + Nick Wellnhofer + Rhodri James + Tomas Korbar + Yury Gribov + and + Clang LeakSan + JetBrains + OSS-Fuzz + +Release 2.3.0 Thu March 25 2021 + Bug fixes: + #438 When calling XML_ParseBuffer without a prior successful call to + XML_GetBuffer as a user, no longer trigger undefined behavior + (by adding an integer to a NULL pointer) but rather return + XML_STATUS_ERROR and set the error code to (new) code + XML_ERROR_NO_BUFFER. Found by UBSan (UndefinedBehaviorSanitizer) + of Clang 11 (but not Clang 9). + #444 xmlwf: Exit status 2 was used for both: + - malformed input files (documented) and + - invalid command-line arguments (undocumented). + The case of invalid command-line arguments now + has its own exit status 4, resolving the ambiguity. + + Other changes: + #439 xmlwf: Add argument -k to allow continuing after + non-fatal errors + #439 xmlwf: Add section about exit status to the -h help output + #422 #426 #447 Windows: Drop support for Visual Studio <=14.0/2015 + #434 Windows: CMake: Detect unsupported Visual Studio at + configure time (rather than at compile time) + #382 #428 testrunner: Make verbose mode (argument "-v") report + about passed tests, and make default mode report about + failures, as well. + #442 CMake: Call "enable_language(CXX)" prior to tinkering + with CMAKE_CXX_* variables + #448 Document use of libexpat from a CMake-based project + #451 Autotools: Install CMake files as generated by CMake 3.19.6 + so that users with "find_package(expat [..] CONFIG [..])" + are served on distributions that are *not* using the CMake + build system inside for libexpat packaging + #436 #437 Autotools: Drop obsolescent macro AC_HEADER_STDC + #450 #452 Autotools: Resolve use of obsolete macro AC_CONFIG_HEADER + #441 Address compiler warnings + #443 Version info bumped from 7:12:6 to 8:0:7 + due to addition of error code XML_ERROR_NO_BUFFER + (see https://verbump.de/ for what these numbers do) + + Infrastructure: + #435 #446 Replace Travis CI by GitHub Actions + + Special thanks to: + Alexander Richardson + Oleksandr Popovych + Thomas Beutlich + Tim Bray + and + Clang LeakSan, Clang 11 UBSan and the Clang team Release 2.2.10 Sat October 3 2020 Bug fixes: @@ -46,7 +782,7 @@ Release 2.2.10 Sat October 3 2020 #354 #355 .. #356 #412 Address compiler warnings #368 #369 Address pngcheck warnings with doc/*.png images - Version info bumped from 7:11:6 to 7:12:6 + #425 Version info bumped from 7:11:6 to 7:12:6 Special thanks to: asavah diff --git a/3rdparty/expat/ConfigureChecks.cmake b/3rdparty/expat/ConfigureChecks.cmake index d85e48c972d..c06b2f27857 100644 --- a/3rdparty/expat/ConfigureChecks.cmake +++ b/3rdparty/expat/ConfigureChecks.cmake @@ -2,6 +2,7 @@ include(CheckCCompilerFlag) include(CheckCSourceCompiles) include(CheckIncludeFile) include(CheckIncludeFiles) +include(CheckLibraryExists) include(CheckSymbolExists) include(TestBigEndian) @@ -45,18 +46,25 @@ else(WORDS_BIGENDIAN) endif(WORDS_BIGENDIAN) if(HAVE_SYS_TYPES_H) - check_symbol_exists("off_t" "sys/types.h" OFF_T) - check_symbol_exists("size_t" "sys/types.h" SIZE_T) -else(HAVE_SYS_TYPES_H) - set(OFF_T "long") - set(SIZE_T "unsigned") -endif(HAVE_SYS_TYPES_H) + check_c_source_compiles(" + #include <sys/types.h> + int main(void) { + const off_t offset = -123; + return 0; + }" + HAVE_OFF_T) +endif() + +if(NOT HAVE_OFF_T) + set(off_t "long") +endif() check_c_source_compiles(" + #define _GNU_SOURCE #include <stdlib.h> /* for NULL */ #include <unistd.h> /* for syscall */ #include <sys/syscall.h> /* for SYS_getrandom */ - int main() { + int main(void) { syscall(SYS_getrandom, NULL, 0, 0); return 0; }" @@ -64,3 +72,5 @@ check_c_source_compiles(" check_c_compiler_flag("-fno-strict-aliasing" FLAG_NO_STRICT_ALIASING) check_c_compiler_flag("-fvisibility=hidden" FLAG_VISIBILITY) + +check_library_exists(m cos "" _EXPAT_LIBM_FOUND) diff --git a/3rdparty/expat/Makefile.am b/3rdparty/expat/Makefile.am index 5e1d37dd1a8..3a7f0a0e950 100644 --- a/3rdparty/expat/Makefile.am +++ b/3rdparty/expat/Makefile.am @@ -6,7 +6,12 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2017 Expat development team +# Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2018 KangLin <kl222@126.com> +# Copyright (c) 2022 Johnny Jazeix <jazeix@gmail.com> +# Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com> +# Copyright (c) 2024 Alexander Bluhm <alexander.bluhm@gmx.net> +# Copyright (c) 2024 Dag-Erling Smørgrav <des@des.dev> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -53,20 +58,36 @@ pkgconfig_DATA = expat.pc pkgconfigdir = $(libdir)/pkgconfig +dist_cmake_DATA = \ + cmake/autotools/expat.cmake + +nodist_cmake_DATA = \ + cmake/autotools/expat-config-version.cmake \ + cmake/autotools/expat-noconfig.cmake \ + cmake/expat-config.cmake + +cmakedir = $(libdir)/cmake/expat-@PACKAGE_VERSION@ + + _EXTRA_DIST_CMAKE = \ - cmake/expat-config.cmake.in \ + cmake/autotools/expat-noconfig__linux.cmake.in \ + cmake/autotools/expat-noconfig__macos.cmake.in \ + cmake/autotools/expat-noconfig__windows.cmake.in \ + cmake/autotools/expat-package-init.cmake \ cmake/mingw-toolchain.cmake \ \ CMakeLists.txt \ CMake.README \ ConfigureChecks.cmake \ + expat.pc.cmake \ expat_config.h.cmake _EXTRA_DIST_WINDOWS = \ win32/build_expat_iss.bat \ win32/expat.iss \ win32/MANIFEST.txt \ - win32/README.txt + win32/README.txt \ + win32/version.rc.cmake EXTRA_DIST = \ $(_EXTRA_DIST_CMAKE) \ @@ -74,11 +95,14 @@ EXTRA_DIST = \ \ conftools/expat.m4 \ conftools/get-version.sh \ - conftools/PrintPath \ + \ + fuzz/xml_parsebuffer_fuzzer.c \ + fuzz/xml_parse_fuzzer.c \ \ xmlwf/xmlwf_helpgen.py \ xmlwf/xmlwf_helpgen.sh \ \ + buildconf.sh \ Changes \ README.md \ \ @@ -92,10 +116,10 @@ buildlib: @echo 'ERROR: is no longer supported. INSTEAD please:' >&2 @echo 'ERROR:' >&2 @echo 'ERROR: * Mass-patch Makefile.am, e.g.' >&2 - @echo 'ERROR: # find -name Makefile.am -exec sed \' >&2 + @echo 'ERROR: # find . -name Makefile.am -exec sed \' >&2 @echo 'ERROR: -e "s,libexpat\.la,libexpatw.la," \' >&2 @echo 'ERROR: -e "s,libexpat_la,libexpatw_la," \' >&2 - @echo 'ERROR: -i {} +' >&2 + @echo 'ERROR: -i.bak {} +' >&2 @echo 'ERROR:' >&2 @echo 'ERROR: * Run automake to re-generate Makefile.in files' >&2 @echo 'ERROR:' >&2 @@ -110,6 +134,11 @@ buildlib: run-benchmark: $(MAKE) -C tests/benchmark ./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/recset.xml 65535 3 + ./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/aaaaaa_attr.xml 4096 3 + ./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/aaaaaa_cdata.xml 4096 3 + ./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/aaaaaa_comment.xml 4096 3 + ./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/aaaaaa_tag.xml 4096 3 + ./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/aaaaaa_text.xml 4096 3 .PHONY: download-xmlts-zip download-xmlts-zip: diff --git a/3rdparty/expat/Makefile.in b/3rdparty/expat/Makefile.in index ab846398cb7..2c702547191 100644 --- a/3rdparty/expat/Makefile.in +++ b/3rdparty/expat/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2020 Free Software Foundation, Inc. +# Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -22,7 +22,12 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2017 Expat development team +# Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2018 KangLin <kl222@126.com> +# Copyright (c) 2022 Johnny Jazeix <jazeix@gmail.com> +# Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com> +# Copyright (c) 2024 Alexander Bluhm <alexander.bluhm@gmx.net> +# Copyright (c) 2024 Dag-Erling Smørgrav <des@des.dev> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -134,16 +139,20 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/conftools/ax-append-compile-flags.m4 \ $(top_srcdir)/conftools/ax-append-link-flags.m4 \ $(top_srcdir)/conftools/expatcfg-compiler-supports-visibility.m4 \ + $(top_srcdir)/conftools/ax-cxx-compile-stdcxx.m4 \ + $(top_srcdir)/conftools/ax-cxx-compile-stdcxx-11.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \ - $(am__configure_deps) $(am__DIST_COMMON) + $(am__configure_deps) $(dist_cmake_DATA) $(am__DIST_COMMON) am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno mkinstalldirs = $(install_sh) -d CONFIG_HEADER = expat_config.h -CONFIG_CLEAN_FILES = expat.pc run.sh +CONFIG_CLEAN_FILES = expat.pc cmake/expat-config.cmake \ + cmake/autotools/expat-config-version.cmake \ + cmake/autotools/expat-noconfig.cmake run.sh CONFIG_CLEAN_VPATH_FILES = AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) @@ -199,8 +208,9 @@ am__uninstall_files_from_dir = { \ || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ $(am__cd) "$$dir" && rm -f $$files; }; \ } -am__installdirs = "$(DESTDIR)$(pkgconfigdir)" -DATA = $(pkgconfig_DATA) +am__installdirs = "$(DESTDIR)$(cmakedir)" "$(DESTDIR)$(cmakedir)" \ + "$(DESTDIR)$(pkgconfigdir)" +DATA = $(dist_cmake_DATA) $(nodist_cmake_DATA) $(pkgconfig_DATA) RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ distclean-recursive maintainer-clean-recursive am__recursive_targets = \ @@ -227,18 +237,17 @@ am__define_uniq_tagged_files = \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` -ETAGS = etags -CTAGS = ctags -CSCOPE = cscope DIST_SUBDIRS = lib examples tests xmlwf doc am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/expat.pc.in \ $(srcdir)/expat_config.h.in $(srcdir)/run.sh.in \ + $(top_srcdir)/cmake/autotools/expat-config-version.cmake.in \ + $(top_srcdir)/cmake/expat-config.cmake.in \ $(top_srcdir)/conftools/ar-lib $(top_srcdir)/conftools/compile \ $(top_srcdir)/conftools/config.guess \ $(top_srcdir)/conftools/config.sub \ $(top_srcdir)/conftools/install-sh \ $(top_srcdir)/conftools/ltmain.sh \ - $(top_srcdir)/conftools/missing AUTHORS COPYING \ + $(top_srcdir)/conftools/missing AUTHORS COPYING README.md \ conftools/ar-lib conftools/compile conftools/config.guess \ conftools/config.sub conftools/depcomp conftools/install-sh \ conftools/ltmain.sh conftools/missing @@ -281,6 +290,8 @@ DIST_ARCHIVES = $(distdir).tar.gz $(distdir).tar.bz2 $(distdir).tar.lz \ $(distdir).tar.xz GZIP_ENV = --best DIST_TARGETS = dist-lzip dist-xz dist-bzip2 dist-gzip +# Exists only to be overridden by the user if desired. +AM_DISTCHECK_DVI_TARGET = dvi distuninstallcheck_listfiles = find . -type f -print am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \ | sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$' @@ -301,8 +312,10 @@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ -CPP = @CPP@ +CMAKE_SHARED_LIBRARY_PREFIX = @CMAKE_SHARED_LIBRARY_PREFIX@ CPPFLAGS = @CPPFLAGS@ +CSCOPE = @CSCOPE@ +CTAGS = @CTAGS@ CXX = @CXX@ CXXCPP = @CXXCPP@ CXXDEPMODE = @CXXDEPMODE@ @@ -318,10 +331,20 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ +ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ +EXPAT_ATTR_INFO = @EXPAT_ATTR_INFO@ +EXPAT_CHAR_TYPE = @EXPAT_CHAR_TYPE@ +EXPAT_CONTEXT_BYTES = @EXPAT_CONTEXT_BYTES@ +EXPAT_DTD = @EXPAT_DTD@ +EXPAT_LARGE_SIZE = @EXPAT_LARGE_SIZE@ +EXPAT_MIN_SIZE = @EXPAT_MIN_SIZE@ +EXPAT_NS = @EXPAT_NS@ FGREP = @FGREP@ +FILECMD = @FILECMD@ FILEMAP = @FILEMAP@ GREP = @GREP@ +HAVE_CXX11 = @HAVE_CXX11@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -331,6 +354,8 @@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBAGE = @LIBAGE@ LIBCURRENT = @LIBCURRENT@ +LIBDIR_BASENAME = @LIBDIR_BASENAME@ +LIBM = @LIBM@ LIBOBJS = @LIBOBJS@ LIBREVISION = @LIBREVISION@ LIBS = @LIBS@ @@ -339,6 +364,7 @@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ @@ -360,9 +386,12 @@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SIZEOF_VOID_P = @SIZEOF_VOID_P@ +SO_MAJOR = @SO_MAJOR@ +SO_MINOR = @SO_MINOR@ +SO_PATCH = @SO_PATCH@ STRIP = @STRIP@ VERSION = @VERSION@ -_EXPAT_OUTPUT_NAME = @_EXPAT_OUTPUT_NAME@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ @@ -429,20 +458,34 @@ LIBTOOLFLAGS = --verbose SUBDIRS = lib $(am__append_1) $(am__append_2) $(am__append_3) pkgconfig_DATA = expat.pc pkgconfigdir = $(libdir)/pkgconfig +dist_cmake_DATA = \ + cmake/autotools/expat.cmake + +nodist_cmake_DATA = \ + cmake/autotools/expat-config-version.cmake \ + cmake/autotools/expat-noconfig.cmake \ + cmake/expat-config.cmake + +cmakedir = $(libdir)/cmake/expat-@PACKAGE_VERSION@ _EXTRA_DIST_CMAKE = \ - cmake/expat-config.cmake.in \ + cmake/autotools/expat-noconfig__linux.cmake.in \ + cmake/autotools/expat-noconfig__macos.cmake.in \ + cmake/autotools/expat-noconfig__windows.cmake.in \ + cmake/autotools/expat-package-init.cmake \ cmake/mingw-toolchain.cmake \ \ CMakeLists.txt \ CMake.README \ ConfigureChecks.cmake \ + expat.pc.cmake \ expat_config.h.cmake _EXTRA_DIST_WINDOWS = \ win32/build_expat_iss.bat \ win32/expat.iss \ win32/MANIFEST.txt \ - win32/README.txt + win32/README.txt \ + win32/version.rc.cmake EXTRA_DIST = \ $(_EXTRA_DIST_CMAKE) \ @@ -450,11 +493,14 @@ EXTRA_DIST = \ \ conftools/expat.m4 \ conftools/get-version.sh \ - conftools/PrintPath \ + \ + fuzz/xml_parsebuffer_fuzzer.c \ + fuzz/xml_parse_fuzzer.c \ \ xmlwf/xmlwf_helpgen.py \ xmlwf/xmlwf_helpgen.sh \ \ + buildconf.sh \ Changes \ README.md \ \ @@ -467,7 +513,7 @@ all: expat_config.h .SUFFIXES: am--refresh: Makefile @: -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ @@ -493,9 +539,9 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) $(SHELL) ./config.status --recheck -$(top_srcdir)/configure: $(am__configure_deps) +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) $(am__cd) $(srcdir) && $(AUTOCONF) -$(ACLOCAL_M4): $(am__aclocal_m4_deps) +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) $(am__aclocal_m4_deps): @@ -506,7 +552,7 @@ expat_config.h: stamp-h1 stamp-h1: $(srcdir)/expat_config.h.in $(top_builddir)/config.status @rm -f stamp-h1 cd $(top_builddir) && $(SHELL) ./config.status expat_config.h -$(srcdir)/expat_config.h.in: $(am__configure_deps) +$(srcdir)/expat_config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) ($(am__cd) $(top_srcdir) && $(AUTOHEADER)) rm -f stamp-h1 touch $@ @@ -515,6 +561,12 @@ distclean-hdr: -rm -f expat_config.h stamp-h1 expat.pc: $(top_builddir)/config.status $(srcdir)/expat.pc.in cd $(top_builddir) && $(SHELL) ./config.status $@ +cmake/expat-config.cmake: $(top_builddir)/config.status $(top_srcdir)/cmake/expat-config.cmake.in + cd $(top_builddir) && $(SHELL) ./config.status $@ +cmake/autotools/expat-config-version.cmake: $(top_builddir)/config.status $(top_srcdir)/cmake/autotools/expat-config-version.cmake.in + cd $(top_builddir) && $(SHELL) ./config.status $@ +cmake/autotools/expat-noconfig.cmake: $(top_builddir)/config.status + cd $(top_builddir) && $(SHELL) ./config.status $@ run.sh: $(top_builddir)/config.status $(srcdir)/run.sh.in cd $(top_builddir) && $(SHELL) ./config.status $@ @@ -526,6 +578,48 @@ clean-libtool: distclean-libtool: -rm -f libtool config.lt +install-dist_cmakeDATA: $(dist_cmake_DATA) + @$(NORMAL_INSTALL) + @list='$(dist_cmake_DATA)'; test -n "$(cmakedir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(cmakedir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(cmakedir)" || exit 1; \ + fi; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(cmakedir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(cmakedir)" || exit $$?; \ + done + +uninstall-dist_cmakeDATA: + @$(NORMAL_UNINSTALL) + @list='$(dist_cmake_DATA)'; test -n "$(cmakedir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + dir='$(DESTDIR)$(cmakedir)'; $(am__uninstall_files_from_dir) +install-nodist_cmakeDATA: $(nodist_cmake_DATA) + @$(NORMAL_INSTALL) + @list='$(nodist_cmake_DATA)'; test -n "$(cmakedir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(cmakedir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(cmakedir)" || exit 1; \ + fi; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(cmakedir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(cmakedir)" || exit $$?; \ + done + +uninstall-nodist_cmakeDATA: + @$(NORMAL_UNINSTALL) + @list='$(nodist_cmake_DATA)'; test -n "$(cmakedir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + dir='$(DESTDIR)$(cmakedir)'; $(am__uninstall_files_from_dir) install-pkgconfigDATA: $(pkgconfig_DATA) @$(NORMAL_INSTALL) @list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \ @@ -653,7 +747,6 @@ cscopelist-am: $(am__tagged_files) distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -rm -f cscope.out cscope.in.out cscope.po.out cscope.files - distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am @@ -797,7 +890,7 @@ distcheck: dist $(DISTCHECK_CONFIGURE_FLAGS) \ --srcdir=../.. --prefix="$$dc_install_base" \ && $(MAKE) $(AM_MAKEFLAGS) \ - && $(MAKE) $(AM_MAKEFLAGS) dvi \ + && $(MAKE) $(AM_MAKEFLAGS) $(AM_DISTCHECK_DVI_TARGET) \ && $(MAKE) $(AM_MAKEFLAGS) check \ && $(MAKE) $(AM_MAKEFLAGS) install \ && $(MAKE) $(AM_MAKEFLAGS) installcheck \ @@ -853,7 +946,7 @@ check: check-recursive all-am: Makefile $(DATA) expat_config.h installdirs: installdirs-recursive installdirs-am: - for dir in "$(DESTDIR)$(pkgconfigdir)"; do \ + for dir in "$(DESTDIR)$(cmakedir)" "$(DESTDIR)$(cmakedir)" "$(DESTDIR)$(pkgconfigdir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-recursive @@ -908,7 +1001,8 @@ info: info-recursive info-am: -install-data-am: install-pkgconfigDATA +install-data-am: install-dist_cmakeDATA install-nodist_cmakeDATA \ + install-pkgconfigDATA install-dvi: install-dvi-recursive @@ -954,7 +1048,8 @@ ps: ps-recursive ps-am: -uninstall-am: uninstall-pkgconfigDATA +uninstall-am: uninstall-dist_cmakeDATA uninstall-nodist_cmakeDATA \ + uninstall-pkgconfigDATA .MAKE: $(am__recursive_targets) all install-am install-strip @@ -966,14 +1061,16 @@ uninstall-am: uninstall-pkgconfigDATA distclean-generic distclean-hdr distclean-libtool \ distclean-tags distcleancheck distdir distuninstallcheck dvi \ dvi-am html html-am info info-am install install-am \ - install-data install-data-am install-dvi install-dvi-am \ - install-exec install-exec-am install-html install-html-am \ - install-info install-info-am install-man install-pdf \ + install-data install-data-am install-dist_cmakeDATA \ + install-dvi install-dvi-am install-exec install-exec-am \ + install-html install-html-am install-info install-info-am \ + install-man install-nodist_cmakeDATA install-pdf \ install-pdf-am install-pkgconfigDATA install-ps install-ps-am \ install-strip installcheck installcheck-am installdirs \ installdirs-am maintainer-clean maintainer-clean-generic \ mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \ ps ps-am tags tags-am uninstall uninstall-am \ + uninstall-dist_cmakeDATA uninstall-nodist_cmakeDATA \ uninstall-pkgconfigDATA .PRECIOUS: Makefile @@ -985,10 +1082,10 @@ buildlib: @echo 'ERROR: is no longer supported. INSTEAD please:' >&2 @echo 'ERROR:' >&2 @echo 'ERROR: * Mass-patch Makefile.am, e.g.' >&2 - @echo 'ERROR: # find -name Makefile.am -exec sed \' >&2 + @echo 'ERROR: # find . -name Makefile.am -exec sed \' >&2 @echo 'ERROR: -e "s,libexpat\.la,libexpatw.la," \' >&2 @echo 'ERROR: -e "s,libexpat_la,libexpatw_la," \' >&2 - @echo 'ERROR: -i {} +' >&2 + @echo 'ERROR: -i.bak {} +' >&2 @echo 'ERROR:' >&2 @echo 'ERROR: * Run automake to re-generate Makefile.in files' >&2 @echo 'ERROR:' >&2 @@ -1002,6 +1099,11 @@ buildlib: run-benchmark: $(MAKE) -C tests/benchmark ./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/recset.xml 65535 3 + ./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/aaaaaa_attr.xml 4096 3 + ./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/aaaaaa_cdata.xml 4096 3 + ./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/aaaaaa_comment.xml 4096 3 + ./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/aaaaaa_tag.xml 4096 3 + ./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/aaaaaa_text.xml 4096 3 .PHONY: download-xmlts-zip download-xmlts-zip: diff --git a/3rdparty/expat/README.md b/3rdparty/expat/README.md index 428a11ab245..2a90b376137 100644 --- a/3rdparty/expat/README.md +++ b/3rdparty/expat/README.md @@ -1,12 +1,21 @@ -[](https://travis-ci.org/libexpat/libexpat) +[](https://github.com/libexpat/libexpat/actions/workflows/linux.yml) [](https://ci.appveyor.com/project/libexpat/libexpat) [](https://repology.org/metapackage/expat/versions) +[](https://sourceforge.net/projects/expat/files/) +[](https://github.com/libexpat/libexpat/releases) +> [!CAUTION] +> +> Expat is **understaffed** and without funding. +> There is a [call for help with details](https://github.com/libexpat/libexpat/blob/master/expat/Changes) +> at the top of the `Changes` file. -# Expat, Release 2.2.10 -This is Expat, a C library for parsing XML, started by -[James Clark](https://en.wikipedia.org/wiki/James_Clark_(programmer)) in 1997. +# Expat, Release 2.6.4 + +This is Expat, a C99 library for parsing +[XML 1.0 Fourth Edition](https://www.w3.org/TR/2006/REC-xml-20060816/), started by +[James Clark](https://en.wikipedia.org/wiki/James_Clark_%28programmer%29) in 1997. Expat is a stream-oriented XML parser. This means that you register handlers with the parser before starting the parse. These handlers are called when the parser discovers the associated structures in the @@ -14,13 +23,14 @@ document being parsed. A start tag is an example of the kind of structures for which you may register handlers. Expat supports the following compilers: + - GNU GCC >=4.5 - LLVM Clang >=3.5 -- Microsoft Visual Studio >=9.0/2008 +- Microsoft Visual Studio >=16.0/2019 (rolling `${today} minus 5 years`) Windows users can use the -[`expat_win32` package](https://sourceforge.net/projects/expat/files/expat_win32/), -which includes both precompiled libraries and executables, and source code for +[`expat-win32bin-*.*.*.{exe,zip}` download](https://github.com/libexpat/libexpat/releases), +which includes both pre-compiled libraries and executables, and source code for developers. Expat is [free software](https://www.gnu.org/philosophy/free-sw.en.html). @@ -30,6 +40,106 @@ contained in the file distributed with this package. This license is the same as the MIT/X Consortium license. + +## Using libexpat in your CMake-Based Project + +There are three documented ways of using libexpat with CMake: + +### a) `find_package` with Module Mode + +This approach leverages CMake's own [module `FindEXPAT`](https://cmake.org/cmake/help/latest/module/FindEXPAT.html). + +Notice the *uppercase* `EXPAT` in the following example: + +```cmake +cmake_minimum_required(VERSION 3.0) # or 3.10, see below + +project(hello VERSION 1.0.0) + +find_package(EXPAT 2.2.8 MODULE REQUIRED) + +add_executable(hello + hello.c +) + +# a) for CMake >=3.10 (see CMake's FindEXPAT docs) +target_link_libraries(hello PUBLIC EXPAT::EXPAT) + +# b) for CMake >=3.0 +target_include_directories(hello PRIVATE ${EXPAT_INCLUDE_DIRS}) +target_link_libraries(hello PUBLIC ${EXPAT_LIBRARIES}) +``` + +### b) `find_package` with Config Mode + +This approach requires files from… + +- libexpat >=2.2.8 where packaging uses the CMake build system +or +- libexpat >=2.3.0 where packaging uses the GNU Autotools build system + on Linux +or +- libexpat >=2.4.0 where packaging uses the GNU Autotools build system + on macOS or MinGW. + +Notice the *lowercase* `expat` in the following example: + +```cmake +cmake_minimum_required(VERSION 3.0) + +project(hello VERSION 1.0.0) + +find_package(expat 2.2.8 CONFIG REQUIRED char dtd ns) + +add_executable(hello + hello.c +) + +target_link_libraries(hello PUBLIC expat::expat) +``` + +### c) The `FetchContent` module + +This approach — as demonstrated below — requires CMake >=3.18 for both the +[`FetchContent` module](https://cmake.org/cmake/help/latest/module/FetchContent.html) +and its support for the `SOURCE_SUBDIR` option to be available. + +Please note that: +- Use of the `FetchContent` module with *non-release* SHA1s or `master` + of libexpat is neither advised nor considered officially supported. +- Pinning to a specific commit is great for robust CI. +- Pinning to a specific commit needs updating every time there is a new + release of libexpat — either manually or through automation —, + to not miss out on libexpat security updates. + +For an example that pulls in libexpat via Git: + +```cmake +cmake_minimum_required(VERSION 3.18) + +include(FetchContent) + +project(hello VERSION 1.0.0) + +FetchContent_Declare( + expat + GIT_REPOSITORY https://github.com/libexpat/libexpat/ + GIT_TAG 000000000_GIT_COMMIT_SHA1_HERE_000000000 # i.e. Git tag R_0_Y_Z + SOURCE_SUBDIR expat/ +) + +FetchContent_MakeAvailable(expat) + +add_executable(hello + hello.c +) + +target_link_libraries(hello PUBLIC expat) +``` + + +## Building from a Git Clone + If you are building Expat from a check-out from the [Git repository](https://github.com/libexpat/libexpat/), you need to run a script that generates the configure script using the @@ -43,6 +153,11 @@ autoconf 2.58 or newer. Run the script like this: Once this has been done, follow the same instructions as for building from a source distribution. + +## Building from a Source Distribution + +### a) Building with the configure script (i.e. GNU Autotools) + To build Expat from a source distribution, you first run the configuration shell script in the top level distribution directory: @@ -88,10 +203,10 @@ support this mode of compilation (yet): 1. Mass-patch `Makefile.am` files to use `libexpatw.la` for a library name: <br/> - `find -name Makefile.am -exec sed + `find . -name Makefile.am -exec sed -e 's,libexpat\.la,libexpatw.la,' -e 's,libexpat_la,libexpatw_la,' - -i {} +` + -i.bak {} +` 1. Run `automake` to re-write `Makefile.in` files:<br/> `automake` @@ -132,8 +247,14 @@ A reference manual is available in the file `doc/reference.html` in this distribution. -The CMake build system is still *experimental* and will replace the primary +### b) Building with CMake + +The CMake build system is still *experimental* and may replace the primary build system based on GNU Autotools at some point when it is ready. + + +#### Available Options + For an idea of the available (non-advanced) options for building with CMake: ```console @@ -147,37 +268,37 @@ CMAKE_INSTALL_PREFIX:PATH=/usr/local // Path to a program. DOCBOOK_TO_MAN:FILEPATH=/usr/bin/docbook2x-man -// build man page for xmlwf +// Build man page for xmlwf EXPAT_BUILD_DOCS:BOOL=ON -// build the examples for expat library +// Build the examples for expat library EXPAT_BUILD_EXAMPLES:BOOL=ON -// build fuzzers for the expat library +// Build fuzzers for the expat library EXPAT_BUILD_FUZZERS:BOOL=OFF -// build pkg-config file +// Build pkg-config file EXPAT_BUILD_PKGCONFIG:BOOL=ON -// build the tests for expat library +// Build the tests for expat library EXPAT_BUILD_TESTS:BOOL=ON -// build the xmlwf tool for expat library +// Build the xmlwf tool for expat library EXPAT_BUILD_TOOLS:BOOL=ON // Character type to use (char|ushort|wchar_t) [default=char] EXPAT_CHAR_TYPE:STRING=char -// install expat files in cmake install target +// Install expat files in cmake install target EXPAT_ENABLE_INSTALL:BOOL=ON // Use /MT flag (static CRT) when compiling in MSVC EXPAT_MSVC_STATIC_CRT:BOOL=OFF -// build fuzzers via ossfuzz for the expat library +// Build fuzzers via ossfuzz for the expat library EXPAT_OSSFUZZ_BUILD:BOOL=OFF -// build a shared expat library +// Build a shared expat library EXPAT_SHARED_LIBS:BOOL=ON // Treat all compiler warnings as errors @@ -186,7 +307,7 @@ EXPAT_WARNINGS_AS_ERRORS:BOOL=OFF // Make use of getrandom function (ON|OFF|AUTO) [default=AUTO] EXPAT_WITH_GETRANDOM:STRING=AUTO -// utilize libbsd (for arc4random_buf) +// Utilize libbsd (for arc4random_buf) EXPAT_WITH_LIBBSD:BOOL=OFF // Make use of syscall SYS_getrandom (ON|OFF|AUTO) [default=AUTO] diff --git a/3rdparty/expat/acinclude.m4 b/3rdparty/expat/acinclude.m4 index 7277ab29bbb..498f709bdf9 100644 --- a/3rdparty/expat/acinclude.m4 +++ b/3rdparty/expat/acinclude.m4 @@ -8,5 +8,7 @@ m4_include(conftools/ax-append-flag.m4) m4_include(conftools/ax-append-compile-flags.m4) m4_include(conftools/ax-append-link-flags.m4) m4_include(conftools/expatcfg-compiler-supports-visibility.m4) +m4_include(conftools/ax-cxx-compile-stdcxx.m4) +m4_include(conftools/ax-cxx-compile-stdcxx-11.m4) ### end of file diff --git a/3rdparty/expat/aclocal.m4 b/3rdparty/expat/aclocal.m4 index b8cb1fc8ca0..8a0016bd4e2 100644 --- a/3rdparty/expat/aclocal.m4 +++ b/3rdparty/expat/aclocal.m4 @@ -1,6 +1,6 @@ -# generated automatically by aclocal 1.16.2 -*- Autoconf -*- +# generated automatically by aclocal 1.16.5 -*- Autoconf -*- -# Copyright (C) 1996-2020 Free Software Foundation, Inc. +# Copyright (C) 1996-2021 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -14,13 +14,13 @@ m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])]) m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl -m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],, -[m4_warning([this file was generated for autoconf 2.69. +m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.71],, +[m4_warning([this file was generated for autoconf 2.71. You have another version of autoconf. It may work, but is not guaranteed to. If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically 'autoreconf'.])]) -# Copyright (C) 2002-2020 Free Software Foundation, Inc. +# Copyright (C) 2002-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -35,7 +35,7 @@ AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version='1.16' dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to dnl require some minimum version. Point them to the right macro. -m4_if([$1], [1.16.2], [], +m4_if([$1], [1.16.5], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) @@ -51,12 +51,12 @@ m4_define([_AM_AUTOCONF_VERSION], []) # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE. AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], -[AM_AUTOMAKE_VERSION([1.16.2])dnl +[AM_AUTOMAKE_VERSION([1.16.5])dnl m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) -# Copyright (C) 2011-2020 Free Software Foundation, Inc. +# Copyright (C) 2011-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -118,7 +118,7 @@ AC_SUBST([AR])dnl # AM_AUX_DIR_EXPAND -*- Autoconf -*- -# Copyright (C) 2001-2020 Free Software Foundation, Inc. +# Copyright (C) 2001-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -170,7 +170,7 @@ am_aux_dir=`cd "$ac_aux_dir" && pwd` # AM_CONDITIONAL -*- Autoconf -*- -# Copyright (C) 1997-2020 Free Software Foundation, Inc. +# Copyright (C) 1997-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -201,7 +201,7 @@ AC_CONFIG_COMMANDS_PRE( Usually this means the macro was only invoked conditionally.]]) fi])]) -# Copyright (C) 1999-2020 Free Software Foundation, Inc. +# Copyright (C) 1999-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -392,7 +392,7 @@ _AM_SUBST_NOTMAKE([am__nodep])dnl # Generate code to set up dependency tracking. -*- Autoconf -*- -# Copyright (C) 1999-2020 Free Software Foundation, Inc. +# Copyright (C) 1999-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -460,7 +460,7 @@ AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS], # Do all the work for Automake. -*- Autoconf -*- -# Copyright (C) 1996-2020 Free Software Foundation, Inc. +# Copyright (C) 1996-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -488,6 +488,10 @@ m4_defn([AC_PROG_CC]) # release and drop the old call support. AC_DEFUN([AM_INIT_AUTOMAKE], [AC_PREREQ([2.65])dnl +m4_ifdef([_$0_ALREADY_INIT], + [m4_fatal([$0 expanded multiple times +]m4_defn([_$0_ALREADY_INIT]))], + [m4_define([_$0_ALREADY_INIT], m4_expansion_stack)])dnl dnl Autoconf wants to disallow AM_ names. We explicitly allow dnl the ones we care about. m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl @@ -524,7 +528,7 @@ m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl [_AM_SET_OPTIONS([$1])dnl dnl Diagnose old-style AC_INIT with new-style AM_AUTOMAKE_INIT. m4_if( - m4_ifdef([AC_PACKAGE_NAME], [ok]):m4_ifdef([AC_PACKAGE_VERSION], [ok]), + m4_ifset([AC_PACKAGE_NAME], [ok]):m4_ifset([AC_PACKAGE_VERSION], [ok]), [ok:ok],, [m4_fatal([AC_INIT should be called with package and version arguments])])dnl AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl @@ -576,6 +580,20 @@ AC_PROVIDE_IFELSE([AC_PROG_OBJCXX], [m4_define([AC_PROG_OBJCXX], m4_defn([AC_PROG_OBJCXX])[_AM_DEPENDENCIES([OBJCXX])])])dnl ]) +# Variables for tags utilities; see am/tags.am +if test -z "$CTAGS"; then + CTAGS=ctags +fi +AC_SUBST([CTAGS]) +if test -z "$ETAGS"; then + ETAGS=etags +fi +AC_SUBST([ETAGS]) +if test -z "$CSCOPE"; then + CSCOPE=cscope +fi +AC_SUBST([CSCOPE]) + AC_REQUIRE([AM_SILENT_RULES])dnl dnl The testsuite driver may need to know about EXEEXT, so add the dnl 'am__EXEEXT' conditional if _AM_COMPILER_EXEEXT was seen. This @@ -657,7 +675,7 @@ for _am_header in $config_headers :; do done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) -# Copyright (C) 2001-2020 Free Software Foundation, Inc. +# Copyright (C) 2001-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -678,7 +696,7 @@ if test x"${install_sh+set}" != xset; then fi AC_SUBST([install_sh])]) -# Copyright (C) 2003-2020 Free Software Foundation, Inc. +# Copyright (C) 2003-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -697,9 +715,45 @@ fi rmdir .tst 2>/dev/null AC_SUBST([am__leading_dot])]) +# Add --enable-maintainer-mode option to configure. -*- Autoconf -*- +# From Jim Meyering + +# Copyright (C) 1996-2021 Free Software Foundation, Inc. +# +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# AM_MAINTAINER_MODE([DEFAULT-MODE]) +# ---------------------------------- +# Control maintainer-specific portions of Makefiles. +# Default is to disable them, unless 'enable' is passed literally. +# For symmetry, 'disable' may be passed as well. Anyway, the user +# can override the default with the --enable/--disable switch. +AC_DEFUN([AM_MAINTAINER_MODE], +[m4_case(m4_default([$1], [disable]), + [enable], [m4_define([am_maintainer_other], [disable])], + [disable], [m4_define([am_maintainer_other], [enable])], + [m4_define([am_maintainer_other], [enable]) + m4_warn([syntax], [unexpected argument to AM@&t@_MAINTAINER_MODE: $1])]) +AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles]) + dnl maintainer-mode's default is 'disable' unless 'enable' is passed + AC_ARG_ENABLE([maintainer-mode], + [AS_HELP_STRING([--]am_maintainer_other[-maintainer-mode], + am_maintainer_other[ make rules and dependencies not useful + (and sometimes confusing) to the casual installer])], + [USE_MAINTAINER_MODE=$enableval], + [USE_MAINTAINER_MODE=]m4_if(am_maintainer_other, [enable], [no], [yes])) + AC_MSG_RESULT([$USE_MAINTAINER_MODE]) + AM_CONDITIONAL([MAINTAINER_MODE], [test $USE_MAINTAINER_MODE = yes]) + MAINT=$MAINTAINER_MODE_TRUE + AC_SUBST([MAINT])dnl +] +) + # Check to see how 'make' treats includes. -*- Autoconf -*- -# Copyright (C) 2001-2020 Free Software Foundation, Inc. +# Copyright (C) 2001-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -742,7 +796,7 @@ AC_SUBST([am__quote])]) # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- -# Copyright (C) 1997-2020 Free Software Foundation, Inc. +# Copyright (C) 1997-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -763,12 +817,7 @@ AC_DEFUN([AM_MISSING_HAS_RUN], [AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl AC_REQUIRE_AUX_FILE([missing])dnl if test x"${MISSING+set}" != xset; then - case $am_aux_dir in - *\ * | *\ *) - MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; - *) - MISSING="\${SHELL} $am_aux_dir/missing" ;; - esac + MISSING="\${SHELL} '$am_aux_dir/missing'" fi # Use eval to expand $SHELL if eval "$MISSING --is-lightweight"; then @@ -781,7 +830,7 @@ fi # Helper functions for option handling. -*- Autoconf -*- -# Copyright (C) 2001-2020 Free Software Foundation, Inc. +# Copyright (C) 2001-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -810,7 +859,7 @@ AC_DEFUN([_AM_SET_OPTIONS], AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) -# Copyright (C) 1999-2020 Free Software Foundation, Inc. +# Copyright (C) 1999-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -857,7 +906,7 @@ AC_LANG_POP([C])]) # For backward compatibility. AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])]) -# Copyright (C) 2001-2020 Free Software Foundation, Inc. +# Copyright (C) 2001-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -876,7 +925,7 @@ AC_DEFUN([AM_RUN_LOG], # Check to make sure that the build environment is sane. -*- Autoconf -*- -# Copyright (C) 1996-2020 Free Software Foundation, Inc. +# Copyright (C) 1996-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -957,7 +1006,7 @@ AC_CONFIG_COMMANDS_PRE( rm -f conftest.file ]) -# Copyright (C) 2009-2020 Free Software Foundation, Inc. +# Copyright (C) 2009-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1017,7 +1066,7 @@ AC_SUBST([AM_BACKSLASH])dnl _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl ]) -# Copyright (C) 2001-2020 Free Software Foundation, Inc. +# Copyright (C) 2001-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1045,7 +1094,7 @@ fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) -# Copyright (C) 2006-2020 Free Software Foundation, Inc. +# Copyright (C) 2006-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1064,7 +1113,7 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)]) # Check how to create a tarball. -*- Autoconf -*- -# Copyright (C) 2004-2020 Free Software Foundation, Inc. +# Copyright (C) 2004-2021 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, diff --git a/3rdparty/expat/buildconf.sh b/3rdparty/expat/buildconf.sh new file mode 100755 index 00000000000..4e506b30082 --- /dev/null +++ b/3rdparty/expat/buildconf.sh @@ -0,0 +1,35 @@ +#! /usr/bin/env bash +# __ __ _ +# ___\ \/ /_ __ __ _| |_ +# / _ \\ /| '_ \ / _` | __| +# | __// \| |_) | (_| | |_ +# \___/_/\_\ .__/ \__,_|\__| +# |_| XML parser +# +# Copyright (c) 2017-2022 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> +# Copyright (c) 2024 Dag-Erling Smørgrav <des@des.dev> +# Licensed under the MIT license: +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to permit +# persons to whom the Software is furnished to do so, subject to the +# following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +# USE OR OTHER DEALINGS IN THE SOFTWARE. + +set -e + +exec autoreconf --warnings=all --install --verbose "$@" diff --git a/3rdparty/expat/cmake/autotools/expat-config-version.cmake.in b/3rdparty/expat/cmake/autotools/expat-config-version.cmake.in new file mode 100644 index 00000000000..17ab1924c35 --- /dev/null +++ b/3rdparty/expat/cmake/autotools/expat-config-version.cmake.in @@ -0,0 +1,65 @@ +# This is a basic version file for the Config-mode of find_package(). +# It is used by write_basic_package_version_file() as input file for configure_file() +# to create a version-file which can be installed along a config.cmake file. +# +# The created file sets PACKAGE_VERSION_EXACT if the current version string and +# the requested version string are exactly the same and it sets +# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version, +# but only if the requested major version is the same as the current one. +# The variable CVF_VERSION must be set before calling configure_file(). + + +set(PACKAGE_VERSION "@PACKAGE_VERSION@") + +if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + + if("@PACKAGE_VERSION@" MATCHES "^([0-9]+)\\.") + set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}") + if(NOT CVF_VERSION_MAJOR VERSION_EQUAL 0) + string(REGEX REPLACE "^0+" "" CVF_VERSION_MAJOR "${CVF_VERSION_MAJOR}") + endif() + else() + set(CVF_VERSION_MAJOR "@PACKAGE_VERSION@") + endif() + + if(PACKAGE_FIND_VERSION_RANGE) + # both endpoints of the range must have the expected major version + math (EXPR CVF_VERSION_MAJOR_NEXT "${CVF_VERSION_MAJOR} + 1") + if (NOT PACKAGE_FIND_VERSION_MIN_MAJOR STREQUAL CVF_VERSION_MAJOR + OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND NOT PACKAGE_FIND_VERSION_MAX_MAJOR STREQUAL CVF_VERSION_MAJOR) + OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND NOT PACKAGE_FIND_VERSION_MAX VERSION_LESS_EQUAL CVF_VERSION_MAJOR_NEXT))) + set(PACKAGE_VERSION_COMPATIBLE FALSE) + elseif(PACKAGE_FIND_VERSION_MIN_MAJOR STREQUAL CVF_VERSION_MAJOR + AND ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS_EQUAL PACKAGE_FIND_VERSION_MAX) + OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MAX))) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + else() + set(PACKAGE_VERSION_COMPATIBLE FALSE) + endif() + else() + if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + else() + set(PACKAGE_VERSION_COMPATIBLE FALSE) + endif() + + if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + endif() + endif() +endif() + + +# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it: +if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "@SIZEOF_VOID_P@" STREQUAL "") + return() +endif() + +# check that the installed version has the same 32/64bit-ness as the one which is currently searching: +if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "@SIZEOF_VOID_P@") + math(EXPR installedBits "@SIZEOF_VOID_P@ * 8") + set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)") + set(PACKAGE_VERSION_UNSUITABLE TRUE) +endif() diff --git a/3rdparty/expat/cmake/autotools/expat-noconfig__linux.cmake.in b/3rdparty/expat/cmake/autotools/expat-noconfig__linux.cmake.in new file mode 100644 index 00000000000..d0ad645c03f --- /dev/null +++ b/3rdparty/expat/cmake/autotools/expat-noconfig__linux.cmake.in @@ -0,0 +1,19 @@ +#---------------------------------------------------------------- +# Generated CMake target import file for configuration "NoConfig". +#---------------------------------------------------------------- + +# Commands may need to know the format version. +set(CMAKE_IMPORT_FILE_VERSION 1) + +# Import target "expat::expat" for configuration "NoConfig" +set_property(TARGET expat::expat APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG) +set_target_properties(expat::expat PROPERTIES + IMPORTED_LOCATION_NOCONFIG "${_IMPORT_PREFIX}/@LIBDIR_BASENAME@/libexpat.so.@SO_MAJOR@.@SO_MINOR@.@SO_PATCH@" + IMPORTED_SONAME_NOCONFIG "libexpat.so.@SO_MAJOR@" + ) + +list(APPEND _cmake_import_check_targets expat::expat ) +list(APPEND _cmake_import_check_files_for_expat::expat "${_IMPORT_PREFIX}/@LIBDIR_BASENAME@/libexpat.so.@SO_MAJOR@.@SO_MINOR@.@SO_PATCH@" ) + +# Commands beyond this point should not need to know the version. +set(CMAKE_IMPORT_FILE_VERSION) diff --git a/3rdparty/expat/cmake/autotools/expat-noconfig__macos.cmake.in b/3rdparty/expat/cmake/autotools/expat-noconfig__macos.cmake.in new file mode 100644 index 00000000000..bb48d9810ee --- /dev/null +++ b/3rdparty/expat/cmake/autotools/expat-noconfig__macos.cmake.in @@ -0,0 +1,19 @@ +#---------------------------------------------------------------- +# Generated CMake target import file for configuration "NoConfig". +#---------------------------------------------------------------- + +# Commands may need to know the format version. +set(CMAKE_IMPORT_FILE_VERSION 1) + +# Import target "expat::expat" for configuration "NoConfig" +set_property(TARGET expat::expat APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG) +set_target_properties(expat::expat PROPERTIES + IMPORTED_LOCATION_NOCONFIG "${_IMPORT_PREFIX}/@LIBDIR_BASENAME@/libexpat.@SO_MAJOR@.@SO_MINOR@.@SO_PATCH@.dylib" + IMPORTED_SONAME_NOCONFIG "@rpath/libexpat.@SO_MAJOR@.dylib" + ) + +list(APPEND _cmake_import_check_targets expat::expat ) +list(APPEND _cmake_import_check_files_for_expat::expat "${_IMPORT_PREFIX}/@LIBDIR_BASENAME@/libexpat.@SO_MAJOR@.@SO_MINOR@.@SO_PATCH@.dylib" ) + +# Commands beyond this point should not need to know the version. +set(CMAKE_IMPORT_FILE_VERSION) diff --git a/3rdparty/expat/cmake/autotools/expat-noconfig__windows.cmake.in b/3rdparty/expat/cmake/autotools/expat-noconfig__windows.cmake.in new file mode 100644 index 00000000000..2f7454e2ca2 --- /dev/null +++ b/3rdparty/expat/cmake/autotools/expat-noconfig__windows.cmake.in @@ -0,0 +1,19 @@ +#---------------------------------------------------------------- +# Generated CMake target import file for configuration "NoConfig". +#---------------------------------------------------------------- + +# Commands may need to know the format version. +set(CMAKE_IMPORT_FILE_VERSION 1) + +# Import target "expat::expat" for configuration "NoConfig" +set_property(TARGET expat::expat APPEND PROPERTY IMPORTED_CONFIGURATIONS NOCONFIG) +set_target_properties(expat::expat PROPERTIES + IMPORTED_IMPLIB_NOCONFIG "${_IMPORT_PREFIX}/@LIBDIR_BASENAME@/libexpat.dll.a" + IMPORTED_LOCATION_NOCONFIG "${_IMPORT_PREFIX}/bin/@CMAKE_SHARED_LIBRARY_PREFIX@expat-@SO_MAJOR@.dll" + ) + +list(APPEND _cmake_import_check_targets expat::expat ) +list(APPEND _cmake_import_check_files_for_expat::expat "${_IMPORT_PREFIX}/@LIBDIR_BASENAME@/libexpat.dll.a" "${_IMPORT_PREFIX}/bin/@CMAKE_SHARED_LIBRARY_PREFIX@expat-@SO_MAJOR@.dll" ) + +# Commands beyond this point should not need to know the version. +set(CMAKE_IMPORT_FILE_VERSION) diff --git a/3rdparty/expat/cmake/autotools/expat-package-init.cmake b/3rdparty/expat/cmake/autotools/expat-package-init.cmake new file mode 100644 index 00000000000..5cf17705329 --- /dev/null +++ b/3rdparty/expat/cmake/autotools/expat-package-init.cmake @@ -0,0 +1,25 @@ + +####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() ####### +####### Any changes to this file will be overwritten by the next CMake run #### +####### The input file was expat-config.cmake.in ######## + +get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE) + +macro(set_and_check _var _file) + set(${_var} "${_file}") + if(NOT EXISTS "${_file}") + message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !") + endif() +endmacro() + +macro(check_required_components _NAME) + foreach(comp ${${_NAME}_FIND_COMPONENTS}) + if(NOT ${_NAME}_${comp}_FOUND) + if(${_NAME}_FIND_REQUIRED_${comp}) + set(${_NAME}_FOUND FALSE) + endif() + endif() + endforeach() +endmacro() + +#################################################################################### diff --git a/3rdparty/expat/cmake/autotools/expat.cmake b/3rdparty/expat/cmake/autotools/expat.cmake new file mode 100644 index 00000000000..7850358bb3a --- /dev/null +++ b/3rdparty/expat/cmake/autotools/expat.cmake @@ -0,0 +1,107 @@ +# Generated by CMake + +if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.8) + message(FATAL_ERROR "CMake >= 2.8.0 required") +endif() +if(CMAKE_VERSION VERSION_LESS "2.8.12") + message(FATAL_ERROR "CMake >= 2.8.12 required") +endif() +cmake_policy(PUSH) +cmake_policy(VERSION 2.8.12...3.28) +#---------------------------------------------------------------- +# Generated CMake target import file. +#---------------------------------------------------------------- + +# Commands may need to know the format version. +set(CMAKE_IMPORT_FILE_VERSION 1) + +# Protect against multiple inclusion, which would fail when already imported targets are added once more. +set(_cmake_targets_defined "") +set(_cmake_targets_not_defined "") +set(_cmake_expected_targets "") +foreach(_cmake_expected_target IN ITEMS expat::expat) + list(APPEND _cmake_expected_targets "${_cmake_expected_target}") + if(TARGET "${_cmake_expected_target}") + list(APPEND _cmake_targets_defined "${_cmake_expected_target}") + else() + list(APPEND _cmake_targets_not_defined "${_cmake_expected_target}") + endif() +endforeach() +unset(_cmake_expected_target) +if(_cmake_targets_defined STREQUAL _cmake_expected_targets) + unset(_cmake_targets_defined) + unset(_cmake_targets_not_defined) + unset(_cmake_expected_targets) + unset(CMAKE_IMPORT_FILE_VERSION) + cmake_policy(POP) + return() +endif() +if(NOT _cmake_targets_defined STREQUAL "") + string(REPLACE ";" ", " _cmake_targets_defined_text "${_cmake_targets_defined}") + string(REPLACE ";" ", " _cmake_targets_not_defined_text "${_cmake_targets_not_defined}") + message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_cmake_targets_defined_text}\nTargets not yet defined: ${_cmake_targets_not_defined_text}\n") +endif() +unset(_cmake_targets_defined) +unset(_cmake_targets_not_defined) +unset(_cmake_expected_targets) + + +# Compute the installation prefix relative to this file. +get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) +get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) +get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) +get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) +if(_IMPORT_PREFIX STREQUAL "/") + set(_IMPORT_PREFIX "") +endif() + +# Create imported target expat::expat +add_library(expat::expat SHARED IMPORTED) + +set_target_properties(expat::expat PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include" + INTERFACE_LINK_LIBRARIES "m" +) + +# Load information for each installed configuration. +file(GLOB _cmake_config_files "${CMAKE_CURRENT_LIST_DIR}/expat-*.cmake") +foreach(_cmake_config_file IN LISTS _cmake_config_files) + include("${_cmake_config_file}") +endforeach() +unset(_cmake_config_file) +unset(_cmake_config_files) + +# Cleanup temporary variables. +set(_IMPORT_PREFIX) + +# Loop over all imported files and verify that they actually exist +foreach(_cmake_target IN LISTS _cmake_import_check_targets) + if(CMAKE_VERSION VERSION_LESS "3.28" + OR NOT DEFINED _cmake_import_check_xcframework_for_${_cmake_target} + OR NOT IS_DIRECTORY "${_cmake_import_check_xcframework_for_${_cmake_target}}") + foreach(_cmake_file IN LISTS "_cmake_import_check_files_for_${_cmake_target}") + if(NOT EXISTS "${_cmake_file}") + message(FATAL_ERROR "The imported target \"${_cmake_target}\" references the file + \"${_cmake_file}\" +but this file does not exist. Possible reasons include: +* The file was deleted, renamed, or moved to another location. +* An install or uninstall procedure did not complete successfully. +* The installation package was faulty and contained + \"${CMAKE_CURRENT_LIST_FILE}\" +but not all the files it references. +") + endif() + endforeach() + endif() + unset(_cmake_file) + unset("_cmake_import_check_files_for_${_cmake_target}") +endforeach() +unset(_cmake_target) +unset(_cmake_import_check_targets) + +# This file does not depend on other imported targets which have +# been exported from the same project but in a separate export set. + +# Commands beyond this point should not need to know the version. +set(CMAKE_IMPORT_FILE_VERSION) +cmake_policy(POP) diff --git a/3rdparty/expat/cmake/mingw-toolchain.cmake b/3rdparty/expat/cmake/mingw-toolchain.cmake index 31a238b05ca..9032d9e5522 100644 --- a/3rdparty/expat/cmake/mingw-toolchain.cmake +++ b/3rdparty/expat/cmake/mingw-toolchain.cmake @@ -31,6 +31,7 @@ set(CMAKE_SYSTEM_NAME Windows) set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) +set(CMAKE_RC_COMPILER i686-w64-mingw32-windres) set(WIN32 ON) set(MINGW ON) diff --git a/3rdparty/expat/configure b/3rdparty/expat/configure index 947bc0ebcde..c2f7bb797ef 100755 --- a/3rdparty/expat/configure +++ b/3rdparty/expat/configure @@ -1,11 +1,12 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for expat 2.2.10. +# Generated by GNU Autoconf 2.71 for expat 2.6.4. # -# Report bugs to <expat-bugs@libexpat.org>. +# Report bugs to <https://github.com/libexpat/libexpat/issues>. # # -# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. +# Copyright (C) 1992-1996, 1998-2017, 2020-2021 Free Software Foundation, +# Inc. # # # This configure script is free software; the Free Software Foundation @@ -16,14 +17,16 @@ # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : +as_nop=: +if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 +then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST -else +else $as_nop case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( @@ -33,46 +36,46 @@ esac fi + +# Reset variables that may have inherited troublesome values from +# the environment. + +# IFS needs to be set, to space, tab, and newline, in precisely that order. +# (If _AS_PATH_WALK were called with IFS unset, it would have the +# side effect of setting IFS to empty, thus disabling word splitting.) +# Quoting is to prevent editors from complaining about space-tab. as_nl=' ' export as_nl -# Printing a long string crashes Solaris 7 /usr/bin/printf. -as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' -as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo -as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo -# Prefer a ksh shell builtin over an external printf program on Solaris, -# but without wasting forks for bash or zsh. -if test -z "$BASH_VERSION$ZSH_VERSION" \ - && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then - as_echo='print -r --' - as_echo_n='print -rn --' -elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then - as_echo='printf %s\n' - as_echo_n='printf %s' -else - if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then - as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' - as_echo_n='/usr/ucb/echo -n' - else - as_echo_body='eval expr "X$1" : "X\\(.*\\)"' - as_echo_n_body='eval - arg=$1; - case $arg in #( - *"$as_nl"*) - expr "X$arg" : "X\\(.*\\)$as_nl"; - arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; - esac; - expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" - ' - export as_echo_n_body - as_echo_n='sh -c $as_echo_n_body as_echo' - fi - export as_echo_body - as_echo='sh -c $as_echo_body as_echo' -fi +IFS=" "" $as_nl" + +PS1='$ ' +PS2='> ' +PS4='+ ' + +# Ensure predictable behavior from utilities with locale-dependent output. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# We cannot yet rely on "unset" to work, but we need these variables +# to be unset--not just set to an empty or harmless value--now, to +# avoid bugs in old shells (e.g. pre-3.0 UWIN ksh). This construct +# also avoids known problems related to "unset" and subshell syntax +# in other old shells (e.g. bash 2.01 and pdksh 5.2.14). +for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH +do eval test \${$as_var+y} \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done + +# Ensure that fds 0, 1, and 2 are open. +if (exec 3>&0) 2>/dev/null; then :; else exec 0</dev/null; fi +if (exec 3>&1) 2>/dev/null; then :; else exec 1>/dev/null; fi +if (exec 3>&2) ; then :; else exec 2>/dev/null; fi # The user is always right. -if test "${PATH_SEPARATOR+set}" != set; then +if ${PATH_SEPARATOR+false} :; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || @@ -81,13 +84,6 @@ if test "${PATH_SEPARATOR+set}" != set; then fi -# IFS -# We need space, tab and new line, in precisely that order. Quoting is -# there to prevent editors from complaining about space-tab. -# (If _AS_PATH_WALK were called with IFS unset, it would disable word -# splitting by setting IFS to empty value.) -IFS=" "" $as_nl" - # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( @@ -96,8 +92,12 @@ case $0 in #(( for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + test -r "$as_dir$0" && as_myself=$as_dir$0 && break done IFS=$as_save_IFS @@ -109,30 +109,10 @@ if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then - $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi -# Unset variables that we do not need and which cause bugs (e.g. in -# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" -# suppresses any "Segmentation fault" message there. '((' could -# trigger a bug in pdksh 5.2.14. -for as_var in BASH_ENV ENV MAIL MAILPATH -do eval test x\${$as_var+set} = xset \ - && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : -done -PS1='$ ' -PS2='> ' -PS4='+ ' - -# NLS nuisances. -LC_ALL=C -export LC_ALL -LANGUAGE=C -export LANGUAGE - -# CDPATH. -(unset CDPATH) >/dev/null 2>&1 && unset CDPATH # Use a proper internal environment variable to ensure we don't fall # into an infinite loop, continuously re-executing ourselves. @@ -154,20 +134,22 @@ esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. -$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 -as_fn_exit 255 +printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2 +exit 255 fi # We don't want this to propagate to other subprocesses. { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then - as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : + as_bourne_compatible="as_nop=: +if test \${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 +then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on \${1+\"\$@\"}, which # is contrary to our usage. Disable this feature. alias -g '\${1+\"\$@\"}'='\"\$@\"' setopt NO_GLOB_SUBST -else +else \$as_nop case \`(set -o) 2>/dev/null\` in #( *posix*) : set -o posix ;; #( @@ -187,12 +169,15 @@ as_fn_success || { exitcode=1; echo as_fn_success failed.; } as_fn_failure && { exitcode=1; echo as_fn_failure succeeded.; } as_fn_ret_success || { exitcode=1; echo as_fn_ret_success failed.; } as_fn_ret_failure && { exitcode=1; echo as_fn_ret_failure succeeded.; } -if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then : +if ( set x; as_fn_ret_success y && test x = \"\$1\" ) +then : -else +else \$as_nop exitcode=1; echo positional parameters were not saved. fi test x\$exitcode = x0 || exit 1 +blah=\$(echo \$(echo blah)) +test x\"\$blah\" = xblah || exit 1 test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO @@ -207,30 +192,38 @@ test -x / || exit 1" test \"X\`printf %s \$ECHO\`\" = \"X\$ECHO\" \\ || test \"X\`print -r -- \$ECHO\`\" = \"X\$ECHO\" ) || exit 1 test \$(( 1 + 1 )) = 2 || exit 1" - if (eval "$as_required") 2>/dev/null; then : + if (eval "$as_required") 2>/dev/null +then : as_have_required=yes -else +else $as_nop as_have_required=no fi - if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null; then : + if test x$as_have_required = xyes && (eval "$as_suggested") 2>/dev/null +then : -else +else $as_nop as_save_IFS=$IFS; IFS=$PATH_SEPARATOR as_found=false for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac as_found=: case $as_dir in #( /*) for as_base in sh bash ksh sh5; do # Try only shells that exist, to save several forks. - as_shell=$as_dir/$as_base + as_shell=$as_dir$as_base if { test -f "$as_shell" || test -f "$as_shell.exe"; } && - { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$as_shell"; } 2>/dev/null; then : + as_run=a "$as_shell" -c "$as_bourne_compatible""$as_required" 2>/dev/null +then : CONFIG_SHELL=$as_shell as_have_required=yes - if { $as_echo "$as_bourne_compatible""$as_suggested" | as_run=a "$as_shell"; } 2>/dev/null; then : + if as_run=a "$as_shell" -c "$as_bourne_compatible""$as_suggested" 2>/dev/null +then : break 2 fi fi @@ -238,14 +231,21 @@ fi esac as_found=false done -$as_found || { if { test -f "$SHELL" || test -f "$SHELL.exe"; } && - { $as_echo "$as_bourne_compatible""$as_required" | as_run=a "$SHELL"; } 2>/dev/null; then : - CONFIG_SHELL=$SHELL as_have_required=yes -fi; } IFS=$as_save_IFS +if $as_found +then : + +else $as_nop + if { test -f "$SHELL" || test -f "$SHELL.exe"; } && + as_run=a "$SHELL" -c "$as_bourne_compatible""$as_required" 2>/dev/null +then : + CONFIG_SHELL=$SHELL as_have_required=yes +fi +fi - if test "x$CONFIG_SHELL" != x; then : + if test "x$CONFIG_SHELL" != x +then : export CONFIG_SHELL # We cannot yet assume a decent shell, so we have to provide a # neutralization value for shells without unset; and this also @@ -263,22 +263,23 @@ esac exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} # Admittedly, this is quite paranoid, since all the known shells bail # out after a failed `exec'. -$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +printf "%s\n" "$0: could not re-execute with $CONFIG_SHELL" >&2 exit 255 fi - if test x$as_have_required = xno; then : - $as_echo "$0: This script requires a shell more modern than all" - $as_echo "$0: the shells that I found on your system." - if test x${ZSH_VERSION+set} = xset ; then - $as_echo "$0: In particular, zsh $ZSH_VERSION has bugs and should" - $as_echo "$0: be upgraded to zsh 4.3.4 or later." + if test x$as_have_required = xno +then : + printf "%s\n" "$0: This script requires a shell more modern than all" + printf "%s\n" "$0: the shells that I found on your system." + if test ${ZSH_VERSION+y} ; then + printf "%s\n" "$0: In particular, zsh $ZSH_VERSION has bugs and should" + printf "%s\n" "$0: be upgraded to zsh 4.3.4 or later." else - $as_echo "$0: Please tell bug-autoconf@gnu.org and -$0: expat-bugs@libexpat.org about your system, including -$0: any error possibly output before this message. Then -$0: install a modern shell, or manually run the script -$0: under such a shell if you do have one." + printf "%s\n" "$0: Please tell bug-autoconf@gnu.org and +$0: https://github.com/libexpat/libexpat/issues about your +$0: system, including any error possibly output before this +$0: message. Then install a modern shell, or manually run +$0: the script under such a shell if you do have one." fi exit 1 fi @@ -302,6 +303,7 @@ as_fn_unset () } as_unset=as_fn_unset + # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. @@ -319,6 +321,14 @@ as_fn_exit () as_fn_set_status $1 exit $1 } # as_fn_exit +# as_fn_nop +# --------- +# Do nothing but, unlike ":", preserve the value of $?. +as_fn_nop () +{ + return $? +} +as_nop=as_fn_nop # as_fn_mkdir_p # ------------- @@ -333,7 +343,7 @@ as_fn_mkdir_p () as_dirs= while :; do case $as_dir in #( - *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" @@ -342,7 +352,7 @@ $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$as_dir" | +printf "%s\n" X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -381,12 +391,13 @@ as_fn_executable_p () # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. -if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null +then : eval 'as_fn_append () { eval $1+=\$2 }' -else +else $as_nop as_fn_append () { eval $1=\$$1\$2 @@ -398,18 +409,27 @@ fi # as_fn_append # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. -if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null +then : eval 'as_fn_arith () { as_val=$(( $* )) }' -else +else $as_nop as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` } fi # as_fn_arith +# as_fn_nop +# --------- +# Do nothing but, unlike ":", preserve the value of $?. +as_fn_nop () +{ + return $? +} +as_nop=as_fn_nop # as_fn_error STATUS ERROR [LINENO LOG_FD] # ---------------------------------------- @@ -421,9 +441,9 @@ as_fn_error () as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi - $as_echo "$as_me: error: $2" >&2 + printf "%s\n" "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error @@ -450,7 +470,7 @@ as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X/"$0" | +printf "%s\n" X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q @@ -494,7 +514,7 @@ as_cr_alnum=$as_cr_Letters$as_cr_digits s/-\n.*// ' >$as_me.lineno && chmod +x "$as_me.lineno" || - { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } + { printf "%s\n" "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } # If we had to re-execute with $CONFIG_SHELL, we're ensured to have # already done that, so ensure we don't try to do so again and fall @@ -508,6 +528,10 @@ as_cr_alnum=$as_cr_Letters$as_cr_digits exit } + +# Determine whether it's possible to make 'echo' print without a newline. +# These variables are no longer used directly by Autoconf, but are AC_SUBSTed +# for compatibility with existing Makefiles. ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) @@ -521,6 +545,13 @@ case `echo -n x` in #((((( ECHO_N='-n';; esac +# For backward compatibility with old third-party macros, we provide +# the shell variables $as_echo and $as_echo_n. New code should use +# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively. +as_echo='printf %s\n' +as_echo_n='printf %s' + + rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file @@ -590,66 +621,86 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='expat' PACKAGE_TARNAME='expat' -PACKAGE_VERSION='2.2.10' -PACKAGE_STRING='expat 2.2.10' -PACKAGE_BUGREPORT='expat-bugs@libexpat.org' +PACKAGE_VERSION='2.6.4' +PACKAGE_STRING='expat 2.6.4' +PACKAGE_BUGREPORT='https://github.com/libexpat/libexpat/issues' PACKAGE_URL='' ac_unique_file="Makefile.in" # Factoring default headers for most tests. ac_includes_default="\ -#include <stdio.h> -#ifdef HAVE_SYS_TYPES_H -# include <sys/types.h> +#include <stddef.h> +#ifdef HAVE_STDIO_H +# include <stdio.h> #endif -#ifdef HAVE_SYS_STAT_H -# include <sys/stat.h> -#endif -#ifdef STDC_HEADERS +#ifdef HAVE_STDLIB_H # include <stdlib.h> -# include <stddef.h> -#else -# ifdef HAVE_STDLIB_H -# include <stdlib.h> -# endif #endif #ifdef HAVE_STRING_H -# if !defined STDC_HEADERS && defined HAVE_MEMORY_H -# include <memory.h> -# endif # include <string.h> #endif -#ifdef HAVE_STRINGS_H -# include <strings.h> -#endif #ifdef HAVE_INTTYPES_H # include <inttypes.h> #endif #ifdef HAVE_STDINT_H # include <stdint.h> #endif +#ifdef HAVE_STRINGS_H +# include <strings.h> +#endif +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif +#ifdef HAVE_SYS_STAT_H +# include <sys/stat.h> +#endif #ifdef HAVE_UNISTD_H # include <unistd.h> #endif" -ac_header_list= +ac_header_c_list= +ac_func_c_list= ac_subst_vars='am__EXEEXT_FALSE am__EXEEXT_TRUE LTLIBOBJS LIBOBJS -_EXPAT_OUTPUT_NAME +CMAKE_SHARED_LIBRARY_PREFIX AM_LDFLAGS AM_CXXFLAGS AM_CFLAGS AM_CPPFLAGS -WITH_DOCBOOK_FALSE -WITH_DOCBOOK_TRUE +SIZEOF_VOID_P +SO_PATCH +SO_MINOR +SO_MAJOR +LIBDIR_BASENAME +EXPAT_CHAR_TYPE +EXPAT_CONTEXT_BYTES +EXPAT_NS +EXPAT_MIN_SIZE +EXPAT_LARGE_SIZE +EXPAT_DTD +EXPAT_ATTR_INFO +WITH_DISTRIBUTABLE_MANPAGE_FALSE +WITH_DISTRIBUTABLE_MANPAGE_TRUE +WITH_PREBUILT_MANPAGE_FALSE +WITH_PREBUILT_MANPAGE_TRUE +WITH_MANPAGE_FALSE +WITH_MANPAGE_TRUE DOCBOOK_TO_MAN FILEMAP +LIBM +_INTERNAL_LARGE_SIZE_FALSE +_INTERNAL_LARGE_SIZE_TRUE +_INTERNAL_MIN_SIZE_FALSE +_INTERNAL_MIN_SIZE_TRUE +_INTERNAL_UNICODE_WCHAR_T_FALSE +_INTERNAL_UNICODE_WCHAR_T_TRUE UNICODE_FALSE UNICODE_TRUE MINGW_FALSE MINGW_TRUE +HAVE_CXX11 WITH_TESTS_FALSE WITH_TESTS_TRUE WITH_EXAMPLES_FALSE @@ -666,7 +717,6 @@ CXX LIBAGE LIBREVISION LIBCURRENT -CPP LT_SYS_LIBRARY_PATH OTOOL64 OTOOL @@ -675,6 +725,7 @@ NMEDIT DSYMUTIL MANIFEST_TOOL RANLIB +FILECMD NM ac_ct_DUMPBIN DUMPBIN @@ -706,10 +757,16 @@ CFLAGS CC ac_ct_AR AR +MAINT +MAINTAINER_MODE_FALSE +MAINTAINER_MODE_TRUE AM_BACKSLASH AM_DEFAULT_VERBOSITY AM_DEFAULT_V AM_V +CSCOPE +ETAGS +CTAGS am__untar am__tar AMTAR @@ -781,15 +838,18 @@ PACKAGE_NAME PATH_SEPARATOR SHELL am__quote' -ac_subst_files='' +ac_subst_files='PACKAGE_INIT' ac_user_opts=' enable_option_checking enable_silent_rules +enable_maintainer_mode enable_dependency_tracking enable_shared enable_static +enable_pic with_pic enable_fast_install +enable_aix_soname with_aix_soname with_gnu_ld with_sysroot @@ -813,7 +873,6 @@ LDFLAGS LIBS CPPFLAGS LT_SYS_LIBRARY_PATH -CPP CXX CXXFLAGS CCC @@ -887,8 +946,6 @@ do *) ac_optarg=yes ;; esac - # Accept the important Cygnus configure options, so we can diagnose typos. - case $ac_dashdash$ac_option in --) ac_dashdash=yes ;; @@ -929,9 +986,9 @@ do ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error $? "invalid feature name: $ac_useropt" + as_fn_error $? "invalid feature name: \`$ac_useropt'" ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" @@ -955,9 +1012,9 @@ do ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error $? "invalid feature name: $ac_useropt" + as_fn_error $? "invalid feature name: \`$ac_useropt'" ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "enable_$ac_useropt" @@ -1168,9 +1225,9 @@ do ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error $? "invalid package name: $ac_useropt" + as_fn_error $? "invalid package name: \`$ac_useropt'" ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" @@ -1184,9 +1241,9 @@ do ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error $? "invalid package name: $ac_useropt" + as_fn_error $? "invalid package name: \`$ac_useropt'" ac_useropt_orig=$ac_useropt - ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` + ac_useropt=`printf "%s\n" "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in *" "with_$ac_useropt" @@ -1230,9 +1287,9 @@ Try \`$0 --help' for more information" *) # FIXME: should be removed in autoconf 3.0. - $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 + printf "%s\n" "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && - $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 + printf "%s\n" "$as_me: WARNING: invalid host type: $ac_option" >&2 : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; @@ -1248,7 +1305,7 @@ if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; - *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; + *) printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi @@ -1312,7 +1369,7 @@ $as_expr X"$as_myself" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_myself" : 'X\(//\)[^/]' \| \ X"$as_myself" : 'X\(//\)$' \| \ X"$as_myself" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$as_myself" | +printf "%s\n" X"$as_myself" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -1369,7 +1426,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures expat 2.2.10 to adapt to many kinds of systems. +\`configure' configures expat 2.6.4 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1440,7 +1497,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of expat 2.2.10:";; + short | recursive ) echo "Configuration of expat 2.6.4:";; esac cat <<\_ACEOF @@ -1450,14 +1507,22 @@ Optional Features: --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --enable-silent-rules less verbose build output (undo: "make V=1") --disable-silent-rules verbose build output (undo: "make V=0") + --disable-maintainer-mode + disable make rules and dependencies not useful (and + sometimes confusing) to the casual installer --enable-dependency-tracking do not reject slow dependency extractors --disable-dependency-tracking speeds up one-time build --enable-shared[=PKGS] build shared libraries [default=yes] --enable-static[=PKGS] build static libraries [default=yes] + --enable-pic[=PKGS] try to use only PIC/non-PIC objects [default=use + both] --enable-fast-install[=PKGS] optimize for fast installation [default=yes] + --enable-aix-soname=aix|svr4|both + shared library versioning (aka "SONAME") variant to + provide on AIX, [default=aix]. --disable-libtool-lock avoid locking (might break parallel builds) --enable-xml-attr-info Enable retrieving the byte offsets for attribute names and values [default=no] @@ -1469,11 +1534,6 @@ Optional Features: Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) - --with-pic[=PKGS] try to use only PIC/non-PIC objects [default=use - both] - --with-aix-soname=aix|svr4|both - shared library versioning (aka "SONAME") variant to - provide on AIX, [default=aix]. --with-gnu-ld assume the C compiler uses GNU ld [default=no] --with-sysroot[=DIR] Search for dependent libraries within DIR (or the compiler's sysroot if not specified). @@ -1501,7 +1561,6 @@ Some influential environment variables: you have headers in a nonstandard directory <include dir> LT_SYS_LIBRARY_PATH User-defined run-time library search path. - CPP C preprocessor CXX C++ compiler command CXXFLAGS C++ compiler flags CXXCPP C++ preprocessor @@ -1511,7 +1570,7 @@ Some influential environment variables: Use these variables to override the choices made by `configure' or to help it to find libraries and programs with nonstandard names/locations. -Report bugs to <expat-bugs@libexpat.org>. +Report bugs to <https://github.com/libexpat/libexpat/issues>. _ACEOF ac_status=$? fi @@ -1527,9 +1586,9 @@ if test "$ac_init_help" = "recursive"; then case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) - ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + ac_dir_suffix=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. - ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + ac_top_builddir_sub=`printf "%s\n" "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; @@ -1557,7 +1616,8 @@ esac ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix cd "$ac_dir" || { ac_status=$?; continue; } - # Check for guested configure. + # Check for configure.gnu first; this name is used for a wrapper for + # Metaconfig's "Configure" on case-insensitive file systems. if test -f "$ac_srcdir/configure.gnu"; then echo && $SHELL "$ac_srcdir/configure.gnu" --help=recursive @@ -1565,7 +1625,7 @@ ac_abs_srcdir=$ac_abs_top_srcdir$ac_dir_suffix echo && $SHELL "$ac_srcdir/configure" --help=recursive else - $as_echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2 + printf "%s\n" "$as_me: WARNING: no configuration information is in $ac_dir" >&2 fi || ac_status=$? cd "$ac_pwd" || { ac_status=$?; break; } done @@ -1574,10 +1634,10 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -expat configure 2.2.10 -generated by GNU Autoconf 2.69 +expat configure 2.6.4 +generated by GNU Autoconf 2.71 -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2021 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF @@ -1594,14 +1654,14 @@ fi ac_fn_c_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - rm -f conftest.$ac_objext + rm -f conftest.$ac_objext conftest.beam if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -1609,14 +1669,15 @@ $as_echo "$ac_try_echo"; } >&5 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err - } && test -s conftest.$ac_objext; then : + } && test -s conftest.$ac_objext +then : ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 +else $as_nop + printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 @@ -1632,14 +1693,14 @@ fi ac_fn_c_try_link () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - rm -f conftest.$ac_objext conftest$ac_exeext + rm -f conftest.$ac_objext conftest.beam conftest$ac_exeext if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -1647,17 +1708,18 @@ $as_echo "$ac_try_echo"; } >&5 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_c_werror_flag" || test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || test -x conftest$ac_exeext - }; then : + } +then : ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 +else $as_nop + printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 @@ -1679,120 +1741,44 @@ fi ac_fn_c_check_header_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 -$as_echo_n "checking for $2... " >&6; } -if eval \${$3+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +printf %s "checking for $2... " >&6; } +if eval test \${$3+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 #include <$2> _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : eval "$3=yes" -else +else $as_nop eval "$3=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_header_compile -# ac_fn_c_try_cpp LINENO -# ---------------------- -# Try to preprocess conftest.$ac_ext, and return whether this succeeded. -ac_fn_c_try_cpp () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - if { { ac_try="$ac_cpp conftest.$ac_ext" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err - ac_status=$? - if test -s conftest.err; then - grep -v '^ *+' conftest.err >conftest.er1 - cat conftest.er1 >&5 - mv -f conftest.er1 conftest.err - fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } > conftest.i && { - test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || - test ! -s conftest.err - }; then : - ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_retval=1 -fi - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - as_fn_set_status $ac_retval - -} # ac_fn_c_try_cpp - -# ac_fn_c_try_run LINENO -# ---------------------- -# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes -# that executables *can* be run. -ac_fn_c_try_run () -{ - as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - if { { ac_try="$ac_link" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_link") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' - { { case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; }; then : - ac_retval=0 -else - $as_echo "$as_me: program exited with status $ac_status" >&5 - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_retval=$ac_status -fi - rm -rf conftest.dSYM conftest_ipa8_conftest.oo - eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno - as_fn_set_status $ac_retval - -} # ac_fn_c_try_run - # ac_fn_c_check_func LINENO FUNC VAR # ---------------------------------- # Tests whether FUNC exists, setting the cache variable VAR accordingly ac_fn_c_check_func () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 -$as_echo_n "checking for $2... " >&6; } -if eval \${$3+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +printf %s "checking for $2... " >&6; } +if eval test \${$3+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ /* Define $2 to an innocuous variant, in case <limits.h> declares $2. @@ -1800,16 +1786,9 @@ else #define $2 innocuous_$2 /* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $2 (); below. - Prefer <limits.h> to <assert.h> if __STDC__ is defined, since - <limits.h> exists even on freestanding compilers. */ - -#ifdef __STDC__ -# include <limits.h> -#else -# include <assert.h> -#endif + which can conflict with char $2 (void); below. */ +#include <limits.h> #undef $2 /* Override any GCC internal prototype to avoid an error. @@ -1818,7 +1797,7 @@ else #ifdef __cplusplus extern "C" #endif -char $2 (); +char $2 (void); /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named something starting with __ and the normal name is an alias. */ @@ -1827,24 +1806,25 @@ choke me #endif int -main () +main (void) { return $2 (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : eval "$3=yes" -else +else $as_nop eval "$3=no" fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext fi eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_func @@ -1855,14 +1835,14 @@ $as_echo "$ac_res" >&6; } ac_fn_cxx_try_compile () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - rm -f conftest.$ac_objext + rm -f conftest.$ac_objext conftest.beam if { { ac_try="$ac_compile" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -1870,14 +1850,15 @@ $as_echo "$ac_try_echo"; } >&5 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_cxx_werror_flag" || test ! -s conftest.err - } && test -s conftest.$ac_objext; then : + } && test -s conftest.$ac_objext +then : ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 +else $as_nop + printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 @@ -1899,7 +1880,7 @@ case "(($ac_try" in *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_cpp conftest.$ac_ext") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -1907,14 +1888,15 @@ $as_echo "$ac_try_echo"; } >&5 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } > conftest.i && { test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || test ! -s conftest.err - }; then : + } +then : ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 +else $as_nop + printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 @@ -1930,14 +1912,14 @@ fi ac_fn_cxx_try_link () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - rm -f conftest.$ac_objext conftest$ac_exeext + rm -f conftest.$ac_objext conftest.beam conftest$ac_exeext if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -1945,17 +1927,18 @@ $as_echo "$ac_try_echo"; } >&5 cat conftest.er1 >&5 mv -f conftest.er1 conftest.err fi - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && { test -z "$ac_cxx_werror_flag" || test ! -s conftest.err } && test -s conftest$ac_exeext && { test "$cross_compiling" = yes || test -x conftest$ac_exeext - }; then : + } +then : ac_retval=0 -else - $as_echo "$as_me: failed program was:" >&5 +else $as_nop + printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 ac_retval=1 @@ -1970,6 +1953,49 @@ fi } # ac_fn_cxx_try_link +# ac_fn_c_try_run LINENO +# ---------------------- +# Try to run conftest.$ac_ext, and return whether this succeeded. Assumes that +# executables *can* be run. +ac_fn_c_try_run () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +printf "%s\n" "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { ac_try='./conftest$ac_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +printf "%s\n" "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } +then : + ac_retval=0 +else $as_nop + printf "%s\n" "$as_me: program exited with status $ac_status" >&5 + printf "%s\n" "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=$ac_status +fi + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_try_run + # ac_fn_c_check_type LINENO TYPE VAR INCLUDES # ------------------------------------------- # Tests whether TYPE exists after having included INCLUDES, setting cache @@ -1977,17 +2003,18 @@ fi ac_fn_c_check_type () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 -$as_echo_n "checking for $2... " >&6; } -if eval \${$3+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +printf %s "checking for $2... " >&6; } +if eval test \${$3+y} +then : + printf %s "(cached) " >&6 +else $as_nop eval "$3=no" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int -main () +main (void) { if (sizeof ($2)) return 0; @@ -1995,12 +2022,13 @@ if (sizeof ($2)) return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 int -main () +main (void) { if (sizeof (($2))) return 0; @@ -2008,120 +2036,239 @@ if (sizeof (($2))) return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : -else +else $as_nop eval "$3=yes" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_c_check_type -# ac_fn_c_check_header_mongrel LINENO HEADER VAR INCLUDES -# ------------------------------------------------------- -# Tests whether HEADER exists, giving a warning if it cannot be compiled using -# the include files in INCLUDES and setting the cache variable VAR -# accordingly. -ac_fn_c_check_header_mongrel () +# ac_fn_c_compute_int LINENO EXPR VAR INCLUDES +# -------------------------------------------- +# Tries to find the compile-time value of EXPR in a program that includes +# INCLUDES, setting VAR accordingly. Returns whether the value could be +# computed +ac_fn_c_compute_int () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - if eval \${$3+:} false; then : - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 -$as_echo_n "checking for $2... " >&6; } -if eval \${$3+:} false; then : - $as_echo_n "(cached) " >&6 -fi -eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -else - # Is the header compilable? -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 usability" >&5 -$as_echo_n "checking $2 usability... " >&6; } + if test "$cross_compiling" = yes; then + # Depending upon the size, compute the lo and hi bounds. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $4 -#include <$2> +int +main (void) +{ +static int test_array [1 - 2 * !(($2) >= 0)]; +test_array [0] = 0; +return test_array [0]; + + ; + return 0; +} _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_header_compiler=yes -else - ac_header_compiler=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_compiler" >&5 -$as_echo "$ac_header_compiler" >&6; } +if ac_fn_c_try_compile "$LINENO" +then : + ac_lo=0 ac_mid=0 + while :; do + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main (void) +{ +static int test_array [1 - 2 * !(($2) <= $ac_mid)]; +test_array [0] = 0; +return test_array [0]; -# Is the header present? -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking $2 presence" >&5 -$as_echo_n "checking $2 presence... " >&6; } -cat confdefs.h - <<_ACEOF >conftest.$ac_ext + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + ac_hi=$ac_mid; break +else $as_nop + as_fn_arith $ac_mid + 1 && ac_lo=$as_val + if test $ac_lo -le $ac_mid; then + ac_lo= ac_hi= + break + fi + as_fn_arith 2 '*' $ac_mid + 1 && ac_mid=$as_val +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + done +else $as_nop + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include <$2> +$4 +int +main (void) +{ +static int test_array [1 - 2 * !(($2) < 0)]; +test_array [0] = 0; +return test_array [0]; + + ; + return 0; +} _ACEOF -if ac_fn_c_try_cpp "$LINENO"; then : - ac_header_preproc=yes -else - ac_header_preproc=no +if ac_fn_c_try_compile "$LINENO" +then : + ac_hi=-1 ac_mid=-1 + while :; do + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main (void) +{ +static int test_array [1 - 2 * !(($2) >= $ac_mid)]; +test_array [0] = 0; +return test_array [0]; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + ac_lo=$ac_mid; break +else $as_nop + as_fn_arith '(' $ac_mid ')' - 1 && ac_hi=$as_val + if test $ac_mid -le $ac_hi; then + ac_lo= ac_hi= + break + fi + as_fn_arith 2 '*' $ac_mid && ac_mid=$as_val +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + done +else $as_nop + ac_lo= ac_hi= fi -rm -f conftest.err conftest.i conftest.$ac_ext -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 -$as_echo "$ac_header_preproc" >&6; } - -# So? What about this header? -case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in #(( - yes:no: ) - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&5 -$as_echo "$as_me: WARNING: $2: accepted by the compiler, rejected by the preprocessor!" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} - ;; - no:yes:* ) - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: present but cannot be compiled" >&5 -$as_echo "$as_me: WARNING: $2: present but cannot be compiled" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: check for missing prerequisite headers?" >&5 -$as_echo "$as_me: WARNING: $2: check for missing prerequisite headers?" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: see the Autoconf documentation" >&5 -$as_echo "$as_me: WARNING: $2: see the Autoconf documentation" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&5 -$as_echo "$as_me: WARNING: $2: section \"Present But Cannot Be Compiled\"" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $2: proceeding with the compiler's result" >&5 -$as_echo "$as_me: WARNING: $2: proceeding with the compiler's result" >&2;} -( $as_echo "## -------------------------------------- ## -## Report this to expat-bugs@libexpat.org ## -## -------------------------------------- ##" - ) | sed "s/^/$as_me: WARNING: /" >&2 - ;; -esac - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 -$as_echo_n "checking for $2... " >&6; } -if eval \${$3+:} false; then : - $as_echo_n "(cached) " >&6 -else - eval "$3=\$ac_header_compiler" +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -eval ac_res=\$$3 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +# Binary search between lo and hi bounds. +while test "x$ac_lo" != "x$ac_hi"; do + as_fn_arith '(' $ac_hi - $ac_lo ')' / 2 + $ac_lo && ac_mid=$as_val + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +int +main (void) +{ +static int test_array [1 - 2 * !(($2) <= $ac_mid)]; +test_array [0] = 0; +return test_array [0]; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : + ac_hi=$ac_mid +else $as_nop + as_fn_arith '(' $ac_mid ')' + 1 && ac_lo=$as_val fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext +done +case $ac_lo in #(( +?*) eval "$3=\$ac_lo"; ac_retval=0 ;; +'') ac_retval=1 ;; +esac + else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$4 +static long int longval (void) { return $2; } +static unsigned long int ulongval (void) { return $2; } +#include <stdio.h> +#include <stdlib.h> +int +main (void) +{ + + FILE *f = fopen ("conftest.val", "w"); + if (! f) + return 1; + if (($2) < 0) + { + long int i = longval (); + if (i != ($2)) + return 1; + fprintf (f, "%ld", i); + } + else + { + unsigned long int i = ulongval (); + if (i != ($2)) + return 1; + fprintf (f, "%lu", i); + } + /* Do not output a trailing newline, as this causes \r\n confusion + on some platforms. */ + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_run "$LINENO" +then : + echo >>conftest.val; read $3 <conftest.val; ac_retval=0 +else $as_nop + ac_retval=1 +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +rm -f conftest.val + + fi eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval + +} # ac_fn_c_compute_int +ac_configure_args_raw= +for ac_arg +do + case $ac_arg in + *\'*) + ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + esac + as_fn_append ac_configure_args_raw " '$ac_arg'" +done + +case $ac_configure_args_raw in + *$as_nl*) + ac_safe_unquote= ;; + *) + ac_unsafe_z='|&;<>()$`\\"*?[ '' ' # This string ends in space, tab. + ac_unsafe_a="$ac_unsafe_z#~" + ac_safe_unquote="s/ '\\([^$ac_unsafe_a][^$ac_unsafe_z]*\\)'/ \\1/g" + ac_configure_args_raw=` printf "%s\n" "$ac_configure_args_raw" | sed "$ac_safe_unquote"`;; +esac -} # ac_fn_c_check_header_mongrel cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by expat $as_me 2.2.10, which was -generated by GNU Autoconf 2.69. Invocation command line was +It was created by expat $as_me 2.6.4, which was +generated by GNU Autoconf 2.71. Invocation command line was - $ $0 $@ + $ $0$ac_configure_args_raw _ACEOF exec 5>>config.log @@ -2154,8 +2301,12 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - $as_echo "PATH: $as_dir" + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + printf "%s\n" "PATH: $as_dir" done IFS=$as_save_IFS @@ -2190,7 +2341,7 @@ do | -silent | --silent | --silen | --sile | --sil) continue ;; *\'*) - ac_arg=`$as_echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; + ac_arg=`printf "%s\n" "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;; esac case $ac_pass in 1) as_fn_append ac_configure_args0 " '$ac_arg'" ;; @@ -2225,11 +2376,13 @@ done # WARNING: Use '\'' to represent an apostrophe within the trap. # WARNING: Do not start the trap code with a newline, due to a FreeBSD 4.0 bug. trap 'exit_status=$? + # Sanitize IFS. + IFS=" "" $as_nl" # Save into config.log some information that might help in debugging. { echo - $as_echo "## ---------------- ## + printf "%s\n" "## ---------------- ## ## Cache variables. ## ## ---------------- ##" echo @@ -2240,8 +2393,8 @@ trap 'exit_status=$? case $ac_val in #( *${as_nl}*) case $ac_var in #( - *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 -$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( @@ -2265,7 +2418,7 @@ $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; ) echo - $as_echo "## ----------------- ## + printf "%s\n" "## ----------------- ## ## Output variables. ## ## ----------------- ##" echo @@ -2273,14 +2426,14 @@ $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; do eval ac_val=\$$ac_var case $ac_val in - *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac - $as_echo "$ac_var='\''$ac_val'\''" + printf "%s\n" "$ac_var='\''$ac_val'\''" done | sort echo if test -n "$ac_subst_files"; then - $as_echo "## ------------------- ## + printf "%s\n" "## ------------------- ## ## File substitutions. ## ## ------------------- ##" echo @@ -2288,15 +2441,15 @@ $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; do eval ac_val=\$$ac_var case $ac_val in - *\'\''*) ac_val=`$as_echo "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; + *\'\''*) ac_val=`printf "%s\n" "$ac_val" | sed "s/'\''/'\''\\\\\\\\'\'''\''/g"`;; esac - $as_echo "$ac_var='\''$ac_val'\''" + printf "%s\n" "$ac_var='\''$ac_val'\''" done | sort echo fi if test -s confdefs.h; then - $as_echo "## ----------- ## + printf "%s\n" "## ----------- ## ## confdefs.h. ## ## ----------- ##" echo @@ -2304,8 +2457,8 @@ $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; echo fi test "$ac_signal" != 0 && - $as_echo "$as_me: caught signal $ac_signal" - $as_echo "$as_me: exit $exit_status" + printf "%s\n" "$as_me: caught signal $ac_signal" + printf "%s\n" "$as_me: exit $exit_status" } >&5 rm -f core *.core core.conftest.* && rm -f -r conftest* confdefs* conf$$* $ac_clean_files && @@ -2319,63 +2472,48 @@ ac_signal=0 # confdefs.h avoids OS command line length limits that DEFS can exceed. rm -f -r conftest* confdefs.h -$as_echo "/* confdefs.h */" > confdefs.h +printf "%s\n" "/* confdefs.h */" > confdefs.h # Predefined preprocessor variables. -cat >>confdefs.h <<_ACEOF -#define PACKAGE_NAME "$PACKAGE_NAME" -_ACEOF +printf "%s\n" "#define PACKAGE_NAME \"$PACKAGE_NAME\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define PACKAGE_TARNAME "$PACKAGE_TARNAME" -_ACEOF +printf "%s\n" "#define PACKAGE_TARNAME \"$PACKAGE_TARNAME\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define PACKAGE_VERSION "$PACKAGE_VERSION" -_ACEOF +printf "%s\n" "#define PACKAGE_VERSION \"$PACKAGE_VERSION\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define PACKAGE_STRING "$PACKAGE_STRING" -_ACEOF +printf "%s\n" "#define PACKAGE_STRING \"$PACKAGE_STRING\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT" -_ACEOF +printf "%s\n" "#define PACKAGE_BUGREPORT \"$PACKAGE_BUGREPORT\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define PACKAGE_URL "$PACKAGE_URL" -_ACEOF +printf "%s\n" "#define PACKAGE_URL \"$PACKAGE_URL\"" >>confdefs.h # Let the site file select an alternate cache file if it wants to. # Prefer an explicitly selected file to automatically selected ones. -ac_site_file1=NONE -ac_site_file2=NONE if test -n "$CONFIG_SITE"; then - # We do not want a PATH search for config.site. - case $CONFIG_SITE in #(( - -*) ac_site_file1=./$CONFIG_SITE;; - */*) ac_site_file1=$CONFIG_SITE;; - *) ac_site_file1=./$CONFIG_SITE;; - esac + ac_site_files="$CONFIG_SITE" elif test "x$prefix" != xNONE; then - ac_site_file1=$prefix/share/config.site - ac_site_file2=$prefix/etc/config.site + ac_site_files="$prefix/share/config.site $prefix/etc/config.site" else - ac_site_file1=$ac_default_prefix/share/config.site - ac_site_file2=$ac_default_prefix/etc/config.site + ac_site_files="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" fi -for ac_site_file in "$ac_site_file1" "$ac_site_file2" + +for ac_site_file in $ac_site_files do - test "x$ac_site_file" = xNONE && continue - if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 -$as_echo "$as_me: loading site script $ac_site_file" >&6;} + case $ac_site_file in #( + */*) : + ;; #( + *) : + ac_site_file=./$ac_site_file ;; +esac + if test -f "$ac_site_file" && test -r "$ac_site_file"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 +printf "%s\n" "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 . "$ac_site_file" \ - || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + || { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "failed to load site script $ac_site_file See \`config.log' for more details" "$LINENO" 5; } fi @@ -2385,22 +2523,651 @@ if test -r "$cache_file"; then # Some versions of bash will fail to source /dev/null (special files # actually), so we avoid doing that. DJGPP emulates it as a regular file. if test /dev/null != "$cache_file" && test -f "$cache_file"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 -$as_echo "$as_me: loading cache $cache_file" >&6;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 +printf "%s\n" "$as_me: loading cache $cache_file" >&6;} case $cache_file in [\\/]* | ?:[\\/]* ) . "$cache_file";; *) . "./$cache_file";; esac fi else - { $as_echo "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 -$as_echo "$as_me: creating cache $cache_file" >&6;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating cache $cache_file" >&5 +printf "%s\n" "$as_me: creating cache $cache_file" >&6;} >$cache_file fi -as_fn_append ac_header_list " stdlib.h" -as_fn_append ac_header_list " unistd.h" -as_fn_append ac_header_list " sys/param.h" +# Test code for whether the C compiler supports C89 (global declarations) +ac_c_conftest_c89_globals=' +/* Does the compiler advertise C89 conformance? + Do not test the value of __STDC__, because some compilers set it to 0 + while being otherwise adequately conformant. */ +#if !defined __STDC__ +# error "Compiler does not advertise C89 conformance" +#endif + +#include <stddef.h> +#include <stdarg.h> +struct stat; +/* Most of the following tests are stolen from RCS 5.7 src/conf.sh. */ +struct buf { int x; }; +struct buf * (*rcsopen) (struct buf *, struct stat *, int); +static char *e (char **p, int i) +{ + return p[i]; +} +static char *f (char * (*g) (char **, int), char **p, ...) +{ + char *s; + va_list v; + va_start (v,p); + s = g (p, va_arg (v,int)); + va_end (v); + return s; +} + +/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has + function prototypes and stuff, but not \xHH hex character constants. + These do not provoke an error unfortunately, instead are silently treated + as an "x". The following induces an error, until -std is added to get + proper ANSI mode. Curiously \x00 != x always comes out true, for an + array size at least. It is necessary to write \x00 == 0 to get something + that is true only with -std. */ +int osf4_cc_array ['\''\x00'\'' == 0 ? 1 : -1]; + +/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters + inside strings and character constants. */ +#define FOO(x) '\''x'\'' +int xlc6_cc_array[FOO(a) == '\''x'\'' ? 1 : -1]; + +int test (int i, double x); +struct s1 {int (*f) (int a);}; +struct s2 {int (*f) (double a);}; +int pairnames (int, char **, int *(*)(struct buf *, struct stat *, int), + int, int);' + +# Test code for whether the C compiler supports C89 (body of main). +ac_c_conftest_c89_main=' +ok |= (argc == 0 || f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]); +' + +# Test code for whether the C compiler supports C99 (global declarations) +ac_c_conftest_c99_globals=' +// Does the compiler advertise C99 conformance? +#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L +# error "Compiler does not advertise C99 conformance" +#endif + +#include <stdbool.h> +extern int puts (const char *); +extern int printf (const char *, ...); +extern int dprintf (int, const char *, ...); +extern void *malloc (size_t); +extern void free (void *); + +// Check varargs macros. These examples are taken from C99 6.10.3.5. +// dprintf is used instead of fprintf to avoid needing to declare +// FILE and stderr. +#define debug(...) dprintf (2, __VA_ARGS__) +#define showlist(...) puts (#__VA_ARGS__) +#define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__)) +static void +test_varargs_macros (void) +{ + int x = 1234; + int y = 5678; + debug ("Flag"); + debug ("X = %d\n", x); + showlist (The first, second, and third items.); + report (x>y, "x is %d but y is %d", x, y); +} + +// Check long long types. +#define BIG64 18446744073709551615ull +#define BIG32 4294967295ul +#define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0) +#if !BIG_OK + #error "your preprocessor is broken" +#endif +#if BIG_OK +#else + #error "your preprocessor is broken" +#endif +static long long int bignum = -9223372036854775807LL; +static unsigned long long int ubignum = BIG64; + +struct incomplete_array +{ + int datasize; + double data[]; +}; + +struct named_init { + int number; + const wchar_t *name; + double average; +}; + +typedef const char *ccp; + +static inline int +test_restrict (ccp restrict text) +{ + // See if C++-style comments work. + // Iterate through items via the restricted pointer. + // Also check for declarations in for loops. + for (unsigned int i = 0; *(text+i) != '\''\0'\''; ++i) + continue; + return 0; +} + +// Check varargs and va_copy. +static bool +test_varargs (const char *format, ...) +{ + va_list args; + va_start (args, format); + va_list args_copy; + va_copy (args_copy, args); + + const char *str = ""; + int number = 0; + float fnumber = 0; + + while (*format) + { + switch (*format++) + { + case '\''s'\'': // string + str = va_arg (args_copy, const char *); + break; + case '\''d'\'': // int + number = va_arg (args_copy, int); + break; + case '\''f'\'': // float + fnumber = va_arg (args_copy, double); + break; + default: + break; + } + } + va_end (args_copy); + va_end (args); + + return *str && number && fnumber; +} +' + +# Test code for whether the C compiler supports C99 (body of main). +ac_c_conftest_c99_main=' + // Check bool. + _Bool success = false; + success |= (argc != 0); + + // Check restrict. + if (test_restrict ("String literal") == 0) + success = true; + char *restrict newvar = "Another string"; + + // Check varargs. + success &= test_varargs ("s, d'\'' f .", "string", 65, 34.234); + test_varargs_macros (); + + // Check flexible array members. + struct incomplete_array *ia = + malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10)); + ia->datasize = 10; + for (int i = 0; i < ia->datasize; ++i) + ia->data[i] = i * 1.234; + + // Check named initializers. + struct named_init ni = { + .number = 34, + .name = L"Test wide string", + .average = 543.34343, + }; + + ni.number = 58; + + int dynamic_array[ni.number]; + dynamic_array[0] = argv[0][0]; + dynamic_array[ni.number - 1] = 543; + + // work around unused variable warnings + ok |= (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == '\''x'\'' + || dynamic_array[ni.number - 1] != 543); +' + +# Test code for whether the C compiler supports C11 (global declarations) +ac_c_conftest_c11_globals=' +// Does the compiler advertise C11 conformance? +#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L +# error "Compiler does not advertise C11 conformance" +#endif + +// Check _Alignas. +char _Alignas (double) aligned_as_double; +char _Alignas (0) no_special_alignment; +extern char aligned_as_int; +char _Alignas (0) _Alignas (int) aligned_as_int; + +// Check _Alignof. +enum +{ + int_alignment = _Alignof (int), + int_array_alignment = _Alignof (int[100]), + char_alignment = _Alignof (char) +}; +_Static_assert (0 < -_Alignof (int), "_Alignof is signed"); + +// Check _Noreturn. +int _Noreturn does_not_return (void) { for (;;) continue; } + +// Check _Static_assert. +struct test_static_assert +{ + int x; + _Static_assert (sizeof (int) <= sizeof (long int), + "_Static_assert does not work in struct"); + long int y; +}; + +// Check UTF-8 literals. +#define u8 syntax error! +char const utf8_literal[] = u8"happens to be ASCII" "another string"; + +// Check duplicate typedefs. +typedef long *long_ptr; +typedef long int *long_ptr; +typedef long_ptr long_ptr; + +// Anonymous structures and unions -- taken from C11 6.7.2.1 Example 1. +struct anonymous +{ + union { + struct { int i; int j; }; + struct { int k; long int l; } w; + }; + int m; +} v1; +' + +# Test code for whether the C compiler supports C11 (body of main). +ac_c_conftest_c11_main=' + _Static_assert ((offsetof (struct anonymous, i) + == offsetof (struct anonymous, w.k)), + "Anonymous union alignment botch"); + v1.i = 2; + v1.w.k = 5; + ok |= v1.i != 5; +' + +# Test code for whether the C compiler supports C11 (complete). +ac_c_conftest_c11_program="${ac_c_conftest_c89_globals} +${ac_c_conftest_c99_globals} +${ac_c_conftest_c11_globals} + +int +main (int argc, char **argv) +{ + int ok = 0; + ${ac_c_conftest_c89_main} + ${ac_c_conftest_c99_main} + ${ac_c_conftest_c11_main} + return ok; +} +" + +# Test code for whether the C compiler supports C99 (complete). +ac_c_conftest_c99_program="${ac_c_conftest_c89_globals} +${ac_c_conftest_c99_globals} + +int +main (int argc, char **argv) +{ + int ok = 0; + ${ac_c_conftest_c89_main} + ${ac_c_conftest_c99_main} + return ok; +} +" + +# Test code for whether the C compiler supports C89 (complete). +ac_c_conftest_c89_program="${ac_c_conftest_c89_globals} + +int +main (int argc, char **argv) +{ + int ok = 0; + ${ac_c_conftest_c89_main} + return ok; +} +" + +as_fn_append ac_header_c_list " stdio.h stdio_h HAVE_STDIO_H" +as_fn_append ac_header_c_list " stdlib.h stdlib_h HAVE_STDLIB_H" +as_fn_append ac_header_c_list " string.h string_h HAVE_STRING_H" +as_fn_append ac_header_c_list " inttypes.h inttypes_h HAVE_INTTYPES_H" +as_fn_append ac_header_c_list " stdint.h stdint_h HAVE_STDINT_H" +as_fn_append ac_header_c_list " strings.h strings_h HAVE_STRINGS_H" +as_fn_append ac_header_c_list " sys/stat.h sys_stat_h HAVE_SYS_STAT_H" +as_fn_append ac_header_c_list " sys/types.h sys_types_h HAVE_SYS_TYPES_H" +as_fn_append ac_header_c_list " unistd.h unistd_h HAVE_UNISTD_H" +# Test code for whether the C++ compiler supports C++98 (global declarations) +ac_cxx_conftest_cxx98_globals=' +// Does the compiler advertise C++98 conformance? +#if !defined __cplusplus || __cplusplus < 199711L +# error "Compiler does not advertise C++98 conformance" +#endif + +// These inclusions are to reject old compilers that +// lack the unsuffixed header files. +#include <cstdlib> +#include <exception> + +// <cassert> and <cstring> are *not* freestanding headers in C++98. +extern void assert (int); +namespace std { + extern int strcmp (const char *, const char *); +} + +// Namespaces, exceptions, and templates were all added after "C++ 2.0". +using std::exception; +using std::strcmp; + +namespace { + +void test_exception_syntax() +{ + try { + throw "test"; + } catch (const char *s) { + // Extra parentheses suppress a warning when building autoconf itself, + // due to lint rules shared with more typical C programs. + assert (!(strcmp) (s, "test")); + } +} + +template <typename T> struct test_template +{ + T const val; + explicit test_template(T t) : val(t) {} + template <typename U> T add(U u) { return static_cast<T>(u) + val; } +}; + +} // anonymous namespace +' + +# Test code for whether the C++ compiler supports C++98 (body of main) +ac_cxx_conftest_cxx98_main=' + assert (argc); + assert (! argv[0]); +{ + test_exception_syntax (); + test_template<double> tt (2.0); + assert (tt.add (4) == 6.0); + assert (true && !false); +} +' + +# Test code for whether the C++ compiler supports C++11 (global declarations) +ac_cxx_conftest_cxx11_globals=' +// Does the compiler advertise C++ 2011 conformance? +#if !defined __cplusplus || __cplusplus < 201103L +# error "Compiler does not advertise C++11 conformance" +#endif + +namespace cxx11test +{ + constexpr int get_val() { return 20; } + + struct testinit + { + int i; + double d; + }; + + class delegate + { + public: + delegate(int n) : n(n) {} + delegate(): delegate(2354) {} + + virtual int getval() { return this->n; }; + protected: + int n; + }; + + class overridden : public delegate + { + public: + overridden(int n): delegate(n) {} + virtual int getval() override final { return this->n * 2; } + }; + + class nocopy + { + public: + nocopy(int i): i(i) {} + nocopy() = default; + nocopy(const nocopy&) = delete; + nocopy & operator=(const nocopy&) = delete; + private: + int i; + }; + + // for testing lambda expressions + template <typename Ret, typename Fn> Ret eval(Fn f, Ret v) + { + return f(v); + } + + // for testing variadic templates and trailing return types + template <typename V> auto sum(V first) -> V + { + return first; + } + template <typename V, typename... Args> auto sum(V first, Args... rest) -> V + { + return first + sum(rest...); + } +} +' + +# Test code for whether the C++ compiler supports C++11 (body of main) +ac_cxx_conftest_cxx11_main=' +{ + // Test auto and decltype + auto a1 = 6538; + auto a2 = 48573953.4; + auto a3 = "String literal"; + + int total = 0; + for (auto i = a3; *i; ++i) { total += *i; } + + decltype(a2) a4 = 34895.034; +} +{ + // Test constexpr + short sa[cxx11test::get_val()] = { 0 }; +} +{ + // Test initializer lists + cxx11test::testinit il = { 4323, 435234.23544 }; +} +{ + // Test range-based for + int array[] = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3, + 14, 19, 17, 8, 6, 20, 16, 2, 11, 1}; + for (auto &x : array) { x += 23; } +} +{ + // Test lambda expressions + using cxx11test::eval; + assert (eval ([](int x) { return x*2; }, 21) == 42); + double d = 2.0; + assert (eval ([&](double x) { return d += x; }, 3.0) == 5.0); + assert (d == 5.0); + assert (eval ([=](double x) mutable { return d += x; }, 4.0) == 9.0); + assert (d == 5.0); +} +{ + // Test use of variadic templates + using cxx11test::sum; + auto a = sum(1); + auto b = sum(1, 2); + auto c = sum(1.0, 2.0, 3.0); +} +{ + // Test constructor delegation + cxx11test::delegate d1; + cxx11test::delegate d2(); + cxx11test::delegate d3(45); +} +{ + // Test override and final + cxx11test::overridden o1(55464); +} +{ + // Test nullptr + char *c = nullptr; +} +{ + // Test template brackets + test_template<::test_template<int>> v(test_template<int>(12)); +} +{ + // Unicode literals + char const *utf8 = u8"UTF-8 string \u2500"; + char16_t const *utf16 = u"UTF-8 string \u2500"; + char32_t const *utf32 = U"UTF-32 string \u2500"; +} +' + +# Test code for whether the C compiler supports C++11 (complete). +ac_cxx_conftest_cxx11_program="${ac_cxx_conftest_cxx98_globals} +${ac_cxx_conftest_cxx11_globals} + +int +main (int argc, char **argv) +{ + int ok = 0; + ${ac_cxx_conftest_cxx98_main} + ${ac_cxx_conftest_cxx11_main} + return ok; +} +" + +# Test code for whether the C compiler supports C++98 (complete). +ac_cxx_conftest_cxx98_program="${ac_cxx_conftest_cxx98_globals} +int +main (int argc, char **argv) +{ + int ok = 0; + ${ac_cxx_conftest_cxx98_main} + return ok; +} +" + +as_fn_append ac_header_c_list " sys/param.h sys_param_h HAVE_SYS_PARAM_H" +as_fn_append ac_func_c_list " getpagesize HAVE_GETPAGESIZE" + +# Auxiliary files required by this configure script. +ac_aux_files="ltmain.sh compile ar-lib missing install-sh config.guess config.sub" + +# Locations in which to look for auxiliary files. +ac_aux_dir_candidates="${srcdir}/conftools" + +# Search for a directory containing all of the required auxiliary files, +# $ac_aux_files, from the $PATH-style list $ac_aux_dir_candidates. +# If we don't find one directory that contains all the files we need, +# we report the set of missing files from the *first* directory in +# $ac_aux_dir_candidates and give up. +ac_missing_aux_files="" +ac_first_candidate=: +printf "%s\n" "$as_me:${as_lineno-$LINENO}: looking for aux files: $ac_aux_files" >&5 +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +as_found=false +for as_dir in $ac_aux_dir_candidates +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + as_found=: + + printf "%s\n" "$as_me:${as_lineno-$LINENO}: trying $as_dir" >&5 + ac_aux_dir_found=yes + ac_install_sh= + for ac_aux in $ac_aux_files + do + # As a special case, if "install-sh" is required, that requirement + # can be satisfied by any of "install-sh", "install.sh", or "shtool", + # and $ac_install_sh is set appropriately for whichever one is found. + if test x"$ac_aux" = x"install-sh" + then + if test -f "${as_dir}install-sh"; then + printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}install-sh found" >&5 + ac_install_sh="${as_dir}install-sh -c" + elif test -f "${as_dir}install.sh"; then + printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}install.sh found" >&5 + ac_install_sh="${as_dir}install.sh -c" + elif test -f "${as_dir}shtool"; then + printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}shtool found" >&5 + ac_install_sh="${as_dir}shtool install -c" + else + ac_aux_dir_found=no + if $ac_first_candidate; then + ac_missing_aux_files="${ac_missing_aux_files} install-sh" + else + break + fi + fi + else + if test -f "${as_dir}${ac_aux}"; then + printf "%s\n" "$as_me:${as_lineno-$LINENO}: ${as_dir}${ac_aux} found" >&5 + else + ac_aux_dir_found=no + if $ac_first_candidate; then + ac_missing_aux_files="${ac_missing_aux_files} ${ac_aux}" + else + break + fi + fi + fi + done + if test "$ac_aux_dir_found" = yes; then + ac_aux_dir="$as_dir" + break + fi + ac_first_candidate=false + + as_found=false +done +IFS=$as_save_IFS +if $as_found +then : + +else $as_nop + as_fn_error $? "cannot find required auxiliary files:$ac_missing_aux_files" "$LINENO" 5 +fi + + +# These three variables are undocumented and unsupported, +# and are intended to be withdrawn in a future Autoconf release. +# They can cause serious problems if a builder's source tree is in a directory +# whose full name contains unusual characters. +if test -f "${ac_aux_dir}config.guess"; then + ac_config_guess="$SHELL ${ac_aux_dir}config.guess" +fi +if test -f "${ac_aux_dir}config.sub"; then + ac_config_sub="$SHELL ${ac_aux_dir}config.sub" +fi +if test -f "$ac_aux_dir/configure"; then + ac_configure="$SHELL ${ac_aux_dir}configure" +fi + # Check that the precious variables saved in the cache have kept the same # value. ac_cache_corrupted=false @@ -2411,12 +3178,12 @@ for ac_var in $ac_precious_vars; do eval ac_new_val=\$ac_env_${ac_var}_value case $ac_old_set,$ac_new_set in set,) - { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 -$as_echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5 +printf "%s\n" "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;} ac_cache_corrupted=: ;; ,set) - { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 -$as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' was not set in the previous run" >&5 +printf "%s\n" "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_cache_corrupted=: ;; ,);; *) @@ -2425,24 +3192,24 @@ $as_echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;} ac_old_val_w=`echo x $ac_old_val` ac_new_val_w=`echo x $ac_new_val` if test "$ac_old_val_w" != "$ac_new_val_w"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 -$as_echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: \`$ac_var' has changed since the previous run:" >&5 +printf "%s\n" "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;} ac_cache_corrupted=: else - { $as_echo "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 -$as_echo "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&5 +printf "%s\n" "$as_me: warning: ignoring whitespace changes in \`$ac_var' since the previous run:" >&2;} eval $ac_var=\$ac_old_val fi - { $as_echo "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 -$as_echo "$as_me: former value: \`$ac_old_val'" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 -$as_echo "$as_me: current value: \`$ac_new_val'" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: former value: \`$ac_old_val'" >&5 +printf "%s\n" "$as_me: former value: \`$ac_old_val'" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: current value: \`$ac_new_val'" >&5 +printf "%s\n" "$as_me: current value: \`$ac_new_val'" >&2;} fi;; esac # Pass precious variables to config.status. if test "$ac_new_set" = set; then case $ac_new_val in - *\'*) ac_arg=$ac_var=`$as_echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; + *\'*) ac_arg=$ac_var=`printf "%s\n" "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;; *) ac_arg=$ac_var=$ac_new_val ;; esac case " $ac_configure_args " in @@ -2452,11 +3219,12 @@ $as_echo "$as_me: current value: \`$ac_new_val'" >&2;} fi done if $ac_cache_corrupted; then - { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} - { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 -$as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} - as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 +printf "%s\n" "$as_me: error: changes in the environment can compromise the build" >&2;} + as_fn_error $? "run \`${MAKE-make} distclean' and/or \`rm $cache_file' + and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## @@ -2472,56 +3240,32 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu -ac_aux_dir= -for ac_dir in conftools "$srcdir"/conftools; do - if test -f "$ac_dir/install-sh"; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install-sh -c" - break - elif test -f "$ac_dir/install.sh"; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/install.sh -c" - break - elif test -f "$ac_dir/shtool"; then - ac_aux_dir=$ac_dir - ac_install_sh="$ac_aux_dir/shtool install -c" - break - fi -done -if test -z "$ac_aux_dir"; then - as_fn_error $? "cannot find install-sh, install.sh, or shtool in conftools \"$srcdir\"/conftools" "$LINENO" 5 -fi -# These three variables are undocumented and unsupported, -# and are intended to be withdrawn in a future Autoconf release. -# They can cause serious problems if a builder's source tree is in a directory -# whose full name contains unusual characters. -ac_config_guess="$SHELL $ac_aux_dir/config.guess" # Please don't use this var. -ac_config_sub="$SHELL $ac_aux_dir/config.sub" # Please don't use this var. -ac_configure="$SHELL $ac_aux_dir/configure" # Please don't use this var. -# Make sure we can run config.sub. -$SHELL "$ac_aux_dir/config.sub" sun4 >/dev/null 2>&1 || - as_fn_error $? "cannot run $SHELL $ac_aux_dir/config.sub" "$LINENO" 5 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 -$as_echo_n "checking build system type... " >&6; } -if ${ac_cv_build+:} false; then : - $as_echo_n "(cached) " >&6 -else + # Make sure we can run config.sub. +$SHELL "${ac_aux_dir}config.sub" sun4 >/dev/null 2>&1 || + as_fn_error $? "cannot run $SHELL ${ac_aux_dir}config.sub" "$LINENO" 5 + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking build system type" >&5 +printf %s "checking build system type... " >&6; } +if test ${ac_cv_build+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_build_alias=$build_alias test "x$ac_build_alias" = x && - ac_build_alias=`$SHELL "$ac_aux_dir/config.guess"` + ac_build_alias=`$SHELL "${ac_aux_dir}config.guess"` test "x$ac_build_alias" = x && as_fn_error $? "cannot guess build type; you must specify one" "$LINENO" 5 -ac_cv_build=`$SHELL "$ac_aux_dir/config.sub" $ac_build_alias` || - as_fn_error $? "$SHELL $ac_aux_dir/config.sub $ac_build_alias failed" "$LINENO" 5 +ac_cv_build=`$SHELL "${ac_aux_dir}config.sub" $ac_build_alias` || + as_fn_error $? "$SHELL ${ac_aux_dir}config.sub $ac_build_alias failed" "$LINENO" 5 fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 -$as_echo "$ac_cv_build" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_build" >&5 +printf "%s\n" "$ac_cv_build" >&6; } case $ac_cv_build in *-*-*) ;; *) as_fn_error $? "invalid value of canonical build" "$LINENO" 5;; @@ -2540,21 +3284,22 @@ IFS=$ac_save_IFS case $build_os in *\ *) build_os=`echo "$build_os" | sed 's/ /-/g'`;; esac -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 -$as_echo_n "checking host system type... " >&6; } -if ${ac_cv_host+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking host system type" >&5 +printf %s "checking host system type... " >&6; } +if test ${ac_cv_host+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test "x$host_alias" = x; then ac_cv_host=$ac_cv_build else - ac_cv_host=`$SHELL "$ac_aux_dir/config.sub" $host_alias` || - as_fn_error $? "$SHELL $ac_aux_dir/config.sub $host_alias failed" "$LINENO" 5 + ac_cv_host=`$SHELL "${ac_aux_dir}config.sub" $host_alias` || + as_fn_error $? "$SHELL ${ac_aux_dir}config.sub $host_alias failed" "$LINENO" 5 fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 -$as_echo "$ac_cv_host" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_host" >&5 +printf "%s\n" "$ac_cv_host" >&6; } case $ac_cv_host in *-*-*) ;; *) as_fn_error $? "invalid value of canonical host" "$LINENO" 5;; @@ -2575,7 +3320,8 @@ case $host_os in *\ *) host_os=`echo "$host_os" | sed 's/ /-/g'`;; esac am__api_version='1.16' -# Find a good install program. We prefer a C program (faster), + + # Find a good install program. We prefer a C program (faster), # so one script is as good as another. But avoid the broken or # incompatible versions: # SysV /etc/install, /usr/sbin/install @@ -2589,20 +3335,25 @@ am__api_version='1.16' # OS/2's system install, which has a completely different semantic # ./install, which can be erroneously created by make from ./install.sh. # Reject install programs that cannot install multiple files. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 -$as_echo_n "checking for a BSD-compatible install... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5 +printf %s "checking for a BSD-compatible install... " >&6; } if test -z "$INSTALL"; then -if ${ac_cv_path_install+:} false; then : - $as_echo_n "(cached) " >&6 -else +if test ${ac_cv_path_install+y} +then : + printf %s "(cached) " >&6 +else $as_nop as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - # Account for people who put trailing slashes in PATH elements. -case $as_dir/ in #(( - ./ | .// | /[cC]/* | \ + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + # Account for fact that we put trailing slashes in our PATH walk. +case $as_dir in #(( + ./ | /[cC]/* | \ /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \ ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \ /usr/ucb/* ) ;; @@ -2612,13 +3363,13 @@ case $as_dir/ in #(( # by default. for ac_prog in ginstall scoinst install; do for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_prog$ac_exec_ext"; then if test $ac_prog = install && - grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + grep dspmsg "$as_dir$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # AIX install. It has an incompatible calling convention. : elif test $ac_prog = install && - grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then + grep pwplus "$as_dir$ac_prog$ac_exec_ext" >/dev/null 2>&1; then # program-specific install script used by HP pwplus--don't use. : else @@ -2626,12 +3377,12 @@ case $as_dir/ in #(( echo one > conftest.one echo two > conftest.two mkdir conftest.dir - if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" && + if "$as_dir$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir/" && test -s conftest.one && test -s conftest.two && test -s conftest.dir/conftest.one && test -s conftest.dir/conftest.two then - ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c" + ac_cv_path_install="$as_dir$ac_prog$ac_exec_ext -c" break 3 fi fi @@ -2647,7 +3398,7 @@ IFS=$as_save_IFS rm -rf conftest.one conftest.two conftest.dir fi - if test "${ac_cv_path_install+set}" = set; then + if test ${ac_cv_path_install+y}; then INSTALL=$ac_cv_path_install else # As a last resort, use the slow shell script. Don't cache a @@ -2657,8 +3408,8 @@ fi INSTALL=$ac_install_sh fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 -$as_echo "$INSTALL" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5 +printf "%s\n" "$INSTALL" >&6; } # Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. @@ -2668,8 +3419,8 @@ test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}' test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 -$as_echo_n "checking whether build environment is sane... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether build environment is sane" >&5 +printf %s "checking whether build environment is sane... " >&6; } # Reject unsafe characters in $srcdir or the absolute working directory # name. Accept space and tab only in the latter. am_lf=' @@ -2723,8 +3474,8 @@ else as_fn_error $? "newly created file is older than distributed files! Check your system clock" "$LINENO" 5 fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } # If we didn't sleep, we still need to ensure time stamps of config.status and # generated files are strictly newer. am_sleep_pid= @@ -2743,26 +3494,23 @@ test "$program_suffix" != NONE && # Double any \ or $. # By default was `s,x,x', remove it if useless. ac_script='s/[\\$]/&&/g;s/;s,x,x,$//' -program_transform_name=`$as_echo "$program_transform_name" | sed "$ac_script"` +program_transform_name=`printf "%s\n" "$program_transform_name" | sed "$ac_script"` + # Expand $ac_aux_dir to an absolute path. am_aux_dir=`cd "$ac_aux_dir" && pwd` -if test x"${MISSING+set}" != xset; then - case $am_aux_dir in - *\ * | *\ *) - MISSING="\${SHELL} \"$am_aux_dir/missing\"" ;; - *) - MISSING="\${SHELL} $am_aux_dir/missing" ;; - esac + + if test x"${MISSING+set}" != xset; then + MISSING="\${SHELL} '$am_aux_dir/missing'" fi # Use eval to expand $SHELL if eval "$MISSING --is-lightweight"; then am_missing_run="$MISSING " else am_missing_run= - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5 -$as_echo "$as_me: WARNING: 'missing' script is too old or missing" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: 'missing' script is too old or missing" >&5 +printf "%s\n" "$as_me: WARNING: 'missing' script is too old or missing" >&2;} fi if test x"${install_sh+set}" != xset; then @@ -2782,11 +3530,12 @@ if test "$cross_compiling" != no; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. set dummy ${ac_tool_prefix}strip; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_STRIP+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_STRIP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$STRIP"; then ac_cv_prog_STRIP="$STRIP" # Let the user override the test. else @@ -2794,11 +3543,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_STRIP="${ac_tool_prefix}strip" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -2809,11 +3562,11 @@ fi fi STRIP=$ac_cv_prog_STRIP if test -n "$STRIP"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 -$as_echo "$STRIP" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +printf "%s\n" "$STRIP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -2822,11 +3575,12 @@ if test -z "$ac_cv_prog_STRIP"; then ac_ct_STRIP=$STRIP # Extract the first word of "strip", so it can be a program name with args. set dummy strip; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_STRIP+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_STRIP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_STRIP"; then ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. else @@ -2834,11 +3588,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_STRIP="strip" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -2849,11 +3607,11 @@ fi fi ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP if test -n "$ac_ct_STRIP"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 -$as_echo "$ac_ct_STRIP" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +printf "%s\n" "$ac_ct_STRIP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_STRIP" = x; then @@ -2861,8 +3619,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac STRIP=$ac_ct_STRIP @@ -2874,25 +3632,31 @@ fi fi INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a thread-safe mkdir -p" >&5 -$as_echo_n "checking for a thread-safe mkdir -p... " >&6; } + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a race-free mkdir -p" >&5 +printf %s "checking for a race-free mkdir -p... " >&6; } if test -z "$MKDIR_P"; then - if ${ac_cv_path_mkdir+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${ac_cv_path_mkdir+y} +then : + printf %s "(cached) " >&6 +else $as_nop as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH$PATH_SEPARATOR/opt/sfw/bin do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_prog in mkdir gmkdir; do for ac_exec_ext in '' $ac_executable_extensions; do - as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext" || continue - case `"$as_dir/$ac_prog$ac_exec_ext" --version 2>&1` in #( - 'mkdir (GNU coreutils) '* | \ - 'mkdir (coreutils) '* | \ + as_fn_executable_p "$as_dir$ac_prog$ac_exec_ext" || continue + case `"$as_dir$ac_prog$ac_exec_ext" --version 2>&1` in #( + 'mkdir ('*'coreutils) '* | \ + 'BusyBox '* | \ 'mkdir (fileutils) '4.1*) - ac_cv_path_mkdir=$as_dir/$ac_prog$ac_exec_ext + ac_cv_path_mkdir=$as_dir$ac_prog$ac_exec_ext break 3;; esac done @@ -2903,7 +3667,7 @@ IFS=$as_save_IFS fi test -d ./--version && rmdir ./--version - if test "${ac_cv_path_mkdir+set}" = set; then + if test ${ac_cv_path_mkdir+y}; then MKDIR_P="$ac_cv_path_mkdir -p" else # As a last resort, use the slow shell script. Don't cache a @@ -2913,18 +3677,19 @@ fi MKDIR_P="$ac_install_sh -d" fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 -$as_echo "$MKDIR_P" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MKDIR_P" >&5 +printf "%s\n" "$MKDIR_P" >&6; } for ac_prog in gawk mawk nawk awk do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_AWK+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_AWK+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$AWK"; then ac_cv_prog_AWK="$AWK" # Let the user override the test. else @@ -2932,11 +3697,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_AWK="$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -2947,24 +3716,25 @@ fi fi AWK=$ac_cv_prog_AWK if test -n "$AWK"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 -$as_echo "$AWK" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5 +printf "%s\n" "$AWK" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi test -n "$AWK" && break done -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 -$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +printf %s "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } set x ${MAKE-make} -ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` -if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then : - $as_echo_n "(cached) " >&6 -else +ac_make=`printf "%s\n" "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if eval test \${ac_cv_prog_make_${ac_make}_set+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat >conftest.make <<\_ACEOF SHELL = /bin/sh all: @@ -2980,12 +3750,12 @@ esac rm -f conftest.make fi if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } SET_MAKE= else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } SET_MAKE="MAKE=${MAKE-make}" fi @@ -2999,7 +3769,8 @@ fi rmdir .tst 2>/dev/null # Check whether --enable-silent-rules was given. -if test "${enable_silent_rules+set}" = set; then : +if test ${enable_silent_rules+y} +then : enableval=$enable_silent_rules; fi @@ -3009,12 +3780,13 @@ case $enable_silent_rules in # ((( *) AM_DEFAULT_VERBOSITY=1;; esac am_make=${MAKE-make} -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5 -$as_echo_n "checking whether $am_make supports nested variables... " >&6; } -if ${am_cv_make_support_nested_variables+:} false; then : - $as_echo_n "(cached) " >&6 -else - if $as_echo 'TRUE=$(BAR$(V)) +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $am_make supports nested variables" >&5 +printf %s "checking whether $am_make supports nested variables... " >&6; } +if test ${am_cv_make_support_nested_variables+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if printf "%s\n" 'TRUE=$(BAR$(V)) BAR0=false BAR1=true V=1 @@ -3026,8 +3798,8 @@ else am_cv_make_support_nested_variables=no fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5 -$as_echo "$am_cv_make_support_nested_variables" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_make_support_nested_variables" >&5 +printf "%s\n" "$am_cv_make_support_nested_variables" >&6; } if test $am_cv_make_support_nested_variables = yes; then AM_V='$(V)' AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)' @@ -3059,17 +3831,13 @@ fi # Define the identity of the package. PACKAGE='expat' - VERSION='2.2.10' + VERSION='2.6.4' -cat >>confdefs.h <<_ACEOF -#define PACKAGE "$PACKAGE" -_ACEOF +printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h -cat >>confdefs.h <<_ACEOF -#define VERSION "$VERSION" -_ACEOF +printf "%s\n" "#define VERSION \"$VERSION\"" >>confdefs.h # Some tools Automake needs. @@ -3109,6 +3877,20 @@ am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -' +# Variables for tags utilities; see am/tags.am +if test -z "$CTAGS"; then + CTAGS=ctags +fi + +if test -z "$ETAGS"; then + ETAGS=etags +fi + +if test -z "$CSCOPE"; then + CSCOPE=cscope +fi + + # POSIX will say in a future version that running "rm -f" with no argument # is OK; and we want to be able to make that assumption in our Makefile @@ -3153,53 +3935,56 @@ END fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to enable maintainer-specific portions of Makefiles" >&5 +printf %s "checking whether to enable maintainer-specific portions of Makefiles... " >&6; } + # Check whether --enable-maintainer-mode was given. +if test ${enable_maintainer_mode+y} +then : + enableval=$enable_maintainer_mode; USE_MAINTAINER_MODE=$enableval +else $as_nop + USE_MAINTAINER_MODE=yes +fi + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $USE_MAINTAINER_MODE" >&5 +printf "%s\n" "$USE_MAINTAINER_MODE" >&6; } + if test $USE_MAINTAINER_MODE = yes; then + MAINTAINER_MODE_TRUE= + MAINTAINER_MODE_FALSE='#' +else + MAINTAINER_MODE_TRUE='#' + MAINTAINER_MODE_FALSE= +fi + + MAINT=$MAINTAINER_MODE_TRUE + + # to allow argument --disable-maintainer-mode + + + +LIBCURRENT=11 # sync +LIBREVISION=0 # with +LIBAGE=10 # CMakeLists.txt! + +ac_config_headers="$ac_config_headers expat_config.h" + -LIBCURRENT=7 # sync -LIBREVISION=12 # with -LIBAGE=6 # CMakeLists.txt! -if ${AM_CPPFLAGS+:} false; then : - case " $AM_CPPFLAGS " in #( - *" -DHAVE_EXPAT_CONFIG_H "*) : - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CPPFLAGS already contains -DHAVE_EXPAT_CONFIG_H"; } >&5 - (: AM_CPPFLAGS already contains -DHAVE_EXPAT_CONFIG_H) 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } ;; #( - *) : - as_fn_append AM_CPPFLAGS " -DHAVE_EXPAT_CONFIG_H" - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CPPFLAGS=\"\$AM_CPPFLAGS\""; } >&5 - (: AM_CPPFLAGS="$AM_CPPFLAGS") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } - ;; -esac -else - AM_CPPFLAGS=-DHAVE_EXPAT_CONFIG_H - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CPPFLAGS=\"\$AM_CPPFLAGS\""; } >&5 - (: AM_CPPFLAGS="$AM_CPPFLAGS") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } -fi -ac_config_headers="$ac_config_headers expat_config.h" DEPDIR="${am__leading_dot}deps" ac_config_commands="$ac_config_commands depfiles" -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} supports the include directive" >&5 -$as_echo_n "checking whether ${MAKE-make} supports the include directive... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} supports the include directive" >&5 +printf %s "checking whether ${MAKE-make} supports the include directive... " >&6; } cat > confinc.mk << 'END' am__doit: @echo this is the am__doit target >confinc.out @@ -3235,11 +4020,12 @@ esac fi done rm -f confinc.* confmf.* -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${_am_result}" >&5 -$as_echo "${_am_result}" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${_am_result}" >&5 +printf "%s\n" "${_am_result}" >&6; } # Check whether --enable-dependency-tracking was given. -if test "${enable_dependency_tracking+set}" = set; then : +if test ${enable_dependency_tracking+y} +then : enableval=$enable_dependency_tracking; fi @@ -3265,11 +4051,12 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args. set dummy ${ac_tool_prefix}gcc; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_CC+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -3277,11 +4064,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}gcc" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3292,11 +4083,11 @@ fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 -$as_echo "$CC" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -3305,11 +4096,12 @@ if test -z "$ac_cv_prog_CC"; then ac_ct_CC=$CC # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_CC+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else @@ -3317,11 +4109,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="gcc" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3332,11 +4128,11 @@ fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 -$as_echo "$ac_ct_CC" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +printf "%s\n" "$ac_ct_CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_CC" = x; then @@ -3344,8 +4140,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC @@ -3358,11 +4154,12 @@ if test -z "$CC"; then if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args. set dummy ${ac_tool_prefix}cc; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_CC+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -3370,11 +4167,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_CC="${ac_tool_prefix}cc" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3385,11 +4186,11 @@ fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 -$as_echo "$CC" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -3398,11 +4199,12 @@ fi if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_CC+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -3411,15 +4213,19 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + if test "$as_dir$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then ac_prog_rejected=yes continue fi ac_cv_prog_CC="cc" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3435,18 +4241,18 @@ if test $ac_prog_rejected = yes; then # However, it has the same basename, so the bogon will be chosen # first if we set CC to just the basename; use the full file name. shift - ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@" + ac_cv_prog_CC="$as_dir$ac_word${1+' '}$@" fi fi fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 -$as_echo "$CC" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -3457,11 +4263,12 @@ if test -z "$CC"; then do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_CC+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else @@ -3469,11 +4276,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_CC="$ac_tool_prefix$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3484,11 +4295,11 @@ fi fi CC=$ac_cv_prog_CC if test -n "$CC"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 -$as_echo "$CC" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -3501,11 +4312,12 @@ if test -z "$CC"; then do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_CC+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_CC"; then ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. else @@ -3513,11 +4325,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CC="$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -3528,11 +4344,11 @@ fi fi ac_ct_CC=$ac_cv_prog_ac_ct_CC if test -n "$ac_ct_CC"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 -$as_echo "$ac_ct_CC" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +printf "%s\n" "$ac_ct_CC" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -3544,8 +4360,8 @@ done else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CC=$ac_ct_CC @@ -3553,25 +4369,129 @@ esac fi fi +if test -z "$CC"; then + if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}clang", so it can be a program name with args. +set dummy ${ac_tool_prefix}clang; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_CC="${ac_tool_prefix}clang" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +CC=$ac_cv_prog_CC +if test -n "$CC"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CC" >&5 +printf "%s\n" "$CC" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi -test -z "$CC" && { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +fi +if test -z "$ac_cv_prog_CC"; then + ac_ct_CC=$CC + # Extract the first word of "clang", so it can be a program name with args. +set dummy clang; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_CC+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -n "$ac_ct_CC"; then + ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_CC="clang" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_CC=$ac_cv_prog_ac_ct_CC +if test -n "$ac_ct_CC"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CC" >&5 +printf "%s\n" "$ac_ct_CC" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + if test "x$ac_ct_CC" = x; then + CC="" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + CC=$ac_ct_CC + fi +else + CC="$ac_cv_prog_CC" +fi + +fi + + +test -z "$CC" && { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "no acceptable C compiler found in \$PATH See \`config.log' for more details" "$LINENO" 5; } # Provide some information about the compiler. -$as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 +printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler version" >&5 set X $ac_compile ac_compiler=$2 -for ac_option in --version -v -V -qversion; do +for ac_option in --version -v -V -qversion -version; do { { ac_try="$ac_compiler $ac_option >&5" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -3581,7 +4501,7 @@ $as_echo "$ac_try_echo"; } >&5 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done @@ -3589,7 +4509,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; @@ -3601,9 +4521,9 @@ ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" # Try to create an executable without -o first, disregard a.out. # It will help us diagnose broken compilers, and finding out an intuition # of exeext. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 -$as_echo_n "checking whether the C compiler works... " >&6; } -ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler works" >&5 +printf %s "checking whether the C compiler works... " >&6; } +ac_link_default=`printf "%s\n" "$ac_link" | sed 's/ -o *conftest[^ ]*//'` # The possible output files: ac_files="a.out conftest.exe conftest a.exe a_out.exe b.out conftest.*" @@ -3624,11 +4544,12 @@ case "(($ac_try" in *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link_default") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; then : + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +then : # Autoconf-2.13 could set the ac_cv_exeext variable to `no'. # So ignore a value of `no', otherwise this would lead to `EXEEXT = no' # in a Makefile. We should not override ac_cv_exeext if it was cached, @@ -3645,7 +4566,7 @@ do # certainly right. break;; *.* ) - if test "${ac_cv_exeext+set}" = set && test "$ac_cv_exeext" != no; + if test ${ac_cv_exeext+y} && test "$ac_cv_exeext" != no; then :; else ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'` fi @@ -3661,44 +4582,46 @@ do done test "$ac_cv_exeext" = no && ac_cv_exeext= -else +else $as_nop ac_file='' fi -if test -z "$ac_file"; then : - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -$as_echo "$as_me: failed program was:" >&5 +if test -z "$ac_file" +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 -{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error 77 "C compiler cannot create executables See \`config.log' for more details" "$LINENO" 5; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 -$as_echo_n "checking for C compiler default output file name... " >&6; } -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 -$as_echo "$ac_file" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C compiler default output file name" >&5 +printf %s "checking for C compiler default output file name... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 +printf "%s\n" "$ac_file" >&6; } ac_exeext=$ac_cv_exeext rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out ac_clean_files=$ac_clean_files_save -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 -$as_echo_n "checking for suffix of executables... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 +printf %s "checking for suffix of executables... " >&6; } if { { ac_try="$ac_link" case "(($ac_try" in *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; then : + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +then : # If both `conftest.exe' and `conftest' are `present' (well, observable) # catch `conftest.exe'. For instance with Cygwin, `ls conftest' will # work properly (i.e., refer to `conftest.exe'), while it won't with @@ -3712,15 +4635,15 @@ for ac_file in conftest.exe conftest conftest.*; do * ) break;; esac done -else - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +else $as_nop + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of executables: cannot compile and link See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest conftest$ac_cv_exeext -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 -$as_echo "$ac_cv_exeext" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 +printf "%s\n" "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext @@ -3729,7 +4652,7 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include <stdio.h> int -main () +main (void) { FILE *f = fopen ("conftest.out", "w"); return ferror (f) || fclose (f) != 0; @@ -3741,8 +4664,8 @@ _ACEOF ac_clean_files="$ac_clean_files conftest.out" # Check that the compiler produces executables we can run. If not, either # the compiler is broken, or we cross compile. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 -$as_echo_n "checking whether we are cross compiling... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 +printf %s "checking whether we are cross compiling... " >&6; } if test "$cross_compiling" != yes; then { { ac_try="$ac_link" case "(($ac_try" in @@ -3750,10 +4673,10 @@ case "(($ac_try" in *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_link") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if { ac_try='./conftest$ac_cv_exeext' { { case "(($ac_try" in @@ -3761,39 +4684,40 @@ $as_echo "$ac_try_echo"; } >&5 *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_try") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; }; then cross_compiling=no else if test "$cross_compiling" = maybe; then cross_compiling=yes else - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error $? "cannot run C compiled programs. + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "cannot run C compiled programs. If you meant to cross compile, use \`--host'. See \`config.log' for more details" "$LINENO" 5; } fi fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 -$as_echo "$cross_compiling" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 +printf "%s\n" "$cross_compiling" >&6; } rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out ac_clean_files=$ac_clean_files_save -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 -$as_echo_n "checking for suffix of object files... " >&6; } -if ${ac_cv_objext+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 +printf %s "checking for suffix of object files... " >&6; } +if test ${ac_cv_objext+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; @@ -3807,11 +4731,12 @@ case "(($ac_try" in *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compile") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; then : + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } +then : for ac_file in conftest.o conftest.obj conftest.*; do test -f "$ac_file" || continue; case $ac_file in @@ -3820,31 +4745,32 @@ $as_echo "$ac_try_echo"; } >&5 break;; esac done -else - $as_echo "$as_me: failed program was:" >&5 +else $as_nop + printf "%s\n" "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 -{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +{ { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "cannot compute suffix of object files: cannot compile See \`config.log' for more details" "$LINENO" 5; } fi rm -f conftest.$ac_cv_objext conftest.$ac_ext fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 -$as_echo "$ac_cv_objext" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_objext" >&5 +printf "%s\n" "$ac_cv_objext" >&6; } OBJEXT=$ac_cv_objext ac_objext=$OBJEXT -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C compiler" >&5 -$as_echo_n "checking whether we are using the GNU C compiler... " >&6; } -if ${ac_cv_c_compiler_gnu+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C" >&5 +printf %s "checking whether the compiler supports GNU C... " >&6; } +if test ${ac_cv_c_compiler_gnu+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { #ifndef __GNUC__ choke me @@ -3854,29 +4780,33 @@ main () return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_compiler_gnu=yes -else +else $as_nop ac_compiler_gnu=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_cv_c_compiler_gnu=$ac_compiler_gnu fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 -$as_echo "$ac_cv_c_compiler_gnu" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_compiler_gnu" >&5 +printf "%s\n" "$ac_cv_c_compiler_gnu" >&6; } +ac_compiler_gnu=$ac_cv_c_compiler_gnu + if test $ac_compiler_gnu = yes; then GCC=yes else GCC= fi -ac_test_CFLAGS=${CFLAGS+set} +ac_test_CFLAGS=${CFLAGS+y} ac_save_CFLAGS=$CFLAGS -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 -$as_echo_n "checking whether $CC accepts -g... " >&6; } -if ${ac_cv_prog_cc_g+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC accepts -g" >&5 +printf %s "checking whether $CC accepts -g... " >&6; } +if test ${ac_cv_prog_cc_g+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_save_c_werror_flag=$ac_c_werror_flag ac_c_werror_flag=yes ac_cv_prog_cc_g=no @@ -3885,57 +4815,60 @@ else /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_cv_prog_cc_g=yes -else +else $as_nop CFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : -else +else $as_nop ac_c_werror_flag=$ac_save_c_werror_flag CFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_cv_prog_cc_g=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_c_werror_flag=$ac_save_c_werror_flag fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 -$as_echo "$ac_cv_prog_cc_g" >&6; } -if test "$ac_test_CFLAGS" = set; then +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_g" >&5 +printf "%s\n" "$ac_cv_prog_cc_g" >&6; } +if test $ac_test_CFLAGS; then CFLAGS=$ac_save_CFLAGS elif test $ac_cv_prog_cc_g = yes; then if test "$GCC" = yes; then @@ -3950,94 +4883,144 @@ else CFLAGS= fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C89" >&5 -$as_echo_n "checking for $CC option to accept ISO C89... " >&6; } -if ${ac_cv_prog_cc_c89+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_cv_prog_cc_c89=no +ac_prog_cc_stdc=no +if test x$ac_prog_cc_stdc = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C11 features" >&5 +printf %s "checking for $CC option to enable C11 features... " >&6; } +if test ${ac_cv_prog_cc_c11+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cc_c11=no ac_save_CC=$CC cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include <stdarg.h> -#include <stdio.h> -struct stat; -/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */ -struct buf { int x; }; -FILE * (*rcsopen) (struct buf *, struct stat *, int); -static char *e (p, i) - char **p; - int i; -{ - return p[i]; -} -static char *f (char * (*g) (char **, int), char **p, ...) -{ - char *s; - va_list v; - va_start (v,p); - s = g (p, va_arg (v,int)); - va_end (v); - return s; -} - -/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has - function prototypes and stuff, but not '\xHH' hex character constants. - These don't provoke an error unfortunately, instead are silently treated - as 'x'. The following induces an error, until -std is added to get - proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an - array size at least. It's necessary to write '\x00'==0 to get something - that's true only with -std. */ -int osf4_cc_array ['\x00' == 0 ? 1 : -1]; +$ac_c_conftest_c11_program +_ACEOF +for ac_arg in '' -std=gnu11 +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_prog_cc_c11=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam + test "x$ac_cv_prog_cc_c11" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC +fi -/* IBM C 6 for AIX is almost-ANSI by default, but it replaces macro parameters - inside strings and character constants. */ -#define FOO(x) 'x' -int xlc6_cc_array[FOO(a) == 'x' ? 1 : -1]; +if test "x$ac_cv_prog_cc_c11" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cc_c11" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c11" >&5 +printf "%s\n" "$ac_cv_prog_cc_c11" >&6; } + CC="$CC $ac_cv_prog_cc_c11" +fi + ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c11 + ac_prog_cc_stdc=c11 +fi +fi +if test x$ac_prog_cc_stdc = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C99 features" >&5 +printf %s "checking for $CC option to enable C99 features... " >&6; } +if test ${ac_cv_prog_cc_c99+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cc_c99=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$ac_c_conftest_c99_program +_ACEOF +for ac_arg in '' -std=gnu99 -std=c99 -c99 -qlanglvl=extc1x -qlanglvl=extc99 -AC99 -D_STDC_C99= +do + CC="$ac_save_CC $ac_arg" + if ac_fn_c_try_compile "$LINENO" +then : + ac_cv_prog_cc_c99=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam + test "x$ac_cv_prog_cc_c99" != "xno" && break +done +rm -f conftest.$ac_ext +CC=$ac_save_CC +fi -int test (int i, double x); -struct s1 {int (*f) (int a);}; -struct s2 {int (*f) (double a);}; -int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int); -int argc; -char **argv; -int -main () -{ -return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1]; - ; - return 0; -} +if test "x$ac_cv_prog_cc_c99" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cc_c99" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5 +printf "%s\n" "$ac_cv_prog_cc_c99" >&6; } + CC="$CC $ac_cv_prog_cc_c99" +fi + ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c99 + ac_prog_cc_stdc=c99 +fi +fi +if test x$ac_prog_cc_stdc = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CC option to enable C89 features" >&5 +printf %s "checking for $CC option to enable C89 features... " >&6; } +if test ${ac_cv_prog_cc_c89+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cc_c89=no +ac_save_CC=$CC +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$ac_c_conftest_c89_program _ACEOF -for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std \ - -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" +for ac_arg in '' -qlanglvl=extc89 -qlanglvl=ansi -std -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__" do CC="$ac_save_CC $ac_arg" - if ac_fn_c_try_compile "$LINENO"; then : + if ac_fn_c_try_compile "$LINENO" +then : ac_cv_prog_cc_c89=$ac_arg fi -rm -f core conftest.err conftest.$ac_objext +rm -f core conftest.err conftest.$ac_objext conftest.beam test "x$ac_cv_prog_cc_c89" != "xno" && break done rm -f conftest.$ac_ext CC=$ac_save_CC - fi -# AC_CACHE_VAL -case "x$ac_cv_prog_cc_c89" in - x) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 -$as_echo "none needed" >&6; } ;; - xno) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 -$as_echo "unsupported" >&6; } ;; - *) - CC="$CC $ac_cv_prog_cc_c89" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 -$as_echo "$ac_cv_prog_cc_c89" >&6; } ;; -esac -if test "x$ac_cv_prog_cc_c89" != xno; then : +if test "x$ac_cv_prog_cc_c89" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cc_c89" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c89" >&5 +printf "%s\n" "$ac_cv_prog_cc_c89" >&6; } + CC="$CC $ac_cv_prog_cc_c89" +fi + ac_cv_prog_cc_stdc=$ac_cv_prog_cc_c89 + ac_prog_cc_stdc=c89 +fi fi ac_ext=c @@ -4046,21 +5029,23 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu -ac_ext=c + + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5 -$as_echo_n "checking whether $CC understands -c and -o together... " >&6; } -if ${am_cv_prog_cc_c_o+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CC understands -c and -o together" >&5 +printf %s "checking whether $CC understands -c and -o together... " >&6; } +if test ${am_cv_prog_cc_c_o+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; @@ -4088,8 +5073,8 @@ _ACEOF rm -f core conftest* unset am_i fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5 -$as_echo "$am_cv_prog_cc_c_o" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_prog_cc_c_o" >&5 +printf "%s\n" "$am_cv_prog_cc_c_o" >&6; } if test "$am_cv_prog_cc_c_o" != yes; then # Losing compiler, so override with the script. # FIXME: It is wrong to rewrite CC. @@ -4107,11 +5092,12 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu depcc="$CC" am_compiler_list= -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 -$as_echo_n "checking dependency style of $depcc... " >&6; } -if ${am_cv_CC_dependencies_compiler_type+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 +printf %s "checking dependency style of $depcc... " >&6; } +if test ${am_cv_CC_dependencies_compiler_type+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For @@ -4218,8 +5204,8 @@ else fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 -$as_echo "$am_cv_CC_dependencies_compiler_type" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_CC_dependencies_compiler_type" >&5 +printf "%s\n" "$am_cv_CC_dependencies_compiler_type" >&6; } CCDEPMODE=depmode=$am_cv_CC_dependencies_compiler_type if @@ -4234,16 +5220,18 @@ fi -if test -n "$ac_tool_prefix"; then + + if test -n "$ac_tool_prefix"; then for ac_prog in ar lib "link -lib" do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_AR+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_AR+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$AR"; then ac_cv_prog_AR="$AR" # Let the user override the test. else @@ -4251,11 +5239,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_AR="$ac_tool_prefix$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -4266,11 +5258,11 @@ fi fi AR=$ac_cv_prog_AR if test -n "$AR"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 -$as_echo "$AR" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 +printf "%s\n" "$AR" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -4283,11 +5275,12 @@ if test -z "$AR"; then do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_AR+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_AR+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_AR"; then ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test. else @@ -4295,11 +5288,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_AR="$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -4310,11 +5307,11 @@ fi fi ac_ct_AR=$ac_cv_prog_ac_ct_AR if test -n "$ac_ct_AR"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 -$as_echo "$ac_ct_AR" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 +printf "%s\n" "$ac_ct_AR" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -4326,8 +5323,8 @@ done else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac AR=$ac_ct_AR @@ -4336,11 +5333,12 @@ fi : ${AR=ar} -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the archiver ($AR) interface" >&5 -$as_echo_n "checking the archiver ($AR) interface... " >&6; } -if ${am_cv_ar_interface+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking the archiver ($AR) interface" >&5 +printf %s "checking the archiver ($AR) interface... " >&6; } +if test ${am_cv_ar_interface+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -4352,12 +5350,13 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu /* end confdefs.h. */ int some_variable = 0; _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : am_ar_try='$AR cru libconftest.a conftest.$ac_objext >&5' { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$am_ar_try\""; } >&5 (eval $am_ar_try) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if test "$ac_status" -eq 0; then am_cv_ar_interface=ar @@ -4366,7 +5365,7 @@ if ac_fn_c_try_compile "$LINENO"; then : { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$am_ar_try\""; } >&5 (eval $am_ar_try) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if test "$ac_status" -eq 0; then am_cv_ar_interface=lib @@ -4377,7 +5376,7 @@ if ac_fn_c_try_compile "$LINENO"; then : rm -f conftest.lib libconftest.a fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -4385,8 +5384,8 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_ar_interface" >&5 -$as_echo "$am_cv_ar_interface" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_ar_interface" >&5 +printf "%s\n" "$am_cv_ar_interface" >&6; } case $am_cv_ar_interface in ar) @@ -4406,24 +5405,25 @@ unknown) esac -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5 -$as_echo_n "checking whether ln -s works... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5 +printf %s "checking whether ln -s works... " >&6; } LN_S=$as_ln_s if test "$LN_S" = "ln -s"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5 -$as_echo "no, using $LN_S" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5 +printf "%s\n" "no, using $LN_S" >&6; } fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 -$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5 +printf %s "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; } set x ${MAKE-make} -ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` -if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then : - $as_echo_n "(cached) " >&6 -else +ac_make=`printf "%s\n" "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'` +if eval test \${ac_cv_prog_make_${ac_make}_set+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat >conftest.make <<\_ACEOF SHELL = /bin/sh all: @@ -4439,12 +5439,12 @@ esac rm -f conftest.make fi if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } SET_MAKE= else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } SET_MAKE="MAKE=${MAKE-make}" fi @@ -4452,14 +5452,15 @@ fi case `pwd` in *\ * | *\ *) - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5 -$as_echo "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;; + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&5 +printf "%s\n" "$as_me: WARNING: Libtool does not cope well with whitespace in \`pwd\`" >&2;} ;; esac -macro_version='2.4.6' -macro_revision='2.4.6' +macro_version='2.5.3' +macro_revision='2.5.3' + @@ -4496,8 +5497,8 @@ ECHO='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO ECHO=$ECHO$ECHO$ECHO$ECHO$ECHO$ECHO -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to print strings" >&5 -$as_echo_n "checking how to print strings... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to print strings" >&5 +printf %s "checking how to print strings... " >&6; } # Test print first, because it will be a builtin if present. if test "X`( print -r -- -n ) 2>/dev/null`" = X-n && \ test "X`print -r -- $ECHO 2>/dev/null`" = "X$ECHO"; then @@ -4523,12 +5524,12 @@ func_echo_all () } case $ECHO in - printf*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: printf" >&5 -$as_echo "printf" >&6; } ;; - print*) { $as_echo "$as_me:${as_lineno-$LINENO}: result: print -r" >&5 -$as_echo "print -r" >&6; } ;; - *) { $as_echo "$as_me:${as_lineno-$LINENO}: result: cat" >&5 -$as_echo "cat" >&6; } ;; + printf*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: printf" >&5 +printf "%s\n" "printf" >&6; } ;; + print*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: print -r" >&5 +printf "%s\n" "print -r" >&6; } ;; + *) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: cat" >&5 +printf "%s\n" "cat" >&6; } ;; esac @@ -4544,11 +5545,12 @@ esac -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 -$as_echo_n "checking for a sed that does not truncate output... " >&6; } -if ${ac_cv_path_SED+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5 +printf %s "checking for a sed that does not truncate output... " >&6; } +if test ${ac_cv_path_SED+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/ for ac_i in 1 2 3 4 5 6 7; do ac_script="$ac_script$as_nl$ac_script" @@ -4562,10 +5564,15 @@ else for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in sed gsed; do + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_prog in sed gsed + do for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_SED="$as_dir/$ac_prog$ac_exec_ext" + ac_path_SED="$as_dir$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_SED" || continue # Check for GNU ac_path_SED and select it if it is found. # Check for GNU $ac_path_SED @@ -4574,13 +5581,13 @@ case `"$ac_path_SED" --version 2>&1` in ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;; *) ac_count=0 - $as_echo_n 0123456789 >"conftest.in" + printf %s 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" - $as_echo '' >> "conftest.nl" + printf "%s\n" '' >> "conftest.nl" "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val @@ -4608,8 +5615,8 @@ else fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 -$as_echo "$ac_cv_path_SED" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5 +printf "%s\n" "$ac_cv_path_SED" >&6; } SED="$ac_cv_path_SED" rm -f conftest.sed @@ -4626,11 +5633,12 @@ Xsed="$SED -e 1s/^X//" -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 -$as_echo_n "checking for grep that handles long lines and -e... " >&6; } -if ${ac_cv_path_GREP+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 +printf %s "checking for grep that handles long lines and -e... " >&6; } +if test ${ac_cv_path_GREP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -z "$GREP"; then ac_path_GREP_found=false # Loop through the user's path and test for each of PROGNAME-LIST @@ -4638,10 +5646,15 @@ else for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in grep ggrep; do + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_prog in grep ggrep + do for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext" + ac_path_GREP="$as_dir$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_GREP" || continue # Check for GNU ac_path_GREP and select it if it is found. # Check for GNU $ac_path_GREP @@ -4650,13 +5663,13 @@ case `"$ac_path_GREP" --version 2>&1` in ac_cv_path_GREP="$ac_path_GREP" ac_path_GREP_found=:;; *) ac_count=0 - $as_echo_n 0123456789 >"conftest.in" + printf %s 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" - $as_echo 'GREP' >> "conftest.nl" + printf "%s\n" 'GREP' >> "conftest.nl" "$ac_path_GREP" -e 'GREP$' -e '-(cannot match)-' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val @@ -4684,16 +5697,17 @@ else fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 -$as_echo "$ac_cv_path_GREP" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_GREP" >&5 +printf "%s\n" "$ac_cv_path_GREP" >&6; } GREP="$ac_cv_path_GREP" -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 -$as_echo_n "checking for egrep... " >&6; } -if ${ac_cv_path_EGREP+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for egrep" >&5 +printf %s "checking for egrep... " >&6; } +if test ${ac_cv_path_EGREP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if echo a | $GREP -E '(a|b)' >/dev/null 2>&1 then ac_cv_path_EGREP="$GREP -E" else @@ -4704,10 +5718,15 @@ else for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in egrep; do + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_prog in egrep + do for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext" + ac_path_EGREP="$as_dir$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_EGREP" || continue # Check for GNU ac_path_EGREP and select it if it is found. # Check for GNU $ac_path_EGREP @@ -4716,13 +5735,13 @@ case `"$ac_path_EGREP" --version 2>&1` in ac_cv_path_EGREP="$ac_path_EGREP" ac_path_EGREP_found=:;; *) ac_count=0 - $as_echo_n 0123456789 >"conftest.in" + printf %s 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" - $as_echo 'EGREP' >> "conftest.nl" + printf "%s\n" 'EGREP' >> "conftest.nl" "$ac_path_EGREP" 'EGREP$' < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val @@ -4751,16 +5770,17 @@ fi fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 -$as_echo "$ac_cv_path_EGREP" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_EGREP" >&5 +printf "%s\n" "$ac_cv_path_EGREP" >&6; } EGREP="$ac_cv_path_EGREP" -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5 -$as_echo_n "checking for fgrep... " >&6; } -if ${ac_cv_path_FGREP+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for fgrep" >&5 +printf %s "checking for fgrep... " >&6; } +if test ${ac_cv_path_FGREP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if echo 'ab*c' | $GREP -F 'ab*c' >/dev/null 2>&1 then ac_cv_path_FGREP="$GREP -F" else @@ -4771,10 +5791,15 @@ else for as_dir in $PATH$PATH_SEPARATOR/usr/xpg4/bin do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in fgrep; do + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_prog in fgrep + do for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_FGREP="$as_dir/$ac_prog$ac_exec_ext" + ac_path_FGREP="$as_dir$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_FGREP" || continue # Check for GNU ac_path_FGREP and select it if it is found. # Check for GNU $ac_path_FGREP @@ -4783,13 +5808,13 @@ case `"$ac_path_FGREP" --version 2>&1` in ac_cv_path_FGREP="$ac_path_FGREP" ac_path_FGREP_found=:;; *) ac_count=0 - $as_echo_n 0123456789 >"conftest.in" + printf %s 0123456789 >"conftest.in" while : do cat "conftest.in" "conftest.in" >"conftest.tmp" mv "conftest.tmp" "conftest.in" cp "conftest.in" "conftest.nl" - $as_echo 'FGREP' >> "conftest.nl" + printf "%s\n" 'FGREP' >> "conftest.nl" "$ac_path_FGREP" FGREP < "conftest.nl" >"conftest.out" 2>/dev/null || break diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break as_fn_arith $ac_count + 1 && ac_count=$as_val @@ -4818,8 +5843,8 @@ fi fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5 -$as_echo "$ac_cv_path_FGREP" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_FGREP" >&5 +printf "%s\n" "$ac_cv_path_FGREP" >&6; } FGREP="$ac_cv_path_FGREP" @@ -4844,19 +5869,20 @@ test -z "$GREP" && GREP=grep # Check whether --with-gnu-ld was given. -if test "${with_gnu_ld+set}" = set; then : +if test ${with_gnu_ld+y} +then : withval=$with_gnu_ld; test no = "$withval" || with_gnu_ld=yes -else +else $as_nop with_gnu_ld=no fi ac_prog=ld if test yes = "$GCC"; then # Check if gcc -print-prog-name=ld gives a path. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 -$as_echo_n "checking for ld used by $CC... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 +printf %s "checking for ld used by $CC... " >&6; } case $host in - *-*-mingw*) + *-*-mingw* | *-*-windows*) # gcc leaves a trailing carriage return, which upsets mingw ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; *) @@ -4883,15 +5909,16 @@ $as_echo_n "checking for ld used by $CC... " >&6; } ;; esac elif test yes = "$with_gnu_ld"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 -$as_echo_n "checking for GNU ld... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +printf %s "checking for GNU ld... " >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 -$as_echo_n "checking for non-GNU ld... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 +printf %s "checking for non-GNU ld... " >&6; } fi -if ${lt_cv_path_LD+:} false; then : - $as_echo_n "(cached) " >&6 -else +if test ${lt_cv_path_LD+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -z "$LD"; then lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR for ac_dir in $PATH; do @@ -4920,18 +5947,19 @@ fi LD=$lt_cv_path_LD if test -n "$LD"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5 -$as_echo "$LD" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LD" >&5 +printf "%s\n" "$LD" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 -$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } -if ${lt_cv_prog_gnu_ld+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 +printf %s "checking if the linker ($LD) is GNU ld... " >&6; } +if test ${lt_cv_prog_gnu_ld+y} +then : + printf %s "(cached) " >&6 +else $as_nop # I'd rather use --version here, but apparently some GNU lds only accept -v. case `$LD -v 2>&1 </dev/null` in *GNU* | *'with BFD'*) @@ -4942,8 +5970,8 @@ case `$LD -v 2>&1 </dev/null` in ;; esac fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_gnu_ld" >&5 -$as_echo "$lt_cv_prog_gnu_ld" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_gnu_ld" >&5 +printf "%s\n" "$lt_cv_prog_gnu_ld" >&6; } with_gnu_ld=$lt_cv_prog_gnu_ld @@ -4954,11 +5982,12 @@ with_gnu_ld=$lt_cv_prog_gnu_ld -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5 -$as_echo_n "checking for BSD- or MS-compatible name lister (nm)... " >&6; } -if ${lt_cv_path_NM+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for BSD- or MS-compatible name lister (nm)" >&5 +printf %s "checking for BSD- or MS-compatible name lister (nm)... " >&6; } +if test ${lt_cv_path_NM+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$NM"; then # Let the user override the test. lt_cv_path_NM=$NM @@ -4980,16 +6009,16 @@ else # Tru64's nm complains that /dev/null is an invalid object file # MSYS converts /dev/null to NUL, MinGW nm treats NUL as empty case $build_os in - mingw*) lt_bad_file=conftest.nm/nofile ;; + mingw* | windows*) lt_bad_file=conftest.nm/nofile ;; *) lt_bad_file=/dev/null ;; esac - case `"$tmp_nm" -B $lt_bad_file 2>&1 | sed '1q'` in + case `"$tmp_nm" -B $lt_bad_file 2>&1 | $SED '1q'` in *$lt_bad_file* | *'Invalid file or object type'*) lt_cv_path_NM="$tmp_nm -B" break 2 ;; *) - case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + case `"$tmp_nm" -p /dev/null 2>&1 | $SED '1q'` in */dev/null*) lt_cv_path_NM="$tmp_nm -p" break 2 @@ -5008,8 +6037,8 @@ else : ${lt_cv_path_NM=no} fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5 -$as_echo "$lt_cv_path_NM" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_NM" >&5 +printf "%s\n" "$lt_cv_path_NM" >&6; } if test no != "$lt_cv_path_NM"; then NM=$lt_cv_path_NM else @@ -5022,11 +6051,12 @@ else do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_DUMPBIN+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_DUMPBIN+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$DUMPBIN"; then ac_cv_prog_DUMPBIN="$DUMPBIN" # Let the user override the test. else @@ -5034,11 +6064,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_DUMPBIN="$ac_tool_prefix$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5049,11 +6083,11 @@ fi fi DUMPBIN=$ac_cv_prog_DUMPBIN if test -n "$DUMPBIN"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5 -$as_echo "$DUMPBIN" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DUMPBIN" >&5 +printf "%s\n" "$DUMPBIN" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -5066,11 +6100,12 @@ if test -z "$DUMPBIN"; then do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_DUMPBIN+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_DUMPBIN+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_DUMPBIN"; then ac_cv_prog_ac_ct_DUMPBIN="$ac_ct_DUMPBIN" # Let the user override the test. else @@ -5078,11 +6113,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_DUMPBIN="$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5093,11 +6132,11 @@ fi fi ac_ct_DUMPBIN=$ac_cv_prog_ac_ct_DUMPBIN if test -n "$ac_ct_DUMPBIN"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5 -$as_echo "$ac_ct_DUMPBIN" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DUMPBIN" >&5 +printf "%s\n" "$ac_ct_DUMPBIN" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -5109,15 +6148,15 @@ done else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DUMPBIN=$ac_ct_DUMPBIN fi fi - case `$DUMPBIN -symbols -headers /dev/null 2>&1 | sed '1q'` in + case `$DUMPBIN -symbols -headers /dev/null 2>&1 | $SED '1q'` in *COFF*) DUMPBIN="$DUMPBIN -symbols -headers" ;; @@ -5138,11 +6177,12 @@ test -z "$NM" && NM=nm -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5 -$as_echo_n "checking the name lister ($NM) interface... " >&6; } -if ${lt_cv_nm_interface+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking the name lister ($NM) interface" >&5 +printf %s "checking the name lister ($NM) interface... " >&6; } +if test ${lt_cv_nm_interface+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_nm_interface="BSD nm" echo "int some_variable = 0;" > conftest.$ac_ext (eval echo "\"\$as_me:$LINENO: $ac_compile\"" >&5) @@ -5158,15 +6198,16 @@ else fi rm -f conftest* fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5 -$as_echo "$lt_cv_nm_interface" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_nm_interface" >&5 +printf "%s\n" "$lt_cv_nm_interface" >&6; } # find the maximum length of command line arguments -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5 -$as_echo_n "checking the maximum length of command line arguments... " >&6; } -if ${lt_cv_sys_max_cmd_len+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking the maximum length of command line arguments" >&5 +printf %s "checking the maximum length of command line arguments... " >&6; } +if test ${lt_cv_sys_max_cmd_len+y} +then : + printf %s "(cached) " >&6 +else $as_nop i=0 teststring=ABCD @@ -5186,7 +6227,7 @@ else lt_cv_sys_max_cmd_len=-1; ;; - cygwin* | mingw* | cegcc*) + cygwin* | mingw* | windows* | cegcc*) # On Win9x/ME, this test blows up -- it succeeds, but takes # about 5 minutes as the teststring grows exponentially. # Worse, since 9x/ME are not pre-emptively multitasking, @@ -5202,18 +6243,13 @@ else lt_cv_sys_max_cmd_len=8192; ;; - mint*) - # On MiNT this can take a long time and run out of memory. - lt_cv_sys_max_cmd_len=8192; - ;; - amigaos*) # On AmigaOS with pdksh, this test takes hours, literally. # So we just punt and use a minimum line length of 8192. lt_cv_sys_max_cmd_len=8192; ;; - bitrig* | darwin* | dragonfly* | freebsd* | netbsd* | openbsd*) + darwin* | dragonfly* | freebsd* | midnightbsd* | netbsd* | openbsd*) # This has been around since 386BSD, at least. Likely further. if test -x /sbin/sysctl; then lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` @@ -5256,7 +6292,7 @@ else sysv5* | sco5v6* | sysv4.2uw2*) kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` if test -n "$kargmax"; then - lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[ ]//'` + lt_cv_sys_max_cmd_len=`echo $kargmax | $SED 's/.*[ ]//'` else lt_cv_sys_max_cmd_len=32768 fi @@ -5298,11 +6334,11 @@ else fi if test -n "$lt_cv_sys_max_cmd_len"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5 -$as_echo "$lt_cv_sys_max_cmd_len" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sys_max_cmd_len" >&5 +printf "%s\n" "$lt_cv_sys_max_cmd_len" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: none" >&5 -$as_echo "none" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none" >&5 +printf "%s\n" "none" >&6; } fi max_cmd_len=$lt_cv_sys_max_cmd_len @@ -5346,15 +6382,16 @@ esac -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to $host format" >&5 -$as_echo_n "checking how to convert $build file names to $host format... " >&6; } -if ${lt_cv_to_host_file_cmd+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to $host format" >&5 +printf %s "checking how to convert $build file names to $host format... " >&6; } +if test ${lt_cv_to_host_file_cmd+y} +then : + printf %s "(cached) " >&6 +else $as_nop case $host in *-*-mingw* ) case $build in - *-*-mingw* ) # actually msys + *-*-mingw* | *-*-windows* ) # actually msys lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32 ;; *-*-cygwin* ) @@ -5367,7 +6404,7 @@ else ;; *-*-cygwin* ) case $build in - *-*-mingw* ) # actually msys + *-*-mingw* | *-*-windows* ) # actually msys lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin ;; *-*-cygwin* ) @@ -5386,24 +6423,25 @@ esac fi to_host_file_cmd=$lt_cv_to_host_file_cmd -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_host_file_cmd" >&5 -$as_echo "$lt_cv_to_host_file_cmd" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_host_file_cmd" >&5 +printf "%s\n" "$lt_cv_to_host_file_cmd" >&6; } -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to toolchain format" >&5 -$as_echo_n "checking how to convert $build file names to toolchain format... " >&6; } -if ${lt_cv_to_tool_file_cmd+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to convert $build file names to toolchain format" >&5 +printf %s "checking how to convert $build file names to toolchain format... " >&6; } +if test ${lt_cv_to_tool_file_cmd+y} +then : + printf %s "(cached) " >&6 +else $as_nop #assume ordinary cross tools, or native build. lt_cv_to_tool_file_cmd=func_convert_file_noop case $host in - *-*-mingw* ) + *-*-mingw* | *-*-windows* ) case $build in - *-*-mingw* ) # actually msys + *-*-mingw* | *-*-windows* ) # actually msys lt_cv_to_tool_file_cmd=func_convert_file_msys_to_w32 ;; esac @@ -5413,22 +6451,23 @@ esac fi to_tool_file_cmd=$lt_cv_to_tool_file_cmd -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_tool_file_cmd" >&5 -$as_echo "$lt_cv_to_tool_file_cmd" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_to_tool_file_cmd" >&5 +printf "%s\n" "$lt_cv_to_tool_file_cmd" >&6; } -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5 -$as_echo_n "checking for $LD option to reload object files... " >&6; } -if ${lt_cv_ld_reload_flag+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $LD option to reload object files" >&5 +printf %s "checking for $LD option to reload object files... " >&6; } +if test ${lt_cv_ld_reload_flag+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_ld_reload_flag='-r' fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5 -$as_echo "$lt_cv_ld_reload_flag" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_reload_flag" >&5 +printf "%s\n" "$lt_cv_ld_reload_flag" >&6; } reload_flag=$lt_cv_ld_reload_flag case $reload_flag in "" | " "*) ;; @@ -5436,7 +6475,7 @@ case $reload_flag in esac reload_cmds='$LD$reload_flag -o $output$reload_objs' case $host_os in - cygwin* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | windows* | pw32* | cegcc*) if test yes != "$GCC"; then reload_cmds=false fi @@ -5458,14 +6497,64 @@ esac +# Extract the first word of "file", so it can be a program name with args. +set dummy file; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_FILECMD+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -n "$FILECMD"; then + ac_cv_prog_FILECMD="$FILECMD" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_FILECMD="file" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + + test -z "$ac_cv_prog_FILECMD" && ac_cv_prog_FILECMD=":" +fi +fi +FILECMD=$ac_cv_prog_FILECMD +if test -n "$FILECMD"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $FILECMD" >&5 +printf "%s\n" "$FILECMD" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + + + + + + + if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args. set dummy ${ac_tool_prefix}objdump; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_OBJDUMP+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_OBJDUMP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$OBJDUMP"; then ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test. else @@ -5473,11 +6562,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5488,11 +6581,11 @@ fi fi OBJDUMP=$ac_cv_prog_OBJDUMP if test -n "$OBJDUMP"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 -$as_echo "$OBJDUMP" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 +printf "%s\n" "$OBJDUMP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -5501,11 +6594,12 @@ if test -z "$ac_cv_prog_OBJDUMP"; then ac_ct_OBJDUMP=$OBJDUMP # Extract the first word of "objdump", so it can be a program name with args. set dummy objdump; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_OBJDUMP+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_OBJDUMP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_OBJDUMP"; then ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test. else @@ -5513,11 +6607,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OBJDUMP="objdump" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5528,11 +6626,11 @@ fi fi ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP if test -n "$ac_ct_OBJDUMP"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 -$as_echo "$ac_ct_OBJDUMP" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 +printf "%s\n" "$ac_ct_OBJDUMP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_OBJDUMP" = x; then @@ -5540,8 +6638,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OBJDUMP=$ac_ct_OBJDUMP @@ -5557,11 +6655,12 @@ test -z "$OBJDUMP" && OBJDUMP=objdump -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5 -$as_echo_n "checking how to recognize dependent libraries... " >&6; } -if ${lt_cv_deplibs_check_method+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to recognize dependent libraries" >&5 +printf %s "checking how to recognize dependent libraries... " >&6; } +if test ${lt_cv_deplibs_check_method+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_file_magic_cmd='$MAGIC_CMD' lt_cv_file_magic_test_file= lt_cv_deplibs_check_method='unknown' @@ -5570,7 +6669,6 @@ lt_cv_deplibs_check_method='unknown' # 'none' -- dependencies not supported. # 'unknown' -- same as none, but documents that we really don't know. # 'pass_all' -- all dependencies passed with no checks. -# 'test_compile' -- check by making test program. # 'file_magic [[regex]]' -- check by looking for files in library path # that responds to the $file_magic_cmd with a given extended regex. # If you have 'file' or equivalent on your system and you're not sure @@ -5587,7 +6685,7 @@ beos*) bsdi[45]*) lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (shared object|dynamic lib)' - lt_cv_file_magic_cmd='/usr/bin/file -L' + lt_cv_file_magic_cmd='$FILECMD -L' lt_cv_file_magic_test_file=/shlib/libc.so ;; @@ -5597,7 +6695,7 @@ cygwin*) lt_cv_file_magic_cmd='func_win32_libid' ;; -mingw* | pw32*) +mingw* | windows* | pw32*) # Base MSYS/MinGW do not provide the 'file' command needed by # func_win32_libid shell function, so use a weaker test based on 'objdump', # unless we find 'file', for example because we are cross-compiling. @@ -5606,7 +6704,7 @@ mingw* | pw32*) lt_cv_file_magic_cmd='func_win32_libid' else # Keep this pattern in sync with the one in func_win32_libid. - lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' + lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64|pe-aarch64)' lt_cv_file_magic_cmd='$OBJDUMP -f' fi ;; @@ -5621,14 +6719,14 @@ darwin* | rhapsody*) lt_cv_deplibs_check_method=pass_all ;; -freebsd* | dragonfly*) +freebsd* | dragonfly* | midnightbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then case $host_cpu in i*86 ) # Not sure whether the presence of OpenBSD here was a mistake. # Let's accept both of them until this is cleared up. lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[3-9]86 (compact )?demand paged shared library' - lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_cmd=$FILECMD lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` ;; esac @@ -5642,7 +6740,7 @@ haiku*) ;; hpux10.20* | hpux11*) - lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_cmd=$FILECMD case $host_cpu in ia64*) lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - IA64' @@ -5689,7 +6787,7 @@ netbsd*) newos6*) lt_cv_deplibs_check_method='file_magic ELF [0-9][0-9]*-bit [ML]SB (executable|dynamic lib)' - lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_cmd=$FILECMD lt_cv_file_magic_test_file=/usr/lib/libnls.so ;; @@ -5697,7 +6795,7 @@ newos6*) lt_cv_deplibs_check_method=pass_all ;; -openbsd* | bitrig*) +openbsd*) if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then lt_cv_deplibs_check_method='match_pattern /lib[^/]+(\.so\.[0-9]+\.[0-9]+|\.so|_pic\.a)$' else @@ -5757,14 +6855,14 @@ os2*) esac fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5 -$as_echo "$lt_cv_deplibs_check_method" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_deplibs_check_method" >&5 +printf "%s\n" "$lt_cv_deplibs_check_method" >&6; } file_magic_glob= want_nocaseglob=no if test "$build" = "$host"; then case $host_os in - mingw* | pw32*) + mingw* | windows* | pw32*) if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then want_nocaseglob=yes else @@ -5802,11 +6900,12 @@ test -z "$deplibs_check_method" && deplibs_check_method=unknown if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}dlltool", so it can be a program name with args. set dummy ${ac_tool_prefix}dlltool; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_DLLTOOL+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_DLLTOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$DLLTOOL"; then ac_cv_prog_DLLTOOL="$DLLTOOL" # Let the user override the test. else @@ -5814,11 +6913,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_DLLTOOL="${ac_tool_prefix}dlltool" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5829,11 +6932,11 @@ fi fi DLLTOOL=$ac_cv_prog_DLLTOOL if test -n "$DLLTOOL"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5 -$as_echo "$DLLTOOL" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5 +printf "%s\n" "$DLLTOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -5842,11 +6945,12 @@ if test -z "$ac_cv_prog_DLLTOOL"; then ac_ct_DLLTOOL=$DLLTOOL # Extract the first word of "dlltool", so it can be a program name with args. set dummy dlltool; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_DLLTOOL+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_DLLTOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_DLLTOOL"; then ac_cv_prog_ac_ct_DLLTOOL="$ac_ct_DLLTOOL" # Let the user override the test. else @@ -5854,11 +6958,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_DLLTOOL="dlltool" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5869,11 +6977,11 @@ fi fi ac_ct_DLLTOOL=$ac_cv_prog_ac_ct_DLLTOOL if test -n "$ac_ct_DLLTOOL"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5 -$as_echo "$ac_ct_DLLTOOL" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5 +printf "%s\n" "$ac_ct_DLLTOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_DLLTOOL" = x; then @@ -5881,8 +6989,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DLLTOOL=$ac_ct_DLLTOOL @@ -5899,15 +7007,16 @@ test -z "$DLLTOOL" && DLLTOOL=dlltool -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to associate runtime and link libraries" >&5 -$as_echo_n "checking how to associate runtime and link libraries... " >&6; } -if ${lt_cv_sharedlib_from_linklib_cmd+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to associate runtime and link libraries" >&5 +printf %s "checking how to associate runtime and link libraries... " >&6; } +if test ${lt_cv_sharedlib_from_linklib_cmd+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_sharedlib_from_linklib_cmd='unknown' case $host_os in -cygwin* | mingw* | pw32* | cegcc*) +cygwin* | mingw* | windows* | pw32* | cegcc*) # two different shell functions defined in ltmain.sh; # decide which one to use based on capabilities of $DLLTOOL case `$DLLTOOL --help 2>&1` in @@ -5926,8 +7035,8 @@ cygwin* | mingw* | pw32* | cegcc*) esac fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sharedlib_from_linklib_cmd" >&5 -$as_echo "$lt_cv_sharedlib_from_linklib_cmd" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_sharedlib_from_linklib_cmd" >&5 +printf "%s\n" "$lt_cv_sharedlib_from_linklib_cmd" >&6; } sharedlib_from_linklib_cmd=$lt_cv_sharedlib_from_linklib_cmd test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO @@ -5938,15 +7047,118 @@ test -z "$sharedlib_from_linklib_cmd" && sharedlib_from_linklib_cmd=$ECHO if test -n "$ac_tool_prefix"; then + # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. +set dummy ${ac_tool_prefix}ranlib; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_RANLIB+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -n "$RANLIB"; then + ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +RANLIB=$ac_cv_prog_RANLIB +if test -n "$RANLIB"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 +printf "%s\n" "$RANLIB" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + +fi +if test -z "$ac_cv_prog_RANLIB"; then + ac_ct_RANLIB=$RANLIB + # Extract the first word of "ranlib", so it can be a program name with args. +set dummy ranlib; ac_word=$2 +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_RANLIB+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test -n "$ac_ct_RANLIB"; then + ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then + ac_cv_prog_ac_ct_RANLIB="ranlib" + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB +if test -n "$ac_ct_RANLIB"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 +printf "%s\n" "$ac_ct_RANLIB" >&6; } +else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +fi + + if test "x$ac_ct_RANLIB" = x; then + RANLIB=":" + else + case $cross_compiling:$ac_tool_warned in +yes:) +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +ac_tool_warned=yes ;; +esac + RANLIB=$ac_ct_RANLIB + fi +else + RANLIB="$ac_cv_prog_RANLIB" +fi + +if test -n "$ac_tool_prefix"; then for ac_prog in ar do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_AR+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_AR+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$AR"; then ac_cv_prog_AR="$AR" # Let the user override the test. else @@ -5954,11 +7166,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_AR="$ac_tool_prefix$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -5969,11 +7185,11 @@ fi fi AR=$ac_cv_prog_AR if test -n "$AR"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 -$as_echo "$AR" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AR" >&5 +printf "%s\n" "$AR" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -5986,11 +7202,12 @@ if test -z "$AR"; then do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_AR+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_AR+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_AR"; then ac_cv_prog_ac_ct_AR="$ac_ct_AR" # Let the user override the test. else @@ -5998,11 +7215,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_AR="$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6013,11 +7234,11 @@ fi fi ac_ct_AR=$ac_cv_prog_ac_ct_AR if test -n "$ac_ct_AR"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 -$as_echo "$ac_ct_AR" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AR" >&5 +printf "%s\n" "$ac_ct_AR" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -6029,8 +7250,8 @@ done else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac AR=$ac_ct_AR @@ -6038,42 +7259,60 @@ esac fi : ${AR=ar} -: ${AR_FLAGS=cru} +# Use ARFLAGS variable as AR's operation code to sync the variable naming with +# Automake. If both AR_FLAGS and ARFLAGS are specified, AR_FLAGS should have +# higher priority because that's what people were doing historically (setting +# ARFLAGS for automake and AR_FLAGS for libtool). FIXME: Make the AR_FLAGS +# variable obsoleted/removed. +test ${AR_FLAGS+y} || AR_FLAGS=${ARFLAGS-cr} +lt_ar_flags=$AR_FLAGS -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for archiver @FILE support" >&5 -$as_echo_n "checking for archiver @FILE support... " >&6; } -if ${lt_cv_ar_at_file+:} false; then : - $as_echo_n "(cached) " >&6 -else + + +# Make AR_FLAGS overridable by 'make ARFLAGS='. Don't try to run-time override +# by AR_FLAGS because that was never working and AR_FLAGS is about to die. + + + + + + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for archiver @FILE support" >&5 +printf %s "checking for archiver @FILE support... " >&6; } +if test ${lt_cv_ar_at_file+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_ar_at_file=no cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : echo conftest.$ac_objext > conftest.lst lt_ar_try='$AR $AR_FLAGS libconftest.a @conftest.lst >&5' { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5 (eval $lt_ar_try) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if test 0 -eq "$ac_status"; then # Ensure the archiver fails upon bogus file names. @@ -6081,7 +7320,7 @@ if ac_fn_c_try_compile "$LINENO"; then : { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$lt_ar_try\""; } >&5 (eval $lt_ar_try) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } if test 0 -ne "$ac_status"; then lt_cv_ar_at_file=@ @@ -6090,11 +7329,11 @@ if ac_fn_c_try_compile "$LINENO"; then : rm -f conftest.* libconftest.a fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ar_at_file" >&5 -$as_echo "$lt_cv_ar_at_file" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ar_at_file" >&5 +printf "%s\n" "$lt_cv_ar_at_file" >&6; } if test no = "$lt_cv_ar_at_file"; then archiver_list_spec= @@ -6111,11 +7350,12 @@ fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}strip", so it can be a program name with args. set dummy ${ac_tool_prefix}strip; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_STRIP+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_STRIP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$STRIP"; then ac_cv_prog_STRIP="$STRIP" # Let the user override the test. else @@ -6123,11 +7363,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_STRIP="${ac_tool_prefix}strip" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6138,11 +7382,11 @@ fi fi STRIP=$ac_cv_prog_STRIP if test -n "$STRIP"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 -$as_echo "$STRIP" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $STRIP" >&5 +printf "%s\n" "$STRIP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -6151,11 +7395,12 @@ if test -z "$ac_cv_prog_STRIP"; then ac_ct_STRIP=$STRIP # Extract the first word of "strip", so it can be a program name with args. set dummy strip; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_STRIP+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_STRIP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_STRIP"; then ac_cv_prog_ac_ct_STRIP="$ac_ct_STRIP" # Let the user override the test. else @@ -6163,11 +7408,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_STRIP="strip" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -6178,11 +7427,11 @@ fi fi ac_ct_STRIP=$ac_cv_prog_ac_ct_STRIP if test -n "$ac_ct_STRIP"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 -$as_echo "$ac_ct_STRIP" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_STRIP" >&5 +printf "%s\n" "$ac_ct_STRIP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_STRIP" = x; then @@ -6190,8 +7439,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac STRIP=$ac_ct_STRIP @@ -6207,97 +7456,6 @@ test -z "$STRIP" && STRIP=: -if test -n "$ac_tool_prefix"; then - # Extract the first word of "${ac_tool_prefix}ranlib", so it can be a program name with args. -set dummy ${ac_tool_prefix}ranlib; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_RANLIB+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$RANLIB"; then - ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_RANLIB="${ac_tool_prefix}ranlib" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -RANLIB=$ac_cv_prog_RANLIB -if test -n "$RANLIB"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RANLIB" >&5 -$as_echo "$RANLIB" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - -fi -if test -z "$ac_cv_prog_RANLIB"; then - ac_ct_RANLIB=$RANLIB - # Extract the first word of "ranlib", so it can be a program name with args. -set dummy ranlib; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_RANLIB+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test -n "$ac_ct_RANLIB"; then - ac_cv_prog_ac_ct_RANLIB="$ac_ct_RANLIB" # Let the user override the test. -else -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then - ac_cv_prog_ac_ct_RANLIB="ranlib" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 - break 2 - fi -done - done -IFS=$as_save_IFS - -fi -fi -ac_ct_RANLIB=$ac_cv_prog_ac_ct_RANLIB -if test -n "$ac_ct_RANLIB"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_RANLIB" >&5 -$as_echo "$ac_ct_RANLIB" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } -fi - - if test "x$ac_ct_RANLIB" = x; then - RANLIB=":" - else - case $cross_compiling:$ac_tool_warned in -yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} -ac_tool_warned=yes ;; -esac - RANLIB=$ac_ct_RANLIB - fi -else - RANLIB="$ac_cv_prog_RANLIB" -fi test -z "$RANLIB" && RANLIB=: @@ -6312,15 +7470,8 @@ old_postinstall_cmds='chmod 644 $oldlib' old_postuninstall_cmds= if test -n "$RANLIB"; then - case $host_os in - bitrig* | openbsd*) - old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$tool_oldlib" - ;; - *) - old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib" - ;; - esac old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib" + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib" fi case $host_os in @@ -6379,11 +7530,12 @@ compiler=$CC # Check for command to grab the raw symbol name followed by C symbol from nm. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5 -$as_echo_n "checking command to parse $NM output from $compiler object... " >&6; } -if ${lt_cv_sys_global_symbol_pipe+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking command to parse $NM output from $compiler object" >&5 +printf %s "checking command to parse $NM output from $compiler object... " >&6; } +if test ${lt_cv_sys_global_symbol_pipe+y} +then : + printf %s "(cached) " >&6 +else $as_nop # These are sane defaults that work on at least a few old systems. # [They come from Ultrix. What could be older than Ultrix?!! ;)] @@ -6399,7 +7551,7 @@ case $host_os in aix*) symcode='[BCDT]' ;; -cygwin* | mingw* | pw32* | cegcc*) +cygwin* | mingw* | windows* | pw32* | cegcc*) symcode='[ABCDGISTW]' ;; hpux*) @@ -6414,7 +7566,7 @@ osf*) symcode='[BCDEGQRST]' ;; solaris*) - symcode='[BDRT]' + symcode='[BCDRT]' ;; sco3.2v5*) symcode='[DT]' @@ -6438,7 +7590,7 @@ esac if test "$lt_cv_nm_interface" = "MS dumpbin"; then # Gets list of data symbols to import. - lt_cv_sys_global_symbol_to_import="sed -n -e 's/^I .* \(.*\)$/\1/p'" + lt_cv_sys_global_symbol_to_import="$SED -n -e 's/^I .* \(.*\)$/\1/p'" # Adjust the below global symbol transforms to fixup imported variables. lt_cdecl_hook=" -e 's/^I .* \(.*\)$/extern __declspec(dllimport) char \1;/p'" lt_c_name_hook=" -e 's/^I .* \(.*\)$/ {\"\1\", (void *) 0},/p'" @@ -6456,20 +7608,20 @@ fi # Transform an extracted symbol line into a proper C declaration. # Some systems (esp. on ia64) link data and code symbols differently, # so use this general approach. -lt_cv_sys_global_symbol_to_cdecl="sed -n"\ +lt_cv_sys_global_symbol_to_cdecl="$SED -n"\ $lt_cdecl_hook\ " -e 's/^T .* \(.*\)$/extern int \1();/p'"\ " -e 's/^$symcode$symcode* .* \(.*\)$/extern char \1;/p'" # Transform an extracted symbol line into symbol name and symbol address -lt_cv_sys_global_symbol_to_c_name_address="sed -n"\ +lt_cv_sys_global_symbol_to_c_name_address="$SED -n"\ $lt_c_name_hook\ " -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ " -e 's/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/p'" # Transform an extracted symbol line into symbol name with lib prefix and # symbol address. -lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n"\ +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="$SED -n"\ $lt_c_name_lib_hook\ " -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ " -e 's/^$symcode$symcode* .* \(lib.*\)$/ {\"\1\", (void *) \&\1},/p'"\ @@ -6478,7 +7630,7 @@ $lt_c_name_lib_hook\ # Handle CRLF in mingw tool chain opt_cr= case $build_os in -mingw*) +mingw* | windows*) opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp ;; esac @@ -6493,7 +7645,7 @@ for ac_symprfx in "" "_"; do if test "$lt_cv_nm_interface" = "MS dumpbin"; then # Fake it for dumpbin and say T for any non-static function, # D for any global variable and I for any imported variable. - # Also find C++ and __fastcall symbols from MSVC++, + # Also find C++ and __fastcall symbols from MSVC++ or ICC, # which start with @ or ?. lt_cv_sys_global_symbol_pipe="$AWK '"\ " {last_section=section; section=\$ 3};"\ @@ -6511,9 +7663,9 @@ for ac_symprfx in "" "_"; do " s[1]~prfx {split(s[1],t,\"@\"); print f,t[1],substr(t[1],length(prfx))}"\ " ' prfx=^$ac_symprfx" else - lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[ ]\($symcode$symcode*\)[ ][ ]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + lt_cv_sys_global_symbol_pipe="$SED -n -e 's/^.*[ ]\($symcode$symcode*\)[ ][ ]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" fi - lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | sed '/ __gnu_lto/d'" + lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | $SED '/ __gnu_lto/d'" # Check to see that the pipe works correctly. pipe_works=no @@ -6529,20 +7681,20 @@ void nm_test_func(void){} #ifdef __cplusplus } #endif -int main(){nm_test_var='a';nm_test_func();return(0);} +int main(void){nm_test_var='a';nm_test_func();return(0);} _LT_EOF if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then # Now try to grab the symbols. nlist=conftest.nm if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist\""; } >&5 (eval $NM conftest.$ac_objext \| "$lt_cv_sys_global_symbol_pipe" \> $nlist) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s "$nlist"; then # Try sorting and uniquifying the output. if sort "$nlist" | uniq > "$nlist"T; then @@ -6611,7 +7763,7 @@ _LT_EOF if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 (eval $ac_link) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s conftest$ac_exeext; then pipe_works=yes fi @@ -6646,11 +7798,11 @@ if test -z "$lt_cv_sys_global_symbol_pipe"; then lt_cv_sys_global_symbol_to_cdecl= fi if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: failed" >&5 -$as_echo "failed" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: failed" >&5 +printf "%s\n" "failed" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5 -$as_echo "ok" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ok" >&5 +printf "%s\n" "ok" >&6; } fi # Response file support. @@ -6696,13 +7848,14 @@ fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sysroot" >&5 -$as_echo_n "checking for sysroot... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for sysroot" >&5 +printf %s "checking for sysroot... " >&6; } # Check whether --with-sysroot was given. -if test "${with_sysroot+set}" = set; then : +if test ${with_sysroot+y} +then : withval=$with_sysroot; -else +else $as_nop with_sysroot=no fi @@ -6711,33 +7864,36 @@ lt_sysroot= case $with_sysroot in #( yes) if test yes = "$GCC"; then - lt_sysroot=`$CC --print-sysroot 2>/dev/null` + # Trim trailing / since we'll always append absolute paths and we want + # to avoid //, if only for less confusing output for the user. + lt_sysroot=`$CC --print-sysroot 2>/dev/null | $SED 's:/\+$::'` fi ;; #( /*) - lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"` + lt_sysroot=`echo "$with_sysroot" | $SED -e "$sed_quote_subst"` ;; #( no|'') ;; #( *) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_sysroot" >&5 -$as_echo "$with_sysroot" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_sysroot" >&5 +printf "%s\n" "$with_sysroot" >&6; } as_fn_error $? "The sysroot must be an absolute path." "$LINENO" 5 ;; esac - { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${lt_sysroot:-no}" >&5 -$as_echo "${lt_sysroot:-no}" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${lt_sysroot:-no}" >&5 +printf "%s\n" "${lt_sysroot:-no}" >&6; } -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a working dd" >&5 -$as_echo_n "checking for a working dd... " >&6; } -if ${ac_cv_path_lt_DD+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for a working dd" >&5 +printf %s "checking for a working dd... " >&6; } +if test ${ac_cv_path_lt_DD+y} +then : + printf %s "(cached) " >&6 +else $as_nop printf 0123456789abcdef0123456789abcdef >conftest.i cat conftest.i conftest.i >conftest2.i : ${lt_DD:=$DD} @@ -6748,10 +7904,15 @@ if test -z "$lt_DD"; then for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for ac_prog in dd; do + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + for ac_prog in dd + do for ac_exec_ext in '' $ac_executable_extensions; do - ac_path_lt_DD="$as_dir/$ac_prog$ac_exec_ext" + ac_path_lt_DD="$as_dir$ac_prog$ac_exec_ext" as_fn_executable_p "$ac_path_lt_DD" || continue if "$ac_path_lt_DD" bs=32 count=1 <conftest2.i >conftest.out 2>/dev/null; then cmp -s conftest.i conftest.out \ @@ -6771,15 +7932,16 @@ fi rm -f conftest.i conftest2.i conftest.out fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_lt_DD" >&5 -$as_echo "$ac_cv_path_lt_DD" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_lt_DD" >&5 +printf "%s\n" "$ac_cv_path_lt_DD" >&6; } -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to truncate binary pipes" >&5 -$as_echo_n "checking how to truncate binary pipes... " >&6; } -if ${lt_cv_truncate_bin+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to truncate binary pipes" >&5 +printf %s "checking how to truncate binary pipes... " >&6; } +if test ${lt_cv_truncate_bin+y} +then : + printf %s "(cached) " >&6 +else $as_nop printf 0123456789abcdef0123456789abcdef >conftest.i cat conftest.i conftest.i >conftest2.i lt_cv_truncate_bin= @@ -6790,8 +7952,8 @@ fi rm -f conftest.i conftest2.i conftest.out test -z "$lt_cv_truncate_bin" && lt_cv_truncate_bin="$SED -e 4q" fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_truncate_bin" >&5 -$as_echo "$lt_cv_truncate_bin" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_truncate_bin" >&5 +printf "%s\n" "$lt_cv_truncate_bin" >&6; } @@ -6814,7 +7976,8 @@ func_cc_basename () } # Check whether --enable-libtool-lock was given. -if test "${enable_libtool_lock+set}" = set; then : +if test ${enable_libtool_lock+y} +then : enableval=$enable_libtool_lock; fi @@ -6830,9 +7993,9 @@ ia64-*-hpux*) if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then - case `/usr/bin/file conftest.$ac_objext` in + case `$FILECMD conftest.$ac_objext` in *ELF-32*) HPUX_IA64_MODE=32 ;; @@ -6850,10 +8013,10 @@ ia64-*-hpux*) if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then if test yes = "$lt_cv_prog_gnu_ld"; then - case `/usr/bin/file conftest.$ac_objext` in + case `$FILECMD conftest.$ac_objext` in *32-bit*) LD="${LD-ld} -melf32bsmip" ;; @@ -6865,7 +8028,7 @@ ia64-*-hpux*) ;; esac else - case `/usr/bin/file conftest.$ac_objext` in + case `$FILECMD conftest.$ac_objext` in *32-bit*) LD="${LD-ld} -32" ;; @@ -6888,10 +8051,10 @@ mips64*-*linux*) if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then emul=elf - case `/usr/bin/file conftest.$ac_objext` in + case `$FILECMD conftest.$ac_objext` in *32-bit*) emul="${emul}32" ;; @@ -6899,7 +8062,7 @@ mips64*-*linux*) emul="${emul}64" ;; esac - case `/usr/bin/file conftest.$ac_objext` in + case `$FILECMD conftest.$ac_objext` in *MSB*) emul="${emul}btsmip" ;; @@ -6907,7 +8070,7 @@ mips64*-*linux*) emul="${emul}ltsmip" ;; esac - case `/usr/bin/file conftest.$ac_objext` in + case `$FILECMD conftest.$ac_objext` in *N32*) emul="${emul}n32" ;; @@ -6918,7 +8081,7 @@ mips64*-*linux*) ;; x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \ -s390*-*linux*|s390*-*tpf*|sparc*-*linux*) +s390*-*linux*|s390*-*tpf*|sparc*-*linux*|x86_64-gnu*) # Find out what ABI is being produced by ac_compile, and set linker # options accordingly. Note that the listed cases only cover the # situations where additional linker options are needed (such as when @@ -6929,16 +8092,16 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then - case `/usr/bin/file conftest.o` in + case `$FILECMD conftest.o` in *32-bit*) case $host in x86_64-*kfreebsd*-gnu) LD="${LD-ld} -m elf_i386_fbsd" ;; - x86_64-*linux*) - case `/usr/bin/file conftest.o` in + x86_64-*linux*|x86_64-gnu*) + case `$FILECMD conftest.o` in *x86-64*) LD="${LD-ld} -m elf32_x86_64" ;; @@ -6966,7 +8129,7 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) x86_64-*kfreebsd*-gnu) LD="${LD-ld} -m elf_x86_64_fbsd" ;; - x86_64-*linux*) + x86_64-*linux*|x86_64-gnu*) LD="${LD-ld} -m elf_x86_64" ;; powerpcle-*linux*|powerpc64le-*linux*) @@ -6992,11 +8155,12 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) # On SCO OpenServer 5, we need -belf to get full-featured binaries. SAVE_CFLAGS=$CFLAGS CFLAGS="$CFLAGS -belf" - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5 -$as_echo_n "checking whether the C compiler needs -belf... " >&6; } -if ${lt_cv_cc_needs_belf+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the C compiler needs -belf" >&5 +printf %s "checking whether the C compiler needs -belf... " >&6; } +if test ${lt_cv_cc_needs_belf+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -7007,19 +8171,20 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : lt_cv_cc_needs_belf=yes -else +else $as_nop lt_cv_cc_needs_belf=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -7028,8 +8193,8 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5 -$as_echo "$lt_cv_cc_needs_belf" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_cc_needs_belf" >&5 +printf "%s\n" "$lt_cv_cc_needs_belf" >&6; } if test yes != "$lt_cv_cc_needs_belf"; then # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf CFLAGS=$SAVE_CFLAGS @@ -7042,9 +8207,9 @@ $as_echo "$lt_cv_cc_needs_belf" >&6; } if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then - case `/usr/bin/file conftest.o` in + case `$FILECMD conftest.o` in *64-bit*) case $lt_cv_prog_gnu_ld in yes*) @@ -7079,11 +8244,12 @@ need_locks=$enable_libtool_lock if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}mt", so it can be a program name with args. set dummy ${ac_tool_prefix}mt; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_MANIFEST_TOOL+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_MANIFEST_TOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$MANIFEST_TOOL"; then ac_cv_prog_MANIFEST_TOOL="$MANIFEST_TOOL" # Let the user override the test. else @@ -7091,11 +8257,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_MANIFEST_TOOL="${ac_tool_prefix}mt" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7106,11 +8276,11 @@ fi fi MANIFEST_TOOL=$ac_cv_prog_MANIFEST_TOOL if test -n "$MANIFEST_TOOL"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MANIFEST_TOOL" >&5 -$as_echo "$MANIFEST_TOOL" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MANIFEST_TOOL" >&5 +printf "%s\n" "$MANIFEST_TOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -7119,11 +8289,12 @@ if test -z "$ac_cv_prog_MANIFEST_TOOL"; then ac_ct_MANIFEST_TOOL=$MANIFEST_TOOL # Extract the first word of "mt", so it can be a program name with args. set dummy mt; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_MANIFEST_TOOL+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_MANIFEST_TOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_MANIFEST_TOOL"; then ac_cv_prog_ac_ct_MANIFEST_TOOL="$ac_ct_MANIFEST_TOOL" # Let the user override the test. else @@ -7131,11 +8302,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_MANIFEST_TOOL="mt" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7146,11 +8321,11 @@ fi fi ac_ct_MANIFEST_TOOL=$ac_cv_prog_ac_ct_MANIFEST_TOOL if test -n "$ac_ct_MANIFEST_TOOL"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_MANIFEST_TOOL" >&5 -$as_echo "$ac_ct_MANIFEST_TOOL" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_MANIFEST_TOOL" >&5 +printf "%s\n" "$ac_ct_MANIFEST_TOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_MANIFEST_TOOL" = x; then @@ -7158,8 +8333,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac MANIFEST_TOOL=$ac_ct_MANIFEST_TOOL @@ -7169,23 +8344,24 @@ else fi test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $MANIFEST_TOOL is a manifest tool" >&5 -$as_echo_n "checking if $MANIFEST_TOOL is a manifest tool... " >&6; } -if ${lt_cv_path_mainfest_tool+:} false; then : - $as_echo_n "(cached) " >&6 -else - lt_cv_path_mainfest_tool=no +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $MANIFEST_TOOL is a manifest tool" >&5 +printf %s "checking if $MANIFEST_TOOL is a manifest tool... " >&6; } +if test ${lt_cv_path_manifest_tool+y} +then : + printf %s "(cached) " >&6 +else $as_nop + lt_cv_path_manifest_tool=no echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&5 $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out cat conftest.err >&5 if $GREP 'Manifest Tool' conftest.out > /dev/null; then - lt_cv_path_mainfest_tool=yes + lt_cv_path_manifest_tool=yes fi rm -f conftest* fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_mainfest_tool" >&5 -$as_echo "$lt_cv_path_mainfest_tool" >&6; } -if test yes != "$lt_cv_path_mainfest_tool"; then +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_path_manifest_tool" >&5 +printf "%s\n" "$lt_cv_path_manifest_tool" >&6; } +if test yes != "$lt_cv_path_manifest_tool"; then MANIFEST_TOOL=: fi @@ -7199,11 +8375,12 @@ fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}dsymutil", so it can be a program name with args. set dummy ${ac_tool_prefix}dsymutil; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_DSYMUTIL+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_DSYMUTIL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$DSYMUTIL"; then ac_cv_prog_DSYMUTIL="$DSYMUTIL" # Let the user override the test. else @@ -7211,11 +8388,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_DSYMUTIL="${ac_tool_prefix}dsymutil" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7226,11 +8407,11 @@ fi fi DSYMUTIL=$ac_cv_prog_DSYMUTIL if test -n "$DSYMUTIL"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5 -$as_echo "$DSYMUTIL" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DSYMUTIL" >&5 +printf "%s\n" "$DSYMUTIL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -7239,11 +8420,12 @@ if test -z "$ac_cv_prog_DSYMUTIL"; then ac_ct_DSYMUTIL=$DSYMUTIL # Extract the first word of "dsymutil", so it can be a program name with args. set dummy dsymutil; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_DSYMUTIL+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_DSYMUTIL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_DSYMUTIL"; then ac_cv_prog_ac_ct_DSYMUTIL="$ac_ct_DSYMUTIL" # Let the user override the test. else @@ -7251,11 +8433,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_DSYMUTIL="dsymutil" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7266,11 +8452,11 @@ fi fi ac_ct_DSYMUTIL=$ac_cv_prog_ac_ct_DSYMUTIL if test -n "$ac_ct_DSYMUTIL"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5 -$as_echo "$ac_ct_DSYMUTIL" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DSYMUTIL" >&5 +printf "%s\n" "$ac_ct_DSYMUTIL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_DSYMUTIL" = x; then @@ -7278,8 +8464,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DSYMUTIL=$ac_ct_DSYMUTIL @@ -7291,11 +8477,12 @@ fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}nmedit", so it can be a program name with args. set dummy ${ac_tool_prefix}nmedit; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_NMEDIT+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_NMEDIT+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$NMEDIT"; then ac_cv_prog_NMEDIT="$NMEDIT" # Let the user override the test. else @@ -7303,11 +8490,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_NMEDIT="${ac_tool_prefix}nmedit" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7318,11 +8509,11 @@ fi fi NMEDIT=$ac_cv_prog_NMEDIT if test -n "$NMEDIT"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5 -$as_echo "$NMEDIT" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $NMEDIT" >&5 +printf "%s\n" "$NMEDIT" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -7331,11 +8522,12 @@ if test -z "$ac_cv_prog_NMEDIT"; then ac_ct_NMEDIT=$NMEDIT # Extract the first word of "nmedit", so it can be a program name with args. set dummy nmedit; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_NMEDIT+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_NMEDIT+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_NMEDIT"; then ac_cv_prog_ac_ct_NMEDIT="$ac_ct_NMEDIT" # Let the user override the test. else @@ -7343,11 +8535,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_NMEDIT="nmedit" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7358,11 +8554,11 @@ fi fi ac_ct_NMEDIT=$ac_cv_prog_ac_ct_NMEDIT if test -n "$ac_ct_NMEDIT"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5 -$as_echo "$ac_ct_NMEDIT" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_NMEDIT" >&5 +printf "%s\n" "$ac_ct_NMEDIT" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_NMEDIT" = x; then @@ -7370,8 +8566,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac NMEDIT=$ac_ct_NMEDIT @@ -7383,11 +8579,12 @@ fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}lipo", so it can be a program name with args. set dummy ${ac_tool_prefix}lipo; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_LIPO+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_LIPO+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$LIPO"; then ac_cv_prog_LIPO="$LIPO" # Let the user override the test. else @@ -7395,11 +8592,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_LIPO="${ac_tool_prefix}lipo" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7410,11 +8611,11 @@ fi fi LIPO=$ac_cv_prog_LIPO if test -n "$LIPO"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5 -$as_echo "$LIPO" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5 +printf "%s\n" "$LIPO" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -7423,11 +8624,12 @@ if test -z "$ac_cv_prog_LIPO"; then ac_ct_LIPO=$LIPO # Extract the first word of "lipo", so it can be a program name with args. set dummy lipo; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_LIPO+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_LIPO+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_LIPO"; then ac_cv_prog_ac_ct_LIPO="$ac_ct_LIPO" # Let the user override the test. else @@ -7435,11 +8637,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_LIPO="lipo" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7450,11 +8656,11 @@ fi fi ac_ct_LIPO=$ac_cv_prog_ac_ct_LIPO if test -n "$ac_ct_LIPO"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5 -$as_echo "$ac_ct_LIPO" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_LIPO" >&5 +printf "%s\n" "$ac_ct_LIPO" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_LIPO" = x; then @@ -7462,8 +8668,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac LIPO=$ac_ct_LIPO @@ -7475,11 +8681,12 @@ fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}otool", so it can be a program name with args. set dummy ${ac_tool_prefix}otool; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_OTOOL+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_OTOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$OTOOL"; then ac_cv_prog_OTOOL="$OTOOL" # Let the user override the test. else @@ -7487,11 +8694,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_OTOOL="${ac_tool_prefix}otool" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7502,11 +8713,11 @@ fi fi OTOOL=$ac_cv_prog_OTOOL if test -n "$OTOOL"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5 -$as_echo "$OTOOL" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OTOOL" >&5 +printf "%s\n" "$OTOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -7515,11 +8726,12 @@ if test -z "$ac_cv_prog_OTOOL"; then ac_ct_OTOOL=$OTOOL # Extract the first word of "otool", so it can be a program name with args. set dummy otool; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_OTOOL+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_OTOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_OTOOL"; then ac_cv_prog_ac_ct_OTOOL="$ac_ct_OTOOL" # Let the user override the test. else @@ -7527,11 +8739,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OTOOL="otool" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7542,11 +8758,11 @@ fi fi ac_ct_OTOOL=$ac_cv_prog_ac_ct_OTOOL if test -n "$ac_ct_OTOOL"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5 -$as_echo "$ac_ct_OTOOL" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL" >&5 +printf "%s\n" "$ac_ct_OTOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_OTOOL" = x; then @@ -7554,8 +8770,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OTOOL=$ac_ct_OTOOL @@ -7567,11 +8783,12 @@ fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}otool64", so it can be a program name with args. set dummy ${ac_tool_prefix}otool64; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_OTOOL64+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_OTOOL64+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$OTOOL64"; then ac_cv_prog_OTOOL64="$OTOOL64" # Let the user override the test. else @@ -7579,11 +8796,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_OTOOL64="${ac_tool_prefix}otool64" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7594,11 +8815,11 @@ fi fi OTOOL64=$ac_cv_prog_OTOOL64 if test -n "$OTOOL64"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5 -$as_echo "$OTOOL64" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OTOOL64" >&5 +printf "%s\n" "$OTOOL64" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -7607,11 +8828,12 @@ if test -z "$ac_cv_prog_OTOOL64"; then ac_ct_OTOOL64=$OTOOL64 # Extract the first word of "otool64", so it can be a program name with args. set dummy otool64; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_OTOOL64+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_OTOOL64+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_OTOOL64"; then ac_cv_prog_ac_ct_OTOOL64="$ac_ct_OTOOL64" # Let the user override the test. else @@ -7619,11 +8841,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OTOOL64="otool64" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -7634,11 +8860,11 @@ fi fi ac_ct_OTOOL64=$ac_cv_prog_ac_ct_OTOOL64 if test -n "$ac_ct_OTOOL64"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5 -$as_echo "$ac_ct_OTOOL64" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OTOOL64" >&5 +printf "%s\n" "$ac_ct_OTOOL64" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_OTOOL64" = x; then @@ -7646,8 +8872,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OTOOL64=$ac_ct_OTOOL64 @@ -7682,11 +8908,12 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5 -$as_echo_n "checking for -single_module linker flag... " >&6; } -if ${lt_cv_apple_cc_single_mod+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -single_module linker flag" >&5 +printf %s "checking for -single_module linker flag... " >&6; } +if test ${lt_cv_apple_cc_single_mod+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_apple_cc_single_mod=no if test -z "$LT_MULTI_MODULE"; then # By default we will add the -single_module flag. You can override @@ -7715,14 +8942,52 @@ else rm -f conftest.* fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5 -$as_echo "$lt_cv_apple_cc_single_mod" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_apple_cc_single_mod" >&5 +printf "%s\n" "$lt_cv_apple_cc_single_mod" >&6; } + + # Feature test to disable chained fixups since it is not + # compatible with '-undefined dynamic_lookup' + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -no_fixup_chains linker flag" >&5 +printf %s "checking for -no_fixup_chains linker flag... " >&6; } +if test ${lt_cv_support_no_fixup_chains+y} +then : + printf %s "(cached) " >&6 +else $as_nop + save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS -Wl,-no_fixup_chains" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5 -$as_echo_n "checking for -exported_symbols_list linker flag... " >&6; } -if ${lt_cv_ld_exported_symbols_list+:} false; then : - $as_echo_n "(cached) " >&6 -else +int +main (void) +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + lt_cv_support_no_fixup_chains=yes +else $as_nop + lt_cv_support_no_fixup_chains=no + +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + LDFLAGS=$save_LDFLAGS + + +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_support_no_fixup_chains" >&5 +printf "%s\n" "$lt_cv_support_no_fixup_chains" >&6; } + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -exported_symbols_list linker flag" >&5 +printf %s "checking for -exported_symbols_list linker flag... " >&6; } +if test ${lt_cv_ld_exported_symbols_list+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_ld_exported_symbols_list=no save_LDFLAGS=$LDFLAGS echo "_main" > conftest.sym @@ -7731,43 +8996,45 @@ else /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : lt_cv_ld_exported_symbols_list=yes -else +else $as_nop lt_cv_ld_exported_symbols_list=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LDFLAGS=$save_LDFLAGS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5 -$as_echo "$lt_cv_ld_exported_symbols_list" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_exported_symbols_list" >&5 +printf "%s\n" "$lt_cv_ld_exported_symbols_list" >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -force_load linker flag" >&5 -$as_echo_n "checking for -force_load linker flag... " >&6; } -if ${lt_cv_ld_force_load+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for -force_load linker flag" >&5 +printf %s "checking for -force_load linker flag... " >&6; } +if test ${lt_cv_ld_force_load+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_ld_force_load=no cat > conftest.c << _LT_EOF int forced_loaded() { return 2;} _LT_EOF echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&5 $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&5 - echo "$AR cru libconftest.a conftest.o" >&5 - $AR cru libconftest.a conftest.o 2>&5 + echo "$AR $AR_FLAGS libconftest.a conftest.o" >&5 + $AR $AR_FLAGS libconftest.a conftest.o 2>&5 echo "$RANLIB libconftest.a" >&5 $RANLIB libconftest.a 2>&5 cat > conftest.c << _LT_EOF -int main() { return 0;} +int main(void) { return 0;} _LT_EOF echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&5 $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err @@ -7783,24 +9050,23 @@ _LT_EOF rm -rf conftest.dSYM fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5 -$as_echo "$lt_cv_ld_force_load" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_ld_force_load" >&5 +printf "%s\n" "$lt_cv_ld_force_load" >&6; } case $host_os in rhapsody* | darwin1.[012]) _lt_dar_allow_undefined='$wl-undefined ${wl}suppress' ;; darwin1.*) _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; - darwin*) # darwin 5.x on - # if running on 10.5 or later, the deployment target defaults - # to the OS version, if on x86, and 10.4, the deployment - # target defaults to 10.4. Don't you love it? - case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in - 10.0,*86*-darwin8*|10.0,*-darwin[91]*) - _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; - 10.[012][,.]*) - _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; - 10.*) - _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + darwin*) + case $MACOSX_DEPLOYMENT_TARGET,$host in + 10.[012],*|,*powerpc*-darwin[5-8]*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; + *) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' + if test yes = "$lt_cv_support_no_fixup_chains"; then + as_fn_append _lt_dar_allow_undefined ' $wl-no_fixup_chains' + fi + ;; esac ;; esac @@ -7855,286 +9121,43 @@ func_munge_path_list () esac } -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5 -$as_echo_n "checking how to run the C preprocessor... " >&6; } -# On Suns, sometimes $CPP names a directory. -if test -n "$CPP" && test -d "$CPP"; then - CPP= -fi -if test -z "$CPP"; then - if ${ac_cv_prog_CPP+:} false; then : - $as_echo_n "(cached) " >&6 -else - # Double quotes because CPP needs to be expanded - for CPP in "$CC -E" "$CC -E -traditional-cpp" "/lib/cpp" - do - ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes -do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since - # <limits.h> exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#ifdef __STDC__ -# include <limits.h> -#else -# include <assert.h> -#endif - Syntax error -_ACEOF -if ac_fn_c_try_cpp "$LINENO"; then : - -else - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.i conftest.$ac_ext - - # OK, works on sane cases. Now check whether nonexistent headers - # can be detected and how. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include <ac_nonexistent.h> -_ACEOF -if ac_fn_c_try_cpp "$LINENO"; then : - # Broken: success on invalid input. -continue -else - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.i conftest.$ac_ext - -done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.i conftest.err conftest.$ac_ext -if $ac_preproc_ok; then : - break -fi - - done - ac_cv_prog_CPP=$CPP - -fi - CPP=$ac_cv_prog_CPP -else - ac_cv_prog_CPP=$CPP -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CPP" >&5 -$as_echo "$CPP" >&6; } -ac_preproc_ok=false -for ac_c_preproc_warn_flag in '' yes +ac_header= ac_cache= +for ac_item in $ac_header_c_list do - # Use a header file that comes with gcc, so configuring glibc - # with a fresh cross-compiler works. - # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since - # <limits.h> exists even on freestanding compilers. - # On the NeXT, cc -E runs the code through the compiler's parser, - # not just through cpp. "Syntax error" is here to catch this case. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#ifdef __STDC__ -# include <limits.h> -#else -# include <assert.h> -#endif - Syntax error -_ACEOF -if ac_fn_c_try_cpp "$LINENO"; then : - -else - # Broken: fails on valid input. -continue -fi -rm -f conftest.err conftest.i conftest.$ac_ext - - # OK, works on sane cases. Now check whether nonexistent headers - # can be detected and how. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include <ac_nonexistent.h> -_ACEOF -if ac_fn_c_try_cpp "$LINENO"; then : - # Broken: success on invalid input. -continue -else - # Passes both tests. -ac_preproc_ok=: -break -fi -rm -f conftest.err conftest.i conftest.$ac_ext - + if test $ac_cache; then + ac_fn_c_check_header_compile "$LINENO" $ac_header ac_cv_header_$ac_cache "$ac_includes_default" + if eval test \"x\$ac_cv_header_$ac_cache\" = xyes; then + printf "%s\n" "#define $ac_item 1" >> confdefs.h + fi + ac_header= ac_cache= + elif test $ac_header; then + ac_cache=$ac_item + else + ac_header=$ac_item + fi done -# Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. -rm -f conftest.i conftest.err conftest.$ac_ext -if $ac_preproc_ok; then : -else - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error $? "C preprocessor \"$CPP\" fails sanity check -See \`config.log' for more details" "$LINENO" 5; } -fi -ac_ext=c -ac_cpp='$CPP $CPPFLAGS' -ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' -ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' -ac_compiler_gnu=$ac_cv_c_compiler_gnu -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 -$as_echo_n "checking for ANSI C header files... " >&6; } -if ${ac_cv_header_stdc+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include <stdlib.h> -#include <stdarg.h> -#include <string.h> -#include <float.h> -int -main () -{ - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_header_stdc=yes -else - ac_cv_header_stdc=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -if test $ac_cv_header_stdc = yes; then - # SunOS 4.x string.h does not declare mem*, contrary to ANSI. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include <string.h> -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "memchr" >/dev/null 2>&1; then : +if test $ac_cv_header_stdlib_h = yes && test $ac_cv_header_string_h = yes +then : -else - ac_cv_header_stdc=no -fi -rm -f conftest* +printf "%s\n" "#define STDC_HEADERS 1" >>confdefs.h fi - -if test $ac_cv_header_stdc = yes; then - # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include <stdlib.h> - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "free" >/dev/null 2>&1; then : - -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. - if test "$cross_compiling" = yes; then : - : -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include <ctype.h> -#include <stdlib.h> -#if ((' ' & 0x0FF) == 0x020) -# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') -# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) -#else -# define ISLOWER(c) \ - (('a' <= (c) && (c) <= 'i') \ - || ('j' <= (c) && (c) <= 'r') \ - || ('s' <= (c) && (c) <= 'z')) -# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) -#endif - -#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) -int -main () -{ - int i; - for (i = 0; i < 256; i++) - if (XOR (islower (i), ISLOWER (i)) - || toupper (i) != TOUPPER (i)) - return 2; - return 0; -} -_ACEOF -if ac_fn_c_try_run "$LINENO"; then : - -else - ac_cv_header_stdc=no -fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ - conftest.$ac_objext conftest.beam conftest.$ac_ext -fi - -fi -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 -$as_echo "$ac_cv_header_stdc" >&6; } -if test $ac_cv_header_stdc = yes; then - -$as_echo "#define STDC_HEADERS 1" >>confdefs.h - -fi - -# On IRIX 5.3, sys/types and inttypes.h are conflicting. -for ac_header in sys/types.h sys/stat.h stdlib.h string.h memory.h strings.h \ - inttypes.h stdint.h unistd.h -do : - as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default +ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default " -if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF +if test "x$ac_cv_header_dlfcn_h" = xyes +then : + printf "%s\n" "#define HAVE_DLFCN_H 1" >>confdefs.h fi -done - - -for ac_header in dlfcn.h -do : - ac_fn_c_check_header_compile "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default -" -if test "x$ac_cv_header_dlfcn_h" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_DLFCN_H 1 -_ACEOF - -fi - -done - @@ -8143,15 +9166,16 @@ done enable_win32_dll=yes case $host in -*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-cegcc*) +*-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-cegcc*) if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}as", so it can be a program name with args. set dummy ${ac_tool_prefix}as; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_AS+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_AS+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$AS"; then ac_cv_prog_AS="$AS" # Let the user override the test. else @@ -8159,11 +9183,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_AS="${ac_tool_prefix}as" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8174,11 +9202,11 @@ fi fi AS=$ac_cv_prog_AS if test -n "$AS"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AS" >&5 -$as_echo "$AS" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $AS" >&5 +printf "%s\n" "$AS" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -8187,11 +9215,12 @@ if test -z "$ac_cv_prog_AS"; then ac_ct_AS=$AS # Extract the first word of "as", so it can be a program name with args. set dummy as; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_AS+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_AS+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_AS"; then ac_cv_prog_ac_ct_AS="$ac_ct_AS" # Let the user override the test. else @@ -8199,11 +9228,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_AS="as" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8214,11 +9247,11 @@ fi fi ac_ct_AS=$ac_cv_prog_ac_ct_AS if test -n "$ac_ct_AS"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AS" >&5 -$as_echo "$ac_ct_AS" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_AS" >&5 +printf "%s\n" "$ac_ct_AS" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_AS" = x; then @@ -8226,8 +9259,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac AS=$ac_ct_AS @@ -8239,11 +9272,12 @@ fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}dlltool", so it can be a program name with args. set dummy ${ac_tool_prefix}dlltool; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_DLLTOOL+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_DLLTOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$DLLTOOL"; then ac_cv_prog_DLLTOOL="$DLLTOOL" # Let the user override the test. else @@ -8251,11 +9285,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_DLLTOOL="${ac_tool_prefix}dlltool" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8266,11 +9304,11 @@ fi fi DLLTOOL=$ac_cv_prog_DLLTOOL if test -n "$DLLTOOL"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5 -$as_echo "$DLLTOOL" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DLLTOOL" >&5 +printf "%s\n" "$DLLTOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -8279,11 +9317,12 @@ if test -z "$ac_cv_prog_DLLTOOL"; then ac_ct_DLLTOOL=$DLLTOOL # Extract the first word of "dlltool", so it can be a program name with args. set dummy dlltool; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_DLLTOOL+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_DLLTOOL+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_DLLTOOL"; then ac_cv_prog_ac_ct_DLLTOOL="$ac_ct_DLLTOOL" # Let the user override the test. else @@ -8291,11 +9330,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_DLLTOOL="dlltool" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8306,11 +9349,11 @@ fi fi ac_ct_DLLTOOL=$ac_cv_prog_ac_ct_DLLTOOL if test -n "$ac_ct_DLLTOOL"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5 -$as_echo "$ac_ct_DLLTOOL" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_DLLTOOL" >&5 +printf "%s\n" "$ac_ct_DLLTOOL" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_DLLTOOL" = x; then @@ -8318,8 +9361,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac DLLTOOL=$ac_ct_DLLTOOL @@ -8331,11 +9374,12 @@ fi if test -n "$ac_tool_prefix"; then # Extract the first word of "${ac_tool_prefix}objdump", so it can be a program name with args. set dummy ${ac_tool_prefix}objdump; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_OBJDUMP+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_OBJDUMP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$OBJDUMP"; then ac_cv_prog_OBJDUMP="$OBJDUMP" # Let the user override the test. else @@ -8343,11 +9387,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_OBJDUMP="${ac_tool_prefix}objdump" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8358,11 +9406,11 @@ fi fi OBJDUMP=$ac_cv_prog_OBJDUMP if test -n "$OBJDUMP"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 -$as_echo "$OBJDUMP" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $OBJDUMP" >&5 +printf "%s\n" "$OBJDUMP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -8371,11 +9419,12 @@ if test -z "$ac_cv_prog_OBJDUMP"; then ac_ct_OBJDUMP=$OBJDUMP # Extract the first word of "objdump", so it can be a program name with args. set dummy objdump; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_OBJDUMP+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_OBJDUMP+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_OBJDUMP"; then ac_cv_prog_ac_ct_OBJDUMP="$ac_ct_OBJDUMP" # Let the user override the test. else @@ -8383,11 +9432,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_OBJDUMP="objdump" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -8398,11 +9451,11 @@ fi fi ac_ct_OBJDUMP=$ac_cv_prog_ac_ct_OBJDUMP if test -n "$ac_ct_OBJDUMP"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 -$as_echo "$ac_ct_OBJDUMP" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_OBJDUMP" >&5 +printf "%s\n" "$ac_ct_OBJDUMP" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi if test "x$ac_ct_OBJDUMP" = x; then @@ -8410,8 +9463,8 @@ fi else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac OBJDUMP=$ac_ct_OBJDUMP @@ -8448,7 +9501,8 @@ test -z "$OBJDUMP" && OBJDUMP=objdump # Check whether --enable-shared was given. -if test "${enable_shared+set}" = set; then : +if test ${enable_shared+y} +then : enableval=$enable_shared; p=${PACKAGE-default} case $enableval in yes) enable_shared=yes ;; @@ -8466,7 +9520,7 @@ if test "${enable_shared+set}" = set; then : IFS=$lt_save_ifs ;; esac -else +else $as_nop enable_shared=yes fi @@ -8479,7 +9533,8 @@ fi # Check whether --enable-static was given. -if test "${enable_static+set}" = set; then : +if test ${enable_static+y} +then : enableval=$enable_static; p=${PACKAGE-default} case $enableval in yes) enable_static=yes ;; @@ -8497,7 +9552,7 @@ if test "${enable_static+set}" = set; then : IFS=$lt_save_ifs ;; esac -else +else $as_nop enable_static=yes fi @@ -8509,30 +9564,53 @@ fi - -# Check whether --with-pic was given. -if test "${with_pic+set}" = set; then : + # Check whether --enable-pic was given. +if test ${enable_pic+y} +then : + enableval=$enable_pic; lt_p=${PACKAGE-default} + case $enableval in + yes|no) pic_mode=$enableval ;; + *) + pic_mode=default + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for lt_pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$lt_pkg" = "X$lt_p"; then + pic_mode=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else $as_nop + # Check whether --with-pic was given. +if test ${with_pic+y} +then : withval=$with_pic; lt_p=${PACKAGE-default} - case $withval in - yes|no) pic_mode=$withval ;; - *) - pic_mode=default - # Look at the argument we got. We use all the common list separators. - lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, - for lt_pkg in $withval; do - IFS=$lt_save_ifs - if test "X$lt_pkg" = "X$lt_p"; then - pic_mode=yes - fi - done - IFS=$lt_save_ifs - ;; - esac -else + case $withval in + yes|no) pic_mode=$withval ;; + *) + pic_mode=default + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for lt_pkg in $withval; do + IFS=$lt_save_ifs + if test "X$lt_pkg" = "X$lt_p"; then + pic_mode=yes + fi + done + IFS=$lt_save_ifs + ;; + esac +else $as_nop pic_mode=default fi +fi + + @@ -8540,7 +9618,8 @@ fi # Check whether --enable-fast-install was given. -if test "${enable_fast_install+set}" = set; then : +if test ${enable_fast_install+y} +then : enableval=$enable_fast_install; p=${PACKAGE-default} case $enableval in yes) enable_fast_install=yes ;; @@ -8558,7 +9637,7 @@ if test "${enable_fast_install+set}" = set; then : IFS=$lt_save_ifs ;; esac -else +else $as_nop enable_fast_install=yes fi @@ -8572,31 +9651,47 @@ fi shared_archive_member_spec= case $host,$enable_shared in power*-*-aix[5-9]*,yes) - { $as_echo "$as_me:${as_lineno-$LINENO}: checking which variant of shared library versioning to provide" >&5 -$as_echo_n "checking which variant of shared library versioning to provide... " >&6; } - -# Check whether --with-aix-soname was given. -if test "${with_aix_soname+set}" = set; then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking which variant of shared library versioning to provide" >&5 +printf %s "checking which variant of shared library versioning to provide... " >&6; } + # Check whether --enable-aix-soname was given. +if test ${enable_aix_soname+y} +then : + enableval=$enable_aix_soname; case $enableval in + aix|svr4|both) + ;; + *) + as_fn_error $? "Unknown argument to --enable-aix-soname" "$LINENO" 5 + ;; + esac + lt_cv_with_aix_soname=$enable_aix_soname +else $as_nop + # Check whether --with-aix-soname was given. +if test ${with_aix_soname+y} +then : withval=$with_aix_soname; case $withval in - aix|svr4|both) - ;; - *) - as_fn_error $? "Unknown argument to --with-aix-soname" "$LINENO" 5 - ;; - esac - lt_cv_with_aix_soname=$with_aix_soname -else - if ${lt_cv_with_aix_soname+:} false; then : - $as_echo_n "(cached) " >&6 -else + aix|svr4|both) + ;; + *) + as_fn_error $? "Unknown argument to --with-aix-soname" "$LINENO" 5 + ;; + esac + lt_cv_with_aix_soname=$with_aix_soname +else $as_nop + if test ${lt_cv_with_aix_soname+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_with_aix_soname=aix fi - with_aix_soname=$lt_cv_with_aix_soname fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_aix_soname" >&5 -$as_echo "$with_aix_soname" >&6; } + enable_aix_soname=$lt_cv_with_aix_soname +fi + + with_aix_soname=$enable_aix_soname + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $with_aix_soname" >&5 +printf "%s\n" "$with_aix_soname" >&6; } if test aix != "$with_aix_soname"; then # For the AIX way of multilib, we name the shared archive member # based on the bitwidth used, traditionally 'shr.o' or 'shr_64.o', @@ -8678,11 +9773,12 @@ if test -n "${ZSH_VERSION+set}"; then setopt NO_GLOB_SUBST fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5 -$as_echo_n "checking for objdir... " >&6; } -if ${lt_cv_objdir+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for objdir" >&5 +printf %s "checking for objdir... " >&6; } +if test ${lt_cv_objdir+y} +then : + printf %s "(cached) " >&6 +else $as_nop rm -f .libs 2>/dev/null mkdir .libs 2>/dev/null if test -d .libs; then @@ -8693,17 +9789,15 @@ else fi rmdir .libs 2>/dev/null fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5 -$as_echo "$lt_cv_objdir" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_objdir" >&5 +printf "%s\n" "$lt_cv_objdir" >&6; } objdir=$lt_cv_objdir -cat >>confdefs.h <<_ACEOF -#define LT_OBJDIR "$lt_cv_objdir/" -_ACEOF +printf "%s\n" "#define LT_OBJDIR \"$lt_cv_objdir/\"" >>confdefs.h @@ -8724,8 +9818,8 @@ esac ofile=libtool can_build_shared=yes -# All known linkers require a '.a' archive for static linking (except MSVC, -# which needs '.lib'). +# All known linkers require a '.a' archive for static linking (except MSVC and +# ICC, which need '.lib'). libext=a with_gnu_ld=$lt_cv_prog_gnu_ld @@ -8749,11 +9843,12 @@ test -z "$MAGIC_CMD" && MAGIC_CMD=file case $deplibs_check_method in file_magic*) if test "$file_magic_cmd" = '$MAGIC_CMD'; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5 -$as_echo_n "checking for ${ac_tool_prefix}file... " >&6; } -if ${lt_cv_path_MAGIC_CMD+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ${ac_tool_prefix}file" >&5 +printf %s "checking for ${ac_tool_prefix}file... " >&6; } +if test ${lt_cv_path_MAGIC_CMD+y} +then : + printf %s "(cached) " >&6 +else $as_nop case $MAGIC_CMD in [\\/*] | ?:[\\/]*) lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. @@ -8802,11 +9897,11 @@ fi MAGIC_CMD=$lt_cv_path_MAGIC_CMD if test -n "$MAGIC_CMD"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 -$as_echo "$MAGIC_CMD" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +printf "%s\n" "$MAGIC_CMD" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -8815,11 +9910,12 @@ fi if test -z "$lt_cv_path_MAGIC_CMD"; then if test -n "$ac_tool_prefix"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for file" >&5 -$as_echo_n "checking for file... " >&6; } -if ${lt_cv_path_MAGIC_CMD+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for file" >&5 +printf %s "checking for file... " >&6; } +if test ${lt_cv_path_MAGIC_CMD+y} +then : + printf %s "(cached) " >&6 +else $as_nop case $MAGIC_CMD in [\\/*] | ?:[\\/]*) lt_cv_path_MAGIC_CMD=$MAGIC_CMD # Let the user override the test with a path. @@ -8868,11 +9964,11 @@ fi MAGIC_CMD=$lt_cv_path_MAGIC_CMD if test -n "$MAGIC_CMD"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 -$as_echo "$MAGIC_CMD" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $MAGIC_CMD" >&5 +printf "%s\n" "$MAGIC_CMD" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -8906,7 +10002,7 @@ objext=$objext lt_simple_compile_test_code="int some_variable = 0;" # Code to be used in simple link tests -lt_simple_link_test_code='int main(){return(0);}' +lt_simple_link_test_code='int main(void){return(0);}' @@ -8957,11 +10053,12 @@ if test yes = "$GCC"; then lt_prog_compiler_no_builtin_flag=' -fno-builtin' ;; esac - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5 -$as_echo_n "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; } -if ${lt_cv_prog_compiler_rtti_exceptions+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -fno-rtti -fno-exceptions" >&5 +printf %s "checking if $compiler supports -fno-rtti -fno-exceptions... " >&6; } +if test ${lt_cv_prog_compiler_rtti_exceptions+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_rtti_exceptions=no ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" > conftest.$ac_ext @@ -8992,8 +10089,8 @@ else $RM conftest* fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5 -$as_echo "$lt_cv_prog_compiler_rtti_exceptions" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_rtti_exceptions" >&5 +printf "%s\n" "$lt_cv_prog_compiler_rtti_exceptions" >&6; } if test yes = "$lt_cv_prog_compiler_rtti_exceptions"; then lt_prog_compiler_no_builtin_flag="$lt_prog_compiler_no_builtin_flag -fno-rtti -fno-exceptions" @@ -9046,7 +10143,7 @@ lt_prog_compiler_static= # PIC is the default for these OSes. ;; - mingw* | cygwin* | pw32* | os2* | cegcc*) + mingw* | windows* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). # Although the cygwin gcc ignores -fPIC, still need this for old-style @@ -9149,7 +10246,7 @@ lt_prog_compiler_static= esac ;; - mingw* | cygwin* | pw32* | os2* | cegcc*) + mingw* | windows* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). lt_prog_compiler_pic='-DDLL_EXPORT' @@ -9190,6 +10287,12 @@ lt_prog_compiler_static= lt_prog_compiler_pic='-KPIC' lt_prog_compiler_static='-static' ;; + *flang* | ftn) + # Flang compiler. + lt_prog_compiler_wl='-Wl,' + lt_prog_compiler_pic='-fPIC' + lt_prog_compiler_static='-static' + ;; # icc used to be incompatible with GCC. # ICC 10 doesn't accept -KPIC any more. icc* | ifort*) @@ -9234,7 +10337,7 @@ lt_prog_compiler_static= lt_prog_compiler_static='-qstaticlink' ;; *) - case `$CC -V 2>&1 | sed 5q` in + case `$CC -V 2>&1 | $SED 5q` in *Sun\ Ceres\ Fortran* | *Sun*Fortran*\ [1-7].* | *Sun*Fortran*\ 8.[0-3]*) # Sun Fortran 8.3 passes all unrecognized flags to the linker lt_prog_compiler_pic='-KPIC' @@ -9350,26 +10453,28 @@ case $host_os in ;; esac -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 -$as_echo_n "checking for $compiler option to produce PIC... " >&6; } -if ${lt_cv_prog_compiler_pic+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 +printf %s "checking for $compiler option to produce PIC... " >&6; } +if test ${lt_cv_prog_compiler_pic+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_pic=$lt_prog_compiler_pic fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic" >&5 -$as_echo "$lt_cv_prog_compiler_pic" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic" >&5 +printf "%s\n" "$lt_cv_prog_compiler_pic" >&6; } lt_prog_compiler_pic=$lt_cv_prog_compiler_pic # # Check to make sure the PIC flag actually works. # if test -n "$lt_prog_compiler_pic"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5 -$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; } -if ${lt_cv_prog_compiler_pic_works+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic works" >&5 +printf %s "checking if $compiler PIC flag $lt_prog_compiler_pic works... " >&6; } +if test ${lt_cv_prog_compiler_pic_works+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_pic_works=no ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" > conftest.$ac_ext @@ -9400,8 +10505,8 @@ else $RM conftest* fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5 -$as_echo "$lt_cv_prog_compiler_pic_works" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works" >&5 +printf "%s\n" "$lt_cv_prog_compiler_pic_works" >&6; } if test yes = "$lt_cv_prog_compiler_pic_works"; then case $lt_prog_compiler_pic in @@ -9429,11 +10534,12 @@ fi # Check to make sure the static flag actually works. # wl=$lt_prog_compiler_wl eval lt_tmp_static_flag=\"$lt_prog_compiler_static\" -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 -$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } -if ${lt_cv_prog_compiler_static_works+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +printf %s "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } +if test ${lt_cv_prog_compiler_static_works+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_static_works=no save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS $lt_tmp_static_flag" @@ -9457,8 +10563,8 @@ else LDFLAGS=$save_LDFLAGS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5 -$as_echo "$lt_cv_prog_compiler_static_works" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works" >&5 +printf "%s\n" "$lt_cv_prog_compiler_static_works" >&6; } if test yes = "$lt_cv_prog_compiler_static_works"; then : @@ -9472,11 +10578,12 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 -$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } -if ${lt_cv_prog_compiler_c_o+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +printf %s "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if test ${lt_cv_prog_compiler_c_o+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_c_o=no $RM -r conftest 2>/dev/null mkdir conftest @@ -9519,19 +10626,20 @@ else $RM conftest* fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 -$as_echo "$lt_cv_prog_compiler_c_o" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +printf "%s\n" "$lt_cv_prog_compiler_c_o" >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 -$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } -if ${lt_cv_prog_compiler_c_o+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +printf %s "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if test ${lt_cv_prog_compiler_c_o+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_c_o=no $RM -r conftest 2>/dev/null mkdir conftest @@ -9574,8 +10682,8 @@ else $RM conftest* fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 -$as_echo "$lt_cv_prog_compiler_c_o" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o" >&5 +printf "%s\n" "$lt_cv_prog_compiler_c_o" >&6; } @@ -9583,19 +10691,19 @@ $as_echo "$lt_cv_prog_compiler_c_o" >&6; } hard_links=nottested if test no = "$lt_cv_prog_compiler_c_o" && test no != "$need_locks"; then # do not overwrite the value of need_locks provided by the user - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 -$as_echo_n "checking if we can lock with hard links... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 +printf %s "checking if we can lock with hard links... " >&6; } hard_links=yes $RM conftest* ln conftest.a conftest.b 2>/dev/null && hard_links=no touch conftest.a ln conftest.a conftest.b 2>&5 || hard_links=no ln conftest.a conftest.b 2>/dev/null && hard_links=no - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 -$as_echo "$hard_links" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 +printf "%s\n" "$hard_links" >&6; } if test no = "$hard_links"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 -$as_echo "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 +printf "%s\n" "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} need_locks=warn fi else @@ -9607,8 +10715,8 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 -$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +printf %s "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } runpath_var= allow_undefined_flag= @@ -9651,19 +10759,19 @@ $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie extract_expsyms_cmds= case $host_os in - cygwin* | mingw* | pw32* | cegcc*) - # FIXME: the MSVC++ port hasn't been tested in a loooong time + cygwin* | mingw* | windows* | pw32* | cegcc*) + # FIXME: the MSVC++ and ICC port hasn't been tested in a loooong time # When not using gcc, we currently assume that we are using - # Microsoft Visual C++. + # Microsoft Visual C++ or Intel C++ Compiler. if test yes != "$GCC"; then with_gnu_ld=no fi ;; interix*) - # we just hope/assume this is gcc and not c89 (= MSVC++) + # we just hope/assume this is gcc and not c89 (= MSVC++ or ICC) with_gnu_ld=yes ;; - openbsd* | bitrig*) + openbsd*) with_gnu_ld=no ;; esac @@ -9712,7 +10820,7 @@ $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie whole_archive_flag_spec= fi supports_anon_versioning=no - case `$LD -v | $SED -e 's/(^)\+)\s\+//' 2>&1` in + case `$LD -v | $SED -e 's/([^)]\+)\s\+//' 2>&1` in *GNU\ gold*) supports_anon_versioning=yes ;; *\ [01].* | *\ 2.[0-9].* | *\ 2.10.*) ;; # catch versions < 2.11 *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... @@ -9766,7 +10874,7 @@ _LT_EOF fi ;; - cygwin* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | windows* | pw32* | cegcc*) # _LT_TAGVAR(hardcode_libdir_flag_spec, ) is actually meaningless, # as there is no search path for DLLs. hardcode_libdir_flag_spec='-L$libdir' @@ -9822,8 +10930,9 @@ _LT_EOF cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ emximp -o $lib $output_objdir/$libname.def' - old_archive_From_new_cmds='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + old_archive_from_new_cmds='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' enable_shared_with_static_runtimes=yes + file_list_spec='@' ;; interix[3-9]*) @@ -9838,7 +10947,7 @@ _LT_EOF # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link # time. Moving up from 0x10000000 also allows more sbrk(2) space. archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' - archive_expsym_cmds='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + archive_expsym_cmds='$SED "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' ;; gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) @@ -9881,7 +10990,7 @@ _LT_EOF compiler_needs_object=yes ;; esac - case `$CC -V 2>&1 | sed 5q` in + case `$CC -V 2>&1 | $SED 5q` in *Sun\ C*) # Sun C 5.9 whole_archive_flag_spec='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' compiler_needs_object=yes @@ -9893,7 +11002,7 @@ _LT_EOF if test yes = "$supports_anon_versioning"; then archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~ - cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' fi @@ -9909,7 +11018,7 @@ _LT_EOF archive_cmds='$LD -shared $libobjs $deplibs $linker_flags -soname $soname -o $lib' if test yes = "$supports_anon_versioning"; then archive_expsym_cmds='echo "{ global:" > $output_objdir/$libname.ver~ - cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $LD -shared $libobjs $deplibs $linker_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' fi @@ -10041,7 +11150,7 @@ _LT_EOF if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then export_symbols_cmds='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && (substr(\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' else - export_symbols_cmds='`func_echo_all $NM | $SED -e '\''s/B\([^B]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && (substr(\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + export_symbols_cmds='`func_echo_all $NM | $SED -e '\''s/B\([^B]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "L") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && (substr(\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' fi aix_use_runtimelinking=no @@ -10163,21 +11272,23 @@ _LT_EOF if test set = "${lt_cv_aix_libpath+set}"; then aix_libpath=$lt_cv_aix_libpath else - if ${lt_cv_aix_libpath_+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${lt_cv_aix_libpath_+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { @@ -10192,7 +11303,7 @@ if ac_fn_c_try_link "$LINENO"; then : lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext if test -z "$lt_cv_aix_libpath_"; then lt_cv_aix_libpath_=/usr/lib:/lib @@ -10216,21 +11327,23 @@ fi if test set = "${lt_cv_aix_libpath+set}"; then aix_libpath=$lt_cv_aix_libpath else - if ${lt_cv_aix_libpath_+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${lt_cv_aix_libpath_+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { @@ -10245,7 +11358,7 @@ if ac_fn_c_try_link "$LINENO"; then : lt_cv_aix_libpath_=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext if test -z "$lt_cv_aix_libpath_"; then lt_cv_aix_libpath_=/usr/lib:/lib @@ -10306,14 +11419,14 @@ fi export_dynamic_flag_spec=-rdynamic ;; - cygwin* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | windows* | pw32* | cegcc*) # When not using gcc, we currently assume that we are using - # Microsoft Visual C++. + # Microsoft Visual C++ or Intel C++ Compiler. # hardcode_libdir_flag_spec is actually meaningless, as there is # no search path for DLLs. case $cc_basename in - cl*) - # Native MSVC + cl* | icl*) + # Native MSVC or ICC hardcode_libdir_flag_spec=' ' allow_undefined_flag=unsupported always_export_symbols=yes @@ -10323,14 +11436,14 @@ fi # Tell ltmain to make .dll files, not .so files. shrext_cmds=.dll # FIXME: Setting linknames here is a bad hack. - archive_cmds='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' + archive_cmds='$CC -Fe $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' archive_expsym_cmds='if test DEF = "`$SED -n -e '\''s/^[ ]*//'\'' -e '\''/^\(;.*\)*$/d'\'' -e '\''s/^\(EXPORTS\|LIBRARY\)\([ ].*\)*$/DEF/p'\'' -e q $export_symbols`" ; then cp "$export_symbols" "$output_objdir/$soname.def"; echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; else $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; fi~ - $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ + $CC -Fe $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ linknames=' # The linker will not automatically build a static lib if we build a DLL. # _LT_TAGVAR(old_archive_from_new_cmds, )='true' @@ -10354,7 +11467,7 @@ fi fi' ;; *) - # Assume MSVC wrapper + # Assume MSVC and ICC wrapper hardcode_libdir_flag_spec=' ' allow_undefined_flag=unsupported # Tell ltmain to make .lib files, not .a files. @@ -10395,8 +11508,8 @@ fi output_verbose_link_cmd=func_echo_all archive_cmds="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dsymutil" module_cmds="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dsymutil" - archive_expsym_cmds="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" - module_expsym_cmds="sed -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" + archive_expsym_cmds="$SED 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" + module_expsym_cmds="$SED -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" else ld_shlibs=no @@ -10430,7 +11543,7 @@ fi ;; # FreeBSD 3 and greater uses gcc -shared to do shared libraries. - freebsd* | dragonfly*) + freebsd* | dragonfly* | midnightbsd*) archive_cmds='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' hardcode_libdir_flag_spec='-R$libdir' hardcode_direct=yes @@ -10496,11 +11609,12 @@ fi # Older versions of the 11.00 compiler do not understand -b yet # (HP92453-01 A.11.01.20 doesn't, HP92453-01 B.11.X.35175-35176.GP does) - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $CC understands -b" >&5 -$as_echo_n "checking if $CC understands -b... " >&6; } -if ${lt_cv_prog_compiler__b+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $CC understands -b" >&5 +printf %s "checking if $CC understands -b... " >&6; } +if test ${lt_cv_prog_compiler__b+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler__b=no save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS -b" @@ -10524,8 +11638,8 @@ else LDFLAGS=$save_LDFLAGS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler__b" >&5 -$as_echo "$lt_cv_prog_compiler__b" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler__b" >&5 +printf "%s\n" "$lt_cv_prog_compiler__b" >&6; } if test yes = "$lt_cv_prog_compiler__b"; then archive_cmds='$CC -b $wl+h $wl$soname $wl+b $wl$install_libdir -o $lib $libobjs $deplibs $compiler_flags' @@ -10565,28 +11679,30 @@ fi # work, assume that -exports_file does not work either and # implicitly export all symbols. # This should be the same for all languages, so no per-tag cache variable. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $host_os linker accepts -exported_symbol" >&5 -$as_echo_n "checking whether the $host_os linker accepts -exported_symbol... " >&6; } -if ${lt_cv_irix_exported_symbol+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $host_os linker accepts -exported_symbol" >&5 +printf %s "checking whether the $host_os linker accepts -exported_symbol... " >&6; } +if test ${lt_cv_irix_exported_symbol+y} +then : + printf %s "(cached) " >&6 +else $as_nop save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS -shared $wl-exported_symbol ${wl}foo $wl-update_registry $wl/dev/null" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int foo (void) { return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : lt_cv_irix_exported_symbol=yes -else +else $as_nop lt_cv_irix_exported_symbol=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LDFLAGS=$save_LDFLAGS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_irix_exported_symbol" >&5 -$as_echo "$lt_cv_irix_exported_symbol" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_irix_exported_symbol" >&5 +printf "%s\n" "$lt_cv_irix_exported_symbol" >&6; } if test yes = "$lt_cv_irix_exported_symbol"; then archive_expsym_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname `test -n "$verstring" && func_echo_all "$wl-set_version $wl$verstring"` $wl-update_registry $wl$output_objdir/so_locations $wl-exports_file $wl$export_symbols -o $lib' fi @@ -10633,7 +11749,7 @@ $as_echo "$lt_cv_irix_exported_symbol" >&6; } *nto* | *qnx*) ;; - openbsd* | bitrig*) + openbsd*) if test -f /usr/libexec/ld.so; then hardcode_direct=yes hardcode_shlibpath_var=no @@ -10676,8 +11792,9 @@ $as_echo "$lt_cv_irix_exported_symbol" >&6; } cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ emximp -o $lib $output_objdir/$libname.def' - old_archive_From_new_cmds='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + old_archive_from_new_cmds='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' enable_shared_with_static_runtimes=yes + file_list_spec='@' ;; osf3*) @@ -10866,8 +11983,8 @@ $as_echo "$lt_cv_irix_exported_symbol" >&6; } fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5 -$as_echo "$ld_shlibs" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs" >&5 +printf "%s\n" "$ld_shlibs" >&6; } test no = "$ld_shlibs" && can_build_shared=no with_gnu_ld=$with_gnu_ld @@ -10903,18 +12020,19 @@ x|xyes) # Test whether the compiler implicitly links with -lc since on some # systems, -lgcc has to come before -lc. If gcc already passes -lc # to ld, don't add -lc before -lgcc. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 -$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; } -if ${lt_cv_archive_cmds_need_lc+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 +printf %s "checking whether -lc should be explicitly linked in... " >&6; } +if test ${lt_cv_archive_cmds_need_lc+y} +then : + printf %s "(cached) " >&6 +else $as_nop $RM conftest* echo "$lt_simple_compile_test_code" > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } 2>conftest.err; then soname=conftest lib=conftest @@ -10932,7 +12050,7 @@ else if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5 (eval $archive_cmds 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then lt_cv_archive_cmds_need_lc=no @@ -10946,8 +12064,8 @@ else $RM conftest* fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc" >&5 -$as_echo "$lt_cv_archive_cmds_need_lc" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc" >&5 +printf "%s\n" "$lt_cv_archive_cmds_need_lc" >&6; } archive_cmds_need_lc=$lt_cv_archive_cmds_need_lc ;; esac @@ -11106,8 +12224,8 @@ esac - { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 -$as_echo_n "checking dynamic linker characteristics... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 +printf %s "checking dynamic linker characteristics... " >&6; } if test yes = "$GCC"; then case $host_os in @@ -11115,7 +12233,7 @@ if test yes = "$GCC"; then *) lt_awk_arg='/^libraries:/' ;; esac case $host_os in - mingw* | cegcc*) lt_sed_strip_eq='s|=\([A-Za-z]:\)|\1|g' ;; + mingw* | windows* | cegcc*) lt_sed_strip_eq='s|=\([A-Za-z]:\)|\1|g' ;; *) lt_sed_strip_eq='s|=/|/|g' ;; esac lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e $lt_sed_strip_eq` @@ -11173,7 +12291,7 @@ BEGIN {RS = " "; FS = "/|\n";} { # AWK program above erroneously prepends '/' to C:/dos/paths # for these hosts. case $host_os in - mingw* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\ + mingw* | windows* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\ $SED 's|/\([A-Za-z]:\)|\1|g'` ;; esac sys_lib_search_path_spec=`$ECHO "$lt_search_path_spec" | $lt_NL2SP` @@ -11247,7 +12365,7 @@ aix[4-9]*) # Unfortunately, runtime linking may impact performance, so we do # not want this to be the default eventually. Also, we use the # versioned .so libs for executables only if there is the -brtl - # linker flag in LDFLAGS as well, or --with-aix-soname=svr4 only. + # linker flag in LDFLAGS as well, or --enable-aix-soname=svr4 only. # To allow for filename-based versioning support, we need to create # libNAME.so.V as an archive file, containing: # *) an Import File, referring to the versioned filename of the @@ -11341,7 +12459,7 @@ bsdi[45]*) # libtool to hard-code these into programs ;; -cygwin* | mingw* | pw32* | cegcc*) +cygwin* | mingw* | windows* | pw32* | cegcc*) version_type=windows shrext_cmds=.dll need_version=no @@ -11352,6 +12470,19 @@ cygwin* | mingw* | pw32* | cegcc*) # gcc library_names_spec='$libname.dll.a' # DLL is installed to $(libdir)/../bin by postinstall_cmds + # If user builds GCC with mulitlibs enabled, + # it should just install on $(libdir) + # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones. + if test yes = $multilib; then + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + $install_prog $dir/$dlname $destdir/$dlname~ + chmod a+x $destdir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib $destdir/$dlname'\'' || exit \$?; + fi' + else postinstall_cmds='base_file=`basename \$file`~ dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ dldir=$destdir/`dirname \$dlpath`~ @@ -11361,6 +12492,7 @@ cygwin* | mingw* | pw32* | cegcc*) if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; fi' + fi postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ dlpath=$dir/\$dldll~ $RM \$dlpath' @@ -11369,30 +12501,30 @@ cygwin* | mingw* | pw32* | cegcc*) case $host_os in cygwin*) # Cygwin DLLs use 'cyg' prefix rather than 'lib' - soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + soname_spec='`echo $libname | $SED -e 's/^lib/cyg/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api" ;; - mingw* | cegcc*) + mingw* | windows* | cegcc*) # MinGW DLLs use traditional 'lib' prefix soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' ;; pw32*) # pw32 DLLs use 'pw' prefix rather than 'lib' - library_names_spec='`echo $libname | sed -e 's/^lib/pw/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + library_names_spec='`echo $libname | $SED -e 's/^lib/pw/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' ;; esac dynamic_linker='Win32 ld.exe' ;; - *,cl*) - # Native MSVC + *,cl* | *,icl*) + # Native MSVC or ICC libname_spec='$name' soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' library_names_spec='$libname.dll.lib' case $build_os in - mingw*) + mingw* | windows*) sys_lib_search_path_spec= lt_save_ifs=$IFS IFS=';' @@ -11405,7 +12537,7 @@ cygwin* | mingw* | pw32* | cegcc*) done IFS=$lt_save_ifs # Convert to MSYS style. - sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([a-zA-Z]\\):| /\\1|g' -e 's|^ ||'` + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's|\\\\|/|g' -e 's| \\([a-zA-Z]\\):| /\\1|g' -e 's|^ ||'` ;; cygwin*) # Convert to unix form, then to dos form, then back to unix form @@ -11442,7 +12574,7 @@ cygwin* | mingw* | pw32* | cegcc*) ;; *) - # Assume MSVC wrapper + # Assume MSVC and ICC wrapper library_names_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext $libname.lib' dynamic_linker='Win32 ld.exe' ;; @@ -11475,7 +12607,7 @@ dgux*) shlibpath_var=LD_LIBRARY_PATH ;; -freebsd* | dragonfly*) +freebsd* | dragonfly* | midnightbsd*) # DragonFly does not have aout. When/if they implement a new # versioning mechanism, adjust this. if test -x /usr/bin/objformat; then @@ -11512,7 +12644,27 @@ freebsd* | dragonfly*) need_version=no ;; esac + case $host_cpu in + powerpc64) + # On FreeBSD bi-arch platforms, a different variable is used for 32-bit + # binaries. See <https://man.freebsd.org/cgi/man.cgi?query=ld.so>. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int test_pointer_size[sizeof (void *) - 5]; + +_ACEOF +if ac_fn_c_try_compile "$LINENO" +then : shlibpath_var=LD_LIBRARY_PATH +else $as_nop + shlibpath_var=LD_32_LIBRARY_PATH +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + ;; + *) + shlibpath_var=LD_LIBRARY_PATH + ;; + esac case $host_os in freebsd2.*) shlibpath_overrides_runpath=yes @@ -11653,7 +12805,7 @@ linux*android*) version_type=none # Android doesn't support versioned libraries. need_lib_prefix=no need_version=no - library_names_spec='$libname$release$shared_ext' + library_names_spec='$libname$release$shared_ext $libname$shared_ext' soname_spec='$libname$release$shared_ext' finish_cmds= shlibpath_var=LD_LIBRARY_PATH @@ -11665,8 +12817,9 @@ linux*android*) hardcode_into_libs=yes dynamic_linker='Android linker' - # Don't embed -rpath directories since the linker doesn't support them. - hardcode_libdir_flag_spec='-L$libdir' + # -rpath works at least for libraries that are not overridden by + # libraries installed in system locations. + hardcode_libdir_flag_spec='$wl-rpath $wl$libdir' ;; # This must be glibc/ELF. @@ -11681,9 +12834,10 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) shlibpath_overrides_runpath=no # Some binutils ld are patched to set DT_RUNPATH - if ${lt_cv_shlibpath_overrides_runpath+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${lt_cv_shlibpath_overrides_runpath+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_shlibpath_overrides_runpath=no save_LDFLAGS=$LDFLAGS save_libdir=$libdir @@ -11693,19 +12847,21 @@ else /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : - if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then : +if ac_fn_c_try_link "$LINENO" +then : + if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null +then : lt_cv_shlibpath_overrides_runpath=yes fi fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LDFLAGS=$save_LDFLAGS libdir=$save_libdir @@ -11719,7 +12875,7 @@ fi # before this can be enabled. hardcode_into_libs=yes - # Ideally, we could use ldconfig to report *all* directores which are + # Ideally, we could use ldconfig to report *all* directories which are # searched for libraries, however this is still not possible. Aside from not # being certain /sbin/ldconfig is available, command # 'ldconfig -N -X -v | grep ^/' on 64bit Fedora does not report /usr/lib64, @@ -11776,7 +12932,7 @@ newsos6) dynamic_linker='ldqnx.so' ;; -openbsd* | bitrig*) +openbsd*) version_type=sunos sys_lib_dlsearch_path_spec=/usr/lib need_lib_prefix=no @@ -11937,8 +13093,8 @@ uts4*) dynamic_linker=no ;; esac -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 -$as_echo "$dynamic_linker" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 +printf "%s\n" "$dynamic_linker" >&6; } test no = "$dynamic_linker" && can_build_shared=no variables_saved_for_relink="PATH $shlibpath_var $runpath_var" @@ -12059,8 +13215,8 @@ configure_time_lt_sys_library_path=$LT_SYS_LIBRARY_PATH - { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 -$as_echo_n "checking how to hardcode library paths into programs... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 +printf %s "checking how to hardcode library paths into programs... " >&6; } hardcode_action= if test -n "$hardcode_libdir_flag_spec" || test -n "$runpath_var" || @@ -12084,8 +13240,8 @@ else # directories. hardcode_action=unsupported fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5 -$as_echo "$hardcode_action" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $hardcode_action" >&5 +printf "%s\n" "$hardcode_action" >&6; } if test relink = "$hardcode_action" || test yes = "$inherit_rpath"; then @@ -12117,7 +13273,7 @@ else lt_cv_dlopen_self=yes ;; - mingw* | pw32* | cegcc*) + mingw* | windows* | pw32* | cegcc*) lt_cv_dlopen=LoadLibrary lt_cv_dlopen_libs= ;; @@ -12129,11 +13285,12 @@ else darwin*) # if libdl is installed we need to link against it - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 -$as_echo_n "checking for dlopen in -ldl... " >&6; } -if ${ac_cv_lib_dl_dlopen+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +printf %s "checking for dlopen in -ldl... " >&6; } +if test ${ac_cv_lib_dl_dlopen+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-ldl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12141,33 +13298,38 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ + builtin and then its argument prototype would still apply. + The 'extern "C"' is for builds by C++ compilers; + although this is not generally supported in C code supporting it here + has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif -char dlopen (); +char dlopen (void); int -main () +main (void) { return dlopen (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_dl_dlopen=yes -else +else $as_nop ac_cv_lib_dl_dlopen=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 -$as_echo "$ac_cv_lib_dl_dlopen" >&6; } -if test "x$ac_cv_lib_dl_dlopen" = xyes; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +printf "%s\n" "$ac_cv_lib_dl_dlopen" >&6; } +if test "x$ac_cv_lib_dl_dlopen" = xyes +then : lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl -else +else $as_nop lt_cv_dlopen=dyld lt_cv_dlopen_libs= @@ -12187,14 +13349,16 @@ fi *) ac_fn_c_check_func "$LINENO" "shl_load" "ac_cv_func_shl_load" -if test "x$ac_cv_func_shl_load" = xyes; then : +if test "x$ac_cv_func_shl_load" = xyes +then : lt_cv_dlopen=shl_load -else - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 -$as_echo_n "checking for shl_load in -ldld... " >&6; } -if ${ac_cv_lib_dld_shl_load+:} false; then : - $as_echo_n "(cached) " >&6 -else +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for shl_load in -ldld" >&5 +printf %s "checking for shl_load in -ldld... " >&6; } +if test ${ac_cv_lib_dld_shl_load+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-ldld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12202,42 +13366,49 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ + builtin and then its argument prototype would still apply. + The 'extern "C"' is for builds by C++ compilers; + although this is not generally supported in C code supporting it here + has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif -char shl_load (); +char shl_load (void); int -main () +main (void) { return shl_load (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_dld_shl_load=yes -else +else $as_nop ac_cv_lib_dld_shl_load=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 -$as_echo "$ac_cv_lib_dld_shl_load" >&6; } -if test "x$ac_cv_lib_dld_shl_load" = xyes; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_shl_load" >&5 +printf "%s\n" "$ac_cv_lib_dld_shl_load" >&6; } +if test "x$ac_cv_lib_dld_shl_load" = xyes +then : lt_cv_dlopen=shl_load lt_cv_dlopen_libs=-ldld -else +else $as_nop ac_fn_c_check_func "$LINENO" "dlopen" "ac_cv_func_dlopen" -if test "x$ac_cv_func_dlopen" = xyes; then : +if test "x$ac_cv_func_dlopen" = xyes +then : lt_cv_dlopen=dlopen -else - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 -$as_echo_n "checking for dlopen in -ldl... " >&6; } -if ${ac_cv_lib_dl_dlopen+:} false; then : - $as_echo_n "(cached) " >&6 -else +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -ldl" >&5 +printf %s "checking for dlopen in -ldl... " >&6; } +if test ${ac_cv_lib_dl_dlopen+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-ldl $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12245,38 +13416,44 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ + builtin and then its argument prototype would still apply. + The 'extern "C"' is for builds by C++ compilers; + although this is not generally supported in C code supporting it here + has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif -char dlopen (); +char dlopen (void); int -main () +main (void) { return dlopen (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_dl_dlopen=yes -else +else $as_nop ac_cv_lib_dl_dlopen=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 -$as_echo "$ac_cv_lib_dl_dlopen" >&6; } -if test "x$ac_cv_lib_dl_dlopen" = xyes; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dl_dlopen" >&5 +printf "%s\n" "$ac_cv_lib_dl_dlopen" >&6; } +if test "x$ac_cv_lib_dl_dlopen" = xyes +then : lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-ldl -else - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5 -$as_echo_n "checking for dlopen in -lsvld... " >&6; } -if ${ac_cv_lib_svld_dlopen+:} false; then : - $as_echo_n "(cached) " >&6 -else +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dlopen in -lsvld" >&5 +printf %s "checking for dlopen in -lsvld... " >&6; } +if test ${ac_cv_lib_svld_dlopen+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-lsvld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12284,38 +13461,44 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ + builtin and then its argument prototype would still apply. + The 'extern "C"' is for builds by C++ compilers; + although this is not generally supported in C code supporting it here + has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif -char dlopen (); +char dlopen (void); int -main () +main (void) { return dlopen (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_svld_dlopen=yes -else +else $as_nop ac_cv_lib_svld_dlopen=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5 -$as_echo "$ac_cv_lib_svld_dlopen" >&6; } -if test "x$ac_cv_lib_svld_dlopen" = xyes; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_svld_dlopen" >&5 +printf "%s\n" "$ac_cv_lib_svld_dlopen" >&6; } +if test "x$ac_cv_lib_svld_dlopen" = xyes +then : lt_cv_dlopen=dlopen lt_cv_dlopen_libs=-lsvld -else - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5 -$as_echo_n "checking for dld_link in -ldld... " >&6; } -if ${ac_cv_lib_dld_dld_link+:} false; then : - $as_echo_n "(cached) " >&6 -else +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for dld_link in -ldld" >&5 +printf %s "checking for dld_link in -ldld... " >&6; } +if test ${ac_cv_lib_dld_dld_link+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-ldld $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -12323,31 +13506,36 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ + builtin and then its argument prototype would still apply. + The 'extern "C"' is for builds by C++ compilers; + although this is not generally supported in C code supporting it here + has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif -char dld_link (); +char dld_link (void); int -main () +main (void) { return dld_link (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_dld_dld_link=yes -else +else $as_nop ac_cv_lib_dld_dld_link=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5 -$as_echo "$ac_cv_lib_dld_dld_link" >&6; } -if test "x$ac_cv_lib_dld_dld_link" = xyes; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_dld_dld_link" >&5 +printf "%s\n" "$ac_cv_lib_dld_dld_link" >&6; } +if test "x$ac_cv_lib_dld_dld_link" = xyes +then : lt_cv_dlopen=dld_link lt_cv_dlopen_libs=-ldld fi @@ -12386,11 +13574,12 @@ fi save_LIBS=$LIBS LIBS="$lt_cv_dlopen_libs $LIBS" - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5 -$as_echo_n "checking whether a program can dlopen itself... " >&6; } -if ${lt_cv_dlopen_self+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether a program can dlopen itself" >&5 +printf %s "checking whether a program can dlopen itself... " >&6; } +if test ${lt_cv_dlopen_self+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test yes = "$cross_compiling"; then : lt_cv_dlopen_self=cross else @@ -12441,11 +13630,11 @@ else /* When -fvisibility=hidden is used, assume the code has been annotated correspondingly for the symbols needed. */ #if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) -int fnord () __attribute__((visibility("default"))); +int fnord (void) __attribute__((visibility("default"))); #endif -int fnord () { return 42; } -int main () +int fnord (void) { return 42; } +int main (void) { void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); int status = $lt_dlunknown; @@ -12469,7 +13658,7 @@ _LT_EOF if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 (eval $ac_link) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s "conftest$ac_exeext" 2>/dev/null; then (./conftest; exit; ) >&5 2>/dev/null lt_status=$? @@ -12487,16 +13676,17 @@ rm -fr conftest* fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5 -$as_echo "$lt_cv_dlopen_self" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self" >&5 +printf "%s\n" "$lt_cv_dlopen_self" >&6; } if test yes = "$lt_cv_dlopen_self"; then wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\" - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5 -$as_echo_n "checking whether a statically linked program can dlopen itself... " >&6; } -if ${lt_cv_dlopen_self_static+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether a statically linked program can dlopen itself" >&5 +printf %s "checking whether a statically linked program can dlopen itself... " >&6; } +if test ${lt_cv_dlopen_self_static+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test yes = "$cross_compiling"; then : lt_cv_dlopen_self_static=cross else @@ -12547,11 +13737,11 @@ else /* When -fvisibility=hidden is used, assume the code has been annotated correspondingly for the symbols needed. */ #if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) -int fnord () __attribute__((visibility("default"))); +int fnord (void) __attribute__((visibility("default"))); #endif -int fnord () { return 42; } -int main () +int fnord (void) { return 42; } +int main (void) { void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); int status = $lt_dlunknown; @@ -12575,7 +13765,7 @@ _LT_EOF if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_link\""; } >&5 (eval $ac_link) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } && test -s "conftest$ac_exeext" 2>/dev/null; then (./conftest; exit; ) >&5 2>/dev/null lt_status=$? @@ -12593,8 +13783,8 @@ rm -fr conftest* fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5 -$as_echo "$lt_cv_dlopen_self_static" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_dlopen_self_static" >&5 +printf "%s\n" "$lt_cv_dlopen_self_static" >&6; } fi CPPFLAGS=$save_CPPFLAGS @@ -12632,32 +13822,43 @@ fi striplib= old_striplib= -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5 -$as_echo_n "checking whether stripping libraries is possible... " >&6; } -if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then - test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" - test -z "$striplib" && striplib="$STRIP --strip-unneeded" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } -else -# FIXME - insert some real tests, host_os isn't really good enough - case $host_os in - darwin*) - if test -n "$STRIP"; then +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether stripping libraries is possible" >&5 +printf %s "checking whether stripping libraries is possible... " >&6; } +if test -z "$STRIP"; then + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } +else + if $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + old_striplib="$STRIP --strip-debug" + striplib="$STRIP --strip-unneeded" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + else + case $host_os in + darwin*) + # FIXME - insert some real tests, host_os isn't really good enough striplib="$STRIP -x" old_striplib="$STRIP -S" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - fi - ;; - *) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - ;; - esac + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + ;; + freebsd*) + if $STRIP -V 2>&1 | $GREP "elftoolchain" >/dev/null; then + old_striplib="$STRIP --strip-debug" + striplib="$STRIP --strip-unneeded" + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } + else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + fi + ;; + *) + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + ;; + esac + fi fi @@ -12672,13 +13873,13 @@ fi # Report what library types will actually be built - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5 -$as_echo_n "checking if libtool supports shared libraries... " >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5 -$as_echo "$can_build_shared" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if libtool supports shared libraries" >&5 +printf %s "checking if libtool supports shared libraries... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $can_build_shared" >&5 +printf "%s\n" "$can_build_shared" >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5 -$as_echo_n "checking whether to build shared libraries... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to build shared libraries" >&5 +printf %s "checking whether to build shared libraries... " >&6; } test no = "$can_build_shared" && enable_shared=no # On AIX, shared libraries and static libraries use the same namespace, and @@ -12702,15 +13903,15 @@ $as_echo_n "checking whether to build shared libraries... " >&6; } fi ;; esac - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 -$as_echo "$enable_shared" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_shared" >&5 +printf "%s\n" "$enable_shared" >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5 -$as_echo_n "checking whether to build static libraries... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether to build static libraries" >&5 +printf %s "checking whether to build static libraries... " >&6; } # Make sure either enable_shared or enable_static is yes. test yes = "$enable_shared" || enable_static=yes - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5 -$as_echo "$enable_static" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $enable_static" >&5 +printf "%s\n" "$enable_static" >&6; } @@ -12757,196 +13958,27 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $CC option to accept ISO C99" >&5 -$as_echo_n "checking for $CC option to accept ISO C99... " >&6; } -if ${ac_cv_prog_cc_c99+:} false; then : - $as_echo_n "(cached) " >&6 -else - ac_cv_prog_cc_c99=no -ac_save_CC=$CC -cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include <stdarg.h> -#include <stdbool.h> -#include <stdlib.h> -#include <wchar.h> -#include <stdio.h> - -// Check varargs macros. These examples are taken from C99 6.10.3.5. -#define debug(...) fprintf (stderr, __VA_ARGS__) -#define showlist(...) puts (#__VA_ARGS__) -#define report(test,...) ((test) ? puts (#test) : printf (__VA_ARGS__)) -static void -test_varargs_macros (void) -{ - int x = 1234; - int y = 5678; - debug ("Flag"); - debug ("X = %d\n", x); - showlist (The first, second, and third items.); - report (x>y, "x is %d but y is %d", x, y); -} - -// Check long long types. -#define BIG64 18446744073709551615ull -#define BIG32 4294967295ul -#define BIG_OK (BIG64 / BIG32 == 4294967297ull && BIG64 % BIG32 == 0) -#if !BIG_OK - your preprocessor is broken; -#endif -#if BIG_OK -#else - your preprocessor is broken; -#endif -static long long int bignum = -9223372036854775807LL; -static unsigned long long int ubignum = BIG64; - -struct incomplete_array -{ - int datasize; - double data[]; -}; - -struct named_init { - int number; - const wchar_t *name; - double average; -}; - -typedef const char *ccp; - -static inline int -test_restrict (ccp restrict text) -{ - // See if C++-style comments work. - // Iterate through items via the restricted pointer. - // Also check for declarations in for loops. - for (unsigned int i = 0; *(text+i) != '\0'; ++i) - continue; - return 0; -} - -// Check varargs and va_copy. -static void -test_varargs (const char *format, ...) -{ - va_list args; - va_start (args, format); - va_list args_copy; - va_copy (args_copy, args); - - const char *str; - int number; - float fnumber; - - while (*format) - { - switch (*format++) - { - case 's': // string - str = va_arg (args_copy, const char *); - break; - case 'd': // int - number = va_arg (args_copy, int); - break; - case 'f': // float - fnumber = va_arg (args_copy, double); - break; - default: - break; - } - } - va_end (args_copy); - va_end (args); -} - -int -main () -{ - - // Check bool. - _Bool success = false; - - // Check restrict. - if (test_restrict ("String literal") == 0) - success = true; - char *restrict newvar = "Another string"; - - // Check varargs. - test_varargs ("s, d' f .", "string", 65, 34.234); - test_varargs_macros (); - - // Check flexible array members. - struct incomplete_array *ia = - malloc (sizeof (struct incomplete_array) + (sizeof (double) * 10)); - ia->datasize = 10; - for (int i = 0; i < ia->datasize; ++i) - ia->data[i] = i * 1.234; - - // Check named initializers. - struct named_init ni = { - .number = 34, - .name = L"Test wide string", - .average = 543.34343, - }; - - ni.number = 58; - int dynamic_array[ni.number]; - dynamic_array[ni.number - 1] = 543; - // work around unused variable warnings - return (!success || bignum == 0LL || ubignum == 0uLL || newvar[0] == 'x' - || dynamic_array[ni.number - 1] != 543); - - ; - return 0; -} -_ACEOF -for ac_arg in '' -std=gnu99 -std=c99 -c99 -AC99 -D_STDC_C99= -qlanglvl=extc99 -do - CC="$ac_save_CC $ac_arg" - if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_prog_cc_c99=$ac_arg +if test "${ac_cv_prog_cc_c99}" = no +then : + as_fn_error $? "Expat requires a C99 compiler." "$LINENO" 5 fi -rm -f core conftest.err conftest.$ac_objext - test "x$ac_cv_prog_cc_c99" != "xno" && break -done -rm -f conftest.$ac_ext -CC=$ac_save_CC -fi -# AC_CACHE_VAL -case "x$ac_cv_prog_cc_c99" in - x) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 -$as_echo "none needed" >&6; } ;; - xno) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 -$as_echo "unsupported" >&6; } ;; - *) - CC="$CC $ac_cv_prog_cc_c99" - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cc_c99" >&5 -$as_echo "$ac_cv_prog_cc_c99" >&6; } ;; -esac -if test "x$ac_cv_prog_cc_c99" != xno; then : - -fi - - - -if test "$GCC" = yes; then : +if test "$GCC" = yes +then : for flag in -Wall -Wextra; do - as_CACHEVAR=`$as_echo "ax_cv_check_cflags__$flag" | $as_tr_sh` -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts $flag" >&5 -$as_echo_n "checking whether C compiler accepts $flag... " >&6; } -if eval \${$as_CACHEVAR+:} false; then : - $as_echo_n "(cached) " >&6 -else + as_CACHEVAR=`printf "%s\n" "ax_cv_check_cflags__$flag" | $as_tr_sh` +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts $flag" >&5 +printf %s "checking whether C compiler accepts $flag... " >&6; } +if eval test \${$as_CACHEVAR+y} +then : + printf %s "(cached) " >&6 +else $as_nop ax_check_save_flags=$CFLAGS CFLAGS="$CFLAGS -Werror $flag" @@ -12954,51 +13986,54 @@ else /* end confdefs.h. */ int main(void) { return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : eval "$as_CACHEVAR=yes" -else +else $as_nop eval "$as_CACHEVAR=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext CFLAGS=$ax_check_save_flags fi eval ac_res=\$$as_CACHEVAR - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -if eval test \"x\$"$as_CACHEVAR"\" = x"yes"; then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } +if eval test \"x\$"$as_CACHEVAR"\" = x"yes" +then : -if ${AM_CFLAGS+:} false; then : +if test ${AM_CFLAGS+y} +then : case " $AM_CFLAGS " in #( *" $flag "*) : - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS already contains \$flag"; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS already contains \$flag"; } >&5 (: AM_CFLAGS already contains $flag) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; #( *) : as_fn_append AM_CFLAGS " $flag" - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 (: AM_CFLAGS="$AM_CFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; esac -else +else $as_nop AM_CFLAGS=$flag - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 (: AM_CFLAGS="$AM_CFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } fi -else +else $as_nop : fi @@ -13009,12 +14044,13 @@ done for flag in -fexceptions; do - as_CACHEVAR=`$as_echo "ax_cv_check_cflags__$flag" | $as_tr_sh` -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts $flag" >&5 -$as_echo_n "checking whether C compiler accepts $flag... " >&6; } -if eval \${$as_CACHEVAR+:} false; then : - $as_echo_n "(cached) " >&6 -else + as_CACHEVAR=`printf "%s\n" "ax_cv_check_cflags__$flag" | $as_tr_sh` +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts $flag" >&5 +printf %s "checking whether C compiler accepts $flag... " >&6; } +if eval test \${$as_CACHEVAR+y} +then : + printf %s "(cached) " >&6 +else $as_nop ax_check_save_flags=$CFLAGS CFLAGS="$CFLAGS -Werror $flag" @@ -13022,51 +14058,54 @@ else /* end confdefs.h. */ int main(void) { return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : eval "$as_CACHEVAR=yes" -else +else $as_nop eval "$as_CACHEVAR=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext CFLAGS=$ax_check_save_flags fi eval ac_res=\$$as_CACHEVAR - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -if eval test \"x\$"$as_CACHEVAR"\" = x"yes"; then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } +if eval test \"x\$"$as_CACHEVAR"\" = x"yes" +then : -if ${AM_CFLAGS+:} false; then : +if test ${AM_CFLAGS+y} +then : case " $AM_CFLAGS " in #( *" $flag "*) : - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS already contains \$flag"; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS already contains \$flag"; } >&5 (: AM_CFLAGS already contains $flag) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; #( *) : as_fn_append AM_CFLAGS " $flag" - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 (: AM_CFLAGS="$AM_CFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; esac -else +else $as_nop AM_CFLAGS=$flag - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 (: AM_CFLAGS="$AM_CFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } fi -else +else $as_nop : fi @@ -13077,12 +14116,13 @@ done for flag in -fno-strict-aliasing -Wmissing-prototypes -Wstrict-prototypes; do - as_CACHEVAR=`$as_echo "ax_cv_check_cflags__$flag" | $as_tr_sh` -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts $flag" >&5 -$as_echo_n "checking whether C compiler accepts $flag... " >&6; } -if eval \${$as_CACHEVAR+:} false; then : - $as_echo_n "(cached) " >&6 -else + as_CACHEVAR=`printf "%s\n" "ax_cv_check_cflags__$flag" | $as_tr_sh` +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts $flag" >&5 +printf %s "checking whether C compiler accepts $flag... " >&6; } +if eval test \${$as_CACHEVAR+y} +then : + printf %s "(cached) " >&6 +else $as_nop ax_check_save_flags=$CFLAGS CFLAGS="$CFLAGS -Werror $flag" @@ -13090,51 +14130,54 @@ else /* end confdefs.h. */ int main(void) { return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : eval "$as_CACHEVAR=yes" -else +else $as_nop eval "$as_CACHEVAR=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext CFLAGS=$ax_check_save_flags fi eval ac_res=\$$as_CACHEVAR - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -if eval test \"x\$"$as_CACHEVAR"\" = x"yes"; then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } +if eval test \"x\$"$as_CACHEVAR"\" = x"yes" +then : -if ${AM_CFLAGS+:} false; then : +if test ${AM_CFLAGS+y} +then : case " $AM_CFLAGS " in #( *" $flag "*) : - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS already contains \$flag"; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS already contains \$flag"; } >&5 (: AM_CFLAGS already contains $flag) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; #( *) : as_fn_append AM_CFLAGS " $flag" - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 (: AM_CFLAGS="$AM_CFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; esac -else +else $as_nop AM_CFLAGS=$flag - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 (: AM_CFLAGS="$AM_CFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } fi -else +else $as_nop : fi @@ -13145,12 +14188,13 @@ done for flag in -pedantic -Wduplicated-cond -Wduplicated-branches -Wlogical-op; do - as_CACHEVAR=`$as_echo "ax_cv_check_cflags__$flag" | $as_tr_sh` -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts $flag" >&5 -$as_echo_n "checking whether C compiler accepts $flag... " >&6; } -if eval \${$as_CACHEVAR+:} false; then : - $as_echo_n "(cached) " >&6 -else + as_CACHEVAR=`printf "%s\n" "ax_cv_check_cflags__$flag" | $as_tr_sh` +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts $flag" >&5 +printf %s "checking whether C compiler accepts $flag... " >&6; } +if eval test \${$as_CACHEVAR+y} +then : + printf %s "(cached) " >&6 +else $as_nop ax_check_save_flags=$CFLAGS CFLAGS="$CFLAGS -Werror $flag" @@ -13158,51 +14202,54 @@ else /* end confdefs.h. */ int main(void) { return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : eval "$as_CACHEVAR=yes" -else +else $as_nop eval "$as_CACHEVAR=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext CFLAGS=$ax_check_save_flags fi eval ac_res=\$$as_CACHEVAR - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -if eval test \"x\$"$as_CACHEVAR"\" = x"yes"; then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } +if eval test \"x\$"$as_CACHEVAR"\" = x"yes" +then : -if ${AM_CFLAGS+:} false; then : +if test ${AM_CFLAGS+y} +then : case " $AM_CFLAGS " in #( *" $flag "*) : - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS already contains \$flag"; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS already contains \$flag"; } >&5 (: AM_CFLAGS already contains $flag) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; #( *) : as_fn_append AM_CFLAGS " $flag" - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 (: AM_CFLAGS="$AM_CFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; esac -else +else $as_nop AM_CFLAGS=$flag - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 (: AM_CFLAGS="$AM_CFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } fi -else +else $as_nop : fi @@ -13213,12 +14260,13 @@ done for flag in -Wrestrict -Wnull-dereference -Wjump-misses-init -Wdouble-promotion; do - as_CACHEVAR=`$as_echo "ax_cv_check_cflags__$flag" | $as_tr_sh` -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts $flag" >&5 -$as_echo_n "checking whether C compiler accepts $flag... " >&6; } -if eval \${$as_CACHEVAR+:} false; then : - $as_echo_n "(cached) " >&6 -else + as_CACHEVAR=`printf "%s\n" "ax_cv_check_cflags__$flag" | $as_tr_sh` +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts $flag" >&5 +printf %s "checking whether C compiler accepts $flag... " >&6; } +if eval test \${$as_CACHEVAR+y} +then : + printf %s "(cached) " >&6 +else $as_nop ax_check_save_flags=$CFLAGS CFLAGS="$CFLAGS -Werror $flag" @@ -13226,51 +14274,54 @@ else /* end confdefs.h. */ int main(void) { return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : eval "$as_CACHEVAR=yes" -else +else $as_nop eval "$as_CACHEVAR=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext CFLAGS=$ax_check_save_flags fi eval ac_res=\$$as_CACHEVAR - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -if eval test \"x\$"$as_CACHEVAR"\" = x"yes"; then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } +if eval test \"x\$"$as_CACHEVAR"\" = x"yes" +then : -if ${AM_CFLAGS+:} false; then : +if test ${AM_CFLAGS+y} +then : case " $AM_CFLAGS " in #( *" $flag "*) : - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS already contains \$flag"; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS already contains \$flag"; } >&5 (: AM_CFLAGS already contains $flag) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; #( *) : as_fn_append AM_CFLAGS " $flag" - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 (: AM_CFLAGS="$AM_CFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; esac -else +else $as_nop AM_CFLAGS=$flag - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 (: AM_CFLAGS="$AM_CFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } fi -else +else $as_nop : fi @@ -13280,13 +14331,14 @@ done -for flag in -Wshadow -Wformat=2 -Wmisleading-indentation; do - as_CACHEVAR=`$as_echo "ax_cv_check_cflags__$flag" | $as_tr_sh` -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts $flag" >&5 -$as_echo_n "checking whether C compiler accepts $flag... " >&6; } -if eval \${$as_CACHEVAR+:} false; then : - $as_echo_n "(cached) " >&6 -else +for flag in -Wshadow -Wformat=2 -Wno-pedantic-ms-format -Wmisleading-indentation; do + as_CACHEVAR=`printf "%s\n" "ax_cv_check_cflags__$flag" | $as_tr_sh` +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts $flag" >&5 +printf %s "checking whether C compiler accepts $flag... " >&6; } +if eval test \${$as_CACHEVAR+y} +then : + printf %s "(cached) " >&6 +else $as_nop ax_check_save_flags=$CFLAGS CFLAGS="$CFLAGS -Werror $flag" @@ -13294,51 +14346,54 @@ else /* end confdefs.h. */ int main(void) { return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : eval "$as_CACHEVAR=yes" -else +else $as_nop eval "$as_CACHEVAR=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext CFLAGS=$ax_check_save_flags fi eval ac_res=\$$as_CACHEVAR - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -if eval test \"x\$"$as_CACHEVAR"\" = x"yes"; then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } +if eval test \"x\$"$as_CACHEVAR"\" = x"yes" +then : -if ${AM_CFLAGS+:} false; then : +if test ${AM_CFLAGS+y} +then : case " $AM_CFLAGS " in #( *" $flag "*) : - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS already contains \$flag"; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS already contains \$flag"; } >&5 (: AM_CFLAGS already contains $flag) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; #( *) : as_fn_append AM_CFLAGS " $flag" - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 (: AM_CFLAGS="$AM_CFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; esac -else +else $as_nop AM_CFLAGS=$flag - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 (: AM_CFLAGS="$AM_CFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } fi -else +else $as_nop : fi @@ -13352,6 +14407,12 @@ ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + + + + + ac_ext=cpp ac_cpp='$CXXCPP $CPPFLAGS' ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -13362,15 +14423,16 @@ if test -z "$CXX"; then CXX=$CCC else if test -n "$ac_tool_prefix"; then - for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC clang++ do # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args. set dummy $ac_tool_prefix$ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_CXX+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_CXX+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$CXX"; then ac_cv_prog_CXX="$CXX" # Let the user override the test. else @@ -13378,11 +14440,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -13393,11 +14459,11 @@ fi fi CXX=$ac_cv_prog_CXX if test -n "$CXX"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXX" >&5 -$as_echo "$CXX" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CXX" >&5 +printf "%s\n" "$CXX" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -13406,15 +14472,16 @@ fi fi if test -z "$CXX"; then ac_ct_CXX=$CXX - for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC + for ac_prog in g++ c++ gpp aCC CC cxx cc++ cl.exe FCC KCC RCC xlC_r xlC clang++ do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_ac_ct_CXX+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_ac_ct_CXX+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$ac_ct_CXX"; then ac_cv_prog_ac_ct_CXX="$ac_ct_CXX" # Let the user override the test. else @@ -13422,11 +14489,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CXX="$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -13437,11 +14508,11 @@ fi fi ac_ct_CXX=$ac_cv_prog_ac_ct_CXX if test -n "$ac_ct_CXX"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CXX" >&5 -$as_echo "$ac_ct_CXX" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_ct_CXX" >&5 +printf "%s\n" "$ac_ct_CXX" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -13453,8 +14524,8 @@ done else case $cross_compiling:$ac_tool_warned in yes:) -{ $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 -$as_echo "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: using cross tools not prefixed with host triplet" >&5 +printf "%s\n" "$as_me: WARNING: using cross tools not prefixed with host triplet" >&2;} ac_tool_warned=yes ;; esac CXX=$ac_ct_CXX @@ -13464,7 +14535,7 @@ fi fi fi # Provide some information about the compiler. -$as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ compiler version" >&5 +printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for C++ compiler version" >&5 set X $ac_compile ac_compiler=$2 for ac_option in --version -v -V -qversion; do @@ -13474,7 +14545,7 @@ case "(($ac_try" in *) ac_try_echo=$ac_try;; esac eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 +printf "%s\n" "$ac_try_echo"; } >&5 (eval "$ac_compiler $ac_option >&5") 2>conftest.err ac_status=$? if test -s conftest.err; then @@ -13484,20 +14555,21 @@ $as_echo "$ac_try_echo"; } >&5 cat conftest.er1 >&5 fi rm -f conftest.er1 conftest.err - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are using the GNU C++ compiler" >&5 -$as_echo_n "checking whether we are using the GNU C++ compiler... " >&6; } -if ${ac_cv_cxx_compiler_gnu+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler supports GNU C++" >&5 +printf %s "checking whether the compiler supports GNU C++... " >&6; } +if test ${ac_cv_cxx_compiler_gnu+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { #ifndef __GNUC__ choke me @@ -13507,29 +14579,33 @@ main () return 0; } _ACEOF -if ac_fn_cxx_try_compile "$LINENO"; then : +if ac_fn_cxx_try_compile "$LINENO" +then : ac_compiler_gnu=yes -else +else $as_nop ac_compiler_gnu=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_cv_cxx_compiler_gnu=$ac_compiler_gnu fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_compiler_gnu" >&5 -$as_echo "$ac_cv_cxx_compiler_gnu" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_cxx_compiler_gnu" >&5 +printf "%s\n" "$ac_cv_cxx_compiler_gnu" >&6; } +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + if test $ac_compiler_gnu = yes; then GXX=yes else GXX= fi -ac_test_CXXFLAGS=${CXXFLAGS+set} +ac_test_CXXFLAGS=${CXXFLAGS+y} ac_save_CXXFLAGS=$CXXFLAGS -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -g" >&5 -$as_echo_n "checking whether $CXX accepts -g... " >&6; } -if ${ac_cv_prog_cxx_g+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CXX accepts -g" >&5 +printf %s "checking whether $CXX accepts -g... " >&6; } +if test ${ac_cv_prog_cxx_g+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_save_cxx_werror_flag=$ac_cxx_werror_flag ac_cxx_werror_flag=yes ac_cv_prog_cxx_g=no @@ -13538,57 +14614,60 @@ else /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_cxx_try_compile "$LINENO"; then : +if ac_fn_cxx_try_compile "$LINENO" +then : ac_cv_prog_cxx_g=yes -else +else $as_nop CXXFLAGS="" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_cxx_try_compile "$LINENO"; then : +if ac_fn_cxx_try_compile "$LINENO" +then : -else +else $as_nop ac_cxx_werror_flag=$ac_save_cxx_werror_flag CXXFLAGS="-g" cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_cxx_try_compile "$LINENO"; then : +if ac_fn_cxx_try_compile "$LINENO" +then : ac_cv_prog_cxx_g=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext ac_cxx_werror_flag=$ac_save_cxx_werror_flag fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_g" >&5 -$as_echo "$ac_cv_prog_cxx_g" >&6; } -if test "$ac_test_CXXFLAGS" = set; then +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_g" >&5 +printf "%s\n" "$ac_cv_prog_cxx_g" >&6; } +if test $ac_test_CXXFLAGS; then CXXFLAGS=$ac_save_CXXFLAGS elif test $ac_cv_prog_cxx_g = yes; then if test "$GXX" = yes; then @@ -13603,6 +14682,100 @@ else CXXFLAGS= fi fi +ac_prog_cxx_stdcxx=no +if test x$ac_prog_cxx_stdcxx = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++11 features" >&5 +printf %s "checking for $CXX option to enable C++11 features... " >&6; } +if test ${ac_cv_prog_cxx_cxx11+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cxx_cxx11=no +ac_save_CXX=$CXX +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$ac_cxx_conftest_cxx11_program +_ACEOF +for ac_arg in '' -std=gnu++11 -std=gnu++0x -std=c++11 -std=c++0x -qlanglvl=extended0x -AA +do + CXX="$ac_save_CXX $ac_arg" + if ac_fn_cxx_try_compile "$LINENO" +then : + ac_cv_prog_cxx_cxx11=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam + test "x$ac_cv_prog_cxx_cxx11" != "xno" && break +done +rm -f conftest.$ac_ext +CXX=$ac_save_CXX +fi + +if test "x$ac_cv_prog_cxx_cxx11" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cxx_cxx11" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_cxx11" >&5 +printf "%s\n" "$ac_cv_prog_cxx_cxx11" >&6; } + CXX="$CXX $ac_cv_prog_cxx_cxx11" +fi + ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx11 + ac_prog_cxx_stdcxx=cxx11 +fi +fi +if test x$ac_prog_cxx_stdcxx = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $CXX option to enable C++98 features" >&5 +printf %s "checking for $CXX option to enable C++98 features... " >&6; } +if test ${ac_cv_prog_cxx_cxx98+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_cv_prog_cxx_cxx98=no +ac_save_CXX=$CXX +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +$ac_cxx_conftest_cxx98_program +_ACEOF +for ac_arg in '' -std=gnu++98 -std=c++98 -qlanglvl=extended -AA +do + CXX="$ac_save_CXX $ac_arg" + if ac_fn_cxx_try_compile "$LINENO" +then : + ac_cv_prog_cxx_cxx98=$ac_arg +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam + test "x$ac_cv_prog_cxx_cxx98" != "xno" && break +done +rm -f conftest.$ac_ext +CXX=$ac_save_CXX +fi + +if test "x$ac_cv_prog_cxx_cxx98" = xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: unsupported" >&5 +printf "%s\n" "unsupported" >&6; } +else $as_nop + if test "x$ac_cv_prog_cxx_cxx98" = x +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: none needed" >&5 +printf "%s\n" "none needed" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_prog_cxx_cxx98" >&5 +printf "%s\n" "$ac_cv_prog_cxx_cxx98" >&6; } + CXX="$CXX $ac_cv_prog_cxx_cxx98" +fi + ac_cv_prog_cxx_stdcxx=$ac_cv_prog_cxx_cxx98 + ac_prog_cxx_stdcxx=cxx98 +fi +fi + ac_ext=cpp ac_cpp='$CXXCPP $CPPFLAGS' ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -13611,11 +14784,12 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu depcc="$CXX" am_compiler_list= -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 -$as_echo_n "checking dependency style of $depcc... " >&6; } -if ${am_cv_CXX_dependencies_compiler_type+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dependency style of $depcc" >&5 +printf %s "checking dependency style of $depcc... " >&6; } +if test ${am_cv_CXX_dependencies_compiler_type+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then # We make a subdir and do the tests there. Otherwise we can end up # making bogus files that we don't know about and never remove. For @@ -13722,8 +14896,8 @@ else fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_CXX_dependencies_compiler_type" >&5 -$as_echo "$am_cv_CXX_dependencies_compiler_type" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $am_cv_CXX_dependencies_compiler_type" >&5 +printf "%s\n" "$am_cv_CXX_dependencies_compiler_type" >&6; } CXXDEPMODE=depmode=$am_cv_CXX_dependencies_compiler_type if @@ -13755,36 +14929,32 @@ ac_cpp='$CXXCPP $CPPFLAGS' ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_cxx_compiler_gnu -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C++ preprocessor" >&5 -$as_echo_n "checking how to run the C++ preprocessor... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to run the C++ preprocessor" >&5 +printf %s "checking how to run the C++ preprocessor... " >&6; } if test -z "$CXXCPP"; then - if ${ac_cv_prog_CXXCPP+:} false; then : - $as_echo_n "(cached) " >&6 -else - # Double quotes because CXXCPP needs to be expanded - for CXXCPP in "$CXX -E" "/lib/cpp" + if test ${ac_cv_prog_CXXCPP+y} +then : + printf %s "(cached) " >&6 +else $as_nop + # Double quotes because $CXX needs to be expanded + for CXXCPP in "$CXX -E" cpp /lib/cpp do ac_preproc_ok=false for ac_cxx_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. - # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since - # <limits.h> exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#ifdef __STDC__ -# include <limits.h> -#else -# include <assert.h> -#endif +#include <limits.h> Syntax error _ACEOF -if ac_fn_cxx_try_cpp "$LINENO"; then : +if ac_fn_cxx_try_cpp "$LINENO" +then : -else +else $as_nop # Broken: fails on valid input. continue fi @@ -13796,10 +14966,11 @@ rm -f conftest.err conftest.i conftest.$ac_ext /* end confdefs.h. */ #include <ac_nonexistent.h> _ACEOF -if ac_fn_cxx_try_cpp "$LINENO"; then : +if ac_fn_cxx_try_cpp "$LINENO" +then : # Broken: success on invalid input. continue -else +else $as_nop # Passes both tests. ac_preproc_ok=: break @@ -13809,7 +14980,8 @@ rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext -if $ac_preproc_ok; then : +if $ac_preproc_ok +then : break fi @@ -13821,29 +14993,24 @@ fi else ac_cv_prog_CXXCPP=$CXXCPP fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $CXXCPP" >&5 -$as_echo "$CXXCPP" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $CXXCPP" >&5 +printf "%s\n" "$CXXCPP" >&6; } ac_preproc_ok=false for ac_cxx_preproc_warn_flag in '' yes do # Use a header file that comes with gcc, so configuring glibc # with a fresh cross-compiler works. - # Prefer <limits.h> to <assert.h> if __STDC__ is defined, since - # <limits.h> exists even on freestanding compilers. # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. "Syntax error" is here to catch this case. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#ifdef __STDC__ -# include <limits.h> -#else -# include <assert.h> -#endif +#include <limits.h> Syntax error _ACEOF -if ac_fn_cxx_try_cpp "$LINENO"; then : +if ac_fn_cxx_try_cpp "$LINENO" +then : -else +else $as_nop # Broken: fails on valid input. continue fi @@ -13855,10 +15022,11 @@ rm -f conftest.err conftest.i conftest.$ac_ext /* end confdefs.h. */ #include <ac_nonexistent.h> _ACEOF -if ac_fn_cxx_try_cpp "$LINENO"; then : +if ac_fn_cxx_try_cpp "$LINENO" +then : # Broken: success on invalid input. continue -else +else $as_nop # Passes both tests. ac_preproc_ok=: break @@ -13868,11 +15036,12 @@ rm -f conftest.err conftest.i conftest.$ac_ext done # Because of `break', _AC_PREPROC_IFELSE's cleaning code was skipped. rm -f conftest.i conftest.err conftest.$ac_ext -if $ac_preproc_ok; then : +if $ac_preproc_ok +then : -else - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +else $as_nop + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "C++ preprocessor \"$CXXCPP\" fails sanity check See \`config.log' for more details" "$LINENO" 5; } fi @@ -14008,19 +15177,20 @@ cc_basename=$func_cc_basename_result # Check whether --with-gnu-ld was given. -if test "${with_gnu_ld+set}" = set; then : +if test ${with_gnu_ld+y} +then : withval=$with_gnu_ld; test no = "$withval" || with_gnu_ld=yes -else +else $as_nop with_gnu_ld=no fi ac_prog=ld if test yes = "$GCC"; then # Check if gcc -print-prog-name=ld gives a path. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 -$as_echo_n "checking for ld used by $CC... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for ld used by $CC" >&5 +printf %s "checking for ld used by $CC... " >&6; } case $host in - *-*-mingw*) + *-*-mingw* | *-*-windows*) # gcc leaves a trailing carriage return, which upsets mingw ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; *) @@ -14047,15 +15217,16 @@ $as_echo_n "checking for ld used by $CC... " >&6; } ;; esac elif test yes = "$with_gnu_ld"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 -$as_echo_n "checking for GNU ld... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for GNU ld" >&5 +printf %s "checking for GNU ld... " >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 -$as_echo_n "checking for non-GNU ld... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for non-GNU ld" >&5 +printf %s "checking for non-GNU ld... " >&6; } fi -if ${lt_cv_path_LD+:} false; then : - $as_echo_n "(cached) " >&6 -else +if test ${lt_cv_path_LD+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -z "$LD"; then lt_save_ifs=$IFS; IFS=$PATH_SEPARATOR for ac_dir in $PATH; do @@ -14084,18 +15255,19 @@ fi LD=$lt_cv_path_LD if test -n "$LD"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5 -$as_echo "$LD" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $LD" >&5 +printf "%s\n" "$LD" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi test -z "$LD" && as_fn_error $? "no acceptable ld found in \$PATH" "$LINENO" 5 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 -$as_echo_n "checking if the linker ($LD) is GNU ld... " >&6; } -if ${lt_cv_prog_gnu_ld+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if the linker ($LD) is GNU ld" >&5 +printf %s "checking if the linker ($LD) is GNU ld... " >&6; } +if test ${lt_cv_prog_gnu_ld+y} +then : + printf %s "(cached) " >&6 +else $as_nop # I'd rather use --version here, but apparently some GNU lds only accept -v. case `$LD -v 2>&1 </dev/null` in *GNU* | *'with BFD'*) @@ -14106,8 +15278,8 @@ case `$LD -v 2>&1 </dev/null` in ;; esac fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_gnu_ld" >&5 -$as_echo "$lt_cv_prog_gnu_ld" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_gnu_ld" >&5 +printf "%s\n" "$lt_cv_prog_gnu_ld" >&6; } with_gnu_ld=$lt_cv_prog_gnu_ld @@ -14131,8 +15303,7 @@ with_gnu_ld=$lt_cv_prog_gnu_ld wlarc='$wl' # ancient GNU ld didn't support --whole-archive et. al. - if eval "`$CC -print-prog-name=ld` --help 2>&1" | - $GREP 'no-whole-archive' > /dev/null; then + if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then whole_archive_flag_spec_CXX=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' else whole_archive_flag_spec_CXX= @@ -14152,7 +15323,7 @@ with_gnu_ld=$lt_cv_prog_gnu_ld # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "[-]L"' else GXX=no @@ -14161,8 +15332,8 @@ with_gnu_ld=$lt_cv_prog_gnu_ld fi # PORTME: fill in a description of your system's C++ link characteristics - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 -$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +printf %s "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } ld_shlibs_CXX=yes case $host_os in aix3*) @@ -14300,21 +15471,23 @@ $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie if test set = "${lt_cv_aix_libpath+set}"; then aix_libpath=$lt_cv_aix_libpath else - if ${lt_cv_aix_libpath__CXX+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${lt_cv_aix_libpath__CXX+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_cxx_try_link "$LINENO"; then : +if ac_fn_cxx_try_link "$LINENO" +then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { @@ -14329,7 +15502,7 @@ if ac_fn_cxx_try_link "$LINENO"; then : lt_cv_aix_libpath__CXX=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext if test -z "$lt_cv_aix_libpath__CXX"; then lt_cv_aix_libpath__CXX=/usr/lib:/lib @@ -14354,21 +15527,23 @@ fi if test set = "${lt_cv_aix_libpath+set}"; then aix_libpath=$lt_cv_aix_libpath else - if ${lt_cv_aix_libpath__CXX+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${lt_cv_aix_libpath__CXX+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_cxx_try_link "$LINENO"; then : +if ac_fn_cxx_try_link "$LINENO" +then : lt_aix_libpath_sed=' /Import File Strings/,/^$/ { @@ -14383,7 +15558,7 @@ if ac_fn_cxx_try_link "$LINENO"; then : lt_cv_aix_libpath__CXX=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"` fi fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext if test -z "$lt_cv_aix_libpath__CXX"; then lt_cv_aix_libpath__CXX=/usr/lib:/lib @@ -14446,10 +15621,10 @@ fi esac ;; - cygwin* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | windows* | pw32* | cegcc*) case $GXX,$cc_basename in - ,cl* | no,cl*) - # Native MSVC + ,cl* | no,cl* | ,icl* | no,icl*) + # Native MSVC or ICC # hardcode_libdir_flag_spec is actually meaningless, as there is # no search path for DLLs. hardcode_libdir_flag_spec_CXX=' ' @@ -14540,11 +15715,11 @@ fi output_verbose_link_cmd=func_echo_all archive_cmds_CXX="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dsymutil" module_cmds_CXX="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dsymutil" - archive_expsym_cmds_CXX="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" - module_expsym_cmds_CXX="sed -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" + archive_expsym_cmds_CXX="$SED 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" + module_expsym_cmds_CXX="$SED -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" if test yes != "$lt_cv_apple_cc_single_mod"; then archive_cmds_CXX="\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dsymutil" - archive_expsym_cmds_CXX="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dar_export_syms$_lt_dsymutil" + archive_expsym_cmds_CXX="$SED 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dar_export_syms$_lt_dsymutil" fi else @@ -14577,8 +15752,9 @@ fi cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ emximp -o $lib $output_objdir/$libname.def' - old_archive_From_new_cmds_CXX='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + old_archive_from_new_cmds_CXX='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' enable_shared_with_static_runtimes_CXX=yes + file_list_spec_CXX='@' ;; dgux*) @@ -14609,7 +15785,7 @@ fi archive_cmds_need_lc_CXX=no ;; - freebsd* | dragonfly*) + freebsd* | dragonfly* | midnightbsd*) # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF # conventions ld_shlibs_CXX=yes @@ -14644,7 +15820,7 @@ fi # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. - output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "[-]L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then @@ -14709,7 +15885,7 @@ fi # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. - output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "[-]L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then @@ -14746,7 +15922,7 @@ fi # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link # time. Moving up from 0x10000000 also allows more sbrk(2) space. archive_cmds_CXX='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' - archive_expsym_cmds_CXX='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + archive_expsym_cmds_CXX='$SED "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' ;; irix5* | irix6*) case $cc_basename in @@ -14886,13 +16062,13 @@ fi archive_cmds_CXX='$CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' if test yes = "$supports_anon_versioning"; then archive_expsym_cmds_CXX='echo "{ global:" > $output_objdir/$libname.ver~ - cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' fi ;; *) - case `$CC -V 2>&1 | sed 5q` in + case `$CC -V 2>&1 | $SED 5q` in *Sun\ C*) # Sun C++ 5.9 no_undefined_flag_CXX=' -zdefs' @@ -14957,7 +16133,7 @@ fi ld_shlibs_CXX=yes ;; - openbsd* | bitrig*) + openbsd*) if test -f /usr/libexec/ld.so; then hardcode_direct_CXX=yes hardcode_shlibpath_var_CXX=no @@ -15048,7 +16224,7 @@ fi # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "[-]L"' else # FIXME: insert proper C++ library support @@ -15132,7 +16308,7 @@ fi # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "[-]L"' else # g++ 2.7 appears to require '-G' NOT '-shared' on this # platform. @@ -15143,7 +16319,7 @@ fi # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "[-]L"' fi hardcode_libdir_flag_spec_CXX='$wl-R $wl$libdir' @@ -15234,8 +16410,8 @@ fi ;; esac - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs_CXX" >&5 -$as_echo "$ld_shlibs_CXX" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs_CXX" >&5 +printf "%s\n" "$ld_shlibs_CXX" >&6; } test no = "$ld_shlibs_CXX" && can_build_shared=no GCC_CXX=$GXX @@ -15273,7 +16449,7 @@ esac if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; }; then # Parse the compiler output and extract the necessary # objects, libraries and library flags. @@ -15286,10 +16462,11 @@ if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 case $prev$p in -L* | -R* | -l*) - # Some compilers place space between "-{L,R}" and the path. + # Some compilers place space between "-{L,R,l}" and the path. # Remove the space. - if test x-L = "$p" || - test x-R = "$p"; then + if test x-L = x"$p" || + test x-R = x"$p" || + test x-l = x"$p"; then prev=$p continue fi @@ -15456,7 +16633,7 @@ lt_prog_compiler_static_CXX= beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) # PIC is the default for these OSes. ;; - mingw* | cygwin* | os2* | pw32* | cegcc*) + mingw* | windows* | cygwin* | os2* | pw32* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). # Although the cygwin gcc ignores -fPIC, still need this for old-style @@ -15531,7 +16708,7 @@ lt_prog_compiler_static_CXX= ;; esac ;; - mingw* | cygwin* | os2* | pw32* | cegcc*) + mingw* | windows* | cygwin* | os2* | pw32* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). lt_prog_compiler_pic_CXX='-DDLL_EXPORT' @@ -15549,7 +16726,7 @@ lt_prog_compiler_static_CXX= ;; esac ;; - freebsd* | dragonfly*) + freebsd* | dragonfly* | midnightbsd*) # FreeBSD uses GNU C++ ;; hpux9* | hpux10* | hpux11*) @@ -15632,7 +16809,7 @@ lt_prog_compiler_static_CXX= lt_prog_compiler_static_CXX='-qstaticlink' ;; *) - case `$CC -V 2>&1 | sed 5q` in + case `$CC -V 2>&1 | $SED 5q` in *Sun\ C*) # Sun C++ 5.9 lt_prog_compiler_pic_CXX='-KPIC' @@ -15754,26 +16931,28 @@ case $host_os in ;; esac -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 -$as_echo_n "checking for $compiler option to produce PIC... " >&6; } -if ${lt_cv_prog_compiler_pic_CXX+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $compiler option to produce PIC" >&5 +printf %s "checking for $compiler option to produce PIC... " >&6; } +if test ${lt_cv_prog_compiler_pic_CXX+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_pic_CXX=$lt_prog_compiler_pic_CXX fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_CXX" >&5 -$as_echo "$lt_cv_prog_compiler_pic_CXX" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_CXX" >&5 +printf "%s\n" "$lt_cv_prog_compiler_pic_CXX" >&6; } lt_prog_compiler_pic_CXX=$lt_cv_prog_compiler_pic_CXX # # Check to make sure the PIC flag actually works. # if test -n "$lt_prog_compiler_pic_CXX"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works" >&5 -$as_echo_n "checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works... " >&6; } -if ${lt_cv_prog_compiler_pic_works_CXX+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works" >&5 +printf %s "checking if $compiler PIC flag $lt_prog_compiler_pic_CXX works... " >&6; } +if test ${lt_cv_prog_compiler_pic_works_CXX+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_pic_works_CXX=no ac_outfile=conftest.$ac_objext echo "$lt_simple_compile_test_code" > conftest.$ac_ext @@ -15804,8 +16983,8 @@ else $RM conftest* fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works_CXX" >&5 -$as_echo "$lt_cv_prog_compiler_pic_works_CXX" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_pic_works_CXX" >&5 +printf "%s\n" "$lt_cv_prog_compiler_pic_works_CXX" >&6; } if test yes = "$lt_cv_prog_compiler_pic_works_CXX"; then case $lt_prog_compiler_pic_CXX in @@ -15827,11 +17006,12 @@ fi # Check to make sure the static flag actually works. # wl=$lt_prog_compiler_wl_CXX eval lt_tmp_static_flag=\"$lt_prog_compiler_static_CXX\" -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 -$as_echo_n "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } -if ${lt_cv_prog_compiler_static_works_CXX+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler static flag $lt_tmp_static_flag works" >&5 +printf %s "checking if $compiler static flag $lt_tmp_static_flag works... " >&6; } +if test ${lt_cv_prog_compiler_static_works_CXX+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_static_works_CXX=no save_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS $lt_tmp_static_flag" @@ -15855,8 +17035,8 @@ else LDFLAGS=$save_LDFLAGS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works_CXX" >&5 -$as_echo "$lt_cv_prog_compiler_static_works_CXX" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_static_works_CXX" >&5 +printf "%s\n" "$lt_cv_prog_compiler_static_works_CXX" >&6; } if test yes = "$lt_cv_prog_compiler_static_works_CXX"; then : @@ -15867,11 +17047,12 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 -$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } -if ${lt_cv_prog_compiler_c_o_CXX+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +printf %s "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if test ${lt_cv_prog_compiler_c_o_CXX+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_c_o_CXX=no $RM -r conftest 2>/dev/null mkdir conftest @@ -15914,16 +17095,17 @@ else $RM conftest* fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_CXX" >&5 -$as_echo "$lt_cv_prog_compiler_c_o_CXX" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_CXX" >&5 +printf "%s\n" "$lt_cv_prog_compiler_c_o_CXX" >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 -$as_echo_n "checking if $compiler supports -c -o file.$ac_objext... " >&6; } -if ${lt_cv_prog_compiler_c_o_CXX+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if $compiler supports -c -o file.$ac_objext" >&5 +printf %s "checking if $compiler supports -c -o file.$ac_objext... " >&6; } +if test ${lt_cv_prog_compiler_c_o_CXX+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_prog_compiler_c_o_CXX=no $RM -r conftest 2>/dev/null mkdir conftest @@ -15966,8 +17148,8 @@ else $RM conftest* fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_CXX" >&5 -$as_echo "$lt_cv_prog_compiler_c_o_CXX" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_prog_compiler_c_o_CXX" >&5 +printf "%s\n" "$lt_cv_prog_compiler_c_o_CXX" >&6; } @@ -15975,19 +17157,19 @@ $as_echo "$lt_cv_prog_compiler_c_o_CXX" >&6; } hard_links=nottested if test no = "$lt_cv_prog_compiler_c_o_CXX" && test no != "$need_locks"; then # do not overwrite the value of need_locks provided by the user - { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 -$as_echo_n "checking if we can lock with hard links... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking if we can lock with hard links" >&5 +printf %s "checking if we can lock with hard links... " >&6; } hard_links=yes $RM conftest* ln conftest.a conftest.b 2>/dev/null && hard_links=no touch conftest.a ln conftest.a conftest.b 2>&5 || hard_links=no ln conftest.a conftest.b 2>/dev/null && hard_links=no - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 -$as_echo "$hard_links" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $hard_links" >&5 +printf "%s\n" "$hard_links" >&6; } if test no = "$hard_links"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 -$as_echo "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&5 +printf "%s\n" "$as_me: WARNING: '$CC' does not support '-c -o', so 'make -j' may be unsafe" >&2;} need_locks=warn fi else @@ -15996,8 +17178,8 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 -$as_echo_n "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the $compiler linker ($LD) supports shared libraries" >&5 +printf %s "checking whether the $compiler linker ($LD) supports shared libraries... " >&6; } export_symbols_cmds_CXX='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols' exclude_expsyms_CXX='_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*' @@ -16014,15 +17196,15 @@ $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then export_symbols_cmds_CXX='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && (substr(\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' else - export_symbols_cmds_CXX='`func_echo_all $NM | $SED -e '\''s/B\([^B]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && (substr(\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + export_symbols_cmds_CXX='`func_echo_all $NM | $SED -e '\''s/B\([^B]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "L") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && (substr(\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' fi ;; pw32*) export_symbols_cmds_CXX=$ltdll_cmds ;; - cygwin* | mingw* | cegcc*) + cygwin* | mingw* | windows* | cegcc*) case $cc_basename in - cl*) + cl* | icl*) exclude_expsyms_CXX='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' ;; *) @@ -16036,8 +17218,8 @@ $as_echo_n "checking whether the $compiler linker ($LD) supports shared librarie ;; esac -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs_CXX" >&5 -$as_echo "$ld_shlibs_CXX" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ld_shlibs_CXX" >&5 +printf "%s\n" "$ld_shlibs_CXX" >&6; } test no = "$ld_shlibs_CXX" && can_build_shared=no with_gnu_ld_CXX=$with_gnu_ld @@ -16064,18 +17246,19 @@ x|xyes) # Test whether the compiler implicitly links with -lc since on some # systems, -lgcc has to come before -lc. If gcc already passes -lc # to ld, don't add -lc before -lgcc. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 -$as_echo_n "checking whether -lc should be explicitly linked in... " >&6; } -if ${lt_cv_archive_cmds_need_lc_CXX+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether -lc should be explicitly linked in" >&5 +printf %s "checking whether -lc should be explicitly linked in... " >&6; } +if test ${lt_cv_archive_cmds_need_lc_CXX+y} +then : + printf %s "(cached) " >&6 +else $as_nop $RM conftest* echo "$lt_simple_compile_test_code" > conftest.$ac_ext if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5 (eval $ac_compile) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } 2>conftest.err; then soname=conftest lib=conftest @@ -16093,7 +17276,7 @@ else if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$archive_cmds_CXX 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1\""; } >&5 (eval $archive_cmds_CXX 2\>\&1 \| $GREP \" -lc \" \>/dev/null 2\>\&1) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } then lt_cv_archive_cmds_need_lc_CXX=no @@ -16107,8 +17290,8 @@ else $RM conftest* fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc_CXX" >&5 -$as_echo "$lt_cv_archive_cmds_need_lc_CXX" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $lt_cv_archive_cmds_need_lc_CXX" >&5 +printf "%s\n" "$lt_cv_archive_cmds_need_lc_CXX" >&6; } archive_cmds_need_lc_CXX=$lt_cv_archive_cmds_need_lc_CXX ;; esac @@ -16177,8 +17360,8 @@ esac - { $as_echo "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 -$as_echo_n "checking dynamic linker characteristics... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking dynamic linker characteristics" >&5 +printf %s "checking dynamic linker characteristics... " >&6; } library_names_spec= libname_spec='lib$name' @@ -16247,7 +17430,7 @@ aix[4-9]*) # Unfortunately, runtime linking may impact performance, so we do # not want this to be the default eventually. Also, we use the # versioned .so libs for executables only if there is the -brtl - # linker flag in LDFLAGS as well, or --with-aix-soname=svr4 only. + # linker flag in LDFLAGS as well, or --enable-aix-soname=svr4 only. # To allow for filename-based versioning support, we need to create # libNAME.so.V as an archive file, containing: # *) an Import File, referring to the versioned filename of the @@ -16341,7 +17524,7 @@ bsdi[45]*) # libtool to hard-code these into programs ;; -cygwin* | mingw* | pw32* | cegcc*) +cygwin* | mingw* | windows* | pw32* | cegcc*) version_type=windows shrext_cmds=.dll need_version=no @@ -16352,6 +17535,19 @@ cygwin* | mingw* | pw32* | cegcc*) # gcc library_names_spec='$libname.dll.a' # DLL is installed to $(libdir)/../bin by postinstall_cmds + # If user builds GCC with mulitlibs enabled, + # it should just install on $(libdir) + # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones. + if test yes = $multilib; then + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + $install_prog $dir/$dlname $destdir/$dlname~ + chmod a+x $destdir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib $destdir/$dlname'\'' || exit \$?; + fi' + else postinstall_cmds='base_file=`basename \$file`~ dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ dldir=$destdir/`dirname \$dlpath`~ @@ -16361,6 +17557,7 @@ cygwin* | mingw* | pw32* | cegcc*) if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; fi' + fi postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ dlpath=$dir/\$dldll~ $RM \$dlpath' @@ -16369,29 +17566,29 @@ cygwin* | mingw* | pw32* | cegcc*) case $host_os in cygwin*) # Cygwin DLLs use 'cyg' prefix rather than 'lib' - soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + soname_spec='`echo $libname | $SED -e 's/^lib/cyg/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' ;; - mingw* | cegcc*) + mingw* | windows* | cegcc*) # MinGW DLLs use traditional 'lib' prefix soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' ;; pw32*) # pw32 DLLs use 'pw' prefix rather than 'lib' - library_names_spec='`echo $libname | sed -e 's/^lib/pw/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' + library_names_spec='`echo $libname | $SED -e 's/^lib/pw/'``echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' ;; esac dynamic_linker='Win32 ld.exe' ;; - *,cl*) - # Native MSVC + *,cl* | *,icl*) + # Native MSVC or ICC libname_spec='$name' soname_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext' library_names_spec='$libname.dll.lib' case $build_os in - mingw*) + mingw* | windows*) sys_lib_search_path_spec= lt_save_ifs=$IFS IFS=';' @@ -16404,7 +17601,7 @@ cygwin* | mingw* | pw32* | cegcc*) done IFS=$lt_save_ifs # Convert to MSYS style. - sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([a-zA-Z]\\):| /\\1|g' -e 's|^ ||'` + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's|\\\\|/|g' -e 's| \\([a-zA-Z]\\):| /\\1|g' -e 's|^ ||'` ;; cygwin*) # Convert to unix form, then to dos form, then back to unix form @@ -16441,7 +17638,7 @@ cygwin* | mingw* | pw32* | cegcc*) ;; *) - # Assume MSVC wrapper + # Assume MSVC and ICC wrapper library_names_spec='$libname`echo $release | $SED -e 's/[.]/-/g'`$versuffix$shared_ext $libname.lib' dynamic_linker='Win32 ld.exe' ;; @@ -16473,7 +17670,7 @@ dgux*) shlibpath_var=LD_LIBRARY_PATH ;; -freebsd* | dragonfly*) +freebsd* | dragonfly* | midnightbsd*) # DragonFly does not have aout. When/if they implement a new # versioning mechanism, adjust this. if test -x /usr/bin/objformat; then @@ -16510,7 +17707,27 @@ freebsd* | dragonfly*) need_version=no ;; esac + case $host_cpu in + powerpc64) + # On FreeBSD bi-arch platforms, a different variable is used for 32-bit + # binaries. See <https://man.freebsd.org/cgi/man.cgi?query=ld.so>. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +int test_pointer_size[sizeof (void *) - 5]; + +_ACEOF +if ac_fn_cxx_try_compile "$LINENO" +then : shlibpath_var=LD_LIBRARY_PATH +else $as_nop + shlibpath_var=LD_32_LIBRARY_PATH +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + ;; + *) + shlibpath_var=LD_LIBRARY_PATH + ;; + esac case $host_os in freebsd2.*) shlibpath_overrides_runpath=yes @@ -16651,7 +17868,7 @@ linux*android*) version_type=none # Android doesn't support versioned libraries. need_lib_prefix=no need_version=no - library_names_spec='$libname$release$shared_ext' + library_names_spec='$libname$release$shared_ext $libname$shared_ext' soname_spec='$libname$release$shared_ext' finish_cmds= shlibpath_var=LD_LIBRARY_PATH @@ -16663,8 +17880,9 @@ linux*android*) hardcode_into_libs=yes dynamic_linker='Android linker' - # Don't embed -rpath directories since the linker doesn't support them. - hardcode_libdir_flag_spec_CXX='-L$libdir' + # -rpath works at least for libraries that are not overridden by + # libraries installed in system locations. + hardcode_libdir_flag_spec_CXX='$wl-rpath $wl$libdir' ;; # This must be glibc/ELF. @@ -16679,9 +17897,10 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) shlibpath_overrides_runpath=no # Some binutils ld are patched to set DT_RUNPATH - if ${lt_cv_shlibpath_overrides_runpath+:} false; then : - $as_echo_n "(cached) " >&6 -else + if test ${lt_cv_shlibpath_overrides_runpath+y} +then : + printf %s "(cached) " >&6 +else $as_nop lt_cv_shlibpath_overrides_runpath=no save_LDFLAGS=$LDFLAGS save_libdir=$libdir @@ -16691,19 +17910,21 @@ else /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_cxx_try_link "$LINENO"; then : - if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null; then : +if ac_fn_cxx_try_link "$LINENO" +then : + if ($OBJDUMP -p conftest$ac_exeext) 2>/dev/null | grep "RUNPATH.*$libdir" >/dev/null +then : lt_cv_shlibpath_overrides_runpath=yes fi fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LDFLAGS=$save_LDFLAGS libdir=$save_libdir @@ -16717,7 +17938,7 @@ fi # before this can be enabled. hardcode_into_libs=yes - # Ideally, we could use ldconfig to report *all* directores which are + # Ideally, we could use ldconfig to report *all* directories which are # searched for libraries, however this is still not possible. Aside from not # being certain /sbin/ldconfig is available, command # 'ldconfig -N -X -v | grep ^/' on 64bit Fedora does not report /usr/lib64, @@ -16774,7 +17995,7 @@ newsos6) dynamic_linker='ldqnx.so' ;; -openbsd* | bitrig*) +openbsd*) version_type=sunos sys_lib_dlsearch_path_spec=/usr/lib need_lib_prefix=no @@ -16935,8 +18156,8 @@ uts4*) dynamic_linker=no ;; esac -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 -$as_echo "$dynamic_linker" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $dynamic_linker" >&5 +printf "%s\n" "$dynamic_linker" >&6; } test no = "$dynamic_linker" && can_build_shared=no variables_saved_for_relink="PATH $shlibpath_var $runpath_var" @@ -17000,8 +18221,8 @@ configure_time_lt_sys_library_path=$LT_SYS_LIBRARY_PATH - { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 -$as_echo_n "checking how to hardcode library paths into programs... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking how to hardcode library paths into programs" >&5 +printf %s "checking how to hardcode library paths into programs... " >&6; } hardcode_action_CXX= if test -n "$hardcode_libdir_flag_spec_CXX" || test -n "$runpath_var_CXX" || @@ -17025,8 +18246,8 @@ else # directories. hardcode_action_CXX=unsupported fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $hardcode_action_CXX" >&5 -$as_echo "$hardcode_action_CXX" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $hardcode_action_CXX" >&5 +printf "%s\n" "$hardcode_action_CXX" >&6; } if test relink = "$hardcode_action_CXX" || test yes = "$inherit_rpath_CXX"; then @@ -17066,18 +18287,20 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu -if test "$GCC" = yes; then : +if test "$GCC" = yes +then : for flag in -Wall -Wextra; do - as_CACHEVAR=`$as_echo "ax_cv_check_cxxflags__$flag" | $as_tr_sh` -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C++ compiler accepts $flag" >&5 -$as_echo_n "checking whether C++ compiler accepts $flag... " >&6; } -if eval \${$as_CACHEVAR+:} false; then : - $as_echo_n "(cached) " >&6 -else + as_CACHEVAR=`printf "%s\n" "ax_cv_check_cxxflags__$flag" | $as_tr_sh` +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C++ compiler accepts $flag" >&5 +printf %s "checking whether C++ compiler accepts $flag... " >&6; } +if eval test \${$as_CACHEVAR+y} +then : + printf %s "(cached) " >&6 +else $as_nop ax_check_save_flags=$CXXFLAGS CXXFLAGS="$CXXFLAGS -Werror $flag" @@ -17085,51 +18308,54 @@ else /* end confdefs.h. */ int main(void) { return 0; } _ACEOF -if ac_fn_cxx_try_compile "$LINENO"; then : +if ac_fn_cxx_try_compile "$LINENO" +then : eval "$as_CACHEVAR=yes" -else +else $as_nop eval "$as_CACHEVAR=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext CXXFLAGS=$ax_check_save_flags fi eval ac_res=\$$as_CACHEVAR - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -if eval test \"x\$"$as_CACHEVAR"\" = x"yes"; then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } +if eval test \"x\$"$as_CACHEVAR"\" = x"yes" +then : -if ${AM_CXXFLAGS+:} false; then : +if test ${AM_CXXFLAGS+y} +then : case " $AM_CXXFLAGS " in #( *" $flag "*) : - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS already contains \$flag"; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS already contains \$flag"; } >&5 (: AM_CXXFLAGS already contains $flag) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; #( *) : as_fn_append AM_CXXFLAGS " $flag" - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS=\"\$AM_CXXFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS=\"\$AM_CXXFLAGS\""; } >&5 (: AM_CXXFLAGS="$AM_CXXFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; esac -else +else $as_nop AM_CXXFLAGS=$flag - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS=\"\$AM_CXXFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS=\"\$AM_CXXFLAGS\""; } >&5 (: AM_CXXFLAGS="$AM_CXXFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } fi -else +else $as_nop : fi @@ -17140,12 +18366,13 @@ done for flag in -fexceptions; do - as_CACHEVAR=`$as_echo "ax_cv_check_cxxflags__$flag" | $as_tr_sh` -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C++ compiler accepts $flag" >&5 -$as_echo_n "checking whether C++ compiler accepts $flag... " >&6; } -if eval \${$as_CACHEVAR+:} false; then : - $as_echo_n "(cached) " >&6 -else + as_CACHEVAR=`printf "%s\n" "ax_cv_check_cxxflags__$flag" | $as_tr_sh` +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C++ compiler accepts $flag" >&5 +printf %s "checking whether C++ compiler accepts $flag... " >&6; } +if eval test \${$as_CACHEVAR+y} +then : + printf %s "(cached) " >&6 +else $as_nop ax_check_save_flags=$CXXFLAGS CXXFLAGS="$CXXFLAGS -Werror $flag" @@ -17153,51 +18380,54 @@ else /* end confdefs.h. */ int main(void) { return 0; } _ACEOF -if ac_fn_cxx_try_compile "$LINENO"; then : +if ac_fn_cxx_try_compile "$LINENO" +then : eval "$as_CACHEVAR=yes" -else +else $as_nop eval "$as_CACHEVAR=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext CXXFLAGS=$ax_check_save_flags fi eval ac_res=\$$as_CACHEVAR - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -if eval test \"x\$"$as_CACHEVAR"\" = x"yes"; then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } +if eval test \"x\$"$as_CACHEVAR"\" = x"yes" +then : -if ${AM_CXXFLAGS+:} false; then : +if test ${AM_CXXFLAGS+y} +then : case " $AM_CXXFLAGS " in #( *" $flag "*) : - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS already contains \$flag"; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS already contains \$flag"; } >&5 (: AM_CXXFLAGS already contains $flag) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; #( *) : as_fn_append AM_CXXFLAGS " $flag" - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS=\"\$AM_CXXFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS=\"\$AM_CXXFLAGS\""; } >&5 (: AM_CXXFLAGS="$AM_CXXFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; esac -else +else $as_nop AM_CXXFLAGS=$flag - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS=\"\$AM_CXXFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS=\"\$AM_CXXFLAGS\""; } >&5 (: AM_CXXFLAGS="$AM_CXXFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } fi -else +else $as_nop : fi @@ -17208,12 +18438,13 @@ done for flag in -fno-strict-aliasing; do - as_CACHEVAR=`$as_echo "ax_cv_check_cxxflags__$flag" | $as_tr_sh` -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C++ compiler accepts $flag" >&5 -$as_echo_n "checking whether C++ compiler accepts $flag... " >&6; } -if eval \${$as_CACHEVAR+:} false; then : - $as_echo_n "(cached) " >&6 -else + as_CACHEVAR=`printf "%s\n" "ax_cv_check_cxxflags__$flag" | $as_tr_sh` +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether C++ compiler accepts $flag" >&5 +printf %s "checking whether C++ compiler accepts $flag... " >&6; } +if eval test \${$as_CACHEVAR+y} +then : + printf %s "(cached) " >&6 +else $as_nop ax_check_save_flags=$CXXFLAGS CXXFLAGS="$CXXFLAGS -Werror $flag" @@ -17221,51 +18452,54 @@ else /* end confdefs.h. */ int main(void) { return 0; } _ACEOF -if ac_fn_cxx_try_compile "$LINENO"; then : +if ac_fn_cxx_try_compile "$LINENO" +then : eval "$as_CACHEVAR=yes" -else +else $as_nop eval "$as_CACHEVAR=no" fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext CXXFLAGS=$ax_check_save_flags fi eval ac_res=\$$as_CACHEVAR - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -if eval test \"x\$"$as_CACHEVAR"\" = x"yes"; then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } +if eval test \"x\$"$as_CACHEVAR"\" = x"yes" +then : -if ${AM_CXXFLAGS+:} false; then : +if test ${AM_CXXFLAGS+y} +then : case " $AM_CXXFLAGS " in #( *" $flag "*) : - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS already contains \$flag"; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS already contains \$flag"; } >&5 (: AM_CXXFLAGS already contains $flag) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; #( *) : as_fn_append AM_CXXFLAGS " $flag" - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS=\"\$AM_CXXFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS=\"\$AM_CXXFLAGS\""; } >&5 (: AM_CXXFLAGS="$AM_CXXFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; esac -else +else $as_nop AM_CXXFLAGS=$flag - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS=\"\$AM_CXXFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CXXFLAGS=\"\$AM_CXXFLAGS\""; } >&5 (: AM_CXXFLAGS="$AM_CXXFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } fi -else +else $as_nop : fi @@ -17279,18 +18513,20 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $ ac_compiler_gnu=$ac_cv_c_compiler_gnu -if test "$GCC" = yes; then : +if test "$GCC" = yes +then : for flag in -fno-strict-aliasing; do - as_CACHEVAR=`$as_echo "ax_cv_check_ldflags__$flag" | $as_tr_sh` -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the linker accepts $flag" >&5 -$as_echo_n "checking whether the linker accepts $flag... " >&6; } -if eval \${$as_CACHEVAR+:} false; then : - $as_echo_n "(cached) " >&6 -else + as_CACHEVAR=`printf "%s\n" "ax_cv_check_ldflags__$flag" | $as_tr_sh` +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the linker accepts $flag" >&5 +printf %s "checking whether the linker accepts $flag... " >&6; } +if eval test \${$as_CACHEVAR+y} +then : + printf %s "(cached) " >&6 +else $as_nop ax_check_save_flags=$LDFLAGS LDFLAGS="$LDFLAGS $flag" @@ -17298,59 +18534,62 @@ else /* end confdefs.h. */ int -main () +main (void) { ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : eval "$as_CACHEVAR=yes" -else +else $as_nop eval "$as_CACHEVAR=no" fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LDFLAGS=$ax_check_save_flags fi eval ac_res=\$$as_CACHEVAR - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 -$as_echo "$ac_res" >&6; } -if eval test \"x\$"$as_CACHEVAR"\" = x"yes"; then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } +if eval test \"x\$"$as_CACHEVAR"\" = x"yes" +then : -if ${AM_LDFLAGS+:} false; then : +if test ${AM_LDFLAGS+y} +then : case " $AM_LDFLAGS " in #( *" $flag "*) : - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_LDFLAGS already contains \$flag"; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_LDFLAGS already contains \$flag"; } >&5 (: AM_LDFLAGS already contains $flag) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; #( *) : as_fn_append AM_LDFLAGS " $flag" - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_LDFLAGS=\"\$AM_LDFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_LDFLAGS=\"\$AM_LDFLAGS\""; } >&5 (: AM_LDFLAGS="$AM_LDFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; esac -else +else $as_nop AM_LDFLAGS=$flag - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_LDFLAGS=\"\$AM_LDFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_LDFLAGS=\"\$AM_LDFLAGS\""; } >&5 (: AM_LDFLAGS="$AM_LDFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } fi -else +else $as_nop : fi @@ -17370,11 +18609,12 @@ esac ;; #( ;; esac -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether compiler supports visibility" >&5 -$as_echo_n "checking whether compiler supports visibility... " >&6; } -if ${expatcfg_cv_compiler_supports_visibility+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether compiler supports visibility" >&5 +printf %s "checking whether compiler supports visibility... " >&6; } +if test ${expatcfg_cv_compiler_supports_visibility+y} +then : + printf %s "(cached) " >&6 +else $as_nop expatcfg_cv_compiler_supports_visibility=no OLDFLAGS=$CFLAGS as_fn_append CFLAGS " -fvisibility=hidden -Wall -Werror -Wno-unknown-warning-option" @@ -17385,201 +18625,96 @@ else void foo(void) {} _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : expatcfg_cv_compiler_supports_visibility=yes fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext CFLAGS=$OLDFLAGS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $expatcfg_cv_compiler_supports_visibility" >&5 -$as_echo "$expatcfg_cv_compiler_supports_visibility" >&6; } - if test "$expatcfg_cv_compiler_supports_visibility" = yes; then : +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $expatcfg_cv_compiler_supports_visibility" >&5 +printf "%s\n" "$expatcfg_cv_compiler_supports_visibility" >&6; } + if test "$expatcfg_cv_compiler_supports_visibility" = yes +then : -if ${AM_CFLAGS+:} false; then : +if test ${AM_CFLAGS+y} +then : case " $AM_CFLAGS " in #( *" -fvisibility=hidden "*) : - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS already contains -fvisibility=hidden"; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS already contains -fvisibility=hidden"; } >&5 (: AM_CFLAGS already contains -fvisibility=hidden) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; #( *) : as_fn_append AM_CFLAGS " -fvisibility=hidden" - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 (: AM_CFLAGS="$AM_CFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; esac -else +else $as_nop AM_CFLAGS=-fvisibility=hidden - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CFLAGS=\"\$AM_CFLAGS\""; } >&5 (: AM_CFLAGS="$AM_CFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } fi + if test "${enable_shared}" = yes +then : -if ${AM_CPPFLAGS+:} false; then : +if test ${AM_CPPFLAGS+y} +then : case " $AM_CPPFLAGS " in #( *" -DXML_ENABLE_VISIBILITY=1 "*) : - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CPPFLAGS already contains -DXML_ENABLE_VISIBILITY=1"; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CPPFLAGS already contains -DXML_ENABLE_VISIBILITY=1"; } >&5 (: AM_CPPFLAGS already contains -DXML_ENABLE_VISIBILITY=1) 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; #( *) : as_fn_append AM_CPPFLAGS " -DXML_ENABLE_VISIBILITY=1" - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CPPFLAGS=\"\$AM_CPPFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CPPFLAGS=\"\$AM_CPPFLAGS\""; } >&5 (: AM_CPPFLAGS="$AM_CPPFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } ;; esac -else +else $as_nop AM_CPPFLAGS=-DXML_ENABLE_VISIBILITY=1 - { { $as_echo "$as_me:${as_lineno-$LINENO}: : AM_CPPFLAGS=\"\$AM_CPPFLAGS\""; } >&5 + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: : AM_CPPFLAGS=\"\$AM_CPPFLAGS\""; } >&5 (: AM_CPPFLAGS="$AM_CPPFLAGS") 2>&5 ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } fi fi - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ANSI C header files" >&5 -$as_echo_n "checking for ANSI C header files... " >&6; } -if ${ac_cv_header_stdc+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include <stdlib.h> -#include <stdarg.h> -#include <string.h> -#include <float.h> - -int -main () -{ - - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_header_stdc=yes -else - ac_cv_header_stdc=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -if test $ac_cv_header_stdc = yes; then - # SunOS 4.x string.h does not declare mem*, contrary to ANSI. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include <string.h> - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "memchr" >/dev/null 2>&1; then : - -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include <stdlib.h> - -_ACEOF -if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | - $EGREP "free" >/dev/null 2>&1; then : - -else - ac_cv_header_stdc=no -fi -rm -f conftest* - -fi - -if test $ac_cv_header_stdc = yes; then - # /bin/cc in Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. - if test "$cross_compiling" = yes; then : - : -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include <ctype.h> -#include <stdlib.h> -#if ((' ' & 0x0FF) == 0x020) -# define ISLOWER(c) ('a' <= (c) && (c) <= 'z') -# define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) -#else -# define ISLOWER(c) \ - (('a' <= (c) && (c) <= 'i') \ - || ('j' <= (c) && (c) <= 'r') \ - || ('s' <= (c) && (c) <= 'z')) -# define TOUPPER(c) (ISLOWER(c) ? ((c) | 0x40) : (c)) -#endif - -#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) -int -main () -{ - int i; - for (i = 0; i < 256; i++) - if (XOR (islower (i), ISLOWER (i)) - || toupper (i) != TOUPPER (i)) - return 2; - return 0; -} -_ACEOF -if ac_fn_c_try_run "$LINENO"; then : - -else - ac_cv_header_stdc=no -fi -rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ - conftest.$ac_objext conftest.beam conftest.$ac_ext -fi - -fi -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_header_stdc" >&5 -$as_echo "$ac_cv_header_stdc" >&6; } -if test $ac_cv_header_stdc = yes; then - -$as_echo "#define STDC_HEADERS 1" >>confdefs.h - fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5 -$as_echo_n "checking whether byte ordering is bigendian... " >&6; } -if ${ac_cv_c_bigendian+:} false; then : - $as_echo_n "(cached) " >&6 -else + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5 +printf %s "checking whether byte ordering is bigendian... " >&6; } +if test ${ac_cv_c_bigendian+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_cv_c_bigendian=unknown # See if we're dealing with a universal compiler. cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -17590,7 +18725,8 @@ else typedef int dummy; _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : # Check for potential -arch flags. It is not universal unless # there are at least two -arch flags with different values. @@ -17614,7 +18750,7 @@ if ac_fn_c_try_compile "$LINENO"; then : fi done fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext if test $ac_cv_c_bigendian = unknown; then # See if sys/param.h defines the BYTE_ORDER macro. cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -17623,7 +18759,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext #include <sys/param.h> int -main () +main (void) { #if ! (defined BYTE_ORDER && defined BIG_ENDIAN \ && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \ @@ -17635,7 +18771,8 @@ main () return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : # It does; now see whether it defined to BIG_ENDIAN or not. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -17643,7 +18780,7 @@ if ac_fn_c_try_compile "$LINENO"; then : #include <sys/param.h> int -main () +main (void) { #if BYTE_ORDER != BIG_ENDIAN not big endian @@ -17653,14 +18790,15 @@ main () return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_cv_c_bigendian=yes -else +else $as_nop ac_cv_c_bigendian=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi if test $ac_cv_c_bigendian = unknown; then # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris). @@ -17669,7 +18807,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext #include <limits.h> int -main () +main (void) { #if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN) bogus endian macros @@ -17679,14 +18817,15 @@ main () return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : # It does; now see whether it defined to _BIG_ENDIAN or not. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include <limits.h> int -main () +main (void) { #ifndef _BIG_ENDIAN not big endian @@ -17696,50 +18835,54 @@ main () return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_cv_c_bigendian=yes -else +else $as_nop ac_cv_c_bigendian=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi if test $ac_cv_c_bigendian = unknown; then # Compile a test program. - if test "$cross_compiling" = yes; then : + if test "$cross_compiling" = yes +then : # Try to guess by grepping values from an object file. cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -short int ascii_mm[] = +unsigned short int ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 }; - short int ascii_ii[] = + unsigned short int ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 }; int use_ascii (int i) { return ascii_mm[i] + ascii_ii[i]; } - short int ebcdic_ii[] = + unsigned short int ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 }; - short int ebcdic_mm[] = + unsigned short int ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 }; int use_ebcdic (int i) { return ebcdic_mm[i] + ebcdic_ii[i]; } - extern int foo; - -int -main () -{ -return use_ascii (foo) == use_ebcdic (foo); - ; - return 0; -} + int + main (int argc, char **argv) + { + /* Intimidate the compiler so that it does not + optimize the arrays away. */ + char *p = argv[0]; + ascii_mm[1] = *p++; ebcdic_mm[1] = *p++; + ascii_ii[1] = *p++; ebcdic_ii[1] = *p++; + return use_ascii (argc) == use_ebcdic (*p); + } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then +if ac_fn_c_try_link "$LINENO" +then : + if grep BIGenDianSyS conftest$ac_exeext >/dev/null; then ac_cv_c_bigendian=yes fi - if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then + if grep LiTTleEnDian conftest$ac_exeext >/dev/null ; then if test "$ac_cv_c_bigendian" = unknown; then ac_cv_c_bigendian=no else @@ -17748,13 +18891,14 @@ if ac_fn_c_try_compile "$LINENO"; then : fi fi fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -else +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default int -main () +main (void) { /* Are we little or big endian? From Harbison&Steele. */ @@ -17770,9 +18914,10 @@ main () return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : ac_cv_c_bigendian=no -else +else $as_nop ac_cv_c_bigendian=yes fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -17781,18 +18926,18 @@ fi fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5 -$as_echo "$ac_cv_c_bigendian" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5 +printf "%s\n" "$ac_cv_c_bigendian" >&6; } case $ac_cv_c_bigendian in #( yes) - $as_echo "#define WORDS_BIGENDIAN 1" >>confdefs.h + printf "%s\n" "#define WORDS_BIGENDIAN 1" >>confdefs.h BYTEORDER=4321;; #( no) BYTEORDER=1234 ;; #( universal) -$as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h +printf "%s\n" "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h ;; #( *) @@ -17801,21 +18946,20 @@ $as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h esac -cat >>confdefs.h <<_ACEOF -#define BYTEORDER $BYTEORDER -_ACEOF +printf "%s\n" "#define BYTEORDER $BYTEORDER" >>confdefs.h -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5 -$as_echo_n "checking for an ANSI C-conforming const... " >&6; } -if ${ac_cv_c_const+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for an ANSI C-conforming const" >&5 +printf %s "checking for an ANSI C-conforming const... " >&6; } +if test ${ac_cv_c_const+y} +then : + printf %s "(cached) " >&6 +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ int -main () +main (void) { #ifndef __cplusplus @@ -17828,7 +18972,7 @@ main () /* NEC SVR4.0.2 mips cc rejects this. */ struct point {int x, y;}; static struct point const zero = {0,0}; - /* AIX XL C 1.02.0.0 rejects this. + /* IBM XL C 1.02.0.0 rejects this. It does not let you subtract one const X* pointer from another in an arm of an if-expression whose if-part is not a constant expression */ @@ -17856,7 +19000,7 @@ main () iptr p = 0; ++p; } - { /* AIX XL C 1.02.0.0 rejects this sort of thing, saying + { /* IBM XL C 1.02.0.0 rejects this sort of thing, saying "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ struct s { int j; const int *ap[3]; } bx; struct s *b = &bx; b->j = 5; @@ -17872,38 +19016,29 @@ main () return 0; } _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : +if ac_fn_c_try_compile "$LINENO" +then : ac_cv_c_const=yes -else +else $as_nop ac_cv_c_const=no fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5 -$as_echo "$ac_cv_c_const" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_const" >&5 +printf "%s\n" "$ac_cv_c_const" >&6; } if test $ac_cv_c_const = no; then -$as_echo "#define const /**/" >>confdefs.h - -fi - -ac_fn_c_check_type "$LINENO" "size_t" "ac_cv_type_size_t" "$ac_includes_default" -if test "x$ac_cv_type_size_t" = xyes; then : - -else - -cat >>confdefs.h <<_ACEOF -#define size_t unsigned int -_ACEOF +printf "%s\n" "#define const /**/" >>confdefs.h fi # Check whether --with-xmlwf was given. -if test "${with_xmlwf+set}" = set; then : +if test ${with_xmlwf+y} +then : withval=$with_xmlwf; -else +else $as_nop with_xmlwf=yes fi @@ -17918,9 +19053,10 @@ fi # Check whether --with-examples was given. -if test "${with_examples+set}" = set; then : +if test ${with_examples+y} +then : withval=$with_examples; -else +else $as_nop with_examples=yes fi @@ -17935,9 +19071,10 @@ fi # Check whether --with-tests was given. -if test "${with_tests+set}" = set; then : +if test ${with_tests+y} +then : withval=$with_tests; -else +else $as_nop with_tests=yes fi @@ -17950,13 +19087,389 @@ else fi +if test x${with_tests} = xyes +then : + ax_cxx_compile_alternatives="11 0x" ax_cxx_compile_cxx11_required=true + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + ac_success=no + + + + + + if test x$ac_success = xno; then + for alternative in ${ax_cxx_compile_alternatives}; do + for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}" MSVC; do + if test x"$switch" = xMSVC; then + switch=-std:c++${alternative} + cachevar=`printf "%s\n" "ax_cv_cxx_compile_cxx11_${switch}_MSVC" | $as_tr_sh` + else + cachevar=`printf "%s\n" "ax_cv_cxx_compile_cxx11_$switch" | $as_tr_sh` + fi + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether $CXX supports C++11 features with $switch" >&5 +printf %s "checking whether $CXX supports C++11 features with $switch... " >&6; } +if eval test \${$cachevar+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_save_CXX="$CXX" + CXX="$CXX $switch" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + +// If the compiler admits that it is not ready for C++11, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +// MSVC always sets __cplusplus to 199711L in older versions; newer versions +// only set it correctly if /Zc:__cplusplus is specified as well as a +// /std:c++NN switch: +// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/ +#elif __cplusplus < 201103L && !defined _MSC_VER + +#error "This is not a C++11 compiler" + +#else + +namespace cxx11 +{ + + namespace test_static_assert + { + + template <typename T> + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + } + + namespace test_final_override + { + + struct Base + { + virtual ~Base() {} + virtual void f() {} + }; + + struct Derived : public Base + { + virtual ~Derived() override {} + virtual void f() override {} + }; + + } + + namespace test_double_right_angle_brackets + { + + template < typename T > + struct check {}; + + typedef check<void> single_type; + typedef check<check<void>> double_type; + typedef check<check<check<void>>> triple_type; + typedef check<check<check<check<void>>>> quadruple_type; + + } + + namespace test_decltype + { + + int + f() + { + int a = 1; + decltype(a) b = 2; + return a + b; + } + + } + + namespace test_type_deduction + { + + template < typename T1, typename T2 > + struct is_same + { + static const bool value = false; + }; + + template < typename T > + struct is_same<T, T> + { + static const bool value = true; + }; + + template < typename T1, typename T2 > + auto + add(T1 a1, T2 a2) -> decltype(a1 + a2) + { + return a1 + a2; + } + + int + test(const int c, volatile int v) + { + static_assert(is_same<int, decltype(0)>::value == true, ""); + static_assert(is_same<int, decltype(c)>::value == false, ""); + static_assert(is_same<int, decltype(v)>::value == false, ""); + auto ac = c; + auto av = v; + auto sumi = ac + av + 'x'; + auto sumf = ac + av + 1.0; + static_assert(is_same<int, decltype(ac)>::value == true, ""); + static_assert(is_same<int, decltype(av)>::value == true, ""); + static_assert(is_same<int, decltype(sumi)>::value == true, ""); + static_assert(is_same<int, decltype(sumf)>::value == false, ""); + static_assert(is_same<int, decltype(add(c, v))>::value == true, ""); + return (sumf > 0.0) ? sumi : add(c, v); + } + + } + + namespace test_noexcept + { + + int f() { return 0; } + int g() noexcept { return 0; } + + static_assert(noexcept(f()) == false, ""); + static_assert(noexcept(g()) == true, ""); + + } + + namespace test_constexpr + { + + template < typename CharT > + unsigned long constexpr + strlen_c_r(const CharT *const s, const unsigned long acc) noexcept + { + return *s ? strlen_c_r(s + 1, acc + 1) : acc; + } + + template < typename CharT > + unsigned long constexpr + strlen_c(const CharT *const s) noexcept + { + return strlen_c_r(s, 0UL); + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("1") == 1UL, ""); + static_assert(strlen_c("example") == 7UL, ""); + static_assert(strlen_c("another\0example") == 7UL, ""); + + } + + namespace test_rvalue_references + { + + template < int N > + struct answer + { + static constexpr int value = N; + }; + + answer<1> f(int&) { return answer<1>(); } + answer<2> f(const int&) { return answer<2>(); } + answer<3> f(int&&) { return answer<3>(); } + + void + test() + { + int i = 0; + const int c = 0; + static_assert(decltype(f(i))::value == 1, ""); + static_assert(decltype(f(c))::value == 2, ""); + static_assert(decltype(f(0))::value == 3, ""); + } + + } + + namespace test_uniform_initialization + { + + struct test + { + static const int zero {}; + static const int one {1}; + }; + + static_assert(test::zero == 0, ""); + static_assert(test::one == 1, ""); + + } + + namespace test_lambdas + { + + void + test1() + { + auto lambda1 = [](){}; + auto lambda2 = lambda1; + lambda1(); + lambda2(); + } + + int + test2() + { + auto a = [](int i, int j){ return i + j; }(1, 2); + auto b = []() -> int { return '0'; }(); + auto c = [=](){ return a + b; }(); + auto d = [&](){ return c; }(); + auto e = [a, &b](int x) mutable { + const auto identity = [](int y){ return y; }; + for (auto i = 0; i < a; ++i) + a += b--; + return x + identity(a + b); + }(0); + return a + b + c + d + e; + } + + int + test3() + { + const auto nullary = [](){ return 0; }; + const auto unary = [](int x){ return x; }; + using nullary_t = decltype(nullary); + using unary_t = decltype(unary); + const auto higher1st = [](nullary_t f){ return f(); }; + const auto higher2nd = [unary](nullary_t f1){ + return [unary, f1](unary_t f2){ return f2(unary(f1())); }; + }; + return higher1st(nullary) + higher2nd(nullary)(unary); + } + + } + + namespace test_variadic_templates + { + + template <int...> + struct sum; + + template <int N0, int... N1toN> + struct sum<N0, N1toN...> + { + static constexpr auto value = N0 + sum<N1toN...>::value; + }; + + template <> + struct sum<> + { + static constexpr auto value = 0; + }; + + static_assert(sum<>::value == 0, ""); + static_assert(sum<1>::value == 1, ""); + static_assert(sum<23>::value == 23, ""); + static_assert(sum<1, 2>::value == 3, ""); + static_assert(sum<5, 5, 11>::value == 21, ""); + static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, ""); + + } + + // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae + // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function + // because of this. + namespace test_template_alias_sfinae + { + + struct foo {}; + + template<typename T> + using member = typename T::member_type; + + template<typename T> + void func(...) {} + + template<typename T> + void func(member<T>*) {} + + void test(); + + void test() { func<foo>(0); } + + } + +} // namespace cxx11 + +#endif // __cplusplus >= 201103L + + + +_ACEOF +if ac_fn_cxx_try_compile "$LINENO" +then : + eval $cachevar=yes +else $as_nop + eval $cachevar=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam conftest.$ac_ext + CXX="$ac_save_CXX" +fi +eval ac_res=\$$cachevar + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +printf "%s\n" "$ac_res" >&6; } + if eval test x\$$cachevar = xyes; then + CXX="$CXX $switch" + if test -n "$CXXCPP" ; then + CXXCPP="$CXXCPP $switch" + fi + ac_success=yes + break + fi + done + if test x$ac_success = xyes; then + break + fi + done + fi + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + if test x$ax_cxx_compile_cxx11_required = xtrue; then + if test x$ac_success = xno; then + as_fn_error $? "*** A compiler with support for C++11 language features is required." "$LINENO" 5 + fi + fi + if test x$ac_success = xno; then + HAVE_CXX11=0 + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: No compiler with C++11 support was found" >&5 +printf "%s\n" "$as_me: No compiler with C++11 support was found" >&6;} + else + HAVE_CXX11=1 + +printf "%s\n" "#define HAVE_CXX11 1" >>confdefs.h + + fi + + +fi EXPATCFG_ON_MINGW=no case "${host_os}" in #( mingw*) : EXPATCFG_ON_MINGW=yes - { $as_echo "$as_me:${as_lineno-$LINENO}: detected OS: MinGW" >&5 -$as_echo "$as_me: detected OS: MinGW" >&6;} ;; #( + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: detected OS: MinGW" >&5 +printf "%s\n" "$as_me: detected OS: MinGW" >&6;} ;; #( *) : ;; esac @@ -17977,22 +19490,199 @@ else UNICODE_FALSE= fi + if echo -- "${CPPFLAGS}${CFLAGS}" | ${FGREP} XML_UNICODE_WCHAR_T >/dev/null; then + _INTERNAL_UNICODE_WCHAR_T_TRUE= + _INTERNAL_UNICODE_WCHAR_T_FALSE='#' +else + _INTERNAL_UNICODE_WCHAR_T_TRUE='#' + _INTERNAL_UNICODE_WCHAR_T_FALSE= +fi + + if echo -- "${CPPFLAGS}${CFLAGS}" | ${FGREP} XML_MIN_SIZE >/dev/null; then + _INTERNAL_MIN_SIZE_TRUE= + _INTERNAL_MIN_SIZE_FALSE='#' +else + _INTERNAL_MIN_SIZE_TRUE='#' + _INTERNAL_MIN_SIZE_FALSE= +fi + + if echo -- "${CPPFLAGS}${CFLAGS}" | ${FGREP} XML_LARGE_SIZE >/dev/null; then + _INTERNAL_LARGE_SIZE_TRUE= + _INTERNAL_LARGE_SIZE_FALSE='#' +else + _INTERNAL_LARGE_SIZE_TRUE='#' + _INTERNAL_LARGE_SIZE_FALSE= +fi + + +LIBM= +case $host in +*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-mingw* | *-*-pw32* | *-*-darwin*) + # These system don't have libm, or don't need it + ;; +*-ncr-sysv4.3*) + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for _mwvalidcheckl in -lmw" >&5 +printf %s "checking for _mwvalidcheckl in -lmw... " >&6; } +if test ${ac_cv_lib_mw__mwvalidcheckl+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_check_lib_save_LIBS=$LIBS +LIBS="-lmw $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. + The 'extern "C"' is for builds by C++ compilers; + although this is not generally supported in C code supporting it here + has little cost and some practical benefit (sr 110532). */ +#ifdef __cplusplus +extern "C" +#endif +char _mwvalidcheckl (void); +int +main (void) +{ +return _mwvalidcheckl (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + ac_cv_lib_mw__mwvalidcheckl=yes +else $as_nop + ac_cv_lib_mw__mwvalidcheckl=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_mw__mwvalidcheckl" >&5 +printf "%s\n" "$ac_cv_lib_mw__mwvalidcheckl" >&6; } +if test "x$ac_cv_lib_mw__mwvalidcheckl" = xyes +then : + LIBM=-lmw +fi + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for cos in -lm" >&5 +printf %s "checking for cos in -lm... " >&6; } +if test ${ac_cv_lib_m_cos+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_check_lib_save_LIBS=$LIBS +LIBS="-lm $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. + The 'extern "C"' is for builds by C++ compilers; + although this is not generally supported in C code supporting it here + has little cost and some practical benefit (sr 110532). */ +#ifdef __cplusplus +extern "C" +#endif +char cos (void); +int +main (void) +{ +return cos (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + ac_cv_lib_m_cos=yes +else $as_nop + ac_cv_lib_m_cos=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_cos" >&5 +printf "%s\n" "$ac_cv_lib_m_cos" >&6; } +if test "x$ac_cv_lib_m_cos" = xyes +then : + LIBM="$LIBM -lm" +fi + + ;; +*) + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for cos in -lm" >&5 +printf %s "checking for cos in -lm... " >&6; } +if test ${ac_cv_lib_m_cos+y} +then : + printf %s "(cached) " >&6 +else $as_nop + ac_check_lib_save_LIBS=$LIBS +LIBS="-lm $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. + The 'extern "C"' is for builds by C++ compilers; + although this is not generally supported in C code supporting it here + has little cost and some practical benefit (sr 110532). */ +#ifdef __cplusplus +extern "C" +#endif +char cos (void); +int +main (void) +{ +return cos (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + ac_cv_lib_m_cos=yes +else $as_nop + ac_cv_lib_m_cos=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_m_cos" >&5 +printf "%s\n" "$ac_cv_lib_m_cos" >&6; } +if test "x$ac_cv_lib_m_cos" = xyes +then : + LIBM=-lm +fi + + ;; +esac + # Check whether --with-libbsd was given. -if test "${with_libbsd+set}" = set; then : +if test ${with_libbsd+y} +then : withval=$with_libbsd; -else +else $as_nop with_libbsd=no fi -if test "x${with_libbsd}" != xno; then : - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for arc4random_buf in -lbsd" >&5 -$as_echo_n "checking for arc4random_buf in -lbsd... " >&6; } -if ${ac_cv_lib_bsd_arc4random_buf+:} false; then : - $as_echo_n "(cached) " >&6 -else +if test "x${with_libbsd}" != xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for arc4random_buf in -lbsd" >&5 +printf %s "checking for arc4random_buf in -lbsd... " >&6; } +if test ${ac_cv_lib_bsd_arc4random_buf+y} +then : + printf %s "(cached) " >&6 +else $as_nop ac_check_lib_save_LIBS=$LIBS LIBS="-lbsd $LIBS" cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -18000,71 +19690,78 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. */ + builtin and then its argument prototype would still apply. + The 'extern "C"' is for builds by C++ compilers; + although this is not generally supported in C code supporting it here + has little cost and some practical benefit (sr 110532). */ #ifdef __cplusplus extern "C" #endif -char arc4random_buf (); +char arc4random_buf (void); int -main () +main (void) { return arc4random_buf (); ; return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : ac_cv_lib_bsd_arc4random_buf=yes -else +else $as_nop ac_cv_lib_bsd_arc4random_buf=no fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext LIBS=$ac_check_lib_save_LIBS fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bsd_arc4random_buf" >&5 -$as_echo "$ac_cv_lib_bsd_arc4random_buf" >&6; } -if test "x$ac_cv_lib_bsd_arc4random_buf" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_LIBBSD 1 -_ACEOF +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_bsd_arc4random_buf" >&5 +printf "%s\n" "$ac_cv_lib_bsd_arc4random_buf" >&6; } +if test "x$ac_cv_lib_bsd_arc4random_buf" = xyes +then : + printf "%s\n" "#define HAVE_LIBBSD 1" >>confdefs.h LIBS="-lbsd $LIBS" -else - if test "x${with_libbsd}" = xyes; then : +else $as_nop + if test "x${with_libbsd}" = xyes +then : as_fn_error $? "Enforced use of libbsd cannot be satisfied." "$LINENO" 5 fi fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for arc4random_buf (BSD or libbsd)" >&5 -$as_echo_n "checking for arc4random_buf (BSD or libbsd)... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for arc4random_buf (BSD, libbsd or glibc 2.36+)" >&5 +printf %s "checking for arc4random_buf (BSD, libbsd or glibc 2.36+)... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - #include <stdlib.h> /* for arc4random_buf on BSD, for NULL */ #if defined(HAVE_LIBBSD) # include <bsd/stdlib.h> + #else + # include <stdlib.h> /* for arc4random_buf on BSD */ #endif - int main() { - arc4random_buf(NULL, 0U); + int main(void) { + char dummy[123]; // double brackets for m4 + arc4random_buf(dummy, 0U); return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : -$as_echo "#define HAVE_ARC4RANDOM_BUF 1" >>confdefs.h +printf "%s\n" "#define HAVE_ARC4RANDOM_BUF 1" >>confdefs.h - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for arc4random (BSD, macOS or libbsd)" >&5 -$as_echo_n "checking for arc4random (BSD, macOS or libbsd)... " >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for arc4random (BSD, macOS, libbsd or glibc 2.36+)" >&5 +printf %s "checking for arc4random (BSD, macOS, libbsd or glibc 2.36+)... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -18073,175 +19770,172 @@ $as_echo_n "checking for arc4random (BSD, macOS or libbsd)... " >&6; } #else # include <stdlib.h> #endif - int main() { + int main(void) { arc4random(); return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : +if ac_fn_c_try_link "$LINENO" +then : -$as_echo "#define HAVE_ARC4RANDOM 1" >>confdefs.h +printf "%s\n" "#define HAVE_ARC4RANDOM 1" >>confdefs.h - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext # Check whether --with-getrandom was given. -if test "${with_getrandom+set}" = set; then : +if test ${with_getrandom+y} +then : withval=$with_getrandom; -else +else $as_nop with_getrandom=check fi -if test "x$with_getrandom" != xno; then : - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getrandom (Linux 3.17+, glibc 2.25+)" >&5 -$as_echo_n "checking for getrandom (Linux 3.17+, glibc 2.25+)... " >&6; } +if test "x$with_getrandom" != xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for getrandom (Linux 3.17+, glibc 2.25+)" >&5 +printf %s "checking for getrandom (Linux 3.17+, glibc 2.25+)... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include <stdlib.h> /* for NULL */ #include <sys/random.h> - int main() { + int main(void) { return getrandom(NULL, 0U, 0U); } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : - -$as_echo "#define HAVE_GETRANDOM 1" >>confdefs.h - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - if test "x$with_getrandom" = xyes; then : +if ac_fn_c_try_link "$LINENO" +then : + +printf "%s\n" "#define HAVE_GETRANDOM 1" >>confdefs.h + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + if test "x$with_getrandom" = xyes +then : as_fn_error $? "enforced the use of getrandom --with-getrandom, but not detected" "$LINENO" 5 fi fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext fi # Check whether --with-sys_getrandom was given. -if test "${with_sys_getrandom+set}" = set; then : +if test ${with_sys_getrandom+y} +then : withval=$with_sys_getrandom; -else +else $as_nop with_sys_getrandom=check fi -if test "x$with_sys_getrandom" != xno; then : - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for syscall SYS_getrandom (Linux 3.17+)" >&5 -$as_echo_n "checking for syscall SYS_getrandom (Linux 3.17+)... " >&6; } +if test "x$with_sys_getrandom" != xno +then : + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for syscall SYS_getrandom (Linux 3.17+)" >&5 +printf %s "checking for syscall SYS_getrandom (Linux 3.17+)... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ + #define _GNU_SOURCE #include <stdlib.h> /* for NULL */ #include <unistd.h> /* for syscall */ #include <sys/syscall.h> /* for SYS_getrandom */ - int main() { + int main(void) { syscall(SYS_getrandom, NULL, 0, 0); return 0; } _ACEOF -if ac_fn_c_try_link "$LINENO"; then : - -$as_echo "#define HAVE_SYSCALL_GETRANDOM 1" >>confdefs.h - - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } -else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } - if test "x$with_sys_getrandom" = xyes; then : +if ac_fn_c_try_link "$LINENO" +then : + +printf "%s\n" "#define HAVE_SYSCALL_GETRANDOM 1" >>confdefs.h + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +printf "%s\n" "yes" >&6; } +else $as_nop + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } + if test "x$with_sys_getrandom" = xyes +then : as_fn_error $? "enforced the use of syscall SYS_getrandom --with-sys-getrandom, but not detected" "$LINENO" 5 fi fi -rm -f core conftest.err conftest.$ac_objext \ +rm -f core conftest.err conftest.$ac_objext conftest.beam \ conftest$ac_exeext conftest.$ac_ext fi -for ac_header in fcntl.h unistd.h -do : - as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" -if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF +ac_fn_c_check_header_compile "$LINENO" "fcntl.h" "ac_cv_header_fcntl_h" "$ac_includes_default" +if test "x$ac_cv_header_fcntl_h" = xyes +then : + printf "%s\n" "#define HAVE_FCNTL_H 1" >>confdefs.h fi +ac_fn_c_check_header_compile "$LINENO" "unistd.h" "ac_cv_header_unistd_h" "$ac_includes_default" +if test "x$ac_cv_header_unistd_h" = xyes +then : + printf "%s\n" "#define HAVE_UNISTD_H 1" >>confdefs.h -done +fi ac_fn_c_check_type "$LINENO" "off_t" "ac_cv_type_off_t" "$ac_includes_default" -if test "x$ac_cv_type_off_t" = xyes; then : +if test "x$ac_cv_type_off_t" = xyes +then : -else +else $as_nop -cat >>confdefs.h <<_ACEOF -#define off_t long int -_ACEOF +printf "%s\n" "#define off_t long int" >>confdefs.h fi - - - for ac_header in $ac_header_list -do : - as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -ac_fn_c_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default -" -if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : - cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 -_ACEOF - -fi - +ac_func= +for ac_item in $ac_func_c_list +do + if test $ac_func; then + ac_fn_c_check_func "$LINENO" $ac_func ac_cv_func_$ac_func + if eval test \"x\$ac_cv_func_$ac_func\" = xyes; then + echo "#define $ac_item 1" >> confdefs.h + fi + ac_func= + else + ac_func=$ac_item + fi done - - - - - - -for ac_func in getpagesize -do : - ac_fn_c_check_func "$LINENO" "getpagesize" "ac_cv_func_getpagesize" -if test "x$ac_cv_func_getpagesize" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_GETPAGESIZE 1 -_ACEOF - -fi -done - -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for working mmap" >&5 -$as_echo_n "checking for working mmap... " >&6; } -if ${ac_cv_func_mmap_fixed_mapped+:} false; then : - $as_echo_n "(cached) " >&6 -else - if test "$cross_compiling" = yes; then : - ac_cv_func_mmap_fixed_mapped=no -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for working mmap" >&5 +printf %s "checking for working mmap... " >&6; } +if test ${ac_cv_func_mmap_fixed_mapped+y} +then : + printf %s "(cached) " >&6 +else $as_nop + if test "$cross_compiling" = yes +then : + case "$host_os" in # (( + # Guess yes on platforms where we know the result. + linux*) ac_cv_func_mmap_fixed_mapped=yes ;; + # If we don't know, assume the worst. + *) ac_cv_func_mmap_fixed_mapped=no ;; + esac +else $as_nop cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ $ac_includes_default @@ -18273,10 +19967,6 @@ $ac_includes_default #include <fcntl.h> #include <sys/mman.h> -#if !defined STDC_HEADERS && !defined HAVE_STDLIB_H -char *malloc (); -#endif - /* This mess was copied from the GNU getpagesize.h. */ #ifndef HAVE_GETPAGESIZE # ifdef _SC_PAGESIZE @@ -18310,7 +20000,7 @@ char *malloc (); #endif /* no HAVE_GETPAGESIZE */ int -main () +main (void) { char *data, *data2, *data3; const char *cdata2; @@ -18378,12 +20068,15 @@ main () if (*(data + i) != *(data3 + i)) return 14; close (fd); + free (data); + free (data3); return 0; } _ACEOF -if ac_fn_c_try_run "$LINENO"; then : +if ac_fn_c_try_run "$LINENO" +then : ac_cv_func_mmap_fixed_mapped=yes -else +else $as_nop ac_cv_func_mmap_fixed_mapped=no fi rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ @@ -18391,84 +20084,96 @@ rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ fi fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_mmap_fixed_mapped" >&5 -$as_echo "$ac_cv_func_mmap_fixed_mapped" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_mmap_fixed_mapped" >&5 +printf "%s\n" "$ac_cv_func_mmap_fixed_mapped" >&6; } if test $ac_cv_func_mmap_fixed_mapped = yes; then -$as_echo "#define HAVE_MMAP 1" >>confdefs.h +printf "%s\n" "#define HAVE_MMAP 1" >>confdefs.h fi rm -f conftest.mmap conftest.txt -if test "$ac_cv_func_mmap_fixed_mapped" = "yes"; then : +if test "$ac_cv_func_mmap_fixed_mapped" = "yes" +then : FILEMAP=unixfilemap -else +else $as_nop FILEMAP=readfilemap fi -$as_echo "#define XML_NS 1" >>confdefs.h +printf "%s\n" "#define XML_NS 1" >>confdefs.h + + +printf "%s\n" "#define XML_GE 1" >>confdefs.h -$as_echo "#define XML_DTD 1" >>confdefs.h +printf "%s\n" "#define XML_DTD 1" >>confdefs.h -$as_echo "#define XML_DEV_URANDOM 1" >>confdefs.h +printf "%s\n" "#define XML_DEV_URANDOM 1" >>confdefs.h # Check whether --enable-xml-attr-info was given. -if test "${enable_xml_attr_info+set}" = set; then : +if test ${enable_xml_attr_info+y} +then : enableval=$enable_xml_attr_info; -else +else $as_nop enable_xml_attr_info=no fi -if test "x${enable_xml_attr_info}" = "xyes"; then : +if test "x${enable_xml_attr_info}" = "xyes" +then : -$as_echo "#define XML_ATTR_INFO 1" >>confdefs.h +printf "%s\n" "#define XML_ATTR_INFO 1" >>confdefs.h fi # Check whether --enable-xml-context was given. -if test "${enable_xml_context+set}" = set; then : +if test ${enable_xml_context+y} +then : enableval=$enable_xml_context; enable_xml_context=${enableval} fi -if test "x${enable_xml_context}" != "xno"; then : +if test "x${enable_xml_context}" != "xno" +then : if test "x${enable_xml_context}" = "xyes" \ - -o "x${enable_xml_context}" = "x"; then : + -o "x${enable_xml_context}" = "x" +then : enable_xml_context=1024 fi +else $as_nop + enable_xml_context=0 +fi -cat >>confdefs.h <<_ACEOF -#define XML_CONTEXT_BYTES ${enable_xml_context} -_ACEOF +printf "%s\n" "#define XML_CONTEXT_BYTES ${enable_xml_context}" >>confdefs.h -fi # Check whether --with-docbook was given. -if test "${with_docbook+set}" = set; then : +if test ${with_docbook+y} +then : withval=$with_docbook; -else +else $as_nop with_docbook=check fi -if test "x$with_docbook" != xno; then : +if test "x$with_docbook" != xno +then : for ac_prog in docbook2x-man db2x_docbook2man docbook2man docbook-to-man do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 -$as_echo_n "checking for $ac_word... " >&6; } -if ${ac_cv_prog_DOCBOOK_TO_MAN+:} false; then : - $as_echo_n "(cached) " >&6 -else +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +printf %s "checking for $ac_word... " >&6; } +if test ${ac_cv_prog_DOCBOOK_TO_MAN+y} +then : + printf %s "(cached) " >&6 +else $as_nop if test -n "$DOCBOOK_TO_MAN"; then ac_cv_prog_DOCBOOK_TO_MAN="$DOCBOOK_TO_MAN" # Let the user override the test. else @@ -18476,11 +20181,15 @@ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac for ac_exec_ext in '' $ac_executable_extensions; do - if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + if as_fn_executable_p "$as_dir$ac_word$ac_exec_ext"; then ac_cv_prog_DOCBOOK_TO_MAN="$ac_prog" - $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: found $as_dir$ac_word$ac_exec_ext" >&5 break 2 fi done @@ -18491,11 +20200,11 @@ fi fi DOCBOOK_TO_MAN=$ac_cv_prog_DOCBOOK_TO_MAN if test -n "$DOCBOOK_TO_MAN"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DOCBOOK_TO_MAN" >&5 -$as_echo "$DOCBOOK_TO_MAN" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $DOCBOOK_TO_MAN" >&5 +printf "%s\n" "$DOCBOOK_TO_MAN" >&6; } else - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 -$as_echo "no" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no" >&5 +printf "%s\n" "no" >&6; } fi @@ -18503,11 +20212,14 @@ fi done fi -if test "x${DOCBOOK_TO_MAN}" = x -a "x$with_docbook" = xyes; then : +if test "x${DOCBOOK_TO_MAN}" = x -a "x$with_docbook" = xyes +then : as_fn_error $? "Required program 'docbook2x-man' not found." "$LINENO" 5 fi -if test "x${DOCBOOK_TO_MAN}" != x -a "x$with_docbook" != xno; then : - if ${DOCBOOK_TO_MAN} --help | grep -i -q -F sgmlbase; then : +if test "x${DOCBOOK_TO_MAN}" != x -a "x$with_docbook" != xno +then : + if ${DOCBOOK_TO_MAN} --help | grep -i -q -F sgmlbase +then : as_fn_error $? "Your local ${DOCBOOK_TO_MAN} was found to work with SGML rather than XML. Please install docbook2X and use variable DOCBOOK_TO_MAN to point configure to command docbook2x-man of docbook2X. @@ -18517,24 +20229,188 @@ if test "x${DOCBOOK_TO_MAN}" != x -a "x$with_docbook" != xno; then : fi fi - if test "x${DOCBOOK_TO_MAN}" != x; then - WITH_DOCBOOK_TRUE= - WITH_DOCBOOK_FALSE='#' +if test -f "${srcdir}"/doc/xmlwf.1 +then : + if true; then + WITH_MANPAGE_TRUE= + WITH_MANPAGE_FALSE='#' +else + WITH_MANPAGE_TRUE='#' + WITH_MANPAGE_FALSE= +fi + + if test "x$with_docbook" = xno -o "x${DOCBOOK_TO_MAN}" = x +then : + if true; then + WITH_PREBUILT_MANPAGE_TRUE= + WITH_PREBUILT_MANPAGE_FALSE='#' +else + WITH_PREBUILT_MANPAGE_TRUE='#' + WITH_PREBUILT_MANPAGE_FALSE= +fi + + if false; then + WITH_DISTRIBUTABLE_MANPAGE_TRUE= + WITH_DISTRIBUTABLE_MANPAGE_FALSE='#' +else + WITH_DISTRIBUTABLE_MANPAGE_TRUE='#' + WITH_DISTRIBUTABLE_MANPAGE_FALSE= +fi + +else $as_nop + if false; then + WITH_PREBUILT_MANPAGE_TRUE= + WITH_PREBUILT_MANPAGE_FALSE='#' +else + WITH_PREBUILT_MANPAGE_TRUE='#' + WITH_PREBUILT_MANPAGE_FALSE= +fi + + if true; then + WITH_DISTRIBUTABLE_MANPAGE_TRUE= + WITH_DISTRIBUTABLE_MANPAGE_FALSE='#' +else + WITH_DISTRIBUTABLE_MANPAGE_TRUE='#' + WITH_DISTRIBUTABLE_MANPAGE_FALSE= +fi + +fi + +else $as_nop + if test "x$with_docbook" != xno -a "x${DOCBOOK_TO_MAN}" != x +then : + if true; then + WITH_MANPAGE_TRUE= + WITH_MANPAGE_FALSE='#' else - WITH_DOCBOOK_TRUE='#' - WITH_DOCBOOK_FALSE= + WITH_MANPAGE_TRUE='#' + WITH_MANPAGE_FALSE= fi + if true; then + WITH_DISTRIBUTABLE_MANPAGE_TRUE= + WITH_DISTRIBUTABLE_MANPAGE_FALSE='#' +else + WITH_DISTRIBUTABLE_MANPAGE_TRUE='#' + WITH_DISTRIBUTABLE_MANPAGE_FALSE= +fi + +else $as_nop + if false; then + WITH_MANPAGE_TRUE= + WITH_MANPAGE_FALSE='#' +else + WITH_MANPAGE_TRUE='#' + WITH_MANPAGE_FALSE= +fi + + if false; then + WITH_DISTRIBUTABLE_MANPAGE_TRUE= + WITH_DISTRIBUTABLE_MANPAGE_FALSE='#' +else + WITH_DISTRIBUTABLE_MANPAGE_TRUE='#' + WITH_DISTRIBUTABLE_MANPAGE_FALSE= +fi + +fi + if false; then + WITH_PREBUILT_MANPAGE_TRUE= + WITH_PREBUILT_MANPAGE_FALSE='#' +else + WITH_PREBUILT_MANPAGE_TRUE='#' + WITH_PREBUILT_MANPAGE_FALSE= +fi + +fi + +if test "x${enable_xml_attr_info}" = xyes +then : + EXPAT_ATTR_INFO=ON +else $as_nop + EXPAT_ATTR_INFO=OFF +fi +EXPAT_DTD=ON +if test "x${_INTERNAL_LARGE_SIZE_TRUE}" = x +then : + EXPAT_LARGE_SIZE=ON +else $as_nop + EXPAT_LARGE_SIZE=OFF +fi +if test "x${_INTERNAL_MIN_SIZE_TRUE}" = x +then : + EXPAT_MIN_SIZE=ON +else $as_nop + EXPAT_MIN_SIZE=OFF +fi +EXPAT_NS=ON +if test "x${enable_xml_context}" != xno +then : + EXPAT_CONTEXT_BYTES=${enable_xml_context} +else $as_nop + EXPAT_CONTEXT_BYTES=OFF +fi +if test "x${UNICODE_TRUE}" = x +then : + if test "x${_INTERNAL_UNICODE_WCHAR_T_TRUE}" = x +then : + EXPAT_CHAR_TYPE=wchar_t +else $as_nop + EXPAT_CHAR_TYPE=ushort +fi +else $as_nop + EXPAT_CHAR_TYPE=char +fi +PACKAGE_INIT="${srcdir}"/cmake/autotools/expat-package-init.cmake +LIBDIR_BASENAME="$(basename "${libdir}")" +SO_MAJOR="$(expr "${LIBCURRENT}" - "${LIBAGE}")" +SO_MINOR="${LIBAGE}" +SO_PATCH="${LIBREVISION}" + + + + -_EXPAT_OUTPUT_NAME="$PACKAGE_NAME" -ac_config_files="$ac_config_files Makefile expat.pc doc/Makefile examples/Makefile lib/Makefile tests/Makefile tests/benchmark/Makefile xmlwf/Makefile" + +if ac_fn_c_compute_int "$LINENO" "sizeof(void *)" "SIZEOF_VOID_P" "" +then : + +fi + + + + + + + + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for shared library name prefix" >&5 +printf %s "checking for shared library name prefix... " >&6; } +case "${host_os}" in #( + cygwin*) : + CMAKE_SHARED_LIBRARY_PREFIX=cyg ;; #( + *) : + CMAKE_SHARED_LIBRARY_PREFIX=lib ;; +esac +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${CMAKE_SHARED_LIBRARY_PREFIX}" >&5 +printf "%s\n" "${CMAKE_SHARED_LIBRARY_PREFIX}" >&6; } + + +case "${host_os}" in #( + darwin*) : + CMAKE_NOCONFIG_SOURCE=cmake/autotools/expat-noconfig__macos.cmake.in ;; #( + mingw*|cygwin*) : + CMAKE_NOCONFIG_SOURCE=cmake/autotools/expat-noconfig__windows.cmake.in ;; #( + *) : + CMAKE_NOCONFIG_SOURCE=cmake/autotools/expat-noconfig__linux.cmake.in ;; +esac +ac_config_files="$ac_config_files Makefile expat.pc cmake/expat-config.cmake cmake/autotools/expat-config-version.cmake cmake/autotools/expat-noconfig.cmake:${CMAKE_NOCONFIG_SOURCE} doc/Makefile examples/Makefile lib/Makefile tests/Makefile tests/benchmark/Makefile xmlwf/Makefile" ac_config_files="$ac_config_files run.sh" @@ -18565,8 +20441,8 @@ _ACEOF case $ac_val in #( *${as_nl}*) case $ac_var in #( - *_cv_*) { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 -$as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; + *_cv_*) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: cache variable $ac_var contains a newline" >&5 +printf "%s\n" "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; esac case $ac_var in #( _ | IFS | as_nl) ;; #( @@ -18596,15 +20472,15 @@ $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;; /^ac_cv_env_/b end t clear :clear - s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/ + s/^\([^=]*\)=\(.*[{}].*\)$/test ${\1+y} || &/ t end s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/ :end' >>confcache if diff "$cache_file" confcache >/dev/null 2>&1; then :; else if test -w "$cache_file"; then if test "x$cache_file" != "x/dev/null"; then - { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 -$as_echo "$as_me: updating cache $cache_file" >&6;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5 +printf "%s\n" "$as_me: updating cache $cache_file" >&6;} if test ! -f "$cache_file" || test -h "$cache_file"; then cat confcache >"$cache_file" else @@ -18618,8 +20494,8 @@ $as_echo "$as_me: updating cache $cache_file" >&6;} fi fi else - { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 -$as_echo "$as_me: not updating unwritable cache $cache_file" >&6;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5 +printf "%s\n" "$as_me: not updating unwritable cache $cache_file" >&6;} fi fi rm -f confcache @@ -18636,7 +20512,7 @@ U= for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue # 1. Remove the extension, and $U if already installed. ac_script='s/\$U\././;s/\.o$//;s/\.obj$//' - ac_i=`$as_echo "$ac_i" | sed "$ac_script"` + ac_i=`printf "%s\n" "$ac_i" | sed "$ac_script"` # 2. Prepend LIBOBJDIR. When used with automake>=1.10 LIBOBJDIR # will be set to the directory where LIBOBJS objects are built. as_fn_append ac_libobjs " \${LIBOBJDIR}$ac_i\$U.$ac_objext" @@ -18647,14 +20523,14 @@ LIBOBJS=$ac_libobjs LTLIBOBJS=$ac_ltlibobjs -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5 -$as_echo_n "checking that generated files are newer than configure... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking that generated files are newer than configure" >&5 +printf %s "checking that generated files are newer than configure... " >&6; } if test -n "$am_sleep_pid"; then # Hide warnings about reused PIDs. wait $am_sleep_pid 2>/dev/null fi - { $as_echo "$as_me:${as_lineno-$LINENO}: result: done" >&5 -$as_echo "done" >&6; } + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: done" >&5 +printf "%s\n" "done" >&6; } if test -n "$EXEEXT"; then am__EXEEXT_TRUE= am__EXEEXT_FALSE='#' @@ -18663,6 +20539,10 @@ else am__EXEEXT_FALSE= fi +if test -z "${MAINTAINER_MODE_TRUE}" && test -z "${MAINTAINER_MODE_FALSE}"; then + as_fn_error $? "conditional \"MAINTAINER_MODE\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi if test -z "${AMDEP_TRUE}" && test -z "${AMDEP_FALSE}"; then as_fn_error $? "conditional \"AMDEP\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 @@ -18696,8 +20576,56 @@ if test -z "${UNICODE_TRUE}" && test -z "${UNICODE_FALSE}"; then as_fn_error $? "conditional \"UNICODE\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi -if test -z "${WITH_DOCBOOK_TRUE}" && test -z "${WITH_DOCBOOK_FALSE}"; then - as_fn_error $? "conditional \"WITH_DOCBOOK\" was never defined. +if test -z "${_INTERNAL_UNICODE_WCHAR_T_TRUE}" && test -z "${_INTERNAL_UNICODE_WCHAR_T_FALSE}"; then + as_fn_error $? "conditional \"_INTERNAL_UNICODE_WCHAR_T\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${_INTERNAL_MIN_SIZE_TRUE}" && test -z "${_INTERNAL_MIN_SIZE_FALSE}"; then + as_fn_error $? "conditional \"_INTERNAL_MIN_SIZE\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${_INTERNAL_LARGE_SIZE_TRUE}" && test -z "${_INTERNAL_LARGE_SIZE_FALSE}"; then + as_fn_error $? "conditional \"_INTERNAL_LARGE_SIZE\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${WITH_MANPAGE_TRUE}" && test -z "${WITH_MANPAGE_FALSE}"; then + as_fn_error $? "conditional \"WITH_MANPAGE\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${WITH_PREBUILT_MANPAGE_TRUE}" && test -z "${WITH_PREBUILT_MANPAGE_FALSE}"; then + as_fn_error $? "conditional \"WITH_PREBUILT_MANPAGE\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${WITH_DISTRIBUTABLE_MANPAGE_TRUE}" && test -z "${WITH_DISTRIBUTABLE_MANPAGE_FALSE}"; then + as_fn_error $? "conditional \"WITH_DISTRIBUTABLE_MANPAGE\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${WITH_PREBUILT_MANPAGE_TRUE}" && test -z "${WITH_PREBUILT_MANPAGE_FALSE}"; then + as_fn_error $? "conditional \"WITH_PREBUILT_MANPAGE\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${WITH_DISTRIBUTABLE_MANPAGE_TRUE}" && test -z "${WITH_DISTRIBUTABLE_MANPAGE_FALSE}"; then + as_fn_error $? "conditional \"WITH_DISTRIBUTABLE_MANPAGE\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${WITH_MANPAGE_TRUE}" && test -z "${WITH_MANPAGE_FALSE}"; then + as_fn_error $? "conditional \"WITH_MANPAGE\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${WITH_DISTRIBUTABLE_MANPAGE_TRUE}" && test -z "${WITH_DISTRIBUTABLE_MANPAGE_FALSE}"; then + as_fn_error $? "conditional \"WITH_DISTRIBUTABLE_MANPAGE\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${WITH_MANPAGE_TRUE}" && test -z "${WITH_MANPAGE_FALSE}"; then + as_fn_error $? "conditional \"WITH_MANPAGE\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${WITH_DISTRIBUTABLE_MANPAGE_TRUE}" && test -z "${WITH_DISTRIBUTABLE_MANPAGE_FALSE}"; then + as_fn_error $? "conditional \"WITH_DISTRIBUTABLE_MANPAGE\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${WITH_PREBUILT_MANPAGE_TRUE}" && test -z "${WITH_PREBUILT_MANPAGE_FALSE}"; then + as_fn_error $? "conditional \"WITH_PREBUILT_MANPAGE\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi @@ -18705,8 +20633,8 @@ fi ac_write_fail=0 ac_clean_files_save=$ac_clean_files ac_clean_files="$ac_clean_files $CONFIG_STATUS" -{ $as_echo "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 -$as_echo "$as_me: creating $CONFIG_STATUS" >&6;} +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $CONFIG_STATUS" >&5 +printf "%s\n" "$as_me: creating $CONFIG_STATUS" >&6;} as_write_fail=0 cat >$CONFIG_STATUS <<_ASEOF || as_write_fail=1 #! $SHELL @@ -18729,14 +20657,16 @@ cat >>$CONFIG_STATUS <<\_ASEOF || as_write_fail=1 # Be more Bourne compatible DUALCASE=1; export DUALCASE # for MKS sh -if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then : +as_nop=: +if test ${ZSH_VERSION+y} && (emulate sh) >/dev/null 2>&1 +then : emulate sh NULLCMD=: # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which # is contrary to our usage. Disable this feature. alias -g '${1+"$@"}'='"$@"' setopt NO_GLOB_SUBST -else +else $as_nop case `(set -o) 2>/dev/null` in #( *posix*) : set -o posix ;; #( @@ -18746,46 +20676,46 @@ esac fi + +# Reset variables that may have inherited troublesome values from +# the environment. + +# IFS needs to be set, to space, tab, and newline, in precisely that order. +# (If _AS_PATH_WALK were called with IFS unset, it would have the +# side effect of setting IFS to empty, thus disabling word splitting.) +# Quoting is to prevent editors from complaining about space-tab. as_nl=' ' export as_nl -# Printing a long string crashes Solaris 7 /usr/bin/printf. -as_echo='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\' -as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo -as_echo=$as_echo$as_echo$as_echo$as_echo$as_echo$as_echo -# Prefer a ksh shell builtin over an external printf program on Solaris, -# but without wasting forks for bash or zsh. -if test -z "$BASH_VERSION$ZSH_VERSION" \ - && (test "X`print -r -- $as_echo`" = "X$as_echo") 2>/dev/null; then - as_echo='print -r --' - as_echo_n='print -rn --' -elif (test "X`printf %s $as_echo`" = "X$as_echo") 2>/dev/null; then - as_echo='printf %s\n' - as_echo_n='printf %s' -else - if test "X`(/usr/ucb/echo -n -n $as_echo) 2>/dev/null`" = "X-n $as_echo"; then - as_echo_body='eval /usr/ucb/echo -n "$1$as_nl"' - as_echo_n='/usr/ucb/echo -n' - else - as_echo_body='eval expr "X$1" : "X\\(.*\\)"' - as_echo_n_body='eval - arg=$1; - case $arg in #( - *"$as_nl"*) - expr "X$arg" : "X\\(.*\\)$as_nl"; - arg=`expr "X$arg" : ".*$as_nl\\(.*\\)"`;; - esac; - expr "X$arg" : "X\\(.*\\)" | tr -d "$as_nl" - ' - export as_echo_n_body - as_echo_n='sh -c $as_echo_n_body as_echo' - fi - export as_echo_body - as_echo='sh -c $as_echo_body as_echo' -fi +IFS=" "" $as_nl" + +PS1='$ ' +PS2='> ' +PS4='+ ' + +# Ensure predictable behavior from utilities with locale-dependent output. +LC_ALL=C +export LC_ALL +LANGUAGE=C +export LANGUAGE + +# We cannot yet rely on "unset" to work, but we need these variables +# to be unset--not just set to an empty or harmless value--now, to +# avoid bugs in old shells (e.g. pre-3.0 UWIN ksh). This construct +# also avoids known problems related to "unset" and subshell syntax +# in other old shells (e.g. bash 2.01 and pdksh 5.2.14). +for as_var in BASH_ENV ENV MAIL MAILPATH CDPATH +do eval test \${$as_var+y} \ + && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : +done + +# Ensure that fds 0, 1, and 2 are open. +if (exec 3>&0) 2>/dev/null; then :; else exec 0</dev/null; fi +if (exec 3>&1) 2>/dev/null; then :; else exec 1>/dev/null; fi +if (exec 3>&2) ; then :; else exec 2>/dev/null; fi # The user is always right. -if test "${PATH_SEPARATOR+set}" != set; then +if ${PATH_SEPARATOR+false} :; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 || @@ -18794,13 +20724,6 @@ if test "${PATH_SEPARATOR+set}" != set; then fi -# IFS -# We need space, tab and new line, in precisely that order. Quoting is -# there to prevent editors from complaining about space-tab. -# (If _AS_PATH_WALK were called with IFS unset, it would disable word -# splitting by setting IFS to empty value.) -IFS=" "" $as_nl" - # Find who we are. Look in the path if we contain no directory separator. as_myself= case $0 in #(( @@ -18809,8 +20732,12 @@ case $0 in #(( for as_dir in $PATH do IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break + case $as_dir in #((( + '') as_dir=./ ;; + */) ;; + *) as_dir=$as_dir/ ;; + esac + test -r "$as_dir$0" && as_myself=$as_dir$0 && break done IFS=$as_save_IFS @@ -18822,30 +20749,10 @@ if test "x$as_myself" = x; then as_myself=$0 fi if test ! -f "$as_myself"; then - $as_echo "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 + printf "%s\n" "$as_myself: error: cannot find myself; rerun with an absolute file name" >&2 exit 1 fi -# Unset variables that we do not need and which cause bugs (e.g. in -# pre-3.0 UWIN ksh). But do not cause bugs in bash 2.01; the "|| exit 1" -# suppresses any "Segmentation fault" message there. '((' could -# trigger a bug in pdksh 5.2.14. -for as_var in BASH_ENV ENV MAIL MAILPATH -do eval test x\${$as_var+set} = xset \ - && ( (unset $as_var) || exit 1) >/dev/null 2>&1 && unset $as_var || : -done -PS1='$ ' -PS2='> ' -PS4='+ ' - -# NLS nuisances. -LC_ALL=C -export LC_ALL -LANGUAGE=C -export LANGUAGE - -# CDPATH. -(unset CDPATH) >/dev/null 2>&1 && unset CDPATH # as_fn_error STATUS ERROR [LINENO LOG_FD] @@ -18858,13 +20765,14 @@ as_fn_error () as_status=$1; test $as_status -eq 0 && as_status=1 if test "$4"; then as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 + printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi - $as_echo "$as_me: error: $2" >&2 + printf "%s\n" "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error + # as_fn_set_status STATUS # ----------------------- # Set $? to STATUS, without forking. @@ -18891,18 +20799,20 @@ as_fn_unset () { eval $1=; unset $1;} } as_unset=as_fn_unset + # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take # advantage of any shell optimizations that allow amortized linear growth over # repeated appends, instead of the typical quadratic growth present in naive # implementations. -if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null; then : +if (eval "as_var=1; as_var+=2; test x\$as_var = x12") 2>/dev/null +then : eval 'as_fn_append () { eval $1+=\$2 }' -else +else $as_nop as_fn_append () { eval $1=\$$1\$2 @@ -18914,12 +20824,13 @@ fi # as_fn_append # Perform arithmetic evaluation on the ARGs, and store the result in the # global $as_val. Take advantage of shells that can avoid forks. The arguments # must be portable across $(()) and expr. -if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null; then : +if (eval "test \$(( 1 + 1 )) = 2") 2>/dev/null +then : eval 'as_fn_arith () { as_val=$(( $* )) }' -else +else $as_nop as_fn_arith () { as_val=`expr "$@" || test $? -eq 1` @@ -18950,7 +20861,7 @@ as_me=`$as_basename -- "$0" || $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ X"$0" : 'X\(//\)$' \| \ X"$0" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X/"$0" | +printf "%s\n" X/"$0" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q @@ -18972,6 +20883,10 @@ as_cr_Letters=$as_cr_letters$as_cr_LETTERS as_cr_digits='0123456789' as_cr_alnum=$as_cr_Letters$as_cr_digits + +# Determine whether it's possible to make 'echo' print without a newline. +# These variables are no longer used directly by Autoconf, but are AC_SUBSTed +# for compatibility with existing Makefiles. ECHO_C= ECHO_N= ECHO_T= case `echo -n x` in #((((( -n*) @@ -18985,6 +20900,12 @@ case `echo -n x` in #((((( ECHO_N='-n';; esac +# For backward compatibility with old third-party macros, we provide +# the shell variables $as_echo and $as_echo_n. New code should use +# AS_ECHO(["message"]) and AS_ECHO_N(["message"]), respectively. +as_echo='printf %s\n' +as_echo_n='printf %s' + rm -f conf$$ conf$$.exe conf$$.file if test -d conf$$.dir; then rm -f conf$$.dir/conf$$.file @@ -19026,7 +20947,7 @@ as_fn_mkdir_p () as_dirs= while :; do case $as_dir in #( - *\'*) as_qdir=`$as_echo "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( + *\'*) as_qdir=`printf "%s\n" "$as_dir" | sed "s/'/'\\\\\\\\''/g"`;; #'( *) as_qdir=$as_dir;; esac as_dirs="'$as_qdir' $as_dirs" @@ -19035,7 +20956,7 @@ $as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$as_dir" : 'X\(//\)[^/]' \| \ X"$as_dir" : 'X\(//\)$' \| \ X"$as_dir" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$as_dir" | +printf "%s\n" X"$as_dir" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -19097,8 +21018,8 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by expat $as_me 2.2.10, which was -generated by GNU Autoconf 2.69. Invocation command line was +This file was extended by expat $as_me 2.6.4, which was +generated by GNU Autoconf 2.71. Invocation command line was CONFIG_FILES = $CONFIG_FILES CONFIG_HEADERS = $CONFIG_HEADERS @@ -19157,17 +21078,19 @@ $config_headers Configuration commands: $config_commands -Report bugs to <expat-bugs@libexpat.org>." +Report bugs to <https://github.com/libexpat/libexpat/issues>." _ACEOF +ac_cs_config=`printf "%s\n" "$ac_configure_args" | sed "$ac_safe_unquote"` +ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\''/g"` cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 -ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" +ac_cs_config='$ac_cs_config_escaped' ac_cs_version="\\ -expat config.status 2.2.10 -configured by $0, generated by GNU Autoconf 2.69, +expat config.status 2.6.4 +configured by $0, generated by GNU Autoconf 2.71, with options \\"\$ac_cs_config\\" -Copyright (C) 2012 Free Software Foundation, Inc. +Copyright (C) 2021 Free Software Foundation, Inc. This config.status script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it." @@ -19207,15 +21130,15 @@ do -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) ac_cs_recheck=: ;; --version | --versio | --versi | --vers | --ver | --ve | --v | -V ) - $as_echo "$ac_cs_version"; exit ;; + printf "%s\n" "$ac_cs_version"; exit ;; --config | --confi | --conf | --con | --co | --c ) - $as_echo "$ac_cs_config"; exit ;; + printf "%s\n" "$ac_cs_config"; exit ;; --debug | --debu | --deb | --de | --d | -d ) debug=: ;; --file | --fil | --fi | --f ) $ac_shift case $ac_optarg in - *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + *\'*) ac_optarg=`printf "%s\n" "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; '') as_fn_error $? "missing file argument" ;; esac as_fn_append CONFIG_FILES " '$ac_optarg'" @@ -19223,7 +21146,7 @@ do --header | --heade | --head | --hea ) $ac_shift case $ac_optarg in - *\'*) ac_optarg=`$as_echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; + *\'*) ac_optarg=`printf "%s\n" "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"` ;; esac as_fn_append CONFIG_HEADERS " '$ac_optarg'" ac_need_defaults=false;; @@ -19232,7 +21155,7 @@ do as_fn_error $? "ambiguous option: \`$1' Try \`$0 --help' for more information.";; --help | --hel | -h ) - $as_echo "$ac_cs_usage"; exit ;; + printf "%s\n" "$ac_cs_usage"; exit ;; -q | -quiet | --quiet | --quie | --qui | --qu | --q \ | -silent | --silent | --silen | --sile | --sil | --si | --s) ac_cs_silent=: ;; @@ -19260,7 +21183,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 if \$ac_cs_recheck; then set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion shift - \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6 + \printf "%s\n" "running CONFIG_SHELL=$SHELL \$*" >&6 CONFIG_SHELL='$SHELL' export CONFIG_SHELL exec "\$@" @@ -19274,7 +21197,7 @@ exec 5>>config.log sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX ## Running $as_me. ## _ASBOX - $as_echo "$ac_log" + printf "%s\n" "$ac_log" } >&5 _ACEOF @@ -19329,12 +21252,14 @@ lt_cv_to_host_file_cmd='`$ECHO "$lt_cv_to_host_file_cmd" | $SED "$delay_single_q lt_cv_to_tool_file_cmd='`$ECHO "$lt_cv_to_tool_file_cmd" | $SED "$delay_single_quote_subst"`' reload_flag='`$ECHO "$reload_flag" | $SED "$delay_single_quote_subst"`' reload_cmds='`$ECHO "$reload_cmds" | $SED "$delay_single_quote_subst"`' +FILECMD='`$ECHO "$FILECMD" | $SED "$delay_single_quote_subst"`' deplibs_check_method='`$ECHO "$deplibs_check_method" | $SED "$delay_single_quote_subst"`' file_magic_cmd='`$ECHO "$file_magic_cmd" | $SED "$delay_single_quote_subst"`' file_magic_glob='`$ECHO "$file_magic_glob" | $SED "$delay_single_quote_subst"`' want_nocaseglob='`$ECHO "$want_nocaseglob" | $SED "$delay_single_quote_subst"`' sharedlib_from_linklib_cmd='`$ECHO "$sharedlib_from_linklib_cmd" | $SED "$delay_single_quote_subst"`' AR='`$ECHO "$AR" | $SED "$delay_single_quote_subst"`' +lt_ar_flags='`$ECHO "$lt_ar_flags" | $SED "$delay_single_quote_subst"`' AR_FLAGS='`$ECHO "$AR_FLAGS" | $SED "$delay_single_quote_subst"`' archiver_list_spec='`$ECHO "$archiver_list_spec" | $SED "$delay_single_quote_subst"`' STRIP='`$ECHO "$STRIP" | $SED "$delay_single_quote_subst"`' @@ -19512,13 +21437,13 @@ LN_S \ lt_SP2NL \ lt_NL2SP \ reload_flag \ +FILECMD \ deplibs_check_method \ file_magic_cmd \ file_magic_glob \ want_nocaseglob \ sharedlib_from_linklib_cmd \ AR \ -AR_FLAGS \ archiver_list_spec \ STRIP \ RANLIB \ @@ -19680,6 +21605,9 @@ do "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; "expat.pc") CONFIG_FILES="$CONFIG_FILES expat.pc" ;; + "cmake/expat-config.cmake") CONFIG_FILES="$CONFIG_FILES cmake/expat-config.cmake" ;; + "cmake/autotools/expat-config-version.cmake") CONFIG_FILES="$CONFIG_FILES cmake/autotools/expat-config-version.cmake" ;; + "cmake/autotools/expat-noconfig.cmake") CONFIG_FILES="$CONFIG_FILES cmake/autotools/expat-noconfig.cmake:${CMAKE_NOCONFIG_SOURCE}" ;; "doc/Makefile") CONFIG_FILES="$CONFIG_FILES doc/Makefile" ;; "examples/Makefile") CONFIG_FILES="$CONFIG_FILES examples/Makefile" ;; "lib/Makefile") CONFIG_FILES="$CONFIG_FILES lib/Makefile" ;; @@ -19698,9 +21626,9 @@ done # We use the long form for the default assignment because of an extremely # bizarre bug on SunOS 4.1.3. if $ac_need_defaults; then - test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files - test "${CONFIG_HEADERS+set}" = set || CONFIG_HEADERS=$config_headers - test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands + test ${CONFIG_FILES+y} || CONFIG_FILES=$config_files + test ${CONFIG_HEADERS+y} || CONFIG_HEADERS=$config_headers + test ${CONFIG_COMMANDS+y} || CONFIG_COMMANDS=$config_commands fi # Have a temporary directory for convenience. Make it in the build tree @@ -19735,7 +21663,24 @@ ac_tmp=$tmp # This happens for instance with `./config.status config.h'. if test -n "$CONFIG_FILES"; then - +if $AWK 'BEGIN { getline <"/dev/null" }' </dev/null 2>/dev/null; then + ac_cs_awk_getline=: + ac_cs_awk_pipe_init= + ac_cs_awk_read_file=' + while ((getline aline < (F[key])) > 0) + print(aline) + close(F[key])' + ac_cs_awk_pipe_fini= +else + ac_cs_awk_getline=false + ac_cs_awk_pipe_init="print \"cat <<'|#_!!_#|' &&\"" + ac_cs_awk_read_file=' + print "|#_!!_#|" + print "cat " F[key] " &&" + '$ac_cs_awk_pipe_init + # The final `:' finishes the AND list. + ac_cs_awk_pipe_fini='END { print "|#_!!_#|"; print ":" }' +fi ac_cr=`echo X | tr X '\015'` # On cygwin, bash can eat \r inside `` if the user requested igncr. # But we know of no other shell where ac_cr would be empty at this @@ -19753,6 +21698,17 @@ fi echo 'BEGIN {' >"$ac_tmp/subs1.awk" && _ACEOF +# Create commands to substitute file output variables. +{ + echo "cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1" && + echo 'cat >>"\$ac_tmp/subs1.awk" <<\\_ACAWK &&' && + echo "$ac_subst_files" | sed 's/.*/F["&"]="$&"/' && + echo "_ACAWK" && + echo "_ACEOF" +} >conf$$files.sh && +. ./conf$$files.sh || + as_fn_error $? "could not make $CONFIG_STATUS" "$LINENO" 5 +rm -f conf$$files.sh { echo "cat >conf$$subs.awk <<_ACEOF" && @@ -19829,7 +21785,7 @@ _ACAWK cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && for (key in S) S_is_set[key] = 1 FS = "" - + \$ac_cs_awk_pipe_init } { line = $ 0 @@ -19847,10 +21803,16 @@ cat >>"\$ac_tmp/subs1.awk" <<_ACAWK && } else len += 1 + keylen } - + if (nfields == 3 && !substed) { + key = field[2] + if (F[key] != "" && line ~ /^[ ]*@.*@[ ]*$/) { + \$ac_cs_awk_read_file + next + } + } print line } - +\$ac_cs_awk_pipe_fini _ACAWK _ACEOF cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 @@ -20036,7 +21998,7 @@ do esac || as_fn_error 1 "cannot find input file: \`$ac_f'" "$LINENO" 5;; esac - case $ac_f in *\'*) ac_f=`$as_echo "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac + case $ac_f in *\'*) ac_f=`printf "%s\n" "$ac_f" | sed "s/'/'\\\\\\\\''/g"`;; esac as_fn_append ac_file_inputs " '$ac_f'" done @@ -20044,17 +22006,17 @@ do # use $as_me), people would be surprised to read: # /* config.h. Generated by config.status. */ configure_input='Generated from '` - $as_echo "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' + printf "%s\n" "$*" | sed 's|^[^:]*/||;s|:[^:]*/|, |g' `' by configure.' if test x"$ac_file" != x-; then configure_input="$ac_file. $configure_input" - { $as_echo "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 -$as_echo "$as_me: creating $ac_file" >&6;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: creating $ac_file" >&5 +printf "%s\n" "$as_me: creating $ac_file" >&6;} fi # Neutralize special characters interpreted by sed in replacement strings. case $configure_input in #( *\&* | *\|* | *\\* ) - ac_sed_conf_input=`$as_echo "$configure_input" | + ac_sed_conf_input=`printf "%s\n" "$configure_input" | sed 's/[\\\\&|]/\\\\&/g'`;; #( *) ac_sed_conf_input=$configure_input;; esac @@ -20071,7 +22033,7 @@ $as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$ac_file" : 'X\(//\)[^/]' \| \ X"$ac_file" : 'X\(//\)$' \| \ X"$ac_file" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$ac_file" | +printf "%s\n" X"$ac_file" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -20095,9 +22057,9 @@ $as_echo X"$ac_file" | case "$ac_dir" in .) ac_dir_suffix= ac_top_builddir_sub=. ac_top_build_prefix= ;; *) - ac_dir_suffix=/`$as_echo "$ac_dir" | sed 's|^\.[\\/]||'` + ac_dir_suffix=/`printf "%s\n" "$ac_dir" | sed 's|^\.[\\/]||'` # A ".." for each directory in $ac_dir_suffix. - ac_top_builddir_sub=`$as_echo "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` + ac_top_builddir_sub=`printf "%s\n" "$ac_dir_suffix" | sed 's|/[^\\/]*|/..|g;s|/||'` case $ac_top_builddir_sub in "") ac_top_builddir_sub=. ac_top_build_prefix= ;; *) ac_top_build_prefix=$ac_top_builddir_sub/ ;; @@ -20159,8 +22121,8 @@ ac_sed_dataroot=' case `eval "sed -n \"\$ac_sed_dataroot\" $ac_file_inputs"` in *datarootdir*) ac_datarootdir_seen=yes;; *@datadir@*|*@docdir@*|*@infodir@*|*@localedir@*|*@mandir@*) - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 -$as_echo "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&5 +printf "%s\n" "$as_me: WARNING: $ac_file_inputs seems to ignore the --datarootdir setting" >&2;} _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_datarootdir_hack=' @@ -20197,16 +22159,21 @@ s&@INSTALL@&$ac_INSTALL&;t t s&@MKDIR_P@&$ac_MKDIR_P&;t t $ac_datarootdir_hack " -eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | $AWK -f "$ac_tmp/subs.awk" \ +eval sed \"\$ac_sed_extra\" "$ac_file_inputs" | +if $ac_cs_awk_getline; then + $AWK -f "$ac_tmp/subs.awk" +else + $AWK -f "$ac_tmp/subs.awk" | $SHELL +fi \ >$ac_tmp/out || as_fn_error $? "could not create $ac_file" "$LINENO" 5 test -z "$ac_datarootdir_hack$ac_datarootdir_seen" && { ac_out=`sed -n '/\${datarootdir}/p' "$ac_tmp/out"`; test -n "$ac_out"; } && { ac_out=`sed -n '/^[ ]*datarootdir[ ]*:*=/p' \ "$ac_tmp/out"`; test -z "$ac_out"; } && - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&5 -$as_echo "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' +printf "%s\n" "$as_me: WARNING: $ac_file contains a reference to the variable \`datarootdir' which seems to be undefined. Please make sure it is defined" >&2;} rm -f "$ac_tmp/stdin" @@ -20222,20 +22189,20 @@ which seems to be undefined. Please make sure it is defined" >&2;} # if test x"$ac_file" != x-; then { - $as_echo "/* $configure_input */" \ + printf "%s\n" "/* $configure_input */" >&1 \ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" } >"$ac_tmp/config.h" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 if diff "$ac_file" "$ac_tmp/config.h" >/dev/null 2>&1; then - { $as_echo "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 -$as_echo "$as_me: $ac_file is unchanged" >&6;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: $ac_file is unchanged" >&5 +printf "%s\n" "$as_me: $ac_file is unchanged" >&6;} else rm -f "$ac_file" mv "$ac_tmp/config.h" "$ac_file" \ || as_fn_error $? "could not create $ac_file" "$LINENO" 5 fi else - $as_echo "/* $configure_input */" \ + printf "%s\n" "/* $configure_input */" >&1 \ && eval '$AWK -f "$ac_tmp/defines.awk"' "$ac_file_inputs" \ || as_fn_error $? "could not create -" "$LINENO" 5 fi @@ -20255,7 +22222,7 @@ $as_expr X"$_am_arg" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$_am_arg" : 'X\(//\)[^/]' \| \ X"$_am_arg" : 'X\(//\)$' \| \ X"$_am_arg" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$_am_arg" | +printf "%s\n" X"$_am_arg" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -20275,8 +22242,8 @@ $as_echo X"$_am_arg" | s/.*/./; q'`/stamp-h$_am_stamp_count ;; - :C) { $as_echo "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 -$as_echo "$as_me: executing $ac_file commands" >&6;} + :C) { printf "%s\n" "$as_me:${as_lineno-$LINENO}: executing $ac_file commands" >&5 +printf "%s\n" "$as_me: executing $ac_file commands" >&6;} ;; esac @@ -20302,7 +22269,7 @@ esac for am_mf do # Strip MF so we end up with the name of the file. - am_mf=`$as_echo "$am_mf" | sed -e 's/:.*$//'` + am_mf=`printf "%s\n" "$am_mf" | sed -e 's/:.*$//'` # Check whether this is an Automake generated Makefile which includes # dependency-tracking related rules and includes. # Grep'ing the whole file directly is not great: AIX grep has a line @@ -20314,7 +22281,7 @@ $as_expr X"$am_mf" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ X"$am_mf" : 'X\(//\)[^/]' \| \ X"$am_mf" : 'X\(//\)$' \| \ X"$am_mf" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X"$am_mf" | +printf "%s\n" X"$am_mf" | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/ q @@ -20336,7 +22303,7 @@ $as_echo X"$am_mf" | $as_expr X/"$am_mf" : '.*/\([^/][^/]*\)/*$' \| \ X"$am_mf" : 'X\(//\)$' \| \ X"$am_mf" : 'X\(/\)' \| . 2>/dev/null || -$as_echo X/"$am_mf" | +printf "%s\n" X/"$am_mf" | sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/ q @@ -20361,8 +22328,8 @@ $as_echo X/"$am_mf" | (exit $ac_status); } || am_rc=$? done if test $am_rc -ne 0; then - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} + { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in \`$ac_pwd':" >&2;} as_fn_error $? "Something went wrong bootstrapping makefile fragments for automatic dependency tracking. If GNU make was not used, consider re-running the configure script with MAKE=\"gmake\" (or whatever is @@ -20393,19 +22360,18 @@ See \`config.log' for more details" "$LINENO" 5; } cat <<_LT_EOF >> "$cfgfile" #! $SHELL # Generated automatically by $as_me ($PACKAGE) $VERSION -# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # Provide generalized library-building support services. # Written by Gordon Matzigkeit, 1996 -# Copyright (C) 2014 Free Software Foundation, Inc. +# Copyright (C) 2024 Free Software Foundation, Inc. # This is free software; see the source for copying conditions. There is NO # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # GNU Libtool is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of of the License, or +# the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # As a special exception to the GNU General Public License, if you @@ -20522,6 +22488,9 @@ to_host_file_cmd=$lt_cv_to_host_file_cmd # convert \$build files to toolchain format. to_tool_file_cmd=$lt_cv_to_tool_file_cmd +# A file(cmd) program that detects file types. +FILECMD=$lt_FILECMD + # Method to check whether dependent libraries are shared objects. deplibs_check_method=$lt_deplibs_check_method @@ -20540,8 +22509,11 @@ sharedlib_from_linklib_cmd=$lt_sharedlib_from_linklib_cmd # The archiver. AR=$lt_AR +# Flags to create an archive (by configure). +lt_ar_flags=$lt_ar_flags + # Flags to create an archive. -AR_FLAGS=$lt_AR_FLAGS +AR_FLAGS=\${ARFLAGS-"\$lt_ar_flags"} # How to feed a file listing to the archiver. archiver_list_spec=$lt_archiver_list_spec @@ -20783,7 +22755,7 @@ hardcode_direct=$hardcode_direct # Set to "yes" if using DIR/libNAME\$shared_ext during linking hardcodes # DIR into the resulting binary and the resulting library dependency is -# "absolute",i.e impossible to change by setting \$shlibpath_var if the +# "absolute",i.e. impossible to change by setting \$shlibpath_var if the # library is relocated. hardcode_direct_absolute=$hardcode_direct_absolute @@ -20923,6 +22895,7 @@ _LT_EOF esac + ltmain=$ac_aux_dir/ltmain.sh @@ -20930,7 +22903,7 @@ ltmain=$ac_aux_dir/ltmain.sh # if finds mixed CR/LF and LF-only lines. Since sed operates in # text mode, it properly converts lines to CR/LF. This bash problem # is reportedly fixed, but why not run on old versions too? - sed '$q' "$ltmain" >> "$cfgfile" \ + $SED '$q' "$ltmain" >> "$cfgfile" \ || (rm -f "$cfgfile"; exit 1) mv -f "$cfgfile" "$ofile" || @@ -21025,7 +22998,7 @@ hardcode_direct=$hardcode_direct_CXX # Set to "yes" if using DIR/libNAME\$shared_ext during linking hardcodes # DIR into the resulting binary and the resulting library dependency is -# "absolute",i.e impossible to change by setting \$shlibpath_var if the +# "absolute",i.e. impossible to change by setting \$shlibpath_var if the # library is relocated. hardcode_direct_absolute=$hardcode_direct_absolute_CXX @@ -21126,13 +23099,13 @@ if test "$no_create" != yes; then $ac_cs_success || as_fn_exit 1 fi if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then - { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 -$as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: unrecognized options: $ac_unrecognized_opts" >&5 +printf "%s\n" "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;} fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: Automake flags (can be overridden by user flags): AM_CPPFLAGS: ${AM_CPPFLAGS} @@ -21145,7 +23118,7 @@ User flags (override Automake flags on conflict): CFLAGS: ${CFLAGS} CXXFLAGS: ${CXXFLAGS} LDFLAGS: ${LDFLAGS}" >&5 -$as_echo "$as_me: +printf "%s\n" "$as_me: Automake flags (can be overridden by user flags): AM_CPPFLAGS: ${AM_CPPFLAGS} @@ -21158,3 +23131,4 @@ User flags (override Automake flags on conflict): CFLAGS: ${CFLAGS} CXXFLAGS: ${CXXFLAGS} LDFLAGS: ${LDFLAGS}" >&6;} + diff --git a/3rdparty/expat/configure.ac b/3rdparty/expat/configure.ac index 82ec1fdd178..5685f73bd64 100644 --- a/3rdparty/expat/configure.ac +++ b/3rdparty/expat/configure.ac @@ -1,21 +1,56 @@ dnl configuration script for expat dnl Process this file with autoconf to produce a configure script. +dnl __ __ _ +dnl ___\ \/ /_ __ __ _| |_ +dnl / _ \\ /| '_ \ / _` | __| +dnl | __// \| |_) | (_| | |_ +dnl \___/_/\_\ .__/ \__,_|\__| +dnl |_| XML parser dnl -dnl Copyright 2000 Clark Cooper +dnl Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> +dnl Copyright (c) 2000-2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> +dnl Copyright (c) 2001-2003 Greg Stein <gstein@users.sourceforge.net> +dnl Copyright (c) 2006-2012 Karl Waclawek <karl@waclawek.net> +dnl Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> +dnl Copyright (c) 2017 S. P. Zeidler <spz@netbsd.org> +dnl Copyright (c) 2017 Stephen Groat <stephen@groat.us> +dnl Copyright (c) 2017-2020 Joe Orton <jorton@redhat.com> +dnl Copyright (c) 2018 Yury Gribov <tetra2005@gmail.com> +dnl Copyright (c) 2018 Benjamin Peterson <benjamin@python.org> +dnl Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> +dnl Copyright (c) 2018 KangLin <kl222@126.com> +dnl Copyright (c) 2019 Mohammed Khajapasha <mohammed.khajapasha@intel.com> +dnl Copyright (c) 2019 Kishore Kunche <kishore.kunche@intel.com> +dnl Copyright (c) 2020 Jeffrey Walton <noloader@gmail.com> +dnl Copyright (c) 2024 Ferenc Géczi <ferenc.gm@gmail.com> +dnl Copyright (c) 2024 Dag-Erling Smørgrav <des@des.dev> +dnl Licensed under the MIT license: dnl -dnl This file is part of EXPAT. +dnl Permission is hereby granted, free of charge, to any person obtaining +dnl a copy of this software and associated documentation files (the +dnl "Software"), to deal in the Software without restriction, including +dnl without limitation the rights to use, copy, modify, merge, publish, +dnl distribute, sublicense, and/or sell copies of the Software, and to permit +dnl persons to whom the Software is furnished to do so, subject to the +dnl following conditions: dnl -dnl EXPAT is free software; you can redistribute it and/or modify it -dnl under the terms of the License (based on the MIT/X license) contained -dnl in the file COPYING that comes with this distribution. +dnl The above copyright notice and this permission notice shall be included +dnl in all copies or substantial portions of the Software. dnl +dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +dnl EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +dnl MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +dnl NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +dnl DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +dnl OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +dnl USE OR OTHER DEALINGS IN THE SOFTWARE. dnl Ensure that Expat is configured with autoconf 2.69 or newer. -AC_PREREQ(2.69) +AC_PREREQ([2.69]) dnl Get the version number of Expat, using m4's esyscmd() command to run dnl the command at m4-generation time. This allows us to create an m4 -dnl symbol holding the correct version number. AC_INIT() requires the +dnl symbol holding the correct version number. AC_INIT requires the dnl version number at m4-time, rather than when ./configure is run, so dnl all this must happen as part of m4, not as part of the shell code dnl contained in ./configure. @@ -27,7 +62,7 @@ m4_define([expat_version], m4_ifdef([__gnu__], [esyscmd(conftools/get-version.sh lib/expat.h)], [2.2.x])) -AC_INIT(expat, expat_version, expat-bugs@libexpat.org) +AC_INIT([expat], expat_version, [https://github.com/libexpat/libexpat/issues]) m4_undefine([expat_version]) AC_CONFIG_SRCDIR([Makefile.in]) @@ -35,6 +70,7 @@ AC_CONFIG_AUX_DIR([conftools]) AC_CONFIG_MACRO_DIR([m4]) AC_CANONICAL_HOST AM_INIT_AUTOMAKE +AM_MAINTAINER_MODE([enable]) # to allow argument --disable-maintainer-mode dnl @@ -48,12 +84,14 @@ dnl dnl If the API changes incompatibly set LIBAGE back to 0 dnl -LIBCURRENT=7 # sync -LIBREVISION=12 # with -LIBAGE=6 # CMakeLists.txt! +LIBCURRENT=11 # sync +LIBREVISION=0 # with +LIBAGE=10 # CMakeLists.txt! -AX_APPEND_FLAG([-DHAVE_EXPAT_CONFIG_H], [AM_CPPFLAGS]) -AC_CONFIG_HEADER([expat_config.h]) +AC_CONFIG_HEADERS([expat_config.h]) +AH_TOP([#ifndef EXPAT_CONFIG_H +#define EXPAT_CONFIG_H 1]) +AH_BOTTOM([#endif // ndef EXPAT_CONFIG_H]) AM_PROG_AR AC_PROG_INSTALL @@ -70,6 +108,9 @@ AC_SUBST(LIBAGE) AC_LANG([C]) AC_PROG_CC_C99 +AS_IF([test "${ac_cv_prog_cc_c99}" = no], + [AC_MSG_ERROR([Expat requires a C99 compiler.])]) + AS_IF([test "$GCC" = yes], [AX_APPEND_COMPILE_FLAGS([-Wall -Wextra], [AM_CFLAGS]) dnl Be careful about adding the -fexceptions option; some versions of @@ -79,7 +120,7 @@ AS_IF([test "$GCC" = yes], AX_APPEND_COMPILE_FLAGS([-fno-strict-aliasing -Wmissing-prototypes -Wstrict-prototypes], [AM_CFLAGS]) AX_APPEND_COMPILE_FLAGS([-pedantic -Wduplicated-cond -Wduplicated-branches -Wlogical-op], [AM_CFLAGS]) AX_APPEND_COMPILE_FLAGS([-Wrestrict -Wnull-dereference -Wjump-misses-init -Wdouble-promotion], [AM_CFLAGS]) - AX_APPEND_COMPILE_FLAGS([-Wshadow -Wformat=2 -Wmisleading-indentation], [AM_CFLAGS])]) + AX_APPEND_COMPILE_FLAGS([-Wshadow -Wformat=2 -Wno-pedantic-ms-format -Wmisleading-indentation], [AM_CFLAGS])]) AC_LANG_PUSH([C++]) AC_PROG_CXX @@ -102,11 +143,9 @@ AS_CASE(["$LD"],[*clang*], [*linux*],[archive_cmds='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib'])]) EXPATCFG_COMPILER_SUPPORTS_VISIBILITY([ - AX_APPEND_FLAG([-fvisibility=hidden], [AM_CFLAGS]) - AX_APPEND_FLAG([-DXML_ENABLE_VISIBILITY=1], [AM_CPPFLAGS])]) - -dnl Checks for header files. -AC_HEADER_STDC + AX_APPEND_FLAG([-fvisibility=hidden], [AM_CFLAGS]) + AS_IF([test "${enable_shared}" = yes], + [AX_APPEND_FLAG([-DXML_ENABLE_VISIBILITY=1], [AM_CPPFLAGS])])]) dnl Checks for typedefs, structures, and compiler characteristics. @@ -123,7 +162,6 @@ AC_C_BIGENDIAN([AC_DEFINE([WORDS_BIGENDIAN], 1) AC_DEFINE_UNQUOTED([BYTEORDER], $BYTEORDER, [1234 = LILENDIAN, 4321 = BIGENDIAN]) AC_C_CONST -AC_TYPE_SIZE_T AC_ARG_WITH([xmlwf], [AS_HELP_STRING([--without-xmlwf], [do not build xmlwf])], @@ -143,6 +181,8 @@ AC_ARG_WITH([tests], [with_tests=yes]) AM_CONDITIONAL([WITH_TESTS], [test x${with_tests} = xyes]) +AS_IF([test x${with_tests} = xyes], + [AX_CXX_COMPILE_STDCXX_11([noext], [mandatory])]) AS_VAR_SET([EXPATCFG_ON_MINGW],[no]) AS_CASE("${host_os}", @@ -151,8 +191,13 @@ AS_CASE("${host_os}", AC_MSG_NOTICE([detected OS: MinGW])]) AM_CONDITIONAL([MINGW], [test x${EXPATCFG_ON_MINGW} = xyes]) +dnl Note: Prefix "_INTERNAL_" here means exclusive use inside of file configure.ac AM_CONDITIONAL([UNICODE], [echo -- "${CPPFLAGS}${CFLAGS}" | ${FGREP} XML_UNICODE >/dev/null]) +AM_CONDITIONAL([_INTERNAL_UNICODE_WCHAR_T], [echo -- "${CPPFLAGS}${CFLAGS}" | ${FGREP} XML_UNICODE_WCHAR_T >/dev/null]) +AM_CONDITIONAL([_INTERNAL_MIN_SIZE], [echo -- "${CPPFLAGS}${CFLAGS}" | ${FGREP} XML_MIN_SIZE >/dev/null]) +AM_CONDITIONAL([_INTERNAL_LARGE_SIZE], [echo -- "${CPPFLAGS}${CFLAGS}" | ${FGREP} XML_LARGE_SIZE >/dev/null]) +LT_LIB_M AC_ARG_WITH([libbsd], [AS_HELP_STRING([--with-libbsd], [utilize libbsd (for arc4random_buf)])], @@ -164,14 +209,16 @@ AS_IF([test "x${with_libbsd}" != xno], [], [AS_IF([test "x${with_libbsd}" = xyes], [AC_MSG_ERROR([Enforced use of libbsd cannot be satisfied.])])])]) -AC_MSG_CHECKING([for arc4random_buf (BSD or libbsd)]) +AC_MSG_CHECKING([for arc4random_buf (BSD, libbsd or glibc 2.36+)]) AC_LINK_IFELSE([AC_LANG_SOURCE([ - #include <stdlib.h> /* for arc4random_buf on BSD, for NULL */ #if defined(HAVE_LIBBSD) # include <bsd/stdlib.h> + #else + # include <stdlib.h> /* for arc4random_buf on BSD */ #endif - int main() { - arc4random_buf(NULL, 0U); + int main(void) { + char dummy[[123]]; // double brackets for m4 + arc4random_buf(dummy, 0U); return 0; } ])], @@ -179,14 +226,14 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([ AC_MSG_RESULT([yes])], [AC_MSG_RESULT([no]) - AC_MSG_CHECKING([for arc4random (BSD, macOS or libbsd)]) + AC_MSG_CHECKING([for arc4random (BSD, macOS, libbsd or glibc 2.36+)]) AC_LINK_IFELSE([AC_LANG_SOURCE([ #if defined(HAVE_LIBBSD) # include <bsd/stdlib.h> #else # include <stdlib.h> #endif - int main() { + int main(void) { arc4random(); return 0; } @@ -208,7 +255,7 @@ AS_IF([test "x$with_getrandom" != xno], AC_LINK_IFELSE([AC_LANG_SOURCE([ #include <stdlib.h> /* for NULL */ #include <sys/random.h> - int main() { + int main(void) { return getrandom(NULL, 0U, 0U); } ])], @@ -229,10 +276,11 @@ AS_HELP_STRING([--without-sys-getrandom], AS_IF([test "x$with_sys_getrandom" != xno], [AC_MSG_CHECKING([for syscall SYS_getrandom (Linux 3.17+)]) AC_LINK_IFELSE([AC_LANG_SOURCE([ + #define _GNU_SOURCE #include <stdlib.h> /* for NULL */ #include <unistd.h> /* for syscall */ #include <sys/syscall.h> /* for SYS_getrandom */ - int main() { + int main(void) { syscall(SYS_getrandom, NULL, 0, 0); return 0; } @@ -257,6 +305,8 @@ AC_SUBST(FILEMAP) dnl Some basic configuration: AC_DEFINE([XML_NS], 1, [Define to make XML Namespaces functionality available.]) +AC_DEFINE([XML_GE], 1, + [Define as 1/0 to enable/disable support for general entities.]) AC_DEFINE([XML_DTD], 1, [Define to make parameter entity parsing functionality available.]) AC_DEFINE([XML_DEV_URANDOM], 1, @@ -281,9 +331,10 @@ AS_HELP_STRING([--disable-xml-context], AS_IF([test "x${enable_xml_context}" != "xno"], [AS_IF([test "x${enable_xml_context}" = "xyes" \ -o "x${enable_xml_context}" = "x"], - [AS_VAR_SET(enable_xml_context,1024)]) - AC_DEFINE_UNQUOTED([XML_CONTEXT_BYTES], [${enable_xml_context}], - [Define to specify how much context to retain around the current parse point.])]) + [AS_VAR_SET(enable_xml_context,1024)])], + [AS_VAR_SET(enable_xml_context,0)]) +AC_DEFINE_UNQUOTED([XML_CONTEXT_BYTES], [${enable_xml_context}], + [Define to specify how much context to retain around the current parse point, 0 to disable.]) AC_ARG_WITH([docbook], [AS_HELP_STRING([--with-docbook], @@ -307,7 +358,72 @@ AS_IF([test "x${DOCBOOK_TO_MAN}" != x -a "x$with_docbook" != xno], You can also configure using --without-docbook if you can do without a man page for xmlwf.])])]) -AM_CONDITIONAL(WITH_DOCBOOK, [test "x${DOCBOOK_TO_MAN}" != x]) +dnl This will make sure that a release tarball shipping a pre-rendered xmlwf man page will +dnl get it installed, when no working flavor of docbook2man is available (or wanted). +dnl This relies on file xmlwf.1 being at least as recent as its source file xmlwf.xml. +AS_IF([test -f "${srcdir}"/doc/xmlwf.1], + [AM_CONDITIONAL(WITH_MANPAGE, [true]) + AS_IF([test "x$with_docbook" = xno -o "x${DOCBOOK_TO_MAN}" = x], + [AM_CONDITIONAL(WITH_PREBUILT_MANPAGE, [true]) + AM_CONDITIONAL(WITH_DISTRIBUTABLE_MANPAGE, [false])], + [AM_CONDITIONAL(WITH_PREBUILT_MANPAGE, [false]) + AM_CONDITIONAL(WITH_DISTRIBUTABLE_MANPAGE, [true])]) + ], + [AS_IF([test "x$with_docbook" != xno -a "x${DOCBOOK_TO_MAN}" != x], + [AM_CONDITIONAL(WITH_MANPAGE, [true]) + AM_CONDITIONAL(WITH_DISTRIBUTABLE_MANPAGE, [true])], + [AM_CONDITIONAL(WITH_MANPAGE, [false]) + AM_CONDITIONAL(WITH_DISTRIBUTABLE_MANPAGE, [false])]) + AM_CONDITIONAL(WITH_PREBUILT_MANPAGE, [false])]) + +dnl Configure CMake file templates +dnl NOTE: The *_TRUE variables read here are Automake conditionals +dnl that are either set to "" when enabled or to "#" when disabled +dnl (because they are used to dynamically comment out certain things) +AS_IF([test "x${enable_xml_attr_info}" = xyes], + [EXPAT_ATTR_INFO=ON], + [EXPAT_ATTR_INFO=OFF]) +EXPAT_DTD=ON +AS_IF([test "x${_INTERNAL_LARGE_SIZE_TRUE}" = x], + [EXPAT_LARGE_SIZE=ON], + [EXPAT_LARGE_SIZE=OFF]) +AS_IF([test "x${_INTERNAL_MIN_SIZE_TRUE}" = x], + [EXPAT_MIN_SIZE=ON], + [EXPAT_MIN_SIZE=OFF]) +EXPAT_NS=ON +AS_IF([test "x${enable_xml_context}" != xno], + [EXPAT_CONTEXT_BYTES=${enable_xml_context}], + [EXPAT_CONTEXT_BYTES=OFF]) +AS_IF([test "x${UNICODE_TRUE}" = x], + [AS_IF( + [test "x${_INTERNAL_UNICODE_WCHAR_T_TRUE}" = x], + [EXPAT_CHAR_TYPE=wchar_t], + [EXPAT_CHAR_TYPE=ushort])], + [EXPAT_CHAR_TYPE=char]) +PACKAGE_INIT="${srcdir}"/cmake/autotools/expat-package-init.cmake +LIBDIR_BASENAME="$(basename "${libdir}")" +SO_MAJOR="$(expr "${LIBCURRENT}" - "${LIBAGE}")" +SO_MINOR="${LIBAGE}" +SO_PATCH="${LIBREVISION}" +AC_SUBST([EXPAT_ATTR_INFO]) +AC_SUBST([EXPAT_DTD]) +AC_SUBST([EXPAT_LARGE_SIZE]) +AC_SUBST([EXPAT_MIN_SIZE]) +AC_SUBST([EXPAT_NS]) +AC_SUBST([EXPAT_CONTEXT_BYTES]) +AC_SUBST([EXPAT_CHAR_TYPE]) +AC_SUBST_FILE([PACKAGE_INIT]) +AC_SUBST([LIBDIR_BASENAME]) +AC_SUBST([SO_MAJOR]) +AC_SUBST([SO_MINOR]) +AC_SUBST([SO_PATCH]) + +dnl The canonical way of doing this is AC_CHECK_SIZEOF(void *), but +dnl that adds SIZEOF_VOID_P to expat_config.h.in, making it difficult +dnl to have 32-bit and 64-bit versions of libexpat installed on the +dnl same system with a single, shared copy of the header. +AC_COMPUTE_INT(SIZEOF_VOID_P, [sizeof(void *)]) +AC_SUBST([SIZEOF_VOID_P]) dnl write the Automake flags we set AC_SUBST([AM_CPPFLAGS]) @@ -315,11 +431,23 @@ AC_SUBST([AM_CFLAGS]) AC_SUBST([AM_CXXFLAGS]) AC_SUBST([AM_LDFLAGS]) -dnl updating _EXPAT_OUTPUT_NAME variable to effect the package name in expat.pc file (issue #361) -AC_SUBST(_EXPAT_OUTPUT_NAME, ["$PACKAGE_NAME"]) +dnl Emulate the use of CMAKE_SHARED_LIBRARY_PREFIX under CMake +AC_MSG_CHECKING([for shared library name prefix]) +AS_CASE("${host_os}", + [cygwin*], [CMAKE_SHARED_LIBRARY_PREFIX=cyg], + [CMAKE_SHARED_LIBRARY_PREFIX=lib]) +AC_MSG_RESULT([${CMAKE_SHARED_LIBRARY_PREFIX}]) +AC_SUBST([CMAKE_SHARED_LIBRARY_PREFIX]) +AS_CASE("${host_os}", + [darwin*], [CMAKE_NOCONFIG_SOURCE=cmake/autotools/expat-noconfig__macos.cmake.in], + [mingw*|cygwin*], [CMAKE_NOCONFIG_SOURCE=cmake/autotools/expat-noconfig__windows.cmake.in], + [CMAKE_NOCONFIG_SOURCE=cmake/autotools/expat-noconfig__linux.cmake.in]) AC_CONFIG_FILES([Makefile] [expat.pc] + [cmake/expat-config.cmake] + [cmake/autotools/expat-config-version.cmake] + [cmake/autotools/expat-noconfig.cmake:${CMAKE_NOCONFIG_SOURCE}] [doc/Makefile] [examples/Makefile] [lib/Makefile] diff --git a/3rdparty/expat/conftools/PrintPath b/3rdparty/expat/conftools/PrintPath deleted file mode 100755 index e8559a3d643..00000000000 --- a/3rdparty/expat/conftools/PrintPath +++ /dev/null @@ -1,116 +0,0 @@ -#!/bin/sh -# Look for program[s] somewhere in $PATH. -# -# Options: -# -s -# Do not print out full pathname. (silent) -# -pPATHNAME -# Look in PATHNAME instead of $PATH -# -# Usage: -# PrintPath [-s] [-pPATHNAME] program [program ...] -# -# Initially written by Jim Jagielski for the Apache configuration mechanism -# (with kudos to Kernighan/Pike) -# -# This script falls under the Apache License. -# See http://www.apache.org/licenses/LICENSE - -## -# Some "constants" -## -pathname=$PATH -echo="yes" - -## -# Find out what OS we are running for later on -## -os=`(uname) 2>/dev/null` - -## -# Parse command line -## -for args in $* -do - case $args in - -s ) echo="no" ;; - -p* ) pathname="`echo $args | sed 's/^..//'`" ;; - * ) programs="$programs $args" ;; - esac -done - -## -# Now we make the adjustments required for OS/2 and everyone -# else :) -# -# First of all, all OS/2 programs have the '.exe' extension. -# Next, we adjust PATH (or what was given to us as PATH) to -# be whitespace separated directories. -# Finally, we try to determine the best flag to use for -# test/[] to look for an executable file. OS/2 just has '-r' -# but with other OSs, we do some funny stuff to check to see -# if test/[] knows about -x, which is the preferred flag. -## - -if [ "x$os" = "xOS/2" ] -then - ext=".exe" - pathname=`echo -E $pathname | - sed 's/^;/.;/ - s/;;/;.;/g - s/;$/;./ - s/;/ /g - s/\\\\/\\//g' ` - test_exec_flag="-r" -else - ext="" # No default extensions - pathname=`echo $pathname | - sed 's/^:/.:/ - s/::/:.:/g - s/:$/:./ - s/:/ /g' ` - # Here is how we test to see if test/[] can handle -x - testfile="pp.t.$$" - - cat > $testfile <<ENDTEST -#!/bin/sh -if [ -x / ] || [ -x /bin ] || [ -x /bin/ls ]; then - exit 0 -fi -exit 1 -ENDTEST - - if `/bin/sh $testfile 2>/dev/null`; then - test_exec_flag="-x" - else - test_exec_flag="-r" - fi - rm -f $testfile -fi - -for program in $programs -do - for path in $pathname - do - if [ $test_exec_flag $path/${program}${ext} ] && \ - [ ! -d $path/${program}${ext} ]; then - if [ "x$echo" = "xyes" ]; then - echo $path/${program}${ext} - fi - exit 0 - fi - -# Next try without extension (if one was used above) - if [ "x$ext" != "x" ]; then - if [ $test_exec_flag $path/${program} ] && \ - [ ! -d $path/${program} ]; then - if [ "x$echo" = "xyes" ]; then - echo $path/${program} - fi - exit 0 - fi - fi - done -done -exit 1 - diff --git a/3rdparty/expat/conftools/ar-lib b/3rdparty/expat/conftools/ar-lib index 1e9388e2ae3..c349042c3fa 100755 --- a/3rdparty/expat/conftools/ar-lib +++ b/3rdparty/expat/conftools/ar-lib @@ -4,7 +4,7 @@ me=ar-lib scriptversion=2019-07-04.01; # UTC -# Copyright (C) 2010-2020 Free Software Foundation, Inc. +# Copyright (C) 2010-2021 Free Software Foundation, Inc. # Written by Peter Rosin <peda@lysator.liu.se>. # # This program is free software; you can redistribute it and/or modify diff --git a/3rdparty/expat/conftools/ax-cxx-compile-stdcxx-11.m4 b/3rdparty/expat/conftools/ax-cxx-compile-stdcxx-11.m4 new file mode 100644 index 00000000000..1733fd85f95 --- /dev/null +++ b/3rdparty/expat/conftools/ax-cxx-compile-stdcxx-11.m4 @@ -0,0 +1,39 @@ +# ============================================================================= +# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html +# ============================================================================= +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX_11([ext|noext], [mandatory|optional]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the C++11 +# standard; if necessary, add switches to CXX and CXXCPP to enable +# support. +# +# This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX +# macro with the version set to C++11. The two optional arguments are +# forwarded literally as the second and third argument respectively. +# Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for +# more information. If you want to use this macro, you also need to +# download the ax_cxx_compile_stdcxx.m4 file. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com> +# Copyright (c) 2012 Zack Weinberg <zackw@panix.com> +# Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu> +# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com> +# Copyright (c) 2015 Paul Norman <penorman@mac.com> +# Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu> +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 18 + +AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX]) +AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [AX_CXX_COMPILE_STDCXX([11], [$1], [$2])]) diff --git a/3rdparty/expat/conftools/ax-cxx-compile-stdcxx.m4 b/3rdparty/expat/conftools/ax-cxx-compile-stdcxx.m4 new file mode 100644 index 00000000000..8edf5152ec7 --- /dev/null +++ b/3rdparty/expat/conftools/ax-cxx-compile-stdcxx.m4 @@ -0,0 +1,1018 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CXX_COMPILE_STDCXX(VERSION, [ext|noext], [mandatory|optional]) +# +# DESCRIPTION +# +# Check for baseline language coverage in the compiler for the specified +# version of the C++ standard. If necessary, add switches to CXX and +# CXXCPP to enable support. VERSION may be '11', '14', '17', or '20' for +# the respective C++ standard version. +# +# The second argument, if specified, indicates whether you insist on an +# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g. +# -std=c++11). If neither is specified, you get whatever works, with +# preference for no added switch, and then for an extended mode. +# +# The third argument, if specified 'mandatory' or if left unspecified, +# indicates that baseline support for the specified C++ standard is +# required and that the macro should error out if no mode with that +# support is found. If specified 'optional', then configuration proceeds +# regardless, after defining HAVE_CXX${VERSION} if and only if a +# supporting mode is found. +# +# LICENSE +# +# Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com> +# Copyright (c) 2012 Zack Weinberg <zackw@panix.com> +# Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu> +# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com> +# Copyright (c) 2015 Paul Norman <penorman@mac.com> +# Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu> +# Copyright (c) 2016, 2018 Krzesimir Nowak <qdlacz@gmail.com> +# Copyright (c) 2019 Enji Cooper <yaneurabeya@gmail.com> +# Copyright (c) 2020 Jason Merrill <jason@redhat.com> +# Copyright (c) 2021 Jörn Heusipp <osmanx@problemloesungsmaschine.de> +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 18 + +dnl This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro +dnl (serial version number 13). + +AC_DEFUN([AX_CXX_COMPILE_STDCXX], [dnl + m4_if([$1], [11], [ax_cxx_compile_alternatives="11 0x"], + [$1], [14], [ax_cxx_compile_alternatives="14 1y"], + [$1], [17], [ax_cxx_compile_alternatives="17 1z"], + [$1], [20], [ax_cxx_compile_alternatives="20"], + [m4_fatal([invalid first argument `$1' to AX_CXX_COMPILE_STDCXX])])dnl + m4_if([$2], [], [], + [$2], [ext], [], + [$2], [noext], [], + [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX])])dnl + m4_if([$3], [], [ax_cxx_compile_cxx$1_required=true], + [$3], [mandatory], [ax_cxx_compile_cxx$1_required=true], + [$3], [optional], [ax_cxx_compile_cxx$1_required=false], + [m4_fatal([invalid third argument `$3' to AX_CXX_COMPILE_STDCXX])]) + AC_LANG_PUSH([C++])dnl + ac_success=no + + m4_if([$2], [], [dnl + AC_CACHE_CHECK(whether $CXX supports C++$1 features by default, + ax_cv_cxx_compile_cxx$1, + [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [ax_cv_cxx_compile_cxx$1=yes], + [ax_cv_cxx_compile_cxx$1=no])]) + if test x$ax_cv_cxx_compile_cxx$1 = xyes; then + ac_success=yes + fi]) + + m4_if([$2], [noext], [], [dnl + if test x$ac_success = xno; then + for alternative in ${ax_cxx_compile_alternatives}; do + switch="-std=gnu++${alternative}" + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, + $cachevar, + [ac_save_CXX="$CXX" + CXX="$CXX $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXX="$ac_save_CXX"]) + if eval test x\$$cachevar = xyes; then + CXX="$CXX $switch" + if test -n "$CXXCPP" ; then + CXXCPP="$CXXCPP $switch" + fi + ac_success=yes + break + fi + done + fi]) + + m4_if([$2], [ext], [], [dnl + if test x$ac_success = xno; then + dnl HP's aCC needs +std=c++11 according to: + dnl http://h21007.www2.hp.com/portal/download/files/unprot/aCxx/PDF_Release_Notes/769149-001.pdf + dnl Cray's crayCC needs "-h std=c++11" + dnl MSVC needs -std:c++NN for C++17 and later (default is C++14) + for alternative in ${ax_cxx_compile_alternatives}; do + for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}" MSVC; do + if test x"$switch" = xMSVC; then + dnl AS_TR_SH maps both `:` and `=` to `_` so -std:c++17 would collide + dnl with -std=c++17. We suffix the cache variable name with _MSVC to + dnl avoid this. + switch=-std:c++${alternative} + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_${switch}_MSVC]) + else + cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx$1_$switch]) + fi + AC_CACHE_CHECK(whether $CXX supports C++$1 features with $switch, + $cachevar, + [ac_save_CXX="$CXX" + CXX="$CXX $switch" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])], + [eval $cachevar=yes], + [eval $cachevar=no]) + CXX="$ac_save_CXX"]) + if eval test x\$$cachevar = xyes; then + CXX="$CXX $switch" + if test -n "$CXXCPP" ; then + CXXCPP="$CXXCPP $switch" + fi + ac_success=yes + break + fi + done + if test x$ac_success = xyes; then + break + fi + done + fi]) + AC_LANG_POP([C++]) + if test x$ax_cxx_compile_cxx$1_required = xtrue; then + if test x$ac_success = xno; then + AC_MSG_ERROR([*** A compiler with support for C++$1 language features is required.]) + fi + fi + if test x$ac_success = xno; then + HAVE_CXX$1=0 + AC_MSG_NOTICE([No compiler with C++$1 support was found]) + else + HAVE_CXX$1=1 + AC_DEFINE(HAVE_CXX$1,1, + [define if the compiler supports basic C++$1 syntax]) + fi + AC_SUBST(HAVE_CXX$1) +]) + + +dnl Test body for checking C++11 support + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_11], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 +) + +dnl Test body for checking C++14 support + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_14], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 + _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 +) + +dnl Test body for checking C++17 support + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_17], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 + _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 + _AX_CXX_COMPILE_STDCXX_testbody_new_in_17 +) + +dnl Test body for checking C++20 support + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_20], + _AX_CXX_COMPILE_STDCXX_testbody_new_in_11 + _AX_CXX_COMPILE_STDCXX_testbody_new_in_14 + _AX_CXX_COMPILE_STDCXX_testbody_new_in_17 + _AX_CXX_COMPILE_STDCXX_testbody_new_in_20 +) + + +dnl Tests for new features in C++11 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_11], [[ + +// If the compiler admits that it is not ready for C++11, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +// MSVC always sets __cplusplus to 199711L in older versions; newer versions +// only set it correctly if /Zc:__cplusplus is specified as well as a +// /std:c++NN switch: +// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/ +#elif __cplusplus < 201103L && !defined _MSC_VER + +#error "This is not a C++11 compiler" + +#else + +namespace cxx11 +{ + + namespace test_static_assert + { + + template <typename T> + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + } + + namespace test_final_override + { + + struct Base + { + virtual ~Base() {} + virtual void f() {} + }; + + struct Derived : public Base + { + virtual ~Derived() override {} + virtual void f() override {} + }; + + } + + namespace test_double_right_angle_brackets + { + + template < typename T > + struct check {}; + + typedef check<void> single_type; + typedef check<check<void>> double_type; + typedef check<check<check<void>>> triple_type; + typedef check<check<check<check<void>>>> quadruple_type; + + } + + namespace test_decltype + { + + int + f() + { + int a = 1; + decltype(a) b = 2; + return a + b; + } + + } + + namespace test_type_deduction + { + + template < typename T1, typename T2 > + struct is_same + { + static const bool value = false; + }; + + template < typename T > + struct is_same<T, T> + { + static const bool value = true; + }; + + template < typename T1, typename T2 > + auto + add(T1 a1, T2 a2) -> decltype(a1 + a2) + { + return a1 + a2; + } + + int + test(const int c, volatile int v) + { + static_assert(is_same<int, decltype(0)>::value == true, ""); + static_assert(is_same<int, decltype(c)>::value == false, ""); + static_assert(is_same<int, decltype(v)>::value == false, ""); + auto ac = c; + auto av = v; + auto sumi = ac + av + 'x'; + auto sumf = ac + av + 1.0; + static_assert(is_same<int, decltype(ac)>::value == true, ""); + static_assert(is_same<int, decltype(av)>::value == true, ""); + static_assert(is_same<int, decltype(sumi)>::value == true, ""); + static_assert(is_same<int, decltype(sumf)>::value == false, ""); + static_assert(is_same<int, decltype(add(c, v))>::value == true, ""); + return (sumf > 0.0) ? sumi : add(c, v); + } + + } + + namespace test_noexcept + { + + int f() { return 0; } + int g() noexcept { return 0; } + + static_assert(noexcept(f()) == false, ""); + static_assert(noexcept(g()) == true, ""); + + } + + namespace test_constexpr + { + + template < typename CharT > + unsigned long constexpr + strlen_c_r(const CharT *const s, const unsigned long acc) noexcept + { + return *s ? strlen_c_r(s + 1, acc + 1) : acc; + } + + template < typename CharT > + unsigned long constexpr + strlen_c(const CharT *const s) noexcept + { + return strlen_c_r(s, 0UL); + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("1") == 1UL, ""); + static_assert(strlen_c("example") == 7UL, ""); + static_assert(strlen_c("another\0example") == 7UL, ""); + + } + + namespace test_rvalue_references + { + + template < int N > + struct answer + { + static constexpr int value = N; + }; + + answer<1> f(int&) { return answer<1>(); } + answer<2> f(const int&) { return answer<2>(); } + answer<3> f(int&&) { return answer<3>(); } + + void + test() + { + int i = 0; + const int c = 0; + static_assert(decltype(f(i))::value == 1, ""); + static_assert(decltype(f(c))::value == 2, ""); + static_assert(decltype(f(0))::value == 3, ""); + } + + } + + namespace test_uniform_initialization + { + + struct test + { + static const int zero {}; + static const int one {1}; + }; + + static_assert(test::zero == 0, ""); + static_assert(test::one == 1, ""); + + } + + namespace test_lambdas + { + + void + test1() + { + auto lambda1 = [](){}; + auto lambda2 = lambda1; + lambda1(); + lambda2(); + } + + int + test2() + { + auto a = [](int i, int j){ return i + j; }(1, 2); + auto b = []() -> int { return '0'; }(); + auto c = [=](){ return a + b; }(); + auto d = [&](){ return c; }(); + auto e = [a, &b](int x) mutable { + const auto identity = [](int y){ return y; }; + for (auto i = 0; i < a; ++i) + a += b--; + return x + identity(a + b); + }(0); + return a + b + c + d + e; + } + + int + test3() + { + const auto nullary = [](){ return 0; }; + const auto unary = [](int x){ return x; }; + using nullary_t = decltype(nullary); + using unary_t = decltype(unary); + const auto higher1st = [](nullary_t f){ return f(); }; + const auto higher2nd = [unary](nullary_t f1){ + return [unary, f1](unary_t f2){ return f2(unary(f1())); }; + }; + return higher1st(nullary) + higher2nd(nullary)(unary); + } + + } + + namespace test_variadic_templates + { + + template <int...> + struct sum; + + template <int N0, int... N1toN> + struct sum<N0, N1toN...> + { + static constexpr auto value = N0 + sum<N1toN...>::value; + }; + + template <> + struct sum<> + { + static constexpr auto value = 0; + }; + + static_assert(sum<>::value == 0, ""); + static_assert(sum<1>::value == 1, ""); + static_assert(sum<23>::value == 23, ""); + static_assert(sum<1, 2>::value == 3, ""); + static_assert(sum<5, 5, 11>::value == 21, ""); + static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, ""); + + } + + // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae + // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function + // because of this. + namespace test_template_alias_sfinae + { + + struct foo {}; + + template<typename T> + using member = typename T::member_type; + + template<typename T> + void func(...) {} + + template<typename T> + void func(member<T>*) {} + + void test(); + + void test() { func<foo>(0); } + + } + +} // namespace cxx11 + +#endif // __cplusplus >= 201103L + +]]) + + +dnl Tests for new features in C++14 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_14], [[ + +// If the compiler admits that it is not ready for C++14, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201402L && !defined _MSC_VER + +#error "This is not a C++14 compiler" + +#else + +namespace cxx14 +{ + + namespace test_polymorphic_lambdas + { + + int + test() + { + const auto lambda = [](auto&&... args){ + const auto istiny = [](auto x){ + return (sizeof(x) == 1UL) ? 1 : 0; + }; + const int aretiny[] = { istiny(args)... }; + return aretiny[0]; + }; + return lambda(1, 1L, 1.0f, '1'); + } + + } + + namespace test_binary_literals + { + + constexpr auto ivii = 0b0000000000101010; + static_assert(ivii == 42, "wrong value"); + + } + + namespace test_generalized_constexpr + { + + template < typename CharT > + constexpr unsigned long + strlen_c(const CharT *const s) noexcept + { + auto length = 0UL; + for (auto p = s; *p; ++p) + ++length; + return length; + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("x") == 1UL, ""); + static_assert(strlen_c("test") == 4UL, ""); + static_assert(strlen_c("another\0test") == 7UL, ""); + + } + + namespace test_lambda_init_capture + { + + int + test() + { + auto x = 0; + const auto lambda1 = [a = x](int b){ return a + b; }; + const auto lambda2 = [a = lambda1(x)](){ return a; }; + return lambda2(); + } + + } + + namespace test_digit_separators + { + + constexpr auto ten_million = 100'000'000; + static_assert(ten_million == 100000000, ""); + + } + + namespace test_return_type_deduction + { + + auto f(int& x) { return x; } + decltype(auto) g(int& x) { return x; } + + template < typename T1, typename T2 > + struct is_same + { + static constexpr auto value = false; + }; + + template < typename T > + struct is_same<T, T> + { + static constexpr auto value = true; + }; + + int + test() + { + auto x = 0; + static_assert(is_same<int, decltype(f(x))>::value, ""); + static_assert(is_same<int&, decltype(g(x))>::value, ""); + return x; + } + + } + +} // namespace cxx14 + +#endif // __cplusplus >= 201402L + +]]) + + +dnl Tests for new features in C++17 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_17], [[ + +// If the compiler admits that it is not ready for C++17, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201703L && !defined _MSC_VER + +#error "This is not a C++17 compiler" + +#else + +#include <initializer_list> +#include <utility> +#include <type_traits> + +namespace cxx17 +{ + + namespace test_constexpr_lambdas + { + + constexpr int foo = [](){return 42;}(); + + } + + namespace test::nested_namespace::definitions + { + + } + + namespace test_fold_expression + { + + template<typename... Args> + int multiply(Args... args) + { + return (args * ... * 1); + } + + template<typename... Args> + bool all(Args... args) + { + return (args && ...); + } + + } + + namespace test_extended_static_assert + { + + static_assert (true); + + } + + namespace test_auto_brace_init_list + { + + auto foo = {5}; + auto bar {5}; + + static_assert(std::is_same<std::initializer_list<int>, decltype(foo)>::value); + static_assert(std::is_same<int, decltype(bar)>::value); + } + + namespace test_typename_in_template_template_parameter + { + + template<template<typename> typename X> struct D; + + } + + namespace test_fallthrough_nodiscard_maybe_unused_attributes + { + + int f1() + { + return 42; + } + + [[nodiscard]] int f2() + { + [[maybe_unused]] auto unused = f1(); + + switch (f1()) + { + case 17: + f1(); + [[fallthrough]]; + case 42: + f1(); + } + return f1(); + } + + } + + namespace test_extended_aggregate_initialization + { + + struct base1 + { + int b1, b2 = 42; + }; + + struct base2 + { + base2() { + b3 = 42; + } + int b3; + }; + + struct derived : base1, base2 + { + int d; + }; + + derived d1 {{1, 2}, {}, 4}; // full initialization + derived d2 {{}, {}, 4}; // value-initialized bases + + } + + namespace test_general_range_based_for_loop + { + + struct iter + { + int i; + + int& operator* () + { + return i; + } + + const int& operator* () const + { + return i; + } + + iter& operator++() + { + ++i; + return *this; + } + }; + + struct sentinel + { + int i; + }; + + bool operator== (const iter& i, const sentinel& s) + { + return i.i == s.i; + } + + bool operator!= (const iter& i, const sentinel& s) + { + return !(i == s); + } + + struct range + { + iter begin() const + { + return {0}; + } + + sentinel end() const + { + return {5}; + } + }; + + void f() + { + range r {}; + + for (auto i : r) + { + [[maybe_unused]] auto v = i; + } + } + + } + + namespace test_lambda_capture_asterisk_this_by_value + { + + struct t + { + int i; + int foo() + { + return [*this]() + { + return i; + }(); + } + }; + + } + + namespace test_enum_class_construction + { + + enum class byte : unsigned char + {}; + + byte foo {42}; + + } + + namespace test_constexpr_if + { + + template <bool cond> + int f () + { + if constexpr(cond) + { + return 13; + } + else + { + return 42; + } + } + + } + + namespace test_selection_statement_with_initializer + { + + int f() + { + return 13; + } + + int f2() + { + if (auto i = f(); i > 0) + { + return 3; + } + + switch (auto i = f(); i + 4) + { + case 17: + return 2; + + default: + return 1; + } + } + + } + + namespace test_template_argument_deduction_for_class_templates + { + + template <typename T1, typename T2> + struct pair + { + pair (T1 p1, T2 p2) + : m1 {p1}, + m2 {p2} + {} + + T1 m1; + T2 m2; + }; + + void f() + { + [[maybe_unused]] auto p = pair{13, 42u}; + } + + } + + namespace test_non_type_auto_template_parameters + { + + template <auto n> + struct B + {}; + + B<5> b1; + B<'a'> b2; + + } + + namespace test_structured_bindings + { + + int arr[2] = { 1, 2 }; + std::pair<int, int> pr = { 1, 2 }; + + auto f1() -> int(&)[2] + { + return arr; + } + + auto f2() -> std::pair<int, int>& + { + return pr; + } + + struct S + { + int x1 : 2; + volatile double y1; + }; + + S f3() + { + return {}; + } + + auto [ x1, y1 ] = f1(); + auto& [ xr1, yr1 ] = f1(); + auto [ x2, y2 ] = f2(); + auto& [ xr2, yr2 ] = f2(); + const auto [ x3, y3 ] = f3(); + + } + + namespace test_exception_spec_type_system + { + + struct Good {}; + struct Bad {}; + + void g1() noexcept; + void g2(); + + template<typename T> + Bad + f(T*, T*); + + template<typename T1, typename T2> + Good + f(T1*, T2*); + + static_assert (std::is_same_v<Good, decltype(f(g1, g2))>); + + } + + namespace test_inline_variables + { + + template<class T> void f(T) + {} + + template<class T> inline T g(T) + { + return T{}; + } + + template<> inline void f<>(int) + {} + + template<> int g<>(int) + { + return 5; + } + + } + +} // namespace cxx17 + +#endif // __cplusplus < 201703L && !defined _MSC_VER + +]]) + + +dnl Tests for new features in C++20 + +m4_define([_AX_CXX_COMPILE_STDCXX_testbody_new_in_20], [[ + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 202002L && !defined _MSC_VER + +#error "This is not a C++20 compiler" + +#else + +#include <version> + +namespace cxx20 +{ + +// As C++20 supports feature test macros in the standard, there is no +// immediate need to actually test for feature availability on the +// Autoconf side. + +} // namespace cxx20 + +#endif // __cplusplus < 202002L && !defined _MSC_VER + +]]) diff --git a/3rdparty/expat/conftools/compile b/3rdparty/expat/conftools/compile index 23fcba01132..df363c8fbfb 100755 --- a/3rdparty/expat/conftools/compile +++ b/3rdparty/expat/conftools/compile @@ -3,7 +3,7 @@ scriptversion=2018-03-07.03; # UTC -# Copyright (C) 1999-2020 Free Software Foundation, Inc. +# Copyright (C) 1999-2021 Free Software Foundation, Inc. # Written by Tom Tromey <tromey@cygnus.com>. # # This program is free software; you can redistribute it and/or modify diff --git a/3rdparty/expat/conftools/config.guess b/3rdparty/expat/conftools/config.guess index df895493ef7..160ecf0951b 100755 --- a/3rdparty/expat/conftools/config.guess +++ b/3rdparty/expat/conftools/config.guess @@ -1,12 +1,14 @@ #! /bin/sh # Attempt to guess a canonical system name. -# Copyright 1992-2019 Free Software Foundation, Inc. +# Copyright 1992-2022 Free Software Foundation, Inc. -timestamp='2019-09-10' +# shellcheck disable=SC2006,SC2268 # see below for rationale + +timestamp='2022-05-08' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or +# the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but @@ -27,11 +29,19 @@ timestamp='2019-09-10' # Originally written by Per Bothner; maintained since 2000 by Ben Elliston. # # You can get the latest version of this script from: -# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess +# https://git.savannah.gnu.org/cgit/config.git/plain/config.guess # # Please send patches to <config-patches@gnu.org>. +# The "shellcheck disable" line above the timestamp inhibits complaints +# about features and limitations of the classic Bourne shell that were +# superseded or lifted in POSIX. However, this script identifies a wide +# variety of pre-POSIX systems that do not have POSIX shells at all, and +# even some reasonably current systems (Solaris 10 as case-in-point) still +# have a pre-POSIX /bin/sh. + + me=`echo "$0" | sed -e 's,.*/,,'` usage="\ @@ -50,7 +60,7 @@ version="\ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright 1992-2019 Free Software Foundation, Inc. +Copyright 1992-2022 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -84,6 +94,9 @@ if test $# != 0; then exit 1 fi +# Just in case it came from the environment. +GUESS= + # CC_FOR_BUILD -- compiler used by this script. Note that the use of a # compiler to aid in system detection is discouraged as it requires # temporary files to be created and, as you can see below, it is a @@ -99,8 +112,10 @@ tmp= trap 'test -z "$tmp" || rm -fr "$tmp"' 0 1 2 13 15 set_cc_for_build() { + # prevent multiple calls if $tmp is already set + test "$tmp" && return 0 : "${TMPDIR=/tmp}" - # shellcheck disable=SC2039 + # shellcheck disable=SC2039,SC3028 { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir "$tmp" 2>/dev/null) ; } || { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir "$tmp" 2>/dev/null) && echo "Warning: creating insecure temp directory" >&2 ; } || @@ -110,7 +125,7 @@ set_cc_for_build() { ,,) echo "int x;" > "$dummy.c" for driver in cc gcc c89 c99 ; do if ($driver -c -o "$dummy.o" "$dummy.c") >/dev/null 2>&1 ; then - CC_FOR_BUILD="$driver" + CC_FOR_BUILD=$driver break fi done @@ -131,14 +146,12 @@ fi UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown -UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown -case "$UNAME_SYSTEM" in +case $UNAME_SYSTEM in Linux|GNU|GNU/*) - # If the system lacks a compiler, then just pick glibc. - # We could probably try harder. - LIBC=gnu + LIBC=unknown set_cc_for_build cat <<-EOF > "$dummy.c" @@ -147,24 +160,37 @@ Linux|GNU|GNU/*) LIBC=uclibc #elif defined(__dietlibc__) LIBC=dietlibc - #else + #elif defined(__GLIBC__) LIBC=gnu + #else + #include <stdarg.h> + /* First heuristic to detect musl libc. */ + #ifdef __DEFINED_va_list + LIBC=musl + #endif #endif EOF - eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`" + cc_set_libc=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^LIBC' | sed 's, ,,g'` + eval "$cc_set_libc" - # If ldd exists, use it to detect musl libc. - if command -v ldd >/dev/null && \ - ldd --version 2>&1 | grep -q ^musl - then - LIBC=musl + # Second heuristic to detect musl libc. + if [ "$LIBC" = unknown ] && + command -v ldd >/dev/null && + ldd --version 2>&1 | grep -q ^musl; then + LIBC=musl + fi + + # If the system lacks a compiler, then just pick glibc. + # We could probably try harder. + if [ "$LIBC" = unknown ]; then + LIBC=gnu fi ;; esac # Note: order is significant - the case branches are not exclusive. -case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in +case $UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION in *:NetBSD:*:*) # NetBSD (nbsd) targets should (where applicable) match one or # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*, @@ -176,12 +202,12 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in # # Note: NetBSD doesn't particularly care about the vendor # portion of the name. We always set it to "unknown". - sysctl="sysctl -n hw.machine_arch" UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \ - "/sbin/$sysctl" 2>/dev/null || \ - "/usr/sbin/$sysctl" 2>/dev/null || \ + /sbin/sysctl -n hw.machine_arch 2>/dev/null || \ + /usr/sbin/sysctl -n hw.machine_arch 2>/dev/null || \ echo unknown)` - case "$UNAME_MACHINE_ARCH" in + case $UNAME_MACHINE_ARCH in + aarch64eb) machine=aarch64_be-unknown ;; armeb) machine=armeb-unknown ;; arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; @@ -190,13 +216,13 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in earmv*) arch=`echo "$UNAME_MACHINE_ARCH" | sed -e 's,^e\(armv[0-9]\).*$,\1,'` endian=`echo "$UNAME_MACHINE_ARCH" | sed -ne 's,^.*\(eb\)$,\1,p'` - machine="${arch}${endian}"-unknown + machine=${arch}${endian}-unknown ;; - *) machine="$UNAME_MACHINE_ARCH"-unknown ;; + *) machine=$UNAME_MACHINE_ARCH-unknown ;; esac # The Operating System including object format, if it has switched # to ELF recently (or will in the future) and ABI. - case "$UNAME_MACHINE_ARCH" in + case $UNAME_MACHINE_ARCH in earm*) os=netbsdelf ;; @@ -217,7 +243,7 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in ;; esac # Determine ABI tags. - case "$UNAME_MACHINE_ARCH" in + case $UNAME_MACHINE_ARCH in earm*) expr='s/^earmv[0-9]/-eabi/;s/eb$//' abi=`echo "$UNAME_MACHINE_ARCH" | sed -e "$expr"` @@ -228,7 +254,7 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in # thus, need a distinct triplet. However, they do not need # kernel version information, so it can be replaced with a # suitable tag, in the style of linux-gnu. - case "$UNAME_VERSION" in + case $UNAME_VERSION in Debian*) release='-gnu' ;; @@ -239,51 +265,57 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. - echo "$machine-${os}${release}${abi-}" - exit ;; + GUESS=$machine-${os}${release}${abi-} + ;; *:Bitrig:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` - echo "$UNAME_MACHINE_ARCH"-unknown-bitrig"$UNAME_RELEASE" - exit ;; + GUESS=$UNAME_MACHINE_ARCH-unknown-bitrig$UNAME_RELEASE + ;; *:OpenBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` - echo "$UNAME_MACHINE_ARCH"-unknown-openbsd"$UNAME_RELEASE" - exit ;; + GUESS=$UNAME_MACHINE_ARCH-unknown-openbsd$UNAME_RELEASE + ;; + *:SecBSD:*:*) + UNAME_MACHINE_ARCH=`arch | sed 's/SecBSD.//'` + GUESS=$UNAME_MACHINE_ARCH-unknown-secbsd$UNAME_RELEASE + ;; *:LibertyBSD:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` - echo "$UNAME_MACHINE_ARCH"-unknown-libertybsd"$UNAME_RELEASE" - exit ;; + GUESS=$UNAME_MACHINE_ARCH-unknown-libertybsd$UNAME_RELEASE + ;; *:MidnightBSD:*:*) - echo "$UNAME_MACHINE"-unknown-midnightbsd"$UNAME_RELEASE" - exit ;; + GUESS=$UNAME_MACHINE-unknown-midnightbsd$UNAME_RELEASE + ;; *:ekkoBSD:*:*) - echo "$UNAME_MACHINE"-unknown-ekkobsd"$UNAME_RELEASE" - exit ;; + GUESS=$UNAME_MACHINE-unknown-ekkobsd$UNAME_RELEASE + ;; *:SolidBSD:*:*) - echo "$UNAME_MACHINE"-unknown-solidbsd"$UNAME_RELEASE" - exit ;; + GUESS=$UNAME_MACHINE-unknown-solidbsd$UNAME_RELEASE + ;; *:OS108:*:*) - echo "$UNAME_MACHINE"-unknown-os108_"$UNAME_RELEASE" - exit ;; + GUESS=$UNAME_MACHINE-unknown-os108_$UNAME_RELEASE + ;; macppc:MirBSD:*:*) - echo powerpc-unknown-mirbsd"$UNAME_RELEASE" - exit ;; + GUESS=powerpc-unknown-mirbsd$UNAME_RELEASE + ;; *:MirBSD:*:*) - echo "$UNAME_MACHINE"-unknown-mirbsd"$UNAME_RELEASE" - exit ;; + GUESS=$UNAME_MACHINE-unknown-mirbsd$UNAME_RELEASE + ;; *:Sortix:*:*) - echo "$UNAME_MACHINE"-unknown-sortix - exit ;; + GUESS=$UNAME_MACHINE-unknown-sortix + ;; *:Twizzler:*:*) - echo "$UNAME_MACHINE"-unknown-twizzler - exit ;; + GUESS=$UNAME_MACHINE-unknown-twizzler + ;; *:Redox:*:*) - echo "$UNAME_MACHINE"-unknown-redox - exit ;; + GUESS=$UNAME_MACHINE-unknown-redox + ;; mips:OSF1:*.*) - echo mips-dec-osf1 - exit ;; + GUESS=mips-dec-osf1 + ;; alpha:OSF1:*:*) + # Reset EXIT trap before exiting to avoid spurious non-zero exit code. + trap '' 0 case $UNAME_RELEASE in *4.0) UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` @@ -297,7 +329,7 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in # covers most systems running today. This code pipes the CPU # types through head -n 1, so we only detect the type of CPU 0. ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` - case "$ALPHA_CPU_TYPE" in + case $ALPHA_CPU_TYPE in "EV4 (21064)") UNAME_MACHINE=alpha ;; "EV4.5 (21064)") @@ -334,117 +366,121 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. - echo "$UNAME_MACHINE"-dec-osf"`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`" - # Reset EXIT trap before exiting to avoid spurious non-zero exit code. - exitcode=$? - trap '' 0 - exit $exitcode ;; + OSF_REL=`echo "$UNAME_RELEASE" | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` + GUESS=$UNAME_MACHINE-dec-osf$OSF_REL + ;; Amiga*:UNIX_System_V:4.0:*) - echo m68k-unknown-sysv4 - exit ;; + GUESS=m68k-unknown-sysv4 + ;; *:[Aa]miga[Oo][Ss]:*:*) - echo "$UNAME_MACHINE"-unknown-amigaos - exit ;; + GUESS=$UNAME_MACHINE-unknown-amigaos + ;; *:[Mm]orph[Oo][Ss]:*:*) - echo "$UNAME_MACHINE"-unknown-morphos - exit ;; + GUESS=$UNAME_MACHINE-unknown-morphos + ;; *:OS/390:*:*) - echo i370-ibm-openedition - exit ;; + GUESS=i370-ibm-openedition + ;; *:z/VM:*:*) - echo s390-ibm-zvmoe - exit ;; + GUESS=s390-ibm-zvmoe + ;; *:OS400:*:*) - echo powerpc-ibm-os400 - exit ;; + GUESS=powerpc-ibm-os400 + ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) - echo arm-acorn-riscix"$UNAME_RELEASE" - exit ;; + GUESS=arm-acorn-riscix$UNAME_RELEASE + ;; arm*:riscos:*:*|arm*:RISCOS:*:*) - echo arm-unknown-riscos - exit ;; + GUESS=arm-unknown-riscos + ;; SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) - echo hppa1.1-hitachi-hiuxmpp - exit ;; + GUESS=hppa1.1-hitachi-hiuxmpp + ;; Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. - if test "`(/bin/universe) 2>/dev/null`" = att ; then - echo pyramid-pyramid-sysv3 - else - echo pyramid-pyramid-bsd - fi - exit ;; + case `(/bin/universe) 2>/dev/null` in + att) GUESS=pyramid-pyramid-sysv3 ;; + *) GUESS=pyramid-pyramid-bsd ;; + esac + ;; NILE*:*:*:dcosx) - echo pyramid-pyramid-svr4 - exit ;; + GUESS=pyramid-pyramid-svr4 + ;; DRS?6000:unix:4.0:6*) - echo sparc-icl-nx6 - exit ;; + GUESS=sparc-icl-nx6 + ;; DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) case `/usr/bin/uname -p` in - sparc) echo sparc-icl-nx7; exit ;; - esac ;; + sparc) GUESS=sparc-icl-nx7 ;; + esac + ;; s390x:SunOS:*:*) - echo "$UNAME_MACHINE"-ibm-solaris2"`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`" - exit ;; + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=$UNAME_MACHINE-ibm-solaris2$SUN_REL + ;; sun4H:SunOS:5.*:*) - echo sparc-hal-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`" - exit ;; + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=sparc-hal-solaris2$SUN_REL + ;; sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) - echo sparc-sun-solaris2"`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'`" - exit ;; + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=sparc-sun-solaris2$SUN_REL + ;; i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*) - echo i386-pc-auroraux"$UNAME_RELEASE" - exit ;; + GUESS=i386-pc-auroraux$UNAME_RELEASE + ;; i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) set_cc_for_build SUN_ARCH=i386 # If there is a compiler, see if it is configured for 64-bit objects. # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. # This test works for both compilers. - if [ "$CC_FOR_BUILD" != no_compiler_found ]; then + if test "$CC_FOR_BUILD" != no_compiler_found; then if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + (CCOPTS="" $CC_FOR_BUILD -m64 -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then SUN_ARCH=x86_64 fi fi - echo "$SUN_ARCH"-pc-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`" - exit ;; + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=$SUN_ARCH-pc-solaris2$SUN_REL + ;; sun4*:SunOS:6*:*) # According to config.sub, this is the proper way to canonicalize # SunOS6. Hard to guess exactly what SunOS6 will be like, but # it's likely to be more like Solaris than SunOS4. - echo sparc-sun-solaris3"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`" - exit ;; + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=sparc-sun-solaris3$SUN_REL + ;; sun4*:SunOS:*:*) - case "`/usr/bin/arch -k`" in + case `/usr/bin/arch -k` in Series*|S4*) UNAME_RELEASE=`uname -v` ;; esac # Japanese Language versions have a version number like `4.1.3-JL'. - echo sparc-sun-sunos"`echo "$UNAME_RELEASE"|sed -e 's/-/_/'`" - exit ;; + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/'` + GUESS=sparc-sun-sunos$SUN_REL + ;; sun3*:SunOS:*:*) - echo m68k-sun-sunos"$UNAME_RELEASE" - exit ;; + GUESS=m68k-sun-sunos$UNAME_RELEASE + ;; sun*:*:4.2BSD:*) UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` test "x$UNAME_RELEASE" = x && UNAME_RELEASE=3 - case "`/bin/arch`" in + case `/bin/arch` in sun3) - echo m68k-sun-sunos"$UNAME_RELEASE" + GUESS=m68k-sun-sunos$UNAME_RELEASE ;; sun4) - echo sparc-sun-sunos"$UNAME_RELEASE" + GUESS=sparc-sun-sunos$UNAME_RELEASE ;; esac - exit ;; + ;; aushp:SunOS:*:*) - echo sparc-auspex-sunos"$UNAME_RELEASE" - exit ;; + GUESS=sparc-auspex-sunos$UNAME_RELEASE + ;; # The situation for MiNT is a little confusing. The machine name # can be virtually everything (everything which is not # "atarist" or "atariste" at least should have a processor @@ -454,41 +490,41 @@ case "$UNAME_MACHINE:$UNAME_SYSTEM:$UNAME_RELEASE:$UNAME_VERSION" in # MiNT. But MiNT is downward compatible to TOS, so this should # be no problem. atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint"$UNAME_RELEASE" - exit ;; + GUESS=m68k-atari-mint$UNAME_RELEASE + ;; atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint"$UNAME_RELEASE" - exit ;; + GUESS=m68k-atari-mint$UNAME_RELEASE + ;; *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) - echo m68k-atari-mint"$UNAME_RELEASE" - exit ;; + GUESS=m68k-atari-mint$UNAME_RELEASE + ;; milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) - echo m68k-milan-mint"$UNAME_RELEASE" - exit ;; + GUESS=m68k-milan-mint$UNAME_RELEASE + ;; hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) - echo m68k-hades-mint"$UNAME_RELEASE" - exit ;; + GUESS=m68k-hades-mint$UNAME_RELEASE + ;; *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) - echo m68k-unknown-mint"$UNAME_RELEASE" - exit ;; + GUESS=m68k-unknown-mint$UNAME_RELEASE + ;; m68k:machten:*:*) - echo m68k-apple-machten"$UNAME_RELEASE" - exit ;; + GUESS=m68k-apple-machten$UNAME_RELEASE + ;; powerpc:machten:*:*) - echo powerpc-apple-machten"$UNAME_RELEASE" - exit ;; + GUESS=powerpc-apple-machten$UNAME_RELEASE + ;; RISC*:Mach:*:*) - echo mips-dec-mach_bsd4.3 - exit ;; + GUESS=mips-dec-mach_bsd4.3 + ;; RISC*:ULTRIX:*:*) - echo mips-dec-ultrix"$UNAME_RELEASE" - exit ;; + GUESS=mips-dec-ultrix$UNAME_RELEASE + ;; VAX*:ULTRIX*:*:*) - echo vax-dec-ultrix"$UNAME_RELEASE" - exit ;; + GUESS=vax-dec-ultrix$UNAME_RELEASE + ;; 2020:CLIX:*:* | 2430:CLIX:*:*) - echo clipper-intergraph-clix"$UNAME_RELEASE" - exit ;; + GUESS=clipper-intergraph-clix$UNAME_RELEASE + ;; mips:*:*:UMIPS | mips:*:*:RISCos) set_cc_for_build sed 's/^ //' << EOF > "$dummy.c" @@ -516,75 +552,76 @@ EOF dummyarg=`echo "$UNAME_RELEASE" | sed -n 's/\([0-9]*\).*/\1/p'` && SYSTEM_NAME=`"$dummy" "$dummyarg"` && { echo "$SYSTEM_NAME"; exit; } - echo mips-mips-riscos"$UNAME_RELEASE" - exit ;; + GUESS=mips-mips-riscos$UNAME_RELEASE + ;; Motorola:PowerMAX_OS:*:*) - echo powerpc-motorola-powermax - exit ;; + GUESS=powerpc-motorola-powermax + ;; Motorola:*:4.3:PL8-*) - echo powerpc-harris-powermax - exit ;; + GUESS=powerpc-harris-powermax + ;; Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) - echo powerpc-harris-powermax - exit ;; + GUESS=powerpc-harris-powermax + ;; Night_Hawk:Power_UNIX:*:*) - echo powerpc-harris-powerunix - exit ;; + GUESS=powerpc-harris-powerunix + ;; m88k:CX/UX:7*:*) - echo m88k-harris-cxux7 - exit ;; + GUESS=m88k-harris-cxux7 + ;; m88k:*:4*:R4*) - echo m88k-motorola-sysv4 - exit ;; + GUESS=m88k-motorola-sysv4 + ;; m88k:*:3*:R3*) - echo m88k-motorola-sysv3 - exit ;; + GUESS=m88k-motorola-sysv3 + ;; AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=`/usr/bin/uname -p` - if [ "$UNAME_PROCESSOR" = mc88100 ] || [ "$UNAME_PROCESSOR" = mc88110 ] + if test "$UNAME_PROCESSOR" = mc88100 || test "$UNAME_PROCESSOR" = mc88110 then - if [ "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx ] || \ - [ "$TARGET_BINARY_INTERFACE"x = x ] + if test "$TARGET_BINARY_INTERFACE"x = m88kdguxelfx || \ + test "$TARGET_BINARY_INTERFACE"x = x then - echo m88k-dg-dgux"$UNAME_RELEASE" + GUESS=m88k-dg-dgux$UNAME_RELEASE else - echo m88k-dg-dguxbcs"$UNAME_RELEASE" + GUESS=m88k-dg-dguxbcs$UNAME_RELEASE fi else - echo i586-dg-dgux"$UNAME_RELEASE" + GUESS=i586-dg-dgux$UNAME_RELEASE fi - exit ;; + ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) - echo m88k-dolphin-sysv3 - exit ;; + GUESS=m88k-dolphin-sysv3 + ;; M88*:*:R3*:*) # Delta 88k system running SVR3 - echo m88k-motorola-sysv3 - exit ;; + GUESS=m88k-motorola-sysv3 + ;; XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) - echo m88k-tektronix-sysv3 - exit ;; + GUESS=m88k-tektronix-sysv3 + ;; Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) - echo m68k-tektronix-bsd - exit ;; + GUESS=m68k-tektronix-bsd + ;; *:IRIX*:*:*) - echo mips-sgi-irix"`echo "$UNAME_RELEASE"|sed -e 's/-/_/g'`" - exit ;; + IRIX_REL=`echo "$UNAME_RELEASE" | sed -e 's/-/_/g'` + GUESS=mips-sgi-irix$IRIX_REL + ;; ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. - echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id - exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + GUESS=romp-ibm-aix # uname -m gives an 8 hex-code CPU id + ;; # Note that: echo "'`uname -s`'" gives 'AIX ' i*86:AIX:*:*) - echo i386-ibm-aix - exit ;; + GUESS=i386-ibm-aix + ;; ia64:AIX:*:*) - if [ -x /usr/bin/oslevel ] ; then + if test -x /usr/bin/oslevel ; then IBM_REV=`/usr/bin/oslevel` else - IBM_REV="$UNAME_VERSION.$UNAME_RELEASE" + IBM_REV=$UNAME_VERSION.$UNAME_RELEASE fi - echo "$UNAME_MACHINE"-ibm-aix"$IBM_REV" - exit ;; + GUESS=$UNAME_MACHINE-ibm-aix$IBM_REV + ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then set_cc_for_build @@ -601,16 +638,16 @@ EOF EOF if $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` then - echo "$SYSTEM_NAME" + GUESS=$SYSTEM_NAME else - echo rs6000-ibm-aix3.2.5 + GUESS=rs6000-ibm-aix3.2.5 fi elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then - echo rs6000-ibm-aix3.2.4 + GUESS=rs6000-ibm-aix3.2.4 else - echo rs6000-ibm-aix3.2 + GUESS=rs6000-ibm-aix3.2 fi - exit ;; + ;; *:AIX:*:[4567]) IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` if /usr/sbin/lsattr -El "$IBM_CPU_ID" | grep ' POWER' >/dev/null 2>&1; then @@ -618,56 +655,56 @@ EOF else IBM_ARCH=powerpc fi - if [ -x /usr/bin/lslpp ] ; then - IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | + if test -x /usr/bin/lslpp ; then + IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | \ awk -F: '{ print $3 }' | sed s/[0-9]*$/0/` else - IBM_REV="$UNAME_VERSION.$UNAME_RELEASE" + IBM_REV=$UNAME_VERSION.$UNAME_RELEASE fi - echo "$IBM_ARCH"-ibm-aix"$IBM_REV" - exit ;; + GUESS=$IBM_ARCH-ibm-aix$IBM_REV + ;; *:AIX:*:*) - echo rs6000-ibm-aix - exit ;; + GUESS=rs6000-ibm-aix + ;; ibmrt:4.4BSD:*|romp-ibm:4.4BSD:*) - echo romp-ibm-bsd4.4 - exit ;; + GUESS=romp-ibm-bsd4.4 + ;; ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and - echo romp-ibm-bsd"$UNAME_RELEASE" # 4.3 with uname added to - exit ;; # report: romp-ibm BSD 4.3 + GUESS=romp-ibm-bsd$UNAME_RELEASE # 4.3 with uname added to + ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) - echo rs6000-bull-bosx - exit ;; + GUESS=rs6000-bull-bosx + ;; DPX/2?00:B.O.S.:*:*) - echo m68k-bull-sysv3 - exit ;; + GUESS=m68k-bull-sysv3 + ;; 9000/[34]??:4.3bsd:1.*:*) - echo m68k-hp-bsd - exit ;; + GUESS=m68k-hp-bsd + ;; hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) - echo m68k-hp-bsd4.4 - exit ;; + GUESS=m68k-hp-bsd4.4 + ;; 9000/[34678]??:HP-UX:*:*) - HPUX_REV=`echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//'` - case "$UNAME_MACHINE" in + HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'` + case $UNAME_MACHINE in 9000/31?) HP_ARCH=m68000 ;; 9000/[34]??) HP_ARCH=m68k ;; 9000/[678][0-9][0-9]) - if [ -x /usr/bin/getconf ]; then + if test -x /usr/bin/getconf; then sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` - case "$sc_cpu_version" in + case $sc_cpu_version in 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1 532) # CPU_PA_RISC2_0 - case "$sc_kernel_bits" in + case $sc_kernel_bits in 32) HP_ARCH=hppa2.0n ;; 64) HP_ARCH=hppa2.0w ;; '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20 esac ;; esac fi - if [ "$HP_ARCH" = "" ]; then + if test "$HP_ARCH" = ""; then set_cc_for_build sed 's/^ //' << EOF > "$dummy.c" @@ -706,7 +743,7 @@ EOF test -z "$HP_ARCH" && HP_ARCH=hppa fi ;; esac - if [ "$HP_ARCH" = hppa2.0w ] + if test "$HP_ARCH" = hppa2.0w then set_cc_for_build @@ -727,12 +764,12 @@ EOF HP_ARCH=hppa64 fi fi - echo "$HP_ARCH"-hp-hpux"$HPUX_REV" - exit ;; + GUESS=$HP_ARCH-hp-hpux$HPUX_REV + ;; ia64:HP-UX:*:*) - HPUX_REV=`echo "$UNAME_RELEASE"|sed -e 's/[^.]*.[0B]*//'` - echo ia64-hp-hpux"$HPUX_REV" - exit ;; + HPUX_REV=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*.[0B]*//'` + GUESS=ia64-hp-hpux$HPUX_REV + ;; 3050*:HI-UX:*:*) set_cc_for_build sed 's/^ //' << EOF > "$dummy.c" @@ -762,36 +799,36 @@ EOF EOF $CC_FOR_BUILD -o "$dummy" "$dummy.c" && SYSTEM_NAME=`"$dummy"` && { echo "$SYSTEM_NAME"; exit; } - echo unknown-hitachi-hiuxwe2 - exit ;; + GUESS=unknown-hitachi-hiuxwe2 + ;; 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:*) - echo hppa1.1-hp-bsd - exit ;; + GUESS=hppa1.1-hp-bsd + ;; 9000/8??:4.3bsd:*:*) - echo hppa1.0-hp-bsd - exit ;; + GUESS=hppa1.0-hp-bsd + ;; *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) - echo hppa1.0-hp-mpeix - exit ;; + GUESS=hppa1.0-hp-mpeix + ;; hp7??:OSF1:*:* | hp8?[79]:OSF1:*:*) - echo hppa1.1-hp-osf - exit ;; + GUESS=hppa1.1-hp-osf + ;; hp8??:OSF1:*:*) - echo hppa1.0-hp-osf - exit ;; + GUESS=hppa1.0-hp-osf + ;; i*86:OSF1:*:*) - if [ -x /usr/sbin/sysversion ] ; then - echo "$UNAME_MACHINE"-unknown-osf1mk + if test -x /usr/sbin/sysversion ; then + GUESS=$UNAME_MACHINE-unknown-osf1mk else - echo "$UNAME_MACHINE"-unknown-osf1 + GUESS=$UNAME_MACHINE-unknown-osf1 fi - exit ;; + ;; parisc*:Lites*:*:*) - echo hppa1.1-hp-lites - exit ;; + GUESS=hppa1.1-hp-lites + ;; C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) - echo c1-convex-bsd - exit ;; + GUESS=c1-convex-bsd + ;; C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) if getsysinfo -f scalar_acc then echo c32-convex-bsd @@ -799,17 +836,18 @@ EOF fi exit ;; C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) - echo c34-convex-bsd - exit ;; + GUESS=c34-convex-bsd + ;; C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) - echo c38-convex-bsd - exit ;; + GUESS=c38-convex-bsd + ;; C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) - echo c4-convex-bsd - exit ;; + GUESS=c4-convex-bsd + ;; CRAY*Y-MP:*:*:*) - echo ymp-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' - exit ;; + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=ymp-cray-unicos$CRAY_REL + ;; CRAY*[A-Z]90:*:*:*) echo "$UNAME_MACHINE"-cray-unicos"$UNAME_RELEASE" \ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ @@ -817,114 +855,129 @@ EOF -e 's/\.[^.]*$/.X/' exit ;; CRAY*TS:*:*:*) - echo t90-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' - exit ;; + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=t90-cray-unicos$CRAY_REL + ;; CRAY*T3E:*:*:*) - echo alphaev5-cray-unicosmk"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' - exit ;; + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=alphaev5-cray-unicosmk$CRAY_REL + ;; CRAY*SV1:*:*:*) - echo sv1-cray-unicos"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' - exit ;; + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=sv1-cray-unicos$CRAY_REL + ;; *:UNICOS/mp:*:*) - echo craynv-cray-unicosmp"$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/' - exit ;; + CRAY_REL=`echo "$UNAME_RELEASE" | sed -e 's/\.[^.]*$/.X/'` + GUESS=craynv-cray-unicosmp$CRAY_REL + ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` FUJITSU_REL=`echo "$UNAME_RELEASE" | sed -e 's/ /_/'` - echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; + GUESS=${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL} + ;; 5000:UNIX_System_V:4.*:*) FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` FUJITSU_REL=`echo "$UNAME_RELEASE" | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'` - echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; + GUESS=sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL} + ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) - echo "$UNAME_MACHINE"-pc-bsdi"$UNAME_RELEASE" - exit ;; + GUESS=$UNAME_MACHINE-pc-bsdi$UNAME_RELEASE + ;; sparc*:BSD/OS:*:*) - echo sparc-unknown-bsdi"$UNAME_RELEASE" - exit ;; + GUESS=sparc-unknown-bsdi$UNAME_RELEASE + ;; *:BSD/OS:*:*) - echo "$UNAME_MACHINE"-unknown-bsdi"$UNAME_RELEASE" - exit ;; + GUESS=$UNAME_MACHINE-unknown-bsdi$UNAME_RELEASE + ;; arm:FreeBSD:*:*) UNAME_PROCESSOR=`uname -p` set_cc_for_build if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_PCS_VFP then - echo "${UNAME_PROCESSOR}"-unknown-freebsd"`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`"-gnueabi + FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabi else - echo "${UNAME_PROCESSOR}"-unknown-freebsd"`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`"-gnueabihf + FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL-gnueabihf fi - exit ;; + ;; *:FreeBSD:*:*) UNAME_PROCESSOR=`/usr/bin/uname -p` - case "$UNAME_PROCESSOR" in + case $UNAME_PROCESSOR in amd64) UNAME_PROCESSOR=x86_64 ;; i386) UNAME_PROCESSOR=i586 ;; esac - echo "$UNAME_PROCESSOR"-unknown-freebsd"`echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`" - exit ;; + FREEBSD_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_PROCESSOR-unknown-freebsd$FREEBSD_REL + ;; i*:CYGWIN*:*) - echo "$UNAME_MACHINE"-pc-cygwin - exit ;; + GUESS=$UNAME_MACHINE-pc-cygwin + ;; *:MINGW64*:*) - echo "$UNAME_MACHINE"-pc-mingw64 - exit ;; + GUESS=$UNAME_MACHINE-pc-mingw64 + ;; *:MINGW*:*) - echo "$UNAME_MACHINE"-pc-mingw32 - exit ;; + GUESS=$UNAME_MACHINE-pc-mingw32 + ;; *:MSYS*:*) - echo "$UNAME_MACHINE"-pc-msys - exit ;; + GUESS=$UNAME_MACHINE-pc-msys + ;; i*:PW*:*) - echo "$UNAME_MACHINE"-pc-pw32 - exit ;; + GUESS=$UNAME_MACHINE-pc-pw32 + ;; + *:SerenityOS:*:*) + GUESS=$UNAME_MACHINE-pc-serenity + ;; *:Interix*:*) - case "$UNAME_MACHINE" in + case $UNAME_MACHINE in x86) - echo i586-pc-interix"$UNAME_RELEASE" - exit ;; + GUESS=i586-pc-interix$UNAME_RELEASE + ;; authenticamd | genuineintel | EM64T) - echo x86_64-unknown-interix"$UNAME_RELEASE" - exit ;; + GUESS=x86_64-unknown-interix$UNAME_RELEASE + ;; IA64) - echo ia64-unknown-interix"$UNAME_RELEASE" - exit ;; + GUESS=ia64-unknown-interix$UNAME_RELEASE + ;; esac ;; i*:UWIN*:*) - echo "$UNAME_MACHINE"-pc-uwin - exit ;; + GUESS=$UNAME_MACHINE-pc-uwin + ;; amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) - echo x86_64-pc-cygwin - exit ;; + GUESS=x86_64-pc-cygwin + ;; prep*:SunOS:5.*:*) - echo powerpcle-unknown-solaris2"`echo "$UNAME_RELEASE"|sed -e 's/[^.]*//'`" - exit ;; + SUN_REL=`echo "$UNAME_RELEASE" | sed -e 's/[^.]*//'` + GUESS=powerpcle-unknown-solaris2$SUN_REL + ;; *:GNU:*:*) # the GNU system - echo "`echo "$UNAME_MACHINE"|sed -e 's,[-/].*$,,'`-unknown-$LIBC`echo "$UNAME_RELEASE"|sed -e 's,/.*$,,'`" - exit ;; + GNU_ARCH=`echo "$UNAME_MACHINE" | sed -e 's,[-/].*$,,'` + GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's,/.*$,,'` + GUESS=$GNU_ARCH-unknown-$LIBC$GNU_REL + ;; *:GNU/*:*:*) # other systems with GNU libc and userland - echo "$UNAME_MACHINE-unknown-`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`-$LIBC" - exit ;; + GNU_SYS=`echo "$UNAME_SYSTEM" | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"` + GNU_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_MACHINE-unknown-$GNU_SYS$GNU_REL-$LIBC + ;; *:Minix:*:*) - echo "$UNAME_MACHINE"-unknown-minix - exit ;; + GUESS=$UNAME_MACHINE-unknown-minix + ;; aarch64:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; aarch64_be:Linux:*:*) UNAME_MACHINE=aarch64_be - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; alpha:Linux:*:*) - case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in + case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' /proc/cpuinfo 2>/dev/null` in EV5) UNAME_MACHINE=alphaev5 ;; EV56) UNAME_MACHINE=alphaev56 ;; PCA56) UNAME_MACHINE=alphapca56 ;; @@ -935,60 +988,63 @@ EOF esac objdump --private-headers /bin/sh | grep -q ld.so.1 if test "$?" = 0 ; then LIBC=gnulibc1 ; fi - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; - arc:Linux:*:* | arceb:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + arc:Linux:*:* | arceb:Linux:*:* | arc32:Linux:*:* | arc64:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; arm*:Linux:*:*) set_cc_for_build if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_EABI__ then - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC else if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \ | grep -q __ARM_PCS_VFP then - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabi + GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabi else - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC"eabihf + GUESS=$UNAME_MACHINE-unknown-linux-${LIBC}eabihf fi fi - exit ;; + ;; avr32*:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; cris:Linux:*:*) - echo "$UNAME_MACHINE"-axis-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-axis-linux-$LIBC + ;; crisv32:Linux:*:*) - echo "$UNAME_MACHINE"-axis-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-axis-linux-$LIBC + ;; e2k:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; frv:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; hexagon:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; i*86:Linux:*:*) - echo "$UNAME_MACHINE"-pc-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-pc-linux-$LIBC + ;; ia64:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; k1om:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; + loongarch32:Linux:*:* | loongarch64:Linux:*:* | loongarchx32:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; m32r*:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; m68*:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; mips:Linux:*:* | mips64:Linux:*:*) set_cc_for_build IS_GLIBC=0 @@ -1033,124 +1089,135 @@ EOF #endif #endif EOF - eval "`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'`" + cc_set_vars=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^CPU\|^MIPS_ENDIAN\|^LIBCABI'` + eval "$cc_set_vars" test "x$CPU" != x && { echo "$CPU${MIPS_ENDIAN}-unknown-linux-$LIBCABI"; exit; } ;; mips64el:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; openrisc*:Linux:*:*) - echo or1k-unknown-linux-"$LIBC" - exit ;; + GUESS=or1k-unknown-linux-$LIBC + ;; or32:Linux:*:* | or1k*:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; padre:Linux:*:*) - echo sparc-unknown-linux-"$LIBC" - exit ;; + GUESS=sparc-unknown-linux-$LIBC + ;; parisc64:Linux:*:* | hppa64:Linux:*:*) - echo hppa64-unknown-linux-"$LIBC" - exit ;; + GUESS=hppa64-unknown-linux-$LIBC + ;; parisc:Linux:*:* | hppa:Linux:*:*) # Look for CPU level case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in - PA7*) echo hppa1.1-unknown-linux-"$LIBC" ;; - PA8*) echo hppa2.0-unknown-linux-"$LIBC" ;; - *) echo hppa-unknown-linux-"$LIBC" ;; + PA7*) GUESS=hppa1.1-unknown-linux-$LIBC ;; + PA8*) GUESS=hppa2.0-unknown-linux-$LIBC ;; + *) GUESS=hppa-unknown-linux-$LIBC ;; esac - exit ;; + ;; ppc64:Linux:*:*) - echo powerpc64-unknown-linux-"$LIBC" - exit ;; + GUESS=powerpc64-unknown-linux-$LIBC + ;; ppc:Linux:*:*) - echo powerpc-unknown-linux-"$LIBC" - exit ;; + GUESS=powerpc-unknown-linux-$LIBC + ;; ppc64le:Linux:*:*) - echo powerpc64le-unknown-linux-"$LIBC" - exit ;; + GUESS=powerpc64le-unknown-linux-$LIBC + ;; ppcle:Linux:*:*) - echo powerpcle-unknown-linux-"$LIBC" - exit ;; - riscv32:Linux:*:* | riscv64:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=powerpcle-unknown-linux-$LIBC + ;; + riscv32:Linux:*:* | riscv32be:Linux:*:* | riscv64:Linux:*:* | riscv64be:Linux:*:*) + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; s390:Linux:*:* | s390x:Linux:*:*) - echo "$UNAME_MACHINE"-ibm-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-ibm-linux-$LIBC + ;; sh64*:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; sh*:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; sparc:Linux:*:* | sparc64:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; tile*:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; vax:Linux:*:*) - echo "$UNAME_MACHINE"-dec-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-dec-linux-$LIBC + ;; x86_64:Linux:*:*) set_cc_for_build - X86_64_ABI= - # If there is a compiler, see if it is configured for 32-bit objects. - if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then - if (echo '#ifdef __ILP32__'; echo IS_X32; echo '#endif') | \ - (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ - grep IS_X32 >/dev/null - then - X86_64_ABI=x32 - fi + CPU=$UNAME_MACHINE + LIBCABI=$LIBC + if test "$CC_FOR_BUILD" != no_compiler_found; then + ABI=64 + sed 's/^ //' << EOF > "$dummy.c" + #ifdef __i386__ + ABI=x86 + #else + #ifdef __ILP32__ + ABI=x32 + #endif + #endif +EOF + cc_set_abi=`$CC_FOR_BUILD -E "$dummy.c" 2>/dev/null | grep '^ABI' | sed 's, ,,g'` + eval "$cc_set_abi" + case $ABI in + x86) CPU=i686 ;; + x32) LIBCABI=${LIBC}x32 ;; + esac fi - echo "$UNAME_MACHINE"-pc-linux-"$LIBC$X86_64_ABI" - exit ;; + GUESS=$CPU-pc-linux-$LIBCABI + ;; xtensa*:Linux:*:*) - echo "$UNAME_MACHINE"-unknown-linux-"$LIBC" - exit ;; + GUESS=$UNAME_MACHINE-unknown-linux-$LIBC + ;; i*86:DYNIX/ptx:4*:*) # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. # earlier versions are messed up and put the nodename in both # sysname and nodename. - echo i386-sequent-sysv4 - exit ;; + GUESS=i386-sequent-sysv4 + ;; i*86:UNIX_SV:4.2MP:2.*) # Unixware is an offshoot of SVR4, but it has its own version # number series starting with 2... # I am not positive that other SVR4 systems won't match this, # I just have to hope. -- rms. # Use sysv4.2uw... so that sysv4* matches it. - echo "$UNAME_MACHINE"-pc-sysv4.2uw"$UNAME_VERSION" - exit ;; + GUESS=$UNAME_MACHINE-pc-sysv4.2uw$UNAME_VERSION + ;; i*86:OS/2:*:*) # If we were able to find `uname', then EMX Unix compatibility # is probably installed. - echo "$UNAME_MACHINE"-pc-os2-emx - exit ;; + GUESS=$UNAME_MACHINE-pc-os2-emx + ;; i*86:XTS-300:*:STOP) - echo "$UNAME_MACHINE"-unknown-stop - exit ;; + GUESS=$UNAME_MACHINE-unknown-stop + ;; i*86:atheos:*:*) - echo "$UNAME_MACHINE"-unknown-atheos - exit ;; + GUESS=$UNAME_MACHINE-unknown-atheos + ;; i*86:syllable:*:*) - echo "$UNAME_MACHINE"-pc-syllable - exit ;; + GUESS=$UNAME_MACHINE-pc-syllable + ;; i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*) - echo i386-unknown-lynxos"$UNAME_RELEASE" - exit ;; + GUESS=i386-unknown-lynxos$UNAME_RELEASE + ;; i*86:*DOS:*:*) - echo "$UNAME_MACHINE"-pc-msdosdjgpp - exit ;; + GUESS=$UNAME_MACHINE-pc-msdosdjgpp + ;; i*86:*:4.*:*) UNAME_REL=`echo "$UNAME_RELEASE" | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then - echo "$UNAME_MACHINE"-univel-sysv"$UNAME_REL" + GUESS=$UNAME_MACHINE-univel-sysv$UNAME_REL else - echo "$UNAME_MACHINE"-pc-sysv"$UNAME_REL" + GUESS=$UNAME_MACHINE-pc-sysv$UNAME_REL fi - exit ;; + ;; i*86:*:5:[678]*) # UnixWare 7.x, OpenUNIX and OpenServer 6. case `/bin/uname -X | grep "^Machine"` in @@ -1158,12 +1225,12 @@ EOF *Pentium) UNAME_MACHINE=i586 ;; *Pent*|*Celeron) UNAME_MACHINE=i686 ;; esac - echo "$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}" - exit ;; + GUESS=$UNAME_MACHINE-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} + ;; i*86:*:3.2:*) if test -f /usr/options/cb.name; then UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name` - echo "$UNAME_MACHINE"-pc-isc"$UNAME_REL" + GUESS=$UNAME_MACHINE-pc-isc$UNAME_REL elif /bin/uname -X 2>/dev/null >/dev/null ; then UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 @@ -1173,11 +1240,11 @@ EOF && UNAME_MACHINE=i686 (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ && UNAME_MACHINE=i686 - echo "$UNAME_MACHINE"-pc-sco"$UNAME_REL" + GUESS=$UNAME_MACHINE-pc-sco$UNAME_REL else - echo "$UNAME_MACHINE"-pc-sysv32 + GUESS=$UNAME_MACHINE-pc-sysv32 fi - exit ;; + ;; pc:*:*:*) # Left here for compatibility: # uname -m prints for DJGPP always 'pc', but it prints nothing about @@ -1185,31 +1252,31 @@ EOF # Note: whatever this is, it MUST be the same as what config.sub # prints for the "djgpp" host, or else GDB configure will decide that # this is a cross-build. - echo i586-pc-msdosdjgpp - exit ;; + GUESS=i586-pc-msdosdjgpp + ;; Intel:Mach:3*:*) - echo i386-pc-mach3 - exit ;; + GUESS=i386-pc-mach3 + ;; paragon:*:*:*) - echo i860-intel-osf1 - exit ;; + GUESS=i860-intel-osf1 + ;; i860:*:4.*:*) # i860-SVR4 if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then - echo i860-stardent-sysv"$UNAME_RELEASE" # Stardent Vistra i860-SVR4 + GUESS=i860-stardent-sysv$UNAME_RELEASE # Stardent Vistra i860-SVR4 else # Add other i860-SVR4 vendors below as they are discovered. - echo i860-unknown-sysv"$UNAME_RELEASE" # Unknown i860-SVR4 + GUESS=i860-unknown-sysv$UNAME_RELEASE # Unknown i860-SVR4 fi - exit ;; + ;; mini*:CTIX:SYS*5:*) # "miniframe" - echo m68010-convergent-sysv - exit ;; + GUESS=m68010-convergent-sysv + ;; mc68k:UNIX:SYSTEM5:3.51m) - echo m68k-convergent-sysv - exit ;; + GUESS=m68k-convergent-sysv + ;; M680?0:D-NIX:5.3:*) - echo m68k-diab-dnix - exit ;; + GUESS=m68k-diab-dnix + ;; M68*:*:R3V[5678]*:*) test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) @@ -1234,113 +1301,116 @@ EOF /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \ && { echo i586-ncr-sysv4.3"$OS_REL"; exit; } ;; m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) - echo m68k-unknown-lynxos"$UNAME_RELEASE" - exit ;; + GUESS=m68k-unknown-lynxos$UNAME_RELEASE + ;; mc68030:UNIX_System_V:4.*:*) - echo m68k-atari-sysv4 - exit ;; + GUESS=m68k-atari-sysv4 + ;; TSUNAMI:LynxOS:2.*:*) - echo sparc-unknown-lynxos"$UNAME_RELEASE" - exit ;; + GUESS=sparc-unknown-lynxos$UNAME_RELEASE + ;; rs6000:LynxOS:2.*:*) - echo rs6000-unknown-lynxos"$UNAME_RELEASE" - exit ;; + GUESS=rs6000-unknown-lynxos$UNAME_RELEASE + ;; PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*) - echo powerpc-unknown-lynxos"$UNAME_RELEASE" - exit ;; + GUESS=powerpc-unknown-lynxos$UNAME_RELEASE + ;; SM[BE]S:UNIX_SV:*:*) - echo mips-dde-sysv"$UNAME_RELEASE" - exit ;; + GUESS=mips-dde-sysv$UNAME_RELEASE + ;; RM*:ReliantUNIX-*:*:*) - echo mips-sni-sysv4 - exit ;; + GUESS=mips-sni-sysv4 + ;; RM*:SINIX-*:*:*) - echo mips-sni-sysv4 - exit ;; + GUESS=mips-sni-sysv4 + ;; *:SINIX-*:*:*) if uname -p 2>/dev/null >/dev/null ; then UNAME_MACHINE=`(uname -p) 2>/dev/null` - echo "$UNAME_MACHINE"-sni-sysv4 + GUESS=$UNAME_MACHINE-sni-sysv4 else - echo ns32k-sni-sysv + GUESS=ns32k-sni-sysv fi - exit ;; + ;; PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort # says <Richard.M.Bartel@ccMail.Census.GOV> - echo i586-unisys-sysv4 - exit ;; + GUESS=i586-unisys-sysv4 + ;; *:UNIX_System_V:4*:FTX*) # From Gerald Hewes <hewes@openmarket.com>. # How about differentiating between stratus architectures? -djm - echo hppa1.1-stratus-sysv4 - exit ;; + GUESS=hppa1.1-stratus-sysv4 + ;; *:*:*:FTX*) # From seanf@swdc.stratus.com. - echo i860-stratus-sysv4 - exit ;; + GUESS=i860-stratus-sysv4 + ;; i*86:VOS:*:*) # From Paul.Green@stratus.com. - echo "$UNAME_MACHINE"-stratus-vos - exit ;; + GUESS=$UNAME_MACHINE-stratus-vos + ;; *:VOS:*:*) # From Paul.Green@stratus.com. - echo hppa1.1-stratus-vos - exit ;; + GUESS=hppa1.1-stratus-vos + ;; mc68*:A/UX:*:*) - echo m68k-apple-aux"$UNAME_RELEASE" - exit ;; + GUESS=m68k-apple-aux$UNAME_RELEASE + ;; news*:NEWS-OS:6*:*) - echo mips-sony-newsos6 - exit ;; + GUESS=mips-sony-newsos6 + ;; R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) - if [ -d /usr/nec ]; then - echo mips-nec-sysv"$UNAME_RELEASE" + if test -d /usr/nec; then + GUESS=mips-nec-sysv$UNAME_RELEASE else - echo mips-unknown-sysv"$UNAME_RELEASE" + GUESS=mips-unknown-sysv$UNAME_RELEASE fi - exit ;; + ;; BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. - echo powerpc-be-beos - exit ;; + GUESS=powerpc-be-beos + ;; BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. - echo powerpc-apple-beos - exit ;; + GUESS=powerpc-apple-beos + ;; BePC:BeOS:*:*) # BeOS running on Intel PC compatible. - echo i586-pc-beos - exit ;; + GUESS=i586-pc-beos + ;; BePC:Haiku:*:*) # Haiku running on Intel PC compatible. - echo i586-pc-haiku - exit ;; + GUESS=i586-pc-haiku + ;; x86_64:Haiku:*:*) - echo x86_64-unknown-haiku - exit ;; + GUESS=x86_64-unknown-haiku + ;; SX-4:SUPER-UX:*:*) - echo sx4-nec-superux"$UNAME_RELEASE" - exit ;; + GUESS=sx4-nec-superux$UNAME_RELEASE + ;; SX-5:SUPER-UX:*:*) - echo sx5-nec-superux"$UNAME_RELEASE" - exit ;; + GUESS=sx5-nec-superux$UNAME_RELEASE + ;; SX-6:SUPER-UX:*:*) - echo sx6-nec-superux"$UNAME_RELEASE" - exit ;; + GUESS=sx6-nec-superux$UNAME_RELEASE + ;; SX-7:SUPER-UX:*:*) - echo sx7-nec-superux"$UNAME_RELEASE" - exit ;; + GUESS=sx7-nec-superux$UNAME_RELEASE + ;; SX-8:SUPER-UX:*:*) - echo sx8-nec-superux"$UNAME_RELEASE" - exit ;; + GUESS=sx8-nec-superux$UNAME_RELEASE + ;; SX-8R:SUPER-UX:*:*) - echo sx8r-nec-superux"$UNAME_RELEASE" - exit ;; + GUESS=sx8r-nec-superux$UNAME_RELEASE + ;; SX-ACE:SUPER-UX:*:*) - echo sxace-nec-superux"$UNAME_RELEASE" - exit ;; + GUESS=sxace-nec-superux$UNAME_RELEASE + ;; Power*:Rhapsody:*:*) - echo powerpc-apple-rhapsody"$UNAME_RELEASE" - exit ;; + GUESS=powerpc-apple-rhapsody$UNAME_RELEASE + ;; *:Rhapsody:*:*) - echo "$UNAME_MACHINE"-apple-rhapsody"$UNAME_RELEASE" - exit ;; + GUESS=$UNAME_MACHINE-apple-rhapsody$UNAME_RELEASE + ;; + arm64:Darwin:*:*) + GUESS=aarch64-apple-darwin$UNAME_RELEASE + ;; *:Darwin:*:*) UNAME_PROCESSOR=`uname -p` case $UNAME_PROCESSOR in @@ -1355,7 +1425,7 @@ EOF else set_cc_for_build fi - if [ "$CC_FOR_BUILD" != no_compiler_found ]; then + if test "$CC_FOR_BUILD" != no_compiler_found; then if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null @@ -1376,109 +1446,119 @@ EOF # uname -m returns i386 or x86_64 UNAME_PROCESSOR=$UNAME_MACHINE fi - echo "$UNAME_PROCESSOR"-apple-darwin"$UNAME_RELEASE" - exit ;; + GUESS=$UNAME_PROCESSOR-apple-darwin$UNAME_RELEASE + ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) UNAME_PROCESSOR=`uname -p` if test "$UNAME_PROCESSOR" = x86; then UNAME_PROCESSOR=i386 UNAME_MACHINE=pc fi - echo "$UNAME_PROCESSOR"-"$UNAME_MACHINE"-nto-qnx"$UNAME_RELEASE" - exit ;; + GUESS=$UNAME_PROCESSOR-$UNAME_MACHINE-nto-qnx$UNAME_RELEASE + ;; *:QNX:*:4*) - echo i386-pc-qnx - exit ;; + GUESS=i386-pc-qnx + ;; NEO-*:NONSTOP_KERNEL:*:*) - echo neo-tandem-nsk"$UNAME_RELEASE" - exit ;; + GUESS=neo-tandem-nsk$UNAME_RELEASE + ;; NSE-*:NONSTOP_KERNEL:*:*) - echo nse-tandem-nsk"$UNAME_RELEASE" - exit ;; + GUESS=nse-tandem-nsk$UNAME_RELEASE + ;; NSR-*:NONSTOP_KERNEL:*:*) - echo nsr-tandem-nsk"$UNAME_RELEASE" - exit ;; + GUESS=nsr-tandem-nsk$UNAME_RELEASE + ;; NSV-*:NONSTOP_KERNEL:*:*) - echo nsv-tandem-nsk"$UNAME_RELEASE" - exit ;; + GUESS=nsv-tandem-nsk$UNAME_RELEASE + ;; NSX-*:NONSTOP_KERNEL:*:*) - echo nsx-tandem-nsk"$UNAME_RELEASE" - exit ;; + GUESS=nsx-tandem-nsk$UNAME_RELEASE + ;; *:NonStop-UX:*:*) - echo mips-compaq-nonstopux - exit ;; + GUESS=mips-compaq-nonstopux + ;; BS2000:POSIX*:*:*) - echo bs2000-siemens-sysv - exit ;; + GUESS=bs2000-siemens-sysv + ;; DS/*:UNIX_System_V:*:*) - echo "$UNAME_MACHINE"-"$UNAME_SYSTEM"-"$UNAME_RELEASE" - exit ;; + GUESS=$UNAME_MACHINE-$UNAME_SYSTEM-$UNAME_RELEASE + ;; *:Plan9:*:*) # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 # operating systems. - # shellcheck disable=SC2154 - if test "$cputype" = 386; then + if test "${cputype-}" = 386; then UNAME_MACHINE=i386 - else - UNAME_MACHINE="$cputype" + elif test "x${cputype-}" != x; then + UNAME_MACHINE=$cputype fi - echo "$UNAME_MACHINE"-unknown-plan9 - exit ;; + GUESS=$UNAME_MACHINE-unknown-plan9 + ;; *:TOPS-10:*:*) - echo pdp10-unknown-tops10 - exit ;; + GUESS=pdp10-unknown-tops10 + ;; *:TENEX:*:*) - echo pdp10-unknown-tenex - exit ;; + GUESS=pdp10-unknown-tenex + ;; KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) - echo pdp10-dec-tops20 - exit ;; + GUESS=pdp10-dec-tops20 + ;; XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) - echo pdp10-xkl-tops20 - exit ;; + GUESS=pdp10-xkl-tops20 + ;; *:TOPS-20:*:*) - echo pdp10-unknown-tops20 - exit ;; + GUESS=pdp10-unknown-tops20 + ;; *:ITS:*:*) - echo pdp10-unknown-its - exit ;; + GUESS=pdp10-unknown-its + ;; SEI:*:*:SEIUX) - echo mips-sei-seiux"$UNAME_RELEASE" - exit ;; + GUESS=mips-sei-seiux$UNAME_RELEASE + ;; *:DragonFly:*:*) - echo "$UNAME_MACHINE"-unknown-dragonfly"`echo "$UNAME_RELEASE"|sed -e 's/[-(].*//'`" - exit ;; + DRAGONFLY_REL=`echo "$UNAME_RELEASE" | sed -e 's/[-(].*//'` + GUESS=$UNAME_MACHINE-unknown-dragonfly$DRAGONFLY_REL + ;; *:*VMS:*:*) UNAME_MACHINE=`(uname -p) 2>/dev/null` - case "$UNAME_MACHINE" in - A*) echo alpha-dec-vms ; exit ;; - I*) echo ia64-dec-vms ; exit ;; - V*) echo vax-dec-vms ; exit ;; + case $UNAME_MACHINE in + A*) GUESS=alpha-dec-vms ;; + I*) GUESS=ia64-dec-vms ;; + V*) GUESS=vax-dec-vms ;; esac ;; *:XENIX:*:SysV) - echo i386-pc-xenix - exit ;; + GUESS=i386-pc-xenix + ;; i*86:skyos:*:*) - echo "$UNAME_MACHINE"-pc-skyos"`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'`" - exit ;; + SKYOS_REL=`echo "$UNAME_RELEASE" | sed -e 's/ .*$//'` + GUESS=$UNAME_MACHINE-pc-skyos$SKYOS_REL + ;; i*86:rdos:*:*) - echo "$UNAME_MACHINE"-pc-rdos - exit ;; - i*86:AROS:*:*) - echo "$UNAME_MACHINE"-pc-aros - exit ;; + GUESS=$UNAME_MACHINE-pc-rdos + ;; + i*86:Fiwix:*:*) + GUESS=$UNAME_MACHINE-pc-fiwix + ;; + *:AROS:*:*) + GUESS=$UNAME_MACHINE-unknown-aros + ;; x86_64:VMkernel:*:*) - echo "$UNAME_MACHINE"-unknown-esx - exit ;; + GUESS=$UNAME_MACHINE-unknown-esx + ;; amd64:Isilon\ OneFS:*:*) - echo x86_64-unknown-onefs - exit ;; + GUESS=x86_64-unknown-onefs + ;; *:Unleashed:*:*) - echo "$UNAME_MACHINE"-unknown-unleashed"$UNAME_RELEASE" - exit ;; + GUESS=$UNAME_MACHINE-unknown-unleashed$UNAME_RELEASE + ;; esac +# Do we have a guess based on uname results? +if test "x$GUESS" != x; then + echo "$GUESS" + exit +fi + # No uname command or uname output not recognized. set_cc_for_build cat > "$dummy.c" <<EOF @@ -1610,7 +1690,7 @@ main () } EOF -$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`$dummy` && +$CC_FOR_BUILD -o "$dummy" "$dummy.c" 2>/dev/null && SYSTEM_NAME=`"$dummy"` && { echo "$SYSTEM_NAME"; exit; } # Apollos put the system type in the environment. @@ -1618,7 +1698,7 @@ test -d /usr/apollo && { echo "$ISP-apollo-$SYSTYPE"; exit; } echo "$0: unable to guess system type" >&2 -case "$UNAME_MACHINE:$UNAME_SYSTEM" in +case $UNAME_MACHINE:$UNAME_SYSTEM in mips:Linux | mips64:Linux) # If we got here on MIPS GNU/Linux, output extra information. cat >&2 <<EOF @@ -1635,9 +1715,17 @@ This script (version $timestamp), has failed to recognize the operating system you are using. If your script is old, overwrite *all* copies of config.guess and config.sub with the latest versions from: - https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess + https://git.savannah.gnu.org/cgit/config.git/plain/config.guess and - https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub + https://git.savannah.gnu.org/cgit/config.git/plain/config.sub +EOF + +our_year=`echo $timestamp | sed 's,-.*,,'` +thisyear=`date +%Y` +# shellcheck disable=SC2003 +script_age=`expr "$thisyear" - "$our_year"` +if test "$script_age" -lt 3 ; then + cat >&2 <<EOF If $0 has already been updated, send the following data and any information you think might be pertinent to config-patches@gnu.org to @@ -1665,6 +1753,7 @@ UNAME_RELEASE = "$UNAME_RELEASE" UNAME_SYSTEM = "$UNAME_SYSTEM" UNAME_VERSION = "$UNAME_VERSION" EOF +fi exit 1 diff --git a/3rdparty/expat/conftools/config.sub b/3rdparty/expat/conftools/config.sub index 96fca060bde..a31fff318a1 100755 --- a/3rdparty/expat/conftools/config.sub +++ b/3rdparty/expat/conftools/config.sub @@ -1,12 +1,14 @@ #! /bin/sh # Configuration validation subroutine script. -# Copyright 1992-2019 Free Software Foundation, Inc. +# Copyright 1992-2022 Free Software Foundation, Inc. -timestamp='2019-06-30' +# shellcheck disable=SC2006,SC2268 # see below for rationale + +timestamp='2022-01-03' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or +# the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but @@ -33,7 +35,7 @@ timestamp='2019-06-30' # Otherwise, we print the canonical config type on stdout and succeed. # You can get the latest version of this script from: -# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub +# https://git.savannah.gnu.org/cgit/config.git/plain/config.sub # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases @@ -50,6 +52,13 @@ timestamp='2019-06-30' # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # It is wrong to echo any other type of specification. +# The "shellcheck disable" line above the timestamp inhibits complaints +# about features and limitations of the classic Bourne shell that were +# superseded or lifted in POSIX. However, this script identifies a wide +# variety of pre-POSIX systems that do not have POSIX shells at all, and +# even some reasonably current systems (Solaris 10 as case-in-point) still +# have a pre-POSIX /bin/sh. + me=`echo "$0" | sed -e 's,.*/,,'` usage="\ @@ -67,7 +76,7 @@ Report bugs and patches to <config-patches@gnu.org>." version="\ GNU config.sub ($timestamp) -Copyright 1992-2019 Free Software Foundation, Inc. +Copyright 1992-2022 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -112,9 +121,11 @@ esac # Split fields of configuration type # shellcheck disable=SC2162 +saved_IFS=$IFS IFS="-" read field1 field2 field3 field4 <<EOF $1 EOF +IFS=$saved_IFS # Separate into logical components for further validation case $1 in @@ -124,28 +135,27 @@ case $1 in ;; *-*-*-*) basic_machine=$field1-$field2 - os=$field3-$field4 + basic_os=$field3-$field4 ;; *-*-*) # Ambiguous whether COMPANY is present, or skipped and KERNEL-OS is two # parts maybe_os=$field2-$field3 case $maybe_os in - nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc \ - | linux-newlib* | linux-musl* | linux-uclibc* | uclinux-uclibc* \ + nto-qnx* | linux-* | uclinux-uclibc* \ | uclinux-gnu* | kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* \ | netbsd*-eabi* | kopensolaris*-gnu* | cloudabi*-eabi* \ | storm-chaos* | os2-emx* | rtmk-nova*) basic_machine=$field1 - os=$maybe_os + basic_os=$maybe_os ;; android-linux) basic_machine=$field1-unknown - os=linux-android + basic_os=linux-android ;; *) basic_machine=$field1-$field2 - os=$field3 + basic_os=$field3 ;; esac ;; @@ -154,7 +164,7 @@ case $1 in case $field1-$field2 in decstation-3100) basic_machine=mips-dec - os= + basic_os= ;; *-*) # Second component is usually, but not always the OS @@ -162,7 +172,11 @@ case $1 in # Prevent following clause from handling this valid os sun*os*) basic_machine=$field1 - os=$field2 + basic_os=$field2 + ;; + zephyr*) + basic_machine=$field1-unknown + basic_os=$field2 ;; # Manufacturers dec* | mips* | sequent* | encore* | pc533* | sgi* | sony* \ @@ -175,11 +189,11 @@ case $1 in | microblaze* | sim | cisco \ | oki | wec | wrs | winbond) basic_machine=$field1-$field2 - os= + basic_os= ;; *) basic_machine=$field1 - os=$field2 + basic_os=$field2 ;; esac ;; @@ -191,447 +205,451 @@ case $1 in case $field1 in 386bsd) basic_machine=i386-pc - os=bsd + basic_os=bsd ;; a29khif) basic_machine=a29k-amd - os=udi + basic_os=udi ;; adobe68k) basic_machine=m68010-adobe - os=scout + basic_os=scout ;; alliant) basic_machine=fx80-alliant - os= + basic_os= ;; altos | altos3068) basic_machine=m68k-altos - os= + basic_os= ;; am29k) basic_machine=a29k-none - os=bsd + basic_os=bsd ;; amdahl) basic_machine=580-amdahl - os=sysv + basic_os=sysv ;; amiga) basic_machine=m68k-unknown - os= + basic_os= ;; amigaos | amigados) basic_machine=m68k-unknown - os=amigaos + basic_os=amigaos ;; amigaunix | amix) basic_machine=m68k-unknown - os=sysv4 + basic_os=sysv4 ;; apollo68) basic_machine=m68k-apollo - os=sysv + basic_os=sysv ;; apollo68bsd) basic_machine=m68k-apollo - os=bsd + basic_os=bsd ;; aros) basic_machine=i386-pc - os=aros + basic_os=aros ;; aux) basic_machine=m68k-apple - os=aux + basic_os=aux ;; balance) basic_machine=ns32k-sequent - os=dynix + basic_os=dynix ;; blackfin) basic_machine=bfin-unknown - os=linux + basic_os=linux ;; cegcc) basic_machine=arm-unknown - os=cegcc + basic_os=cegcc ;; convex-c1) basic_machine=c1-convex - os=bsd + basic_os=bsd ;; convex-c2) basic_machine=c2-convex - os=bsd + basic_os=bsd ;; convex-c32) basic_machine=c32-convex - os=bsd + basic_os=bsd ;; convex-c34) basic_machine=c34-convex - os=bsd + basic_os=bsd ;; convex-c38) basic_machine=c38-convex - os=bsd + basic_os=bsd ;; cray) basic_machine=j90-cray - os=unicos + basic_os=unicos ;; crds | unos) basic_machine=m68k-crds - os= + basic_os= ;; da30) basic_machine=m68k-da30 - os= + basic_os= ;; decstation | pmax | pmin | dec3100 | decstatn) basic_machine=mips-dec - os= + basic_os= ;; delta88) basic_machine=m88k-motorola - os=sysv3 + basic_os=sysv3 ;; dicos) basic_machine=i686-pc - os=dicos + basic_os=dicos ;; djgpp) basic_machine=i586-pc - os=msdosdjgpp + basic_os=msdosdjgpp ;; ebmon29k) basic_machine=a29k-amd - os=ebmon + basic_os=ebmon ;; es1800 | OSE68k | ose68k | ose | OSE) basic_machine=m68k-ericsson - os=ose + basic_os=ose ;; gmicro) basic_machine=tron-gmicro - os=sysv + basic_os=sysv ;; go32) basic_machine=i386-pc - os=go32 + basic_os=go32 ;; h8300hms) basic_machine=h8300-hitachi - os=hms + basic_os=hms ;; h8300xray) basic_machine=h8300-hitachi - os=xray + basic_os=xray ;; h8500hms) basic_machine=h8500-hitachi - os=hms + basic_os=hms ;; harris) basic_machine=m88k-harris - os=sysv3 + basic_os=sysv3 ;; hp300 | hp300hpux) basic_machine=m68k-hp - os=hpux + basic_os=hpux ;; hp300bsd) basic_machine=m68k-hp - os=bsd + basic_os=bsd ;; hppaosf) basic_machine=hppa1.1-hp - os=osf + basic_os=osf ;; hppro) basic_machine=hppa1.1-hp - os=proelf + basic_os=proelf ;; i386mach) basic_machine=i386-mach - os=mach + basic_os=mach ;; isi68 | isi) basic_machine=m68k-isi - os=sysv + basic_os=sysv ;; m68knommu) basic_machine=m68k-unknown - os=linux + basic_os=linux ;; magnum | m3230) basic_machine=mips-mips - os=sysv + basic_os=sysv ;; merlin) basic_machine=ns32k-utek - os=sysv + basic_os=sysv ;; mingw64) basic_machine=x86_64-pc - os=mingw64 + basic_os=mingw64 ;; mingw32) basic_machine=i686-pc - os=mingw32 + basic_os=mingw32 ;; mingw32ce) basic_machine=arm-unknown - os=mingw32ce + basic_os=mingw32ce ;; monitor) basic_machine=m68k-rom68k - os=coff + basic_os=coff ;; morphos) basic_machine=powerpc-unknown - os=morphos + basic_os=morphos ;; moxiebox) basic_machine=moxie-unknown - os=moxiebox + basic_os=moxiebox ;; msdos) basic_machine=i386-pc - os=msdos + basic_os=msdos ;; msys) basic_machine=i686-pc - os=msys + basic_os=msys ;; mvs) basic_machine=i370-ibm - os=mvs + basic_os=mvs ;; nacl) basic_machine=le32-unknown - os=nacl + basic_os=nacl ;; ncr3000) basic_machine=i486-ncr - os=sysv4 + basic_os=sysv4 ;; netbsd386) basic_machine=i386-pc - os=netbsd + basic_os=netbsd ;; netwinder) basic_machine=armv4l-rebel - os=linux + basic_os=linux ;; news | news700 | news800 | news900) basic_machine=m68k-sony - os=newsos + basic_os=newsos ;; news1000) basic_machine=m68030-sony - os=newsos + basic_os=newsos ;; necv70) basic_machine=v70-nec - os=sysv + basic_os=sysv ;; nh3000) basic_machine=m68k-harris - os=cxux + basic_os=cxux ;; nh[45]000) basic_machine=m88k-harris - os=cxux + basic_os=cxux ;; nindy960) basic_machine=i960-intel - os=nindy + basic_os=nindy ;; mon960) basic_machine=i960-intel - os=mon960 + basic_os=mon960 ;; nonstopux) basic_machine=mips-compaq - os=nonstopux + basic_os=nonstopux ;; os400) basic_machine=powerpc-ibm - os=os400 + basic_os=os400 ;; OSE68000 | ose68000) basic_machine=m68000-ericsson - os=ose + basic_os=ose ;; os68k) basic_machine=m68k-none - os=os68k + basic_os=os68k ;; paragon) basic_machine=i860-intel - os=osf + basic_os=osf ;; parisc) basic_machine=hppa-unknown - os=linux + basic_os=linux + ;; + psp) + basic_machine=mipsallegrexel-sony + basic_os=psp ;; pw32) basic_machine=i586-unknown - os=pw32 + basic_os=pw32 ;; rdos | rdos64) basic_machine=x86_64-pc - os=rdos + basic_os=rdos ;; rdos32) basic_machine=i386-pc - os=rdos + basic_os=rdos ;; rom68k) basic_machine=m68k-rom68k - os=coff + basic_os=coff ;; sa29200) basic_machine=a29k-amd - os=udi + basic_os=udi ;; sei) basic_machine=mips-sei - os=seiux + basic_os=seiux ;; sequent) basic_machine=i386-sequent - os= + basic_os= ;; sps7) basic_machine=m68k-bull - os=sysv2 + basic_os=sysv2 ;; st2000) basic_machine=m68k-tandem - os= + basic_os= ;; stratus) basic_machine=i860-stratus - os=sysv4 + basic_os=sysv4 ;; sun2) basic_machine=m68000-sun - os= + basic_os= ;; sun2os3) basic_machine=m68000-sun - os=sunos3 + basic_os=sunos3 ;; sun2os4) basic_machine=m68000-sun - os=sunos4 + basic_os=sunos4 ;; sun3) basic_machine=m68k-sun - os= + basic_os= ;; sun3os3) basic_machine=m68k-sun - os=sunos3 + basic_os=sunos3 ;; sun3os4) basic_machine=m68k-sun - os=sunos4 + basic_os=sunos4 ;; sun4) basic_machine=sparc-sun - os= + basic_os= ;; sun4os3) basic_machine=sparc-sun - os=sunos3 + basic_os=sunos3 ;; sun4os4) basic_machine=sparc-sun - os=sunos4 + basic_os=sunos4 ;; sun4sol2) basic_machine=sparc-sun - os=solaris2 + basic_os=solaris2 ;; sun386 | sun386i | roadrunner) basic_machine=i386-sun - os= + basic_os= ;; sv1) basic_machine=sv1-cray - os=unicos + basic_os=unicos ;; symmetry) basic_machine=i386-sequent - os=dynix + basic_os=dynix ;; t3e) basic_machine=alphaev5-cray - os=unicos + basic_os=unicos ;; t90) basic_machine=t90-cray - os=unicos + basic_os=unicos ;; toad1) basic_machine=pdp10-xkl - os=tops20 + basic_os=tops20 ;; tpf) basic_machine=s390x-ibm - os=tpf + basic_os=tpf ;; udi29k) basic_machine=a29k-amd - os=udi + basic_os=udi ;; ultra3) basic_machine=a29k-nyu - os=sym1 + basic_os=sym1 ;; v810 | necv810) basic_machine=v810-nec - os=none + basic_os=none ;; vaxv) basic_machine=vax-dec - os=sysv + basic_os=sysv ;; vms) basic_machine=vax-dec - os=vms + basic_os=vms ;; vsta) basic_machine=i386-pc - os=vsta + basic_os=vsta ;; vxworks960) basic_machine=i960-wrs - os=vxworks + basic_os=vxworks ;; vxworks68) basic_machine=m68k-wrs - os=vxworks + basic_os=vxworks ;; vxworks29k) basic_machine=a29k-wrs - os=vxworks + basic_os=vxworks ;; xbox) basic_machine=i686-pc - os=mingw32 + basic_os=mingw32 ;; ymp) basic_machine=ymp-cray - os=unicos + basic_os=unicos ;; *) basic_machine=$1 - os= + basic_os= ;; esac ;; @@ -683,17 +701,17 @@ case $basic_machine in bluegene*) cpu=powerpc vendor=ibm - os=cnk + basic_os=cnk ;; decsystem10* | dec10*) cpu=pdp10 vendor=dec - os=tops10 + basic_os=tops10 ;; decsystem20* | dec20*) cpu=pdp10 vendor=dec - os=tops20 + basic_os=tops20 ;; delta | 3300 | motorola-3300 | motorola-delta \ | 3300-motorola | delta-motorola) @@ -703,7 +721,7 @@ case $basic_machine in dpx2*) cpu=m68k vendor=bull - os=sysv3 + basic_os=sysv3 ;; encore | umax | mmax) cpu=ns32k @@ -712,7 +730,7 @@ case $basic_machine in elxsi) cpu=elxsi vendor=elxsi - os=${os:-bsd} + basic_os=${basic_os:-bsd} ;; fx2800) cpu=i860 @@ -725,7 +743,7 @@ case $basic_machine in h3050r* | hiux*) cpu=hppa1.1 vendor=hitachi - os=hiuxwe2 + basic_os=hiuxwe2 ;; hp3k9[0-9][0-9] | hp9[0-9][0-9]) cpu=hppa1.0 @@ -768,36 +786,36 @@ case $basic_machine in i*86v32) cpu=`echo "$1" | sed -e 's/86.*/86/'` vendor=pc - os=sysv32 + basic_os=sysv32 ;; i*86v4*) cpu=`echo "$1" | sed -e 's/86.*/86/'` vendor=pc - os=sysv4 + basic_os=sysv4 ;; i*86v) cpu=`echo "$1" | sed -e 's/86.*/86/'` vendor=pc - os=sysv + basic_os=sysv ;; i*86sol2) cpu=`echo "$1" | sed -e 's/86.*/86/'` vendor=pc - os=solaris2 + basic_os=solaris2 ;; j90 | j90-cray) cpu=j90 vendor=cray - os=${os:-unicos} + basic_os=${basic_os:-unicos} ;; iris | iris4d) cpu=mips vendor=sgi - case $os in + case $basic_os in irix*) ;; *) - os=irix4 + basic_os=irix4 ;; esac ;; @@ -808,7 +826,7 @@ case $basic_machine in *mint | mint[0-9]* | *MiNT | *MiNT[0-9]*) cpu=m68k vendor=atari - os=mint + basic_os=mint ;; mipsEE* | ee) cpu=mips64r5900el @@ -834,21 +852,21 @@ case $basic_machine in news-3600 | risc-news) cpu=mips vendor=sony - os=newsos + basic_os=newsos ;; next | m*-next) cpu=m68k vendor=next - case $os in + case $basic_os in openstep*) ;; nextstep*) ;; ns2*) - os=nextstep2 + basic_os=nextstep2 ;; *) - os=nextstep3 + basic_os=nextstep3 ;; esac ;; @@ -859,12 +877,12 @@ case $basic_machine in op50n-* | op60c-*) cpu=hppa1.1 vendor=oki - os=proelf + basic_os=proelf ;; pa-hitachi) cpu=hppa1.1 vendor=hitachi - os=hiuxwe2 + basic_os=hiuxwe2 ;; pbd) cpu=sparc @@ -901,12 +919,12 @@ case $basic_machine in sde) cpu=mipsisa32 vendor=sde - os=${os:-elf} + basic_os=${basic_os:-elf} ;; simso-wrs) cpu=sparclite vendor=wrs - os=vxworks + basic_os=vxworks ;; tower | tower-32) cpu=m68k @@ -923,7 +941,7 @@ case $basic_machine in w89k-*) cpu=hppa1.1 vendor=winbond - os=proelf + basic_os=proelf ;; none) cpu=none @@ -940,9 +958,11 @@ case $basic_machine in *-*) # shellcheck disable=SC2162 + saved_IFS=$IFS IFS="-" read cpu vendor <<EOF $basic_machine EOF + IFS=$saved_IFS ;; # We use `pc' rather than `unknown' # because (1) that's what they normally are, and @@ -976,11 +996,11 @@ case $cpu-$vendor in # some cases the only manufacturer, in others, it is the most popular. craynv-unknown) vendor=cray - os=${os:-unicosmp} + basic_os=${basic_os:-unicosmp} ;; c90-unknown | c90-cray) vendor=cray - os=${os:-unicos} + basic_os=${Basic_os:-unicos} ;; fx80-unknown) vendor=alliant @@ -1021,10 +1041,15 @@ case $cpu-$vendor in ;; # Here we normalize CPU types with a missing or matching vendor + armh-unknown | armh-alt) + cpu=armv7l + vendor=alt + basic_os=${basic_os:-linux-gnueabihf} + ;; dpx20-unknown | dpx20-bull) cpu=rs6000 vendor=bull - os=${os:-bosx} + basic_os=${basic_os:-bosx} ;; # Here we normalize CPU types irrespective of the vendor @@ -1033,7 +1058,7 @@ case $cpu-$vendor in ;; blackfin-*) cpu=bfin - os=linux + basic_os=linux ;; c54x-*) cpu=tic54x @@ -1046,7 +1071,7 @@ case $cpu-$vendor in ;; e500v[12]-*) cpu=powerpc - os=$os"spe" + basic_os=${basic_os}"spe" ;; mips3*-*) cpu=mips64 @@ -1056,7 +1081,7 @@ case $cpu-$vendor in ;; m68knommu-*) cpu=m68k - os=linux + basic_os=linux ;; m9s12z-* | m68hcs12z-* | hcs12z-* | s12z-*) cpu=s12z @@ -1066,7 +1091,7 @@ case $cpu-$vendor in ;; parisc-*) cpu=hppa - os=linux + basic_os=linux ;; pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) cpu=i586 @@ -1122,11 +1147,14 @@ case $cpu-$vendor in xscale-* | xscalee[bl]-*) cpu=`echo "$cpu" | sed 's/^xscale/arm/'` ;; + arm64-* | aarch64le-*) + cpu=aarch64 + ;; # Recognize the canonical CPU Types that limit and/or modify the # company names they are paired with. cr16-*) - os=${os:-elf} + basic_os=${basic_os:-elf} ;; crisv32-* | etraxfs*-*) cpu=crisv32 @@ -1137,7 +1165,7 @@ case $cpu-$vendor in vendor=axis ;; crx-*) - os=${os:-elf} + basic_os=${basic_os:-elf} ;; neo-tandem) cpu=neo @@ -1159,16 +1187,12 @@ case $cpu-$vendor in cpu=nsx vendor=tandem ;; - s390-*) - cpu=s390 - vendor=ibm - ;; - s390x-*) - cpu=s390x - vendor=ibm + mipsallegrexel-sony) + cpu=mipsallegrexel + vendor=sony ;; tile*-*) - os=${os:-linux-gnu} + basic_os=${basic_os:-linux-gnu} ;; *) @@ -1184,8 +1208,8 @@ case $cpu-$vendor in | alphapca5[67] | alpha64pca5[67] \ | am33_2.0 \ | amdgcn \ - | arc | arceb \ - | arm | arm[lb]e | arme[lb] | armv* \ + | arc | arceb | arc32 | arc64 \ + | arm | arm[lb]e | arme[lb] | armv* \ | avr | avr32 \ | asmjs \ | ba \ @@ -1204,6 +1228,7 @@ case $cpu-$vendor in | k1om \ | le32 | le64 \ | lm32 \ + | loongarch32 | loongarch64 | loongarchx32 \ | m32c | m32r | m32rle \ | m5200 | m68000 | m680[012346]0 | m68360 | m683?2 | m68k \ | m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x \ @@ -1222,9 +1247,13 @@ case $cpu-$vendor in | mips64vr5900 | mips64vr5900el \ | mipsisa32 | mipsisa32el \ | mipsisa32r2 | mipsisa32r2el \ + | mipsisa32r3 | mipsisa32r3el \ + | mipsisa32r5 | mipsisa32r5el \ | mipsisa32r6 | mipsisa32r6el \ | mipsisa64 | mipsisa64el \ | mipsisa64r2 | mipsisa64r2el \ + | mipsisa64r3 | mipsisa64r3el \ + | mipsisa64r5 | mipsisa64r5el \ | mipsisa64r6 | mipsisa64r6el \ | mipsisa64sb1 | mipsisa64sb1el \ | mipsisa64sr71k | mipsisa64sr71kel \ @@ -1248,8 +1277,9 @@ case $cpu-$vendor in | powerpc | powerpc64 | powerpc64le | powerpcle | powerpcspe \ | pru \ | pyramid \ - | riscv | riscv32 | riscv64 \ + | riscv | riscv32 | riscv32be | riscv64 | riscv64be \ | rl78 | romp | rs6000 | rx \ + | s390 | s390x \ | score \ | sh | shl \ | sh[1234] | sh[24]a | sh[24]ae[lb] | sh[23]e | she[lb] | sh[lb]e \ @@ -1259,6 +1289,7 @@ case $cpu-$vendor in | sparcv8 | sparcv9 | sparcv9b | sparcv9v | sv1 | sx* \ | spu \ | tahoe \ + | thumbv7* \ | tic30 | tic4x | tic54x | tic55x | tic6x | tic80 \ | tron \ | ubicom32 \ @@ -1296,8 +1327,49 @@ esac # Decode manufacturer-specific aliases for certain operating systems. -if [ x$os != x ] +if test x$basic_os != x then + +# First recognize some ad-hoc cases, or perhaps split kernel-os, or else just +# set os. +case $basic_os in + gnu/linux*) + kernel=linux + os=`echo "$basic_os" | sed -e 's|gnu/linux|gnu|'` + ;; + os2-emx) + kernel=os2 + os=`echo "$basic_os" | sed -e 's|os2-emx|emx|'` + ;; + nto-qnx*) + kernel=nto + os=`echo "$basic_os" | sed -e 's|nto-qnx|qnx|'` + ;; + *-*) + # shellcheck disable=SC2162 + saved_IFS=$IFS + IFS="-" read kernel os <<EOF +$basic_os +EOF + IFS=$saved_IFS + ;; + # Default OS when just kernel was specified + nto*) + kernel=nto + os=`echo "$basic_os" | sed -e 's|nto|qnx|'` + ;; + linux*) + kernel=linux + os=`echo "$basic_os" | sed -e 's|linux|gnu|'` + ;; + *) + kernel= + os=$basic_os + ;; +esac + +# Now, normalize the OS (knowing we just have one component, it's not a kernel, +# etc.) case $os in # First match some system type aliases that might get confused # with valid system types. @@ -1309,7 +1381,7 @@ case $os in os=cnk ;; solaris1 | solaris1.*) - os=`echo $os | sed -e 's|solaris1|sunos4|'` + os=`echo "$os" | sed -e 's|solaris1|sunos4|'` ;; solaris) os=solaris2 @@ -1317,9 +1389,6 @@ case $os in unixware*) os=sysv4.2uw ;; - gnu/linux*) - os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` - ;; # es1800 is here to avoid being matched by es* (a different OS) es1800*) os=ose @@ -1341,12 +1410,9 @@ case $os in os=sco3.2v4 ;; sco3.2.[4-9]*) - os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + os=`echo "$os" | sed -e 's/sco3.2./sco3.2v/'` ;; - sco3.2v[4-9]* | sco5v6*) - # Don't forget version if it is 3.2v4 or newer. - ;; - scout) + sco*v* | scout) # Don't match below ;; sco*) @@ -1355,78 +1421,25 @@ case $os in psos*) os=psos ;; - # Now accept the basic system types. - # The portable systems comes first. - # Each alternative MUST end in a * to match a version number. - # sysv* is not here because it comes later, after sysvr4. - gnu* | bsd* | mach* | minix* | genix* | ultrix* | irix* \ - | *vms* | esix* | aix* | cnk* | sunos | sunos[34]*\ - | hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \ - | sym* | kopensolaris* | plan9* \ - | amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \ - | aos* | aros* | cloudabi* | sortix* | twizzler* \ - | nindy* | vxsim* | vxworks* | ebmon* | hms* | mvs* \ - | clix* | riscos* | uniplus* | iris* | isc* | rtu* | xenix* \ - | knetbsd* | mirbsd* | netbsd* \ - | bitrig* | openbsd* | solidbsd* | libertybsd* | os108* \ - | ekkobsd* | kfreebsd* | freebsd* | riscix* | lynxos* \ - | bosx* | nextstep* | cxux* | aout* | elf* | oabi* \ - | ptx* | coff* | ecoff* | winnt* | domain* | vsta* \ - | udi* | eabi* | lites* | ieee* | go32* | aux* | hcos* \ - | chorusrdb* | cegcc* | glidix* \ - | cygwin* | msys* | pe* | moss* | proelf* | rtems* \ - | midipix* | mingw32* | mingw64* | linux-gnu* | linux-android* \ - | linux-newlib* | linux-musl* | linux-uclibc* \ - | uxpv* | beos* | mpeix* | udk* | moxiebox* \ - | interix* | uwin* | mks* | rhapsody* | darwin* \ - | openstep* | oskit* | conix* | pw32* | nonstopux* \ - | storm-chaos* | tops10* | tenex* | tops20* | its* | irx* \ - | os2* | vos* | palmos* | uclinux* | nucleus* \ - | morphos* | superux* | rtmk* | windiss* \ - | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \ - | skyos* | haiku* | rdos* | toppers* | drops* | es* \ - | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ - | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ - | nsk* | powerunix) - # Remember, each alternative MUST END IN *, to match a version number. - ;; qnx*) - case $cpu in - x86 | i*86) - ;; - *) - os=nto-$os - ;; - esac + os=qnx ;; hiux*) os=hiuxwe2 ;; - nto-qnx*) - ;; - nto*) - os=`echo $os | sed -e 's|nto|nto-qnx|'` - ;; - sim | xray | os68k* | v88r* \ - | windows* | osx | abug | netware* | os9* \ - | macos* | mpw* | magic* | mmixware* | mon960* | lnews*) - ;; - linux-dietlibc) - os=linux-dietlibc - ;; - linux*) - os=`echo $os | sed -e 's|linux|linux-gnu|'` - ;; lynx*178) os=lynxos178 ;; lynx*5) os=lynxos5 ;; + lynxos*) + # don't get caught up in next wildcard + ;; lynx*) os=lynxos ;; - mac*) + mac[0-9]*) os=`echo "$os" | sed -e 's|mac|macos|'` ;; opened*) @@ -1473,7 +1486,7 @@ case $os in ;; # Preserve the version number of sinix5. sinix5.*) - os=`echo $os | sed -e 's|sinix|sysv|'` + os=`echo "$os" | sed -e 's|sinix|sysv|'` ;; sinix*) os=sysv4 @@ -1496,18 +1509,12 @@ case $os in sysvr4) os=sysv4 ;; - # This must come after sysvr4. - sysv*) - ;; ose*) os=ose ;; *mint | mint[0-9]* | *MiNT | MiNT[0-9]*) os=mint ;; - zvmoe) - os=zvmoe - ;; dicos*) os=dicos ;; @@ -1524,19 +1531,11 @@ case $os in ;; esac ;; - nacl*) - ;; - ios) - ;; - none) - ;; - *-eabi) - ;; *) - echo Invalid configuration \`"$1"\': system \`"$os"\' not recognized 1>&2 - exit 1 + # No normalization, but not necessarily accepted, that comes below. ;; esac + else # Here we handle the default operating systems that come with various machines. @@ -1549,6 +1548,7 @@ else # will signal an error saying that MANUFACTURER isn't an operating # system, and we'll never get to this point. +kernel= case $cpu-$vendor in score-*) os=elf @@ -1560,7 +1560,8 @@ case $cpu-$vendor in os=riscix1.2 ;; arm*-rebel) - os=linux + kernel=linux + os=gnu ;; arm*-semi) os=aout @@ -1726,84 +1727,180 @@ case $cpu-$vendor in os=none ;; esac + fi +# Now, validate our (potentially fixed-up) OS. +case $os in + # Sometimes we do "kernel-libc", so those need to count as OSes. + musl* | newlib* | relibc* | uclibc*) + ;; + # Likewise for "kernel-abi" + eabi* | gnueabi*) + ;; + # VxWorks passes extra cpu info in the 4th filed. + simlinux | simwindows | spe) + ;; + # Now accept the basic system types. + # The portable systems comes first. + # Each alternative MUST end in a * to match a version number. + gnu* | android* | bsd* | mach* | minix* | genix* | ultrix* | irix* \ + | *vms* | esix* | aix* | cnk* | sunos | sunos[34]* \ + | hpux* | unos* | osf* | luna* | dgux* | auroraux* | solaris* \ + | sym* | plan9* | psp* | sim* | xray* | os68k* | v88r* \ + | hiux* | abug | nacl* | netware* | windows* \ + | os9* | macos* | osx* | ios* \ + | mpw* | magic* | mmixware* | mon960* | lnews* \ + | amigaos* | amigados* | msdos* | newsos* | unicos* | aof* \ + | aos* | aros* | cloudabi* | sortix* | twizzler* \ + | nindy* | vxsim* | vxworks* | ebmon* | hms* | mvs* \ + | clix* | riscos* | uniplus* | iris* | isc* | rtu* | xenix* \ + | mirbsd* | netbsd* | dicos* | openedition* | ose* \ + | bitrig* | openbsd* | secbsd* | solidbsd* | libertybsd* | os108* \ + | ekkobsd* | freebsd* | riscix* | lynxos* | os400* \ + | bosx* | nextstep* | cxux* | aout* | elf* | oabi* \ + | ptx* | coff* | ecoff* | winnt* | domain* | vsta* \ + | udi* | lites* | ieee* | go32* | aux* | hcos* \ + | chorusrdb* | cegcc* | glidix* | serenity* \ + | cygwin* | msys* | pe* | moss* | proelf* | rtems* \ + | midipix* | mingw32* | mingw64* | mint* \ + | uxpv* | beos* | mpeix* | udk* | moxiebox* \ + | interix* | uwin* | mks* | rhapsody* | darwin* \ + | openstep* | oskit* | conix* | pw32* | nonstopux* \ + | storm-chaos* | tops10* | tenex* | tops20* | its* | irx* \ + | os2* | vos* | palmos* | uclinux* | nucleus* | morphos* \ + | scout* | superux* | sysv* | rtmk* | tpf* | windiss* \ + | powermax* | dnix* | nx6 | nx7 | sei* | dragonfly* \ + | skyos* | haiku* | rdos* | toppers* | drops* | es* \ + | onefs* | tirtos* | phoenix* | fuchsia* | redox* | bme* \ + | midnightbsd* | amdhsa* | unleashed* | emscripten* | wasi* \ + | nsk* | powerunix* | genode* | zvmoe* | qnx* | emx* | zephyr* \ + | fiwix* ) + ;; + # This one is extra strict with allowed versions + sco3.2v2 | sco3.2v[4-9]* | sco5v6*) + # Don't forget version if it is 3.2v4 or newer. + ;; + none) + ;; + *) + echo Invalid configuration \`"$1"\': OS \`"$os"\' not recognized 1>&2 + exit 1 + ;; +esac + +# As a final step for OS-related things, validate the OS-kernel combination +# (given a valid OS), if there is a kernel. +case $kernel-$os in + linux-gnu* | linux-dietlibc* | linux-android* | linux-newlib* \ + | linux-musl* | linux-relibc* | linux-uclibc* ) + ;; + uclinux-uclibc* ) + ;; + -dietlibc* | -newlib* | -musl* | -relibc* | -uclibc* ) + # These are just libc implementations, not actual OSes, and thus + # require a kernel. + echo "Invalid configuration \`$1': libc \`$os' needs explicit kernel." 1>&2 + exit 1 + ;; + kfreebsd*-gnu* | kopensolaris*-gnu*) + ;; + vxworks-simlinux | vxworks-simwindows | vxworks-spe) + ;; + nto-qnx*) + ;; + os2-emx) + ;; + *-eabi* | *-gnueabi*) + ;; + -*) + # Blank kernel with real OS is always fine. + ;; + *-*) + echo "Invalid configuration \`$1': Kernel \`$kernel' not known to work with OS \`$os'." 1>&2 + exit 1 + ;; +esac + # Here we handle the case where we know the os, and the CPU type, but not the # manufacturer. We pick the logical manufacturer. case $vendor in unknown) - case $os in - riscix*) + case $cpu-$os in + *-riscix*) vendor=acorn ;; - sunos*) + *-sunos*) vendor=sun ;; - cnk*|-aix*) + *-cnk* | *-aix*) vendor=ibm ;; - beos*) + *-beos*) vendor=be ;; - hpux*) + *-hpux*) vendor=hp ;; - mpeix*) + *-mpeix*) vendor=hp ;; - hiux*) + *-hiux*) vendor=hitachi ;; - unos*) + *-unos*) vendor=crds ;; - dgux*) + *-dgux*) vendor=dg ;; - luna*) + *-luna*) vendor=omron ;; - genix*) + *-genix*) vendor=ns ;; - clix*) + *-clix*) vendor=intergraph ;; - mvs* | opened*) + *-mvs* | *-opened*) + vendor=ibm + ;; + *-os400*) vendor=ibm ;; - os400*) + s390-* | s390x-*) vendor=ibm ;; - ptx*) + *-ptx*) vendor=sequent ;; - tpf*) + *-tpf*) vendor=ibm ;; - vxsim* | vxworks* | windiss*) + *-vxsim* | *-vxworks* | *-windiss*) vendor=wrs ;; - aux*) + *-aux*) vendor=apple ;; - hms*) + *-hms*) vendor=hitachi ;; - mpw* | macos*) + *-mpw* | *-macos*) vendor=apple ;; - *mint | mint[0-9]* | *MiNT | MiNT[0-9]*) + *-*mint | *-mint[0-9]* | *-*MiNT | *-MiNT[0-9]*) vendor=atari ;; - vos*) + *-vos*) vendor=stratus ;; esac ;; esac -echo "$cpu-$vendor-$os" +echo "$cpu-$vendor-${kernel:+$kernel-}$os" exit # Local variables: diff --git a/3rdparty/expat/conftools/depcomp b/3rdparty/expat/conftools/depcomp index 6b391623c4b..715e34311ed 100755 --- a/3rdparty/expat/conftools/depcomp +++ b/3rdparty/expat/conftools/depcomp @@ -3,7 +3,7 @@ scriptversion=2018-03-07.03; # UTC -# Copyright (C) 1999-2020 Free Software Foundation, Inc. +# Copyright (C) 1999-2021 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/3rdparty/expat/conftools/get-version.sh b/3rdparty/expat/conftools/get-version.sh index 2592f103288..273ed3a3154 100755 --- a/3rdparty/expat/conftools/get-version.sh +++ b/3rdparty/expat/conftools/get-version.sh @@ -1,13 +1,39 @@ #!/bin/sh -# # USAGE: get-version.sh path/to/expat.h # # This script will print Expat's version number on stdout. For example: # # $ ./conftools/get-version.sh ./lib/expat.h # 1.95.3 -# $ +# __ __ _ +# ___\ \/ /_ __ __ _| |_ +# / _ \\ /| '_ \ / _` | __| +# | __// \| |_) | (_| | |_ +# \___/_/\_\ .__/ \__,_|\__| +# |_| XML parser +# +# Copyright (c) 2002 Greg Stein <gstein@users.sourceforge.net> +# Copyright (c) 2017 Kerin Millar <kfm@plushkava.net> +# Licensed under the MIT license: +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to permit +# persons to whom the Software is furnished to do so, subject to the +# following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +# USE OR OTHER DEALINGS IN THE SOFTWARE. if test $# = 0; then echo "ERROR: pathname for expat.h was not provided." diff --git a/3rdparty/expat/conftools/install-sh b/3rdparty/expat/conftools/install-sh index 20d8b2eaea9..ec298b53740 100755 --- a/3rdparty/expat/conftools/install-sh +++ b/3rdparty/expat/conftools/install-sh @@ -1,7 +1,7 @@ #!/bin/sh # install - install a program, script, or datafile -scriptversion=2018-03-11.20; # UTC +scriptversion=2020-11-14.01; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the @@ -69,6 +69,11 @@ posix_mkdir= # Desired mode of installed file. mode=0755 +# Create dirs (including intermediate dirs) using mode 755. +# This is like GNU 'install' as of coreutils 8.32 (2020). +mkdir_umask=22 + +backupsuffix= chgrpcmd= chmodcmd=$chmodprog chowncmd= @@ -99,18 +104,28 @@ Options: --version display version info and exit. -c (ignored) - -C install only if different (preserve the last data modification time) + -C install only if different (preserve data modification time) -d create directories instead of installing files. -g GROUP $chgrpprog installed files to GROUP. -m MODE $chmodprog installed files to MODE. -o USER $chownprog installed files to USER. + -p pass -p to $cpprog. -s $stripprog installed files. + -S SUFFIX attempt to back up existing files, with suffix SUFFIX. -t DIRECTORY install into DIRECTORY. -T report an error if DSTFILE is a directory. Environment variables override the default commands: CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG + +By default, rm is invoked with -f; when overridden with RMPROG, +it's up to you to specify -f if you want it. + +If -S is not specified, no backups are attempted. + +Email bug reports to bug-automake@gnu.org. +Automake home page: https://www.gnu.org/software/automake/ " while test $# -ne 0; do @@ -137,8 +152,13 @@ while test $# -ne 0; do -o) chowncmd="$chownprog $2" shift;; + -p) cpprog="$cpprog -p";; + -s) stripcmd=$stripprog;; + -S) backupsuffix="$2" + shift;; + -t) is_target_a_directory=always dst_arg=$2 @@ -255,6 +275,10 @@ do dstdir=$dst test -d "$dstdir" dstdir_status=$? + # Don't chown directories that already exist. + if test $dstdir_status = 0; then + chowncmd="" + fi else # Waiting for this to be detected by the "$cpprog $src $dsttmp" command @@ -301,22 +325,6 @@ do if test $dstdir_status != 0; then case $posix_mkdir in '') - # Create intermediate dirs using mode 755 as modified by the umask. - # This is like FreeBSD 'install' as of 1997-10-28. - umask=`umask` - case $stripcmd.$umask in - # Optimize common cases. - *[2367][2367]) mkdir_umask=$umask;; - .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; - - *[0-7]) - mkdir_umask=`expr $umask + 22 \ - - $umask % 100 % 40 + $umask % 20 \ - - $umask % 10 % 4 + $umask % 2 - `;; - *) mkdir_umask=$umask,go-w;; - esac - # With -d, create the new directory with the user-specified mode. # Otherwise, rely on $mkdir_umask. if test -n "$dir_arg"; then @@ -326,52 +334,49 @@ do fi posix_mkdir=false - case $umask in - *[123567][0-7][0-7]) - # POSIX mkdir -p sets u+wx bits regardless of umask, which - # is incompatible with FreeBSD 'install' when (umask & 300) != 0. - ;; - *) - # Note that $RANDOM variable is not portable (e.g. dash); Use it - # here however when possible just to lower collision chance. - tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ - - trap 'ret=$?; rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null; exit $ret' 0 - - # Because "mkdir -p" follows existing symlinks and we likely work - # directly in world-writeable /tmp, make sure that the '$tmpdir' - # directory is successfully created first before we actually test - # 'mkdir -p' feature. - if (umask $mkdir_umask && - $mkdirprog $mkdir_mode "$tmpdir" && - exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 - then - if test -z "$dir_arg" || { - # Check for POSIX incompatibilities with -m. - # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or - # other-writable bit of parent directory when it shouldn't. - # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. - test_tmpdir="$tmpdir/a" - ls_ld_tmpdir=`ls -ld "$test_tmpdir"` - case $ls_ld_tmpdir in - d????-?r-*) different_mode=700;; - d????-?--*) different_mode=755;; - *) false;; - esac && - $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { - ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` - test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" - } - } - then posix_mkdir=: - fi - rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" - else - # Remove any dirs left behind by ancient mkdir implementations. - rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null - fi - trap '' 0;; - esac;; + # The $RANDOM variable is not portable (e.g., dash). Use it + # here however when possible just to lower collision chance. + tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ + + trap ' + ret=$? + rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null + exit $ret + ' 0 + + # Because "mkdir -p" follows existing symlinks and we likely work + # directly in world-writeable /tmp, make sure that the '$tmpdir' + # directory is successfully created first before we actually test + # 'mkdir -p'. + if (umask $mkdir_umask && + $mkdirprog $mkdir_mode "$tmpdir" && + exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 + then + if test -z "$dir_arg" || { + # Check for POSIX incompatibilities with -m. + # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or + # other-writable bit of parent directory when it shouldn't. + # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. + test_tmpdir="$tmpdir/a" + ls_ld_tmpdir=`ls -ld "$test_tmpdir"` + case $ls_ld_tmpdir in + d????-?r-*) different_mode=700;; + d????-?--*) different_mode=755;; + *) false;; + esac && + $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { + ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` + test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" + } + } + then posix_mkdir=: + fi + rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" + else + # Remove any dirs left behind by ancient mkdir implementations. + rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null + fi + trap '' 0;; esac if @@ -382,7 +387,7 @@ do then : else - # The umask is ridiculous, or mkdir does not conform to POSIX, + # mkdir does not conform to POSIX, # or it failed possibly due to a race condition. Create the # directory the slow way, step by step, checking for races as we go. @@ -411,7 +416,7 @@ do prefixes= else if $posix_mkdir; then - (umask=$mkdir_umask && + (umask $mkdir_umask && $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break # Don't fail if two instances are running concurrently. test -d "$prefix" || exit 1 @@ -488,6 +493,13 @@ do then rm -f "$dsttmp" else + # If $backupsuffix is set, and the file being installed + # already exists, attempt a backup. Don't worry if it fails, + # e.g., if mv doesn't support -f. + if test -n "$backupsuffix" && test -f "$dst"; then + $doit $mvcmd -f "$dst" "$dst$backupsuffix" 2>/dev/null + fi + # Rename the file to the real destination. $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || @@ -502,9 +514,9 @@ do # file should still install successfully. { test ! -f "$dst" || - $doit $rmcmd -f "$dst" 2>/dev/null || + $doit $rmcmd "$dst" 2>/dev/null || { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && - { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } + { $doit $rmcmd "$rmtmp" 2>/dev/null; :; } } || { echo "$0: cannot unlink or rename $dst" >&2 (exit 1); exit 1 diff --git a/3rdparty/expat/conftools/ltmain.sh b/3rdparty/expat/conftools/ltmain.sh index e774ddfe649..ff225947570 100644..100755 --- a/3rdparty/expat/conftools/ltmain.sh +++ b/3rdparty/expat/conftools/ltmain.sh @@ -1,12 +1,12 @@ -#! /bin/sh +#! /usr/bin/env sh ## DO NOT EDIT - This file generated from ./build-aux/ltmain.in -## by inline-source v2014-01-03.01 +## by inline-source v2019-02-19.15 -# libtool (GNU libtool) 2.4.6 +# libtool (GNU libtool) 2.5.3 # Provide generalized library-building support services. # Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996 -# Copyright (C) 1996-2015 Free Software Foundation, Inc. +# Copyright (C) 1996-2019, 2021-2024 Free Software Foundation, Inc. # This is free software; see the source for copying conditions. There is NO # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. @@ -31,8 +31,8 @@ PROGRAM=libtool PACKAGE=libtool -VERSION=2.4.6 -package_revision=2.4.6 +VERSION=2.5.3 +package_revision=2.5.3 ## ------ ## @@ -64,34 +64,25 @@ package_revision=2.4.6 # libraries, which are installed to $pkgauxdir. # Set a version string for this script. -scriptversion=2015-10-04.22; # UTC +scriptversion=2019-02-19.15; # UTC # General shell script boiler plate, and helper functions. # Written by Gary V. Vaughan, 2004 -# Copyright (C) 2004-2015 Free Software Foundation, Inc. -# This is free software; see the source for copying conditions. There is NO -# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. - -# As a special exception to the GNU General Public License, if you distribute -# this file as part of a program or library that is built using GNU Libtool, -# you may include this file under the same distribution terms that you use -# for the rest of that program. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# This is free software. There is NO warranty; not even for +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# Copyright (C) 2004-2019, 2021, 2023-2024 Bootstrap Authors +# +# This file is dual licensed under the terms of the MIT license +# <https://opensource.org/licenses/MIT>, and GPL version 2 or later +# <https://www.gnu.org/licenses/gpl-2.0.html>. You must apply one of +# these licenses when using or redistributing this software or any of +# the files within it. See the URLs above, or the file `LICENSE` +# included in the Bootstrap distribution for the full license texts. -# Please report bugs or propose patches to gary@gnu.org. +# Please report bugs or propose patches to: +# <https://github.com/gnulib-modules/bootstrap/issues> ## ------ ## @@ -139,9 +130,12 @@ do _G_safe_locale=\"$_G_var=C; \$_G_safe_locale\" fi" done - -# CDPATH. -(unset CDPATH) >/dev/null 2>&1 && unset CDPATH +# These NLS vars are set unconditionally (bootstrap issue #24). Unset those +# in case the environment reset is needed later and the $save_* variant is not +# defined (see the code above). +LC_ALL=C +LANGUAGE=C +export LANGUAGE LC_ALL # Make sure IFS has a sensible default sp=' ' @@ -149,7 +143,7 @@ nl=' ' IFS="$sp $nl" -# There are apparently some retarded systems that use ';' as a PATH separator! +# There are apparently some systems that use ';' as a PATH separator! if test "${PATH_SEPARATOR+set}" != set; then PATH_SEPARATOR=: (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && { @@ -159,6 +153,26 @@ if test "${PATH_SEPARATOR+set}" != set; then fi +# func_unset VAR +# -------------- +# Portably unset VAR. +# In some shells, an 'unset VAR' statement leaves a non-zero return +# status if VAR is already unset, which might be problematic if the +# statement is used at the end of a function (thus poisoning its return +# value) or when 'set -e' is active (causing even a spurious abort of +# the script in this case). +func_unset () +{ + { eval $1=; (eval unset $1) >/dev/null 2>&1 && eval unset $1 || : ; } +} + + +# Make sure CDPATH doesn't cause `cd` commands to output the target dir. +func_unset CDPATH + +# Make sure ${,E,F}GREP behave sanely. +func_unset GREP_OPTIONS + ## ------------------------- ## ## Locate command utilities. ## @@ -259,7 +273,7 @@ test -z "$SED" && { rm -f conftest.in conftest.tmp conftest.nl conftest.out } - func_path_progs "sed gsed" func_check_prog_sed $PATH:/usr/xpg4/bin + func_path_progs "sed gsed" func_check_prog_sed "$PATH:/usr/xpg4/bin" rm -f conftest.sed SED=$func_path_progs_result } @@ -295,7 +309,7 @@ test -z "$GREP" && { rm -f conftest.in conftest.tmp conftest.nl conftest.out } - func_path_progs "grep ggrep" func_check_prog_grep $PATH:/usr/xpg4/bin + func_path_progs "grep ggrep" func_check_prog_grep "$PATH:/usr/xpg4/bin" GREP=$func_path_progs_result } @@ -360,6 +374,35 @@ sed_double_backslash="\ s/\\([^$_G_bs]\\)$_G_bs2$_G_dollar/\\1$_G_bs2$_G_bs$_G_dollar/g s/\n//g" +# require_check_ifs_backslash +# --------------------------- +# Check if we can use backslash as IFS='\' separator, and set +# $check_ifs_backshlash_broken to ':' or 'false'. +require_check_ifs_backslash=func_require_check_ifs_backslash +func_require_check_ifs_backslash () +{ + _G_save_IFS=$IFS + IFS='\' + _G_check_ifs_backshlash='a\\b' + for _G_i in $_G_check_ifs_backshlash + do + case $_G_i in + a) + check_ifs_backshlash_broken=false + ;; + '') + break + ;; + *) + check_ifs_backshlash_broken=: + break + ;; + esac + done + IFS=$_G_save_IFS + require_check_ifs_backslash=: +} + ## ----------------- ## ## Global variables. ## @@ -580,16 +623,16 @@ if test yes = "$_G_HAVE_PLUSEQ_OP"; then { $debug_cmd - func_quote_for_eval "$2" - eval "$1+=\\ \$func_quote_for_eval_result" + func_quote_arg pretty "$2" + eval "$1+=\\ \$func_quote_arg_result" }' else func_append_quoted () { $debug_cmd - func_quote_for_eval "$2" - eval "$1=\$$1\\ \$func_quote_for_eval_result" + func_quote_arg pretty "$2" + eval "$1=\$$1\\ \$func_quote_arg_result" } fi @@ -1091,132 +1134,203 @@ func_relative_path () } -# func_quote ARG -# -------------- -# Aesthetically quote one ARG, store the result into $func_quote_result. Note -# that we keep attention to performance here (so far O(N) complexity as long as -# func_append is O(1)). -func_quote () +# func_quote_portable EVAL ARG +# ---------------------------- +# Internal function to portably implement func_quote_arg. Note that we still +# keep attention to performance here so we as much as possible try to avoid +# calling sed binary (so far O(N) complexity as long as func_append is O(1)). +func_quote_portable () { $debug_cmd - func_quote_result=$1 + $require_check_ifs_backslash - case $func_quote_result in - *[\\\`\"\$]*) - case $func_quote_result in - *[\[\*\?]*) - func_quote_result=`$ECHO "$func_quote_result" | $SED "$sed_quote_subst"` - return 0 - ;; - esac + func_quote_portable_result=$2 - func_quote_old_IFS=$IFS - for _G_char in '\' '`' '"' '$' - do - # STATE($1) PREV($2) SEPARATOR($3) - set start "" "" - func_quote_result=dummy"$_G_char$func_quote_result$_G_char"dummy - IFS=$_G_char - for _G_part in $func_quote_result - do - case $1 in - quote) - func_append func_quote_result "$3$2" - set quote "$_G_part" "\\$_G_char" - ;; - start) - set first "" "" - func_quote_result= - ;; - first) - set quote "$_G_part" "" + # one-time-loop (easy break) + while true + do + if $1; then + func_quote_portable_result=`$ECHO "$2" | $SED \ + -e "$sed_double_quote_subst" -e "$sed_double_backslash"` + break + fi + + # Quote for eval. + case $func_quote_portable_result in + *[\\\`\"\$]*) + # Fallback to sed for $func_check_bs_ifs_broken=:, or when the string + # contains the shell wildcard characters. + case $check_ifs_backshlash_broken$func_quote_portable_result in + :*|*[\[\*\?]*) + func_quote_portable_result=`$ECHO "$func_quote_portable_result" \ + | $SED "$sed_quote_subst"` + break ;; - esac + esac + + func_quote_portable_old_IFS=$IFS + for _G_char in '\' '`' '"' '$' + do + # STATE($1) PREV($2) SEPARATOR($3) + set start "" "" + func_quote_portable_result=dummy"$_G_char$func_quote_portable_result$_G_char"dummy + IFS=$_G_char + for _G_part in $func_quote_portable_result + do + case $1 in + quote) + func_append func_quote_portable_result "$3$2" + set quote "$_G_part" "\\$_G_char" + ;; + start) + set first "" "" + func_quote_portable_result= + ;; + first) + set quote "$_G_part" "" + ;; + esac + done done - IFS=$func_quote_old_IFS - done + IFS=$func_quote_portable_old_IFS + ;; + *) ;; + esac + break + done + + func_quote_portable_unquoted_result=$func_quote_portable_result + case $func_quote_portable_result in + # double-quote args containing shell metacharacters to delay + # word splitting, command substitution and variable expansion + # for a subsequent eval. + # many bourne shells cannot handle close brackets correctly + # in scan sets, so we specify it separately. + *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") + func_quote_portable_result=\"$func_quote_portable_result\" ;; - *) ;; esac } -# func_quote_for_eval ARG... -# -------------------------- -# Aesthetically quote ARGs to be evaled later. -# This function returns two values: -# i) func_quote_for_eval_result -# double-quoted, suitable for a subsequent eval -# ii) func_quote_for_eval_unquoted_result -# has all characters that are still active within double -# quotes backslashified. -func_quote_for_eval () -{ - $debug_cmd - - func_quote_for_eval_unquoted_result= - func_quote_for_eval_result= - while test 0 -lt $#; do - func_quote "$1" - _G_unquoted_arg=$func_quote_result - if test -n "$func_quote_for_eval_unquoted_result"; then - func_append func_quote_for_eval_unquoted_result " $_G_unquoted_arg" - else - func_append func_quote_for_eval_unquoted_result "$_G_unquoted_arg" - fi - - case $_G_unquoted_arg in - # Double-quote args containing shell metacharacters to delay - # word splitting, command substitution and variable expansion - # for a subsequent eval. - # Many Bourne shells cannot handle close brackets correctly - # in scan sets, so we specify it separately. - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - _G_quoted_arg=\"$_G_unquoted_arg\" +# func_quotefast_eval ARG +# ----------------------- +# Quote one ARG (internal). This is equivalent to 'func_quote_arg eval ARG', +# but optimized for speed. Result is stored in $func_quotefast_eval. +if test xyes = `(x=; printf -v x %q yes; echo x"$x") 2>/dev/null`; then + printf -v _GL_test_printf_tilde %q '~' + if test '\~' = "$_GL_test_printf_tilde"; then + func_quotefast_eval () + { + printf -v func_quotefast_eval_result %q "$1" + } + else + # Broken older Bash implementations. Make those faster too if possible. + func_quotefast_eval () + { + case $1 in + '~'*) + func_quote_portable false "$1" + func_quotefast_eval_result=$func_quote_portable_result ;; *) - _G_quoted_arg=$_G_unquoted_arg - ;; + printf -v func_quotefast_eval_result %q "$1" + ;; esac + } + fi +else + func_quotefast_eval () + { + func_quote_portable false "$1" + func_quotefast_eval_result=$func_quote_portable_result + } +fi - if test -n "$func_quote_for_eval_result"; then - func_append func_quote_for_eval_result " $_G_quoted_arg" - else - func_append func_quote_for_eval_result "$_G_quoted_arg" - fi - shift - done -} - - -# func_quote_for_expand ARG -# ------------------------- -# Aesthetically quote ARG to be evaled later; same as above, -# but do not quote variable references. -func_quote_for_expand () -{ - $debug_cmd - case $1 in - *[\\\`\"]*) - _G_arg=`$ECHO "$1" | $SED \ - -e "$sed_double_quote_subst" -e "$sed_double_backslash"` ;; - *) - _G_arg=$1 ;; +# func_quote_arg MODEs ARG +# ------------------------ +# Quote one ARG to be evaled later. MODEs argument may contain zero or more +# specifiers listed below separated by ',' character. This function returns two +# values: +# i) func_quote_arg_result +# double-quoted (when needed), suitable for a subsequent eval +# ii) func_quote_arg_unquoted_result +# has all characters that are still active within double +# quotes backslashified. Available only if 'unquoted' is specified. +# +# Available modes: +# ---------------- +# 'eval' (default) +# - escape shell special characters +# 'expand' +# - the same as 'eval'; but do not quote variable references +# 'pretty' +# - request aesthetic output, i.e. '"a b"' instead of 'a\ b'. This might +# be used later in func_quote to get output like: 'echo "a b"' instead +# of 'echo a\ b'. This is slower than default on some shells. +# 'unquoted' +# - produce also $func_quote_arg_unquoted_result which does not contain +# wrapping double-quotes. +# +# Examples for 'func_quote_arg pretty,unquoted string': +# +# string | *_result | *_unquoted_result +# ------------+-----------------------+------------------- +# " | \" | \" +# a b | "a b" | a b +# "a b" | "\"a b\"" | \"a b\" +# * | "*" | * +# z="${x-$y}" | "z=\"\${x-\$y}\"" | z=\"\${x-\$y}\" +# +# Examples for 'func_quote_arg pretty,unquoted,expand string': +# +# string | *_result | *_unquoted_result +# --------------+---------------------+-------------------- +# z="${x-$y}" | "z=\"${x-$y}\"" | z=\"${x-$y}\" +func_quote_arg () +{ + _G_quote_expand=false + case ,$1, in + *,expand,*) + _G_quote_expand=: + ;; esac - case $_G_arg in - # Double-quote args containing shell metacharacters to delay - # word splitting and command substitution for a subsequent eval. - # Many Bourne shells cannot handle close brackets correctly - # in scan sets, so we specify it separately. - *[\[\~\#\^\&\*\(\)\{\}\|\;\<\>\?\'\ \ ]*|*]*|"") - _G_arg=\"$_G_arg\" + case ,$1, in + *,pretty,*|*,expand,*|*,unquoted,*) + func_quote_portable $_G_quote_expand "$2" + func_quote_arg_result=$func_quote_portable_result + func_quote_arg_unquoted_result=$func_quote_portable_unquoted_result + ;; + *) + # Faster quote-for-eval for some shells. + func_quotefast_eval "$2" + func_quote_arg_result=$func_quotefast_eval_result ;; esac +} + - func_quote_for_expand_result=$_G_arg +# func_quote MODEs ARGs... +# ------------------------ +# Quote all ARGs to be evaled later and join them into single command. See +# func_quote_arg's description for more info. +func_quote () +{ + $debug_cmd + _G_func_quote_mode=$1 ; shift + func_quote_result= + while test 0 -lt $#; do + func_quote_arg "$_G_func_quote_mode" "$1" + if test -n "$func_quote_result"; then + func_append func_quote_result " $func_quote_arg_result" + else + func_append func_quote_result "$func_quote_arg_result" + fi + shift + done } @@ -1262,8 +1376,8 @@ func_show_eval () _G_cmd=$1 _G_fail_exp=${2-':'} - func_quote_for_expand "$_G_cmd" - eval "func_notquiet $func_quote_for_expand_result" + func_quote_arg pretty,expand "$_G_cmd" + eval "func_notquiet $func_quote_arg_result" $opt_dry_run || { eval "$_G_cmd" @@ -1288,8 +1402,8 @@ func_show_eval_locale () _G_fail_exp=${2-':'} $opt_quiet || { - func_quote_for_expand "$_G_cmd" - eval "func_echo $func_quote_for_expand_result" + func_quote_arg expand,pretty "$_G_cmd" + eval "func_echo $func_quote_arg_result" } $opt_dry_run || { @@ -1416,30 +1530,26 @@ func_lt_ver () # End: #! /bin/sh -# Set a version string for this script. -scriptversion=2014-01-07.03; # UTC - # A portable, pluggable option parser for Bourne shell. # Written by Gary V. Vaughan, 2010 -# Copyright (C) 2010-2015 Free Software Foundation, Inc. -# This is free software; see the source for copying conditions. There is NO -# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# This is free software. There is NO warranty; not even for +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# Copyright (C) 2010-2019, 2021, 2023-2024 Bootstrap Authors +# +# This file is dual licensed under the terms of the MIT license +# <https://opensource.org/licenses/MIT>, and GPL version 2 or later +# <https://www.gnu.org/licenses/gpl-2.0.html>. You must apply one of +# these licenses when using or redistributing this software or any of +# the files within it. See the URLs above, or the file `LICENSE` +# included in the Bootstrap distribution for the full license texts. -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# Please report bugs or propose patches to: +# <https://github.com/gnulib-modules/bootstrap/issues> -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -# Please report bugs or propose patches to gary@gnu.org. +# Set a version string for this script. +scriptversion=2019-02-19.15; # UTC ## ------ ## @@ -1462,7 +1572,7 @@ scriptversion=2014-01-07.03; # UTC # # In order for the '--version' option to work, you will need to have a # suitably formatted comment like the one at the top of this file -# starting with '# Written by ' and ending with '# warranty; '. +# starting with '# Written by ' and ending with '# Copyright'. # # For '-h' and '--help' to work, you will also need a one line # description of your script's purpose in a comment directly above the @@ -1474,7 +1584,7 @@ scriptversion=2014-01-07.03; # UTC # to display verbose messages only when your user has specified # '--verbose'. # -# After sourcing this file, you can plug processing for additional +# After sourcing this file, you can plug in processing for additional # options by amending the variables from the 'Configuration' section # below, and following the instructions in the 'Option parsing' # section further down. @@ -1523,8 +1633,8 @@ fatal_help="Try '\$progname --help' for more information." ## ------------------------- ## # This section contains functions for adding, removing, and running hooks -# to the main code. A hook is just a named list of of function, that can -# be run in order later on. +# in the main code. A hook is just a list of function names that can be +# run in order later on. # func_hookable FUNC_NAME # ----------------------- @@ -1557,7 +1667,8 @@ func_add_hook () # func_remove_hook FUNC_NAME HOOK_FUNC # ------------------------------------ -# Remove HOOK_FUNC from the list of functions called by FUNC_NAME. +# Remove HOOK_FUNC from the list of hook functions to be called by +# FUNC_NAME. func_remove_hook () { $debug_cmd @@ -1566,10 +1677,28 @@ func_remove_hook () } +# func_propagate_result FUNC_NAME_A FUNC_NAME_B +# --------------------------------------------- +# If the *_result variable of FUNC_NAME_A _is set_, assign its value to +# *_result variable of FUNC_NAME_B. +func_propagate_result () +{ + $debug_cmd + + func_propagate_result_result=: + if eval "test \"\${${1}_result+set}\" = set" + then + eval "${2}_result=\$${1}_result" + else + func_propagate_result_result=false + fi +} + + # func_run_hooks FUNC_NAME [ARG]... # --------------------------------- # Run all hook functions registered to FUNC_NAME. -# It is assumed that the list of hook functions contains nothing more +# It's assumed that the list of hook functions contains nothing more # than a whitespace-delimited list of legal shell function names, and # no effort is wasted trying to catch shell meta-characters or preserve # whitespace. @@ -1579,22 +1708,19 @@ func_run_hooks () case " $hookable_fns " in *" $1 "*) ;; - *) func_fatal_error "'$1' does not support hook funcions.n" ;; + *) func_fatal_error "'$1' does not support hook functions." ;; esac eval _G_hook_fns=\$$1_hooks; shift for _G_hook in $_G_hook_fns; do - eval $_G_hook '"$@"' - - # store returned options list back into positional - # parameters for next 'cmd' execution. - eval _G_hook_result=\$${_G_hook}_result - eval set dummy "$_G_hook_result"; shift + func_unset "${_G_hook}_result" + eval $_G_hook '${1+"$@"}' + func_propagate_result $_G_hook func_run_hooks + if $func_propagate_result_result; then + eval set dummy "$func_run_hooks_result"; shift + fi done - - func_quote_for_eval ${1+"$@"} - func_run_hooks_result=$func_quote_for_eval_result } @@ -1604,10 +1730,18 @@ func_run_hooks () ## --------------- ## # In order to add your own option parsing hooks, you must accept the -# full positional parameter list in your hook function, remove any -# options that you action, and then pass back the remaining unprocessed -# options in '<hooked_function_name>_result', escaped suitably for -# 'eval'. Like this: +# full positional parameter list from your hook function. You may remove +# or edit any options that you action, and then pass back the remaining +# unprocessed options in '<hooked_function_name>_result', escaped +# suitably for 'eval'. +# +# The '<hooked_function_name>_result' variable is automatically unset +# before your hook gets called; for best performance, only set the +# *_result variable when necessary (i.e. don't call the 'func_quote' +# function unnecessarily because it can be an expensive operation on some +# machines). +# +# Like this: # # my_options_prep () # { @@ -1617,9 +1751,8 @@ func_run_hooks () # usage_message=$usage_message' # -s, --silent don'\''t print informational messages # ' -# -# func_quote_for_eval ${1+"$@"} -# my_options_prep_result=$func_quote_for_eval_result +# # No change in '$@' (ignored completely by this hook). Leave +# # my_options_prep_result variable intact. # } # func_add_hook func_options_prep my_options_prep # @@ -1628,25 +1761,36 @@ func_run_hooks () # { # $debug_cmd # -# # Note that for efficiency, we parse as many options as we can +# args_changed=false +# +# # Note that, for efficiency, we parse as many options as we can # # recognise in a loop before passing the remainder back to the # # caller on the first unrecognised argument we encounter. # while test $# -gt 0; do # opt=$1; shift # case $opt in -# --silent|-s) opt_silent=: ;; +# --silent|-s) opt_silent=: +# args_changed=: +# ;; # # Separate non-argument short options: # -s*) func_split_short_opt "$_G_opt" # set dummy "$func_split_short_opt_name" \ # "-$func_split_short_opt_arg" ${1+"$@"} # shift +# args_changed=: # ;; -# *) set dummy "$_G_opt" "$*"; shift; break ;; +# *) # Make sure the first unrecognised option "$_G_opt" +# # is added back to "$@" in case we need it later, +# # if $args_changed was set to 'true'. +# set dummy "$_G_opt" ${1+"$@"}; shift; break ;; # esac # done # -# func_quote_for_eval ${1+"$@"} -# my_silent_option_result=$func_quote_for_eval_result +# # Only call 'func_quote' here if we processed at least one argument. +# if $args_changed; then +# func_quote eval ${1+"$@"} +# my_silent_option_result=$func_quote_result +# fi # } # func_add_hook func_parse_options my_silent_option # @@ -1657,17 +1801,26 @@ func_run_hooks () # # $opt_silent && $opt_verbose && func_fatal_help "\ # '--silent' and '--verbose' options are mutually exclusive." -# -# func_quote_for_eval ${1+"$@"} -# my_option_validation_result=$func_quote_for_eval_result # } # func_add_hook func_validate_options my_option_validation # -# You'll alse need to manually amend $usage_message to reflect the extra +# You'll also need to manually amend $usage_message to reflect the extra # options you parse. It's preferable to append if you can, so that # multiple option parsing hooks can be added safely. +# func_options_finish [ARG]... +# ---------------------------- +# Finishing the option parse loop (call 'func_options' hooks ATM). +func_options_finish () +{ + $debug_cmd + + func_run_hooks func_options ${1+"$@"} + func_propagate_result func_run_hooks func_options_finish +} + + # func_options [ARG]... # --------------------- # All the functions called inside func_options are hookable. See the @@ -1677,17 +1830,27 @@ func_options () { $debug_cmd - func_options_prep ${1+"$@"} - eval func_parse_options \ - ${func_options_prep_result+"$func_options_prep_result"} - eval func_validate_options \ - ${func_parse_options_result+"$func_parse_options_result"} + _G_options_quoted=false - eval func_run_hooks func_options \ - ${func_validate_options_result+"$func_validate_options_result"} + for my_func in options_prep parse_options validate_options options_finish + do + func_unset func_${my_func}_result + func_unset func_run_hooks_result + eval func_$my_func '${1+"$@"}' + func_propagate_result func_$my_func func_options + if $func_propagate_result_result; then + eval set dummy "$func_options_result"; shift + _G_options_quoted=: + fi + done - # save modified positional parameters for caller - func_options_result=$func_run_hooks_result + $_G_options_quoted || { + # As we (func_options) are top-level options-parser function and + # nobody quoted "$@" for us yet, we need to do it explicitly for + # caller. + func_quote eval ${1+"$@"} + func_options_result=$func_quote_result + } } @@ -1696,9 +1859,8 @@ func_options () # All initialisations required before starting the option parse loop. # Note that when calling hook functions, we pass through the list of # positional parameters. If a hook function modifies that list, and -# needs to propogate that back to rest of this script, then the complete -# modified list must be put in 'func_run_hooks_result' before -# returning. +# needs to propagate that back to rest of this script, then the complete +# modified list must be put in 'func_run_hooks_result' before returning. func_hookable func_options_prep func_options_prep () { @@ -1709,9 +1871,7 @@ func_options_prep () opt_warning_types= func_run_hooks func_options_prep ${1+"$@"} - - # save modified positional parameters for caller - func_options_prep_result=$func_run_hooks_result + func_propagate_result func_run_hooks func_options_prep } @@ -1723,25 +1883,32 @@ func_parse_options () { $debug_cmd - func_parse_options_result= - + _G_parse_options_requote=false # this just eases exit handling while test $# -gt 0; do # Defer to hook functions for initial option parsing, so they # get priority in the event of reusing an option name. func_run_hooks func_parse_options ${1+"$@"} - - # Adjust func_parse_options positional parameters to match - eval set dummy "$func_run_hooks_result"; shift + func_propagate_result func_run_hooks func_parse_options + if $func_propagate_result_result; then + eval set dummy "$func_parse_options_result"; shift + # Even though we may have changed "$@", we passed the "$@" array + # down into the hook and it quoted it for us (because we are in + # this if-branch). No need to quote it again. + _G_parse_options_requote=false + fi # Break out of the loop if we already parsed every option. test $# -gt 0 || break + # We expect that one of the options parsed in this function matches + # and thus we remove _G_opt from "$@" and need to re-quote. + _G_match_parse_options=: _G_opt=$1 shift case $_G_opt in --debug|-x) debug_cmd='set -x' - func_echo "enabling shell trace mode" + func_echo "enabling shell trace mode" >&2 $debug_cmd ;; @@ -1751,7 +1918,10 @@ func_parse_options () ;; --warnings|--warning|-W) - test $# = 0 && func_missing_arg $_G_opt && break + if test $# = 0 && func_missing_arg $_G_opt; then + _G_parse_options_requote=: + break + fi case " $warning_categories $1" in *" $1 "*) # trailing space prevents matching last $1 above @@ -1804,15 +1974,24 @@ func_parse_options () shift ;; - --) break ;; + --) _G_parse_options_requote=: ; break ;; -*) func_fatal_help "unrecognised option: '$_G_opt'" ;; - *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;; + *) set dummy "$_G_opt" ${1+"$@"}; shift + _G_match_parse_options=false + break + ;; esac + + if $_G_match_parse_options; then + _G_parse_options_requote=: + fi done - # save modified positional parameters for caller - func_quote_for_eval ${1+"$@"} - func_parse_options_result=$func_quote_for_eval_result + if $_G_parse_options_requote; then + # save modified positional parameters for caller + func_quote eval ${1+"$@"} + func_parse_options_result=$func_quote_result + fi } @@ -1829,12 +2008,10 @@ func_validate_options () test -n "$opt_warning_types" || opt_warning_types=" $warning_categories" func_run_hooks func_validate_options ${1+"$@"} + func_propagate_result func_run_hooks func_validate_options # Bail if the options were screwed! $exit_cmd $EXIT_FAILURE - - # save modified positional parameters for caller - func_validate_options_result=$func_run_hooks_result } @@ -1890,8 +2067,8 @@ func_missing_arg () # func_split_equals STRING # ------------------------ -# Set func_split_equals_lhs and func_split_equals_rhs shell variables after -# splitting STRING at the '=' sign. +# Set func_split_equals_lhs and func_split_equals_rhs shell variables +# after splitting STRING at the '=' sign. test -z "$_G_HAVE_XSI_OPS" \ && (eval 'x=a/b/c; test 5aa/bb/cc = "${#x}${x%%/*}${x%/*}${x#*/}${x##*/}"') 2>/dev/null \ @@ -1906,8 +2083,9 @@ then func_split_equals_lhs=${1%%=*} func_split_equals_rhs=${1#*=} - test "x$func_split_equals_lhs" = "x$1" \ - && func_split_equals_rhs= + if test "x$func_split_equals_lhs" = "x$1"; then + func_split_equals_rhs= + fi }' else # ...otherwise fall back to using expr, which is often a shell builtin. @@ -1917,7 +2095,7 @@ else func_split_equals_lhs=`expr "x$1" : 'x\([^=]*\)'` func_split_equals_rhs= - test "x$func_split_equals_lhs" = "x$1" \ + test "x$func_split_equals_lhs=" = "x$1" \ || func_split_equals_rhs=`expr "x$1" : 'x[^=]*=\(.*\)$'` } fi #func_split_equals @@ -1943,7 +2121,7 @@ else { $debug_cmd - func_split_short_opt_name=`expr "x$1" : 'x-\(.\)'` + func_split_short_opt_name=`expr "x$1" : 'x\(-.\)'` func_split_short_opt_arg=`expr "x$1" : 'x-.\(.*\)$'` } fi #func_split_short_opt @@ -1985,31 +2163,44 @@ func_usage_message () # func_version # ------------ # Echo version message to standard output and exit. +# The version message is extracted from the calling file's header +# comments, with leading '# ' stripped: +# 1. First display the progname and version +# 2. Followed by the header comment line matching /^# Written by / +# 3. Then a blank line followed by the first following line matching +# /^# Copyright / +# 4. Immediately followed by any lines between the previous matches, +# except lines preceding the intervening completely blank line. +# For example, see the header comments of this file. func_version () { $debug_cmd printf '%s\n' "$progname $scriptversion" $SED -n ' - /(C)/!b go - :more - /\./!{ - N - s|\n# | | - b more - } - :go - /^# Written by /,/# warranty; / { - s|^# || - s|^# *$|| - s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2| - p + /^# Written by /!b + s|^# ||; p; n + + :fwd2blnk + /./ { + n + b fwd2blnk } - /^# Written by / { - s|^# || - p + p; n + + :holdwrnt + s|^# || + s|^# *$|| + /^Copyright /!{ + /./H + n + b holdwrnt } - /^warranty; /q' < "$progpath" + + s|\((C)\)[ 0-9,-]*[ ,-]\([1-9][0-9]* \)|\1 \2| + G + s|\(\n\)\n*|\1|g + p; q' < "$progpath" exit $? } @@ -2019,12 +2210,12 @@ func_version () # mode: shell-script # sh-indentation: 2 # eval: (add-hook 'before-save-hook 'time-stamp) -# time-stamp-pattern: "10/scriptversion=%:y-%02m-%02d.%02H; # UTC" +# time-stamp-pattern: "30/scriptversion=%:y-%02m-%02d.%02H; # UTC" # time-stamp-time-zone: "UTC" # End: # Set a version string. -scriptversion='(GNU libtool) 2.4.6' +scriptversion='(GNU libtool) 2.5.3' # func_echo ARG... @@ -2115,13 +2306,13 @@ include the following information: compiler: $LTCC compiler flags: $LTCFLAGS linker: $LD (gnu? $with_gnu_ld) - version: $progname (GNU libtool) 2.4.6 + version: $progname (GNU libtool) 2.5.3 automake: `($AUTOMAKE --version) 2>/dev/null |$SED 1q` autoconf: `($AUTOCONF --version) 2>/dev/null |$SED 1q` Report bugs to <bug-libtool@gnu.org>. -GNU libtool home page: <http://www.gnu.org/software/libtool/>. -General help using GNU software: <http://www.gnu.org/gethelp/>." +GNU libtool home page: <https://www.gnu.org/software/libtool/>. +General help using GNU software: <https://www.gnu.org/gethelp/>." exit 0 } @@ -2171,7 +2362,7 @@ fi # a configuration failure hint, and exit. func_fatal_configuration () { - func__fatal_error ${1+"$@"} \ + func_fatal_error ${1+"$@"} \ "See the $PACKAGE documentation for more information." \ "Fatal configuration error." } @@ -2317,6 +2508,8 @@ libtool_options_prep () nonopt= preserve_args= + _G_rc_lt_options_prep=: + # Shorthand for --mode=foo, only valid as the first argument case $1 in clean|clea|cle|cl) @@ -2340,11 +2533,16 @@ libtool_options_prep () uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u) shift; set dummy --mode uninstall ${1+"$@"}; shift ;; + *) + _G_rc_lt_options_prep=false + ;; esac - # Pass back the list of options. - func_quote_for_eval ${1+"$@"} - libtool_options_prep_result=$func_quote_for_eval_result + if $_G_rc_lt_options_prep; then + # Pass back the list of options. + func_quote eval ${1+"$@"} + libtool_options_prep_result=$func_quote_result + fi } func_add_hook func_options_prep libtool_options_prep @@ -2356,9 +2554,12 @@ libtool_parse_options () { $debug_cmd + _G_rc_lt_parse_options=false + # Perform our own loop to consume as many options as possible in # each iteration. while test $# -gt 0; do + _G_match_lt_parse_options=: _G_opt=$1 shift case $_G_opt in @@ -2433,15 +2634,20 @@ libtool_parse_options () func_append preserve_args " $_G_opt" ;; - # An option not handled by this hook function: - *) set dummy "$_G_opt" ${1+"$@"}; shift; break ;; + # An option not handled by this hook function: + *) set dummy "$_G_opt" ${1+"$@"} ; shift + _G_match_lt_parse_options=false + break + ;; esac + $_G_match_lt_parse_options && _G_rc_lt_parse_options=: done - - # save modified positional parameters for caller - func_quote_for_eval ${1+"$@"} - libtool_parse_options_result=$func_quote_for_eval_result + if $_G_rc_lt_parse_options; then + # save modified positional parameters for caller + func_quote eval ${1+"$@"} + libtool_parse_options_result=$func_quote_result + fi } func_add_hook func_parse_options libtool_parse_options @@ -2462,10 +2668,10 @@ libtool_validate_options () # preserve --debug test : = "$debug_cmd" || func_append preserve_args " --debug" - case $host in + case $host_os in # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452 # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788 - *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*) + cygwin* | mingw* | windows* | pw32* | cegcc* | solaris2* | os2*) # don't eliminate duplications in $postdeps and $predeps opt_duplicate_compiler_generated_deps=: ;; @@ -2498,8 +2704,8 @@ libtool_validate_options () } # Pass back the unparsed argument list - func_quote_for_eval ${1+"$@"} - libtool_validate_options_result=$func_quote_for_eval_result + func_quote eval ${1+"$@"} + libtool_validate_options_result=$func_quote_result } func_add_hook func_validate_options libtool_validate_options @@ -2797,7 +3003,7 @@ EOF # func_convert_core_file_wine_to_w32 ARG # Helper function used by file name conversion functions when $build is *nix, -# and $host is mingw, cygwin, or some other w32 environment. Relies on a +# and $host is mingw, windows, cygwin, or some other w32 environment. Relies on a # correctly configured wine environment available, with the winepath program # in $build's $PATH. # @@ -2829,9 +3035,10 @@ func_convert_core_file_wine_to_w32 () # func_convert_core_path_wine_to_w32 ARG # Helper function used by path conversion functions when $build is *nix, and -# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly -# configured wine environment available, with the winepath program in $build's -# $PATH. Assumes ARG has no leading or trailing path separator characters. +# $host is mingw, windows, cygwin, or some other w32 environment. Relies on a +# correctly configured wine environment available, with the winepath program +# in $build's $PATH. Assumes ARG has no leading or trailing path separator +# characters. # # ARG is path to be converted from $build format to win32. # Result is available in $func_convert_core_path_wine_to_w32_result. @@ -3465,8 +3672,8 @@ func_mode_compile () esac done - func_quote_for_eval "$libobj" - test "X$libobj" != "X$func_quote_for_eval_result" \ + func_quote_arg pretty "$libobj" + test "X$libobj" != "X$func_quote_arg_result" \ && $ECHO "X$libobj" | $GREP '[]~#^*{};<>?"'"'"' &()|`$[]' \ && func_warning "libobj name '$libobj' may not contain shell special characters." func_dirname_and_basename "$obj" "/" "" @@ -3486,7 +3693,7 @@ func_mode_compile () # On Cygwin there's no "real" PIC flag so we must build both object types case $host_os in - cygwin* | mingw* | pw32* | os2* | cegcc*) + cygwin* | mingw* | windows* | pw32* | os2* | cegcc*) pic_mode=default ;; esac @@ -3539,8 +3746,8 @@ compiler." func_to_tool_file "$srcfile" func_convert_file_msys_to_w32 srcfile=$func_to_tool_file_result - func_quote_for_eval "$srcfile" - qsrcfile=$func_quote_for_eval_result + func_quote_arg pretty "$srcfile" + qsrcfile=$func_quote_arg_result # Only build a PIC object if we are building libtool libraries. if test yes = "$build_libtool_libs"; then @@ -3695,7 +3902,8 @@ This mode accepts the following additional options: -prefer-non-pic try to build non-PIC objects only -shared do not build a '.o' file suitable for static linking -static only build a '.o' file suitable for static linking - -Wc,FLAG pass FLAG directly to the compiler + -Wc,FLAG + -Xcompiler FLAG pass FLAG directly to the compiler COMPILE-COMMAND is a command to be used in creating a 'standard' object file from the given SOURCEFILE. @@ -3801,6 +4009,8 @@ The following components of LINK-COMMAND are treated specially: -weak LIBNAME declare that the target provides the LIBNAME interface -Wc,FLAG -Xcompiler FLAG pass linker-specific FLAG directly to the compiler + -Wa,FLAG + -Xassembler FLAG pass linker-specific FLAG directly to the assembler -Wl,FLAG -Xlinker FLAG pass linker-specific FLAG directly to the linker -XCClinker FLAG pass link-specific FLAG to the compiler driver (CC) @@ -4143,8 +4353,8 @@ func_mode_install () case $nonopt in *shtool*) :;; *) false;; esac then # Aesthetically quote it. - func_quote_for_eval "$nonopt" - install_prog="$func_quote_for_eval_result " + func_quote_arg pretty "$nonopt" + install_prog="$func_quote_arg_result " arg=$1 shift else @@ -4154,8 +4364,8 @@ func_mode_install () # The real first argument should be the name of the installation program. # Aesthetically quote it. - func_quote_for_eval "$arg" - func_append install_prog "$func_quote_for_eval_result" + func_quote_arg pretty "$arg" + func_append install_prog "$func_quote_arg_result" install_shared_prog=$install_prog case " $install_prog " in *[\\\ /]cp\ *) install_cp=: ;; @@ -4212,12 +4422,12 @@ func_mode_install () esac # Aesthetically quote the argument. - func_quote_for_eval "$arg" - func_append install_prog " $func_quote_for_eval_result" + func_quote_arg pretty "$arg" + func_append install_prog " $func_quote_arg_result" if test -n "$arg2"; then - func_quote_for_eval "$arg2" + func_quote_arg pretty "$arg2" fi - func_append install_shared_prog " $func_quote_for_eval_result" + func_append install_shared_prog " $func_quote_arg_result" done test -z "$install_prog" && \ @@ -4228,8 +4438,8 @@ func_mode_install () if test -n "$install_override_mode" && $no_mode; then if $install_cp; then :; else - func_quote_for_eval "$install_override_mode" - func_append install_shared_prog " -m $func_quote_for_eval_result" + func_quote_arg pretty "$install_override_mode" + func_append install_shared_prog " -m $func_quote_arg_result" fi fi @@ -4360,7 +4570,7 @@ func_mode_install () 'exit $?' tstripme=$stripme case $host_os in - cygwin* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | windows* | pw32* | cegcc*) case $realname in *.dll.a) tstripme= @@ -4473,7 +4683,7 @@ func_mode_install () # Do a test to see if this is really a libtool program. case $host in - *cygwin* | *mingw*) + *cygwin* | *mingw* | *windows*) if func_ltwrapper_executable_p "$file"; then func_ltwrapper_scriptname "$file" wrapper=$func_ltwrapper_scriptname_result @@ -4525,8 +4735,8 @@ func_mode_install () relink_command=`$ECHO "$relink_command" | $SED 's%@OUTPUT@%'"$outputname"'%g'` $opt_quiet || { - func_quote_for_expand "$relink_command" - eval "func_echo $func_quote_for_expand_result" + func_quote_arg expand,pretty "$relink_command" + eval "func_echo $func_quote_arg_result" } if eval "$relink_command"; then : else @@ -4701,7 +4911,7 @@ extern \"C\" { $RM $export_symbols eval "$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \(.*\)$/\1/p' "'< "$nlist" > "$export_symbols"' case $host in - *cygwin* | *mingw* | *cegcc* ) + *cygwin* | *mingw* | *windows* | *cegcc* ) eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' eval 'cat "$export_symbols" >> "$output_objdir/$outputname.def"' ;; @@ -4713,7 +4923,7 @@ extern \"C\" { eval '$GREP -f "$output_objdir/$outputname.exp" < "$nlist" > "$nlist"T' eval '$MV "$nlist"T "$nlist"' case $host in - *cygwin* | *mingw* | *cegcc* ) + *cygwin* | *mingw* | *windows* | *cegcc* ) eval "echo EXPORTS "'> "$output_objdir/$outputname.def"' eval 'cat "$nlist" >> "$output_objdir/$outputname.def"' ;; @@ -4727,7 +4937,7 @@ extern \"C\" { func_basename "$dlprefile" name=$func_basename_result case $host in - *cygwin* | *mingw* | *cegcc* ) + *cygwin* | *mingw* | *windows* | *cegcc* ) # if an import library, we need to obtain dlname if func_win32_import_lib_p "$dlprefile"; then func_tr_sh "$dlprefile" @@ -4753,8 +4963,16 @@ extern \"C\" { eval '$ECHO ": $name " >> "$nlist"' fi func_to_tool_file "$dlprefile" func_convert_file_msys_to_w32 - eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe | - $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'" + case $host in + i[3456]86-*-mingw32*) + eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe | + $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'" + ;; + *) + eval "$NM \"$func_to_tool_file_result\" 2>/dev/null | $global_symbol_pipe | + $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/__nm_//' >> '$nlist'" + ;; + esac } else # not an import lib $opt_dry_run || { @@ -4902,7 +5120,7 @@ static const void *lt_preloaded_setup() { # Transform the symbol file into the correct name. symfileobj=$output_objdir/${my_outputname}S.$objext case $host in - *cygwin* | *mingw* | *cegcc* ) + *cygwin* | *mingw* | *windows* | *cegcc* ) if test -f "$output_objdir/$my_outputname.def"; then compile_command=`$ECHO "$compile_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` finalize_command=`$ECHO "$finalize_command" | $SED "s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%"` @@ -4978,7 +5196,7 @@ func_win32_libid () *ar\ archive*) # could be an import, or static # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD. if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null | - $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then + $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64|pe-aarch64)' >/dev/null; then case $nm_interface in "MS dumpbin") if func_cygming_ms_implib_p "$1" || @@ -5245,7 +5463,7 @@ func_extract_archives () # # Emit a libtool wrapper script on stdout. # Don't directly open a file because we may want to -# incorporate the script contents within a cygwin/mingw +# incorporate the script contents within a cygwin/mingw/windows # wrapper executable. Must ONLY be called from within # func_mode_link because it depends on a number of variables # set therein. @@ -5253,7 +5471,7 @@ func_extract_archives () # ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR # variable will take. If 'yes', then the emitted script # will assume that the directory where it is stored is -# the $objdir directory. This is a cygwin/mingw-specific +# the $objdir directory. This is a cygwin/mingw/windows-specific # behavior. func_emit_wrapper () { @@ -5305,8 +5523,8 @@ else if test \"\$libtool_execute_magic\" != \"$magic\"; then file=\"\$0\"" - func_quote "$ECHO" - qECHO=$func_quote_result + func_quote_arg pretty "$ECHO" + qECHO=$func_quote_arg_result $ECHO "\ # A function that is used when there is no print builtin or printf. @@ -5316,7 +5534,7 @@ func_fallback_echo () \$1 _LTECHO_EOF' } - ECHO=\"$qECHO\" + ECHO=$qECHO fi # Very basic option parsing. These options are (a) specific to @@ -5378,7 +5596,7 @@ func_exec_program_core () " case $host in # Backslashes separate directories on plain windows - *-*-mingw | *-*-os2* | *-cegcc*) + *-*-mingw* | *-*-windows* | *-*-os2* | *-cegcc*) $ECHO "\ if test -n \"\$lt_option_debug\"; then \$ECHO \"$outputname:$output:\$LINENO: newargv[0]: \$progdir\\\\\$program\" 1>&2 @@ -5446,7 +5664,7 @@ func_exec_program () file=\`ls -ld \"\$thisdir/\$file\" | $SED -n 's/.*-> //p'\` done - # Usually 'no', except on cygwin/mingw when embedded into + # Usually 'no', except on cygwin/mingw/windows when embedded into # the cwrapper. WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1 if test \"\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\" = \"yes\"; then @@ -5578,7 +5796,7 @@ EOF #endif #include <stdio.h> #include <stdlib.h> -#ifdef _MSC_VER +#if defined _WIN32 && !defined __GNUC__ # include <direct.h> # include <process.h> # include <io.h> @@ -5603,7 +5821,7 @@ EOF /* declarations of non-ANSI functions */ #if defined __MINGW32__ # ifdef __STRICT_ANSI__ -int _putenv (const char *); +_CRTIMP int __cdecl _putenv (const char *); # endif #elif defined __CYGWIN__ # ifdef __STRICT_ANSI__ @@ -5801,7 +6019,7 @@ main (int argc, char *argv[]) { EOF case $host in - *mingw* | *cygwin* ) + *mingw* | *windows* | *cygwin* ) # make stdout use "unix" line endings echo " setmode(1,_O_BINARY);" ;; @@ -5820,7 +6038,7 @@ EOF { /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX namespace, but it is not one of the ones we know about and - have already dealt with, above (inluding dump-script), then + have already dealt with, above (including dump-script), then report an error. Otherwise, targets might begin to believe they are allowed to use options in the LTWRAPPER_OPTION_PREFIX namespace. The first time any user complains about this, we'll @@ -5904,7 +6122,7 @@ EOF EOF case $host_os in - mingw*) + mingw* | windows*) cat <<"EOF" { char* p; @@ -5946,7 +6164,7 @@ EOF EOF case $host_os in - mingw*) + mingw* | windows*) cat <<"EOF" /* execv doesn't actually work on mingw as expected on unix */ newargz = prepare_spawn (newargz); @@ -6365,7 +6583,7 @@ lt_update_lib_path (const char *name, const char *value) EOF case $host_os in - mingw*) + mingw* | windows*) cat <<"EOF" /* Prepares an argument vector before calling spawn(). @@ -6540,7 +6758,7 @@ func_mode_link () $debug_cmd case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*) # It is impossible to link a dll without this setting, and # we shouldn't force the makefile maintainer to figure out # what system we are compiling for in order to pass an extra @@ -6604,10 +6822,12 @@ func_mode_link () xrpath= perm_rpath= temp_rpath= + temp_rpath_tail= thread_safe=no vinfo= vinfo_number=no weak_libs= + rpath_arg= single_module=$wl-single_module func_infer_tag $base_compile @@ -6659,9 +6879,9 @@ func_mode_link () while test "$#" -gt 0; do arg=$1 shift - func_quote_for_eval "$arg" - qarg=$func_quote_for_eval_unquoted_result - func_append libtool_args " $func_quote_for_eval_result" + func_quote_arg pretty,unquoted "$arg" + qarg=$func_quote_arg_unquoted_result + func_append libtool_args " $func_quote_arg_result" # If the previous option needs an argument, assign it. if test -n "$prev"; then @@ -6870,7 +7090,7 @@ func_mode_link () case $arg in [\\/]* | [A-Za-z]:[\\/]*) ;; *) - func_fatal_error "only absolute run-paths are allowed" + func_fatal_error "argument to -rpath is not absolute: $arg" ;; esac if test rpath = "$prev"; then @@ -6897,6 +7117,13 @@ func_mode_link () prev= continue ;; + xassembler) + func_append compiler_flags " -Xassembler $qarg" + prev= + func_append compile_command " -Xassembler $qarg" + func_append finalize_command " -Xassembler $qarg" + continue + ;; xcclinker) func_append linker_flags " $qarg" func_append compiler_flags " $qarg" @@ -7039,7 +7266,7 @@ func_mode_link () ;; esac case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*) testbindir=`$ECHO "$dir" | $SED 's*/lib$*/bin*'` case :$dllsearchpath: in *":$dir:"*) ;; @@ -7059,7 +7286,7 @@ func_mode_link () -l*) if test X-lc = "X$arg" || test X-lm = "X$arg"; then case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*) + *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*) # These systems don't actually have a C or math library (as such) continue ;; @@ -7067,7 +7294,7 @@ func_mode_link () # These systems don't actually have a C library (as such) test X-lc = "X$arg" && continue ;; - *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*) + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*) # Do not include libc due to us having libc/libc_r. test X-lc = "X$arg" && continue ;; @@ -7087,7 +7314,7 @@ func_mode_link () esac elif test X-lc_r = "X$arg"; then case $host in - *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*) + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*) # Do not include libc_r directly, use -pthread flag. continue ;; @@ -7117,9 +7344,21 @@ func_mode_link () prev=xcompiler continue ;; - - -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \ - |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*) + # Solaris ld rejects as of 11.4. Refer to Oracle bug 22985199. + -pthread) + case $host in + *solaris2*) ;; + *) + case "$new_inherited_linker_flags " in + *" $arg "*) ;; + * ) func_append new_inherited_linker_flags " $arg" ;; + esac + ;; + esac + continue + ;; + -mt|-mthreads|-kthread|-Kthread|-pthreads|--thread-safe \ + |-threads|-fopenmp|-fopenmp=*|-openmp|-mp|-xopenmp|-omp|-qsmp=*) func_append compiler_flags " $arg" func_append compile_command " $arg" func_append finalize_command " $arg" @@ -7152,7 +7391,7 @@ func_mode_link () -no-install) case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*) + *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*) # The PATH hackery in wrapper scripts is required on Windows # and Darwin in order for the loader to find any dlls it needs. func_warning "'-no-install' is ignored for $host" @@ -7212,7 +7451,7 @@ func_mode_link () dir=$lt_sysroot$func_stripname_result ;; *) - func_fatal_error "only absolute run-paths are allowed" + func_fatal_error "argument ($arg) to '-R' is not an absolute path: $dir" ;; esac case "$xrpath " in @@ -7269,9 +7508,9 @@ func_mode_link () save_ifs=$IFS; IFS=, for flag in $args; do IFS=$save_ifs - func_quote_for_eval "$flag" - func_append arg " $func_quote_for_eval_result" - func_append compiler_flags " $func_quote_for_eval_result" + func_quote_arg pretty "$flag" + func_append arg " $func_quote_arg_result" + func_append compiler_flags " $func_quote_arg_result" done IFS=$save_ifs func_stripname ' ' '' "$arg" @@ -7285,16 +7524,21 @@ func_mode_link () save_ifs=$IFS; IFS=, for flag in $args; do IFS=$save_ifs - func_quote_for_eval "$flag" - func_append arg " $wl$func_quote_for_eval_result" - func_append compiler_flags " $wl$func_quote_for_eval_result" - func_append linker_flags " $func_quote_for_eval_result" + func_quote_arg pretty "$flag" + func_append arg " $wl$func_quote_arg_result" + func_append compiler_flags " $wl$func_quote_arg_result" + func_append linker_flags " $func_quote_arg_result" done IFS=$save_ifs func_stripname ' ' '' "$arg" arg=$func_stripname_result ;; + -Xassembler) + prev=xassembler + continue + ;; + -Xcompiler) prev=xcompiler continue @@ -7312,8 +7556,8 @@ func_mode_link () # -msg_* for osf cc -msg_*) - func_quote_for_eval "$arg" - arg=$func_quote_for_eval_result + func_quote_arg pretty "$arg" + arg=$func_quote_arg_result ;; # Flags to be passed through unchanged, with rationale: @@ -7332,14 +7576,31 @@ func_mode_link () # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization # -specs=* GCC specs files # -stdlib=* select c++ std lib with clang + # -fdiagnostics-color* simply affects output + # -frecord-gcc-switches used to verify flags were respected # -fsanitize=* Clang/GCC memory and address sanitizer + # -fno-sanitize* Clang/GCC memory and address sanitizer + # -shared-libsan Link with shared sanitizer runtimes (Clang) + # -static-libsan Link with static sanitizer runtimes (Clang) + # -no-canonical-prefixes Do not expand any symbolic links # -fuse-ld=* Linker select flags for GCC + # -static-* direct GCC to link specific libraries statically + # -fcilkplus Cilk Plus language extension features for C/C++ + # -rtlib=* select c runtime lib with clang + # --unwindlib=* select unwinder library with clang + # -f{file|debug|macro|profile}-prefix-map=* needed for lto linking + # -Wa,* Pass flags directly to the assembler + # -Werror, -Werror=* Report (specified) warnings as errors -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \ -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \ - -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*| \ - -specs=*|-fsanitize=*|-fuse-ld=*) - func_quote_for_eval "$arg" - arg=$func_quote_for_eval_result + -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-no-canonical-prefixes| \ + -stdlib=*|-rtlib=*|--unwindlib=*| \ + -specs=*|-fsanitize=*|-fno-sanitize*|-shared-libsan|-static-libsan| \ + -ffile-prefix-map=*|-fdebug-prefix-map=*|-fmacro-prefix-map=*|-fprofile-prefix-map=*| \ + -fdiagnostics-color*|-frecord-gcc-switches| \ + -fuse-ld=*|-static-*|-fcilkplus|-Wa,*|-Werror|-Werror=*) + func_quote_arg pretty "$arg" + arg=$func_quote_arg_result func_append compile_command " $arg" func_append finalize_command " $arg" func_append compiler_flags " $arg" @@ -7360,15 +7621,15 @@ func_mode_link () continue else # Otherwise treat like 'Some other compiler flag' below - func_quote_for_eval "$arg" - arg=$func_quote_for_eval_result + func_quote_arg pretty "$arg" + arg=$func_quote_arg_result fi ;; # Some other compiler flag. -* | +*) - func_quote_for_eval "$arg" - arg=$func_quote_for_eval_result + func_quote_arg pretty "$arg" + arg=$func_quote_arg_result ;; *.$objext) @@ -7488,15 +7749,27 @@ func_mode_link () *) # Unknown arguments in both finalize_command and compile_command need # to be aesthetically quoted because they are evaled later. - func_quote_for_eval "$arg" - arg=$func_quote_for_eval_result + func_quote_arg pretty "$arg" + arg=$func_quote_arg_result ;; esac # arg # Now actually substitute the argument into the commands. if test -n "$arg"; then - func_append compile_command " $arg" - func_append finalize_command " $arg" + if test -n "$rpath_arg"; then + func_append finalize_rpath " ${arg##*,}" + unset rpath_arg + else + case $arg in + -Wl,-rpath,*) + func_append finalize_rpath " ${arg##*,}";; + -Wl,-rpath) + rpath_arg=1;; + *) + func_append compile_command " $arg" + func_append finalize_command " $arg" + esac + fi fi done # argument parsing loop @@ -7667,7 +7940,7 @@ func_mode_link () found=false case $deplib in -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \ - |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*) + |-threads|-fopenmp|-fopenmp=*|-openmp|-mp|-xopenmp|-omp|-qsmp=*) if test prog,link = "$linkmode,$pass"; then compile_deplibs="$deplib $compile_deplibs" finalize_deplibs="$deplib $finalize_deplibs" @@ -7844,18 +8117,15 @@ func_mode_link () ;; esac if $valid_a_lib; then - echo - $ECHO "*** Warning: Linking the shared library $output against the" - $ECHO "*** static library $deplib is not portable!" + func_warning "Linking the shared library $output against the static library $deplib is not portable!" deplibs="$deplib $deplibs" else - echo - $ECHO "*** Warning: Trying to link with static lib archive $deplib." - echo "*** I have the capability to make that library automatically link in when" - echo "*** you link to this library. But I can only do this if you have a" - echo "*** shared version of the library, which you do not appear to have" - echo "*** because the file extensions .$libext of this argument makes me believe" - echo "*** that it is just a static archive that I should not use here." + func_warning "Trying to link with static lib archive $deplib." + func_warning "I have the capability to make that library automatically link in when" + func_warning "you link to this library. But I can only do this if you have a" + func_warning "shared version of the library, which you do not appear to have" + func_warning "because the file extensions .$libext of this argument makes me believe" + func_warning "that it is just a static archive that I should not use here." fi ;; esac @@ -8050,7 +8320,7 @@ func_mode_link () fi case $host in # special handling for platforms with PE-DLLs. - *cygwin* | *mingw* | *cegcc* ) + *cygwin* | *mingw* | *windows* | *cegcc* ) # Linker will automatically link against shared library if both # static and shared are present. Therefore, ensure we extract # symbols from the import library if a shared library is present @@ -8150,7 +8420,10 @@ func_mode_link () # Make sure the rpath contains only unique directories. case $temp_rpath: in *"$absdir:"*) ;; - *) func_append temp_rpath "$absdir:" ;; + *) case $absdir in + "$progdir/"*) func_append temp_rpath "$absdir:" ;; + *) func_append temp_rpath_tail "$absdir:" ;; + esac esac fi @@ -8162,7 +8435,9 @@ func_mode_link () *) case "$compile_rpath " in *" $absdir "*) ;; - *) func_append compile_rpath " $absdir" ;; + *) case $absdir in + "$progdir/"*) func_append compile_rpath " $absdir" ;; + esac esac ;; esac @@ -8193,8 +8468,8 @@ func_mode_link () fi if test -n "$library_names" && { test no = "$use_static_libs" || test -z "$old_library"; }; then - case $host in - *cygwin* | *mingw* | *cegcc* | *os2*) + case $host_os in + cygwin* | mingw* | windows* | cegcc* | os2*) # No point in relinking DLLs because paths are not encoded func_append notinst_deplibs " $lib" need_relink=no @@ -8220,11 +8495,11 @@ func_mode_link () if test -z "$dlopenmodule" && test yes = "$shouldnotlink" && test link = "$pass"; then echo if test prog = "$linkmode"; then - $ECHO "*** Warning: Linking the executable $output against the loadable module" + func_warning "Linking the executable $output against the loadable module" else - $ECHO "*** Warning: Linking the shared library $output against the loadable module" + func_warning "Linking the shared library $output against the loadable module" fi - $ECHO "*** $linklib is not portable!" + func_warning "$linklib is not portable!" fi if test lib = "$linkmode" && test yes = "$hardcode_into_libs"; then @@ -8236,7 +8511,9 @@ func_mode_link () *) case "$compile_rpath " in *" $absdir "*) ;; - *) func_append compile_rpath " $absdir" ;; + *) case $absdir in + "$progdir/"*) func_append compile_rpath " $absdir" ;; + esac esac ;; esac @@ -8263,8 +8540,8 @@ func_mode_link () soname=$dlname elif test -n "$soname_spec"; then # bleh windows - case $host in - *cygwin* | mingw* | *cegcc* | *os2*) + case $host_os in + cygwin* | mingw* | windows* | cegcc* | os2*) func_arith $current - $age major=$func_arith_result versuffix=-$major @@ -8319,11 +8596,10 @@ func_mode_link () if /usr/bin/file -L $add 2> /dev/null | $GREP ": [^:]* bundle" >/dev/null; then if test "X$dlopenmodule" != "X$lib"; then - $ECHO "*** Warning: lib $linklib is a module, not a shared library" + func_warning "lib $linklib is a module, not a shared library" if test -z "$old_library"; then - echo - echo "*** And there doesn't seem to be a static archive available" - echo "*** The link will probably fail, sorry" + func_warning "And there doesn't seem to be a static archive available" + func_warning "The link will probably fail, sorry" else add=$dir/$old_library fi @@ -8406,7 +8682,7 @@ func_mode_link () test no = "$hardcode_direct_absolute"; then add=$libdir/$linklib elif test yes = "$hardcode_minus_L"; then - add_dir=-L$libdir + add_dir=-L$lt_sysroot$libdir add=-l$name elif test yes = "$hardcode_shlibpath_var"; then case :$finalize_shlibpath: in @@ -8423,7 +8699,7 @@ func_mode_link () fi else # We cannot seem to hardcode it, guess we'll fake it. - add_dir=-L$libdir + add_dir=-L$lt_sysroot$libdir # Try looking first in the location we're being installed to. if test -n "$inst_prefix_dir"; then case $libdir in @@ -8463,21 +8739,19 @@ func_mode_link () # Just print a warning and add the library to dependency_libs so # that the program can be linked against the static library. - echo - $ECHO "*** Warning: This system cannot link to static lib archive $lib." - echo "*** I have the capability to make that library automatically link in when" - echo "*** you link to this library. But I can only do this if you have a" - echo "*** shared version of the library, which you do not appear to have." + func_warning "This system cannot link to static lib archive $lib." + func_warning "I have the capability to make that library automatically link in when" + func_warning "you link to this library. But I can only do this if you have a" + func_warning "shared version of the library, which you do not appear to have." if test yes = "$module"; then - echo "*** But as you try to build a module library, libtool will still create " - echo "*** a static module, that should work as long as the dlopening application" - echo "*** is linked with the -dlopen flag to resolve symbols at runtime." + func_warning "But as you try to build a module library, libtool will still create " + func_warning "a static module, that should work as long as the dlopening application" + func_warning "is linked with the -dlopen flag to resolve symbols at runtime." if test -z "$global_symbol_pipe"; then - echo - echo "*** However, this would only work if libtool was able to extract symbol" - echo "*** lists from a program, using 'nm' or equivalent, but libtool could" - echo "*** not find such a program. So, this module is probably useless." - echo "*** 'nm' from GNU binutils and a full rebuild may help." + func_warning "However, this would only work if libtool was able to extract symbol" + func_warning "lists from a program, using 'nm' or equivalent, but libtool could" + func_warning "not find such a program. So, this module is probably useless." + func_warning "'nm' from GNU binutils and a full rebuild may help." fi if test no = "$build_old_libs"; then build_libtool_libs=module @@ -8600,6 +8874,8 @@ func_mode_link () fi # link_all_deplibs != no fi # linkmode = lib done # for deplib in $libs + + func_append temp_rpath "$temp_rpath_tail" if test link = "$pass"; then if test prog = "$linkmode"; then compile_deplibs="$new_inherited_linker_flags $compile_deplibs" @@ -8637,42 +8913,46 @@ func_mode_link () # Add libraries to $var in reverse order eval tmp_libs=\"\$$var\" new_libs= + # FIXME: Pedantically, this is the right thing to do, so + # that some nasty dependency loop isn't accidentally + # broken: new_libs="$deplib $new_libs" for deplib in $tmp_libs; do - # FIXME: Pedantically, this is the right thing to do, so - # that some nasty dependency loop isn't accidentally - # broken: - #new_libs="$deplib $new_libs" - # Pragmatically, this seems to cause very few problems in - # practice: - case $deplib in - -L*) new_libs="$deplib $new_libs" ;; - -R*) ;; - *) - # And here is the reason: when a library appears more - # than once as an explicit dependence of a library, or - # is implicitly linked in more than once by the - # compiler, it is considered special, and multiple - # occurrences thereof are not removed. Compare this - # with having the same library being listed as a - # dependency of multiple other libraries: in this case, - # we know (pedantically, we assume) the library does not - # need to be listed more than once, so we keep only the - # last copy. This is not always right, but it is rare - # enough that we require users that really mean to play - # such unportable linking tricks to link the library - # using -Wl,-lname, so that libtool does not consider it - # for duplicate removal. - case " $specialdeplibs " in - *" $deplib "*) new_libs="$deplib $new_libs" ;; + if $opt_preserve_dup_deps; then + new_libs="$deplib $new_libs" + else + # Pragmatically, this seems to cause very few problems in + # practice: + case $deplib in + -L*) new_libs="$deplib $new_libs" ;; + -R*) ;; *) - case " $new_libs " in - *" $deplib "*) ;; - *) new_libs="$deplib $new_libs" ;; - esac - ;; + # And here is the reason: when a library appears more + # than once as an explicit dependence of a library, or + # is implicitly linked in more than once by the + # compiler, it is considered special, and multiple + # occurrences thereof are not removed. Compare this + # with having the same library being listed as a + # dependency of multiple other libraries: in this case, + # we know (pedantically, we assume) the library does not + # need to be listed more than once, so we keep only the + # last copy. This is not always right, but it is rare + # enough that we require users that really mean to play + # such unportable linking tricks to link the library + # using -Wl,-lname, so that libtool does not consider it + # for duplicate removal. And if not possible for portability + # reasons, then --preserve-dup-deps should be used. + case " $specialdeplibs " in + *" $deplib "*) new_libs="$deplib $new_libs" ;; + *) + case " $new_libs " in + *" $deplib "*) ;; + *) new_libs="$deplib $new_libs" ;; + esac + ;; + esac + ;; esac - ;; - esac + fi done tmp_libs= for deplib in $new_libs; do @@ -8694,7 +8974,7 @@ func_mode_link () test CXX = "$tagname" && { case $host_os in linux*) - case `$CC -V 2>&1 | sed 5q` in + case `$CC -V 2>&1 | $SED 5q` in *Sun\ C*) # Sun C++ 5.9 func_suncc_cstd_abi @@ -8804,9 +9084,7 @@ func_mode_link () if test pass_all != "$deplibs_check_method"; then func_fatal_error "cannot build libtool library '$output' from non-libtool objects on this host:$objs" else - echo - $ECHO "*** Warning: Linking the shared library $output against the non-libtool" - $ECHO "*** objects $objs is not portable!" + func_warning "Linking the shared library $output against the non-libtool objects $objs is not portable!" func_append libobjs " $objs" fi fi @@ -8867,13 +9145,13 @@ func_mode_link () # case $version_type in # correct linux to gnu/linux during the next big refactor - darwin|freebsd-elf|linux|osf|windows|none) + darwin|freebsd-elf|linux|midnightbsd-elf|osf|qnx|windows|none) func_arith $number_major + $number_minor current=$func_arith_result age=$number_minor revision=$number_revision ;; - freebsd-aout|qnx|sunos) + freebsd-aout|sco|sunos) current=$number_major revision=$number_minor age=0 @@ -8958,7 +9236,7 @@ func_mode_link () versuffix=.$current.$revision ;; - freebsd-elf) + freebsd-elf | midnightbsd-elf) func_arith $current - $age major=.$func_arith_result versuffix=$major.$age.$revision @@ -9020,8 +9298,9 @@ func_mode_link () ;; qnx) - major=.$current - versuffix=.$current + func_arith $current - $age + major=.$func_arith_result + versuffix=$major.$age.$revision ;; sco) @@ -9174,7 +9453,7 @@ func_mode_link () if test yes = "$build_libtool_libs"; then if test -n "$rpath"; then case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*) + *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*) # these systems don't actually have a c library (as such)! ;; *-*-rhapsody* | *-*-darwin1.[012]) @@ -9184,7 +9463,7 @@ func_mode_link () *-*-netbsd*) # Don't link with libc until the a.out ld.so is fixed. ;; - *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*) + *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-midnightbsd*) # Do not include libc due to us having libc/libc_r. ;; *-*-sco3.2v5* | *-*-sco5v6*) @@ -9225,108 +9504,6 @@ func_mode_link () # implementing what was already the behavior. newdeplibs=$deplibs ;; - test_compile) - # This code stresses the "libraries are programs" paradigm to its - # limits. Maybe even breaks it. We compile a program, linking it - # against the deplibs as a proxy for the library. Then we can check - # whether they linked in statically or dynamically with ldd. - $opt_dry_run || $RM conftest.c - cat > conftest.c <<EOF - int main() { return 0; } -EOF - $opt_dry_run || $RM conftest - if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then - ldd_output=`ldd conftest` - for i in $deplibs; do - case $i in - -l*) - func_stripname -l '' "$i" - name=$func_stripname_result - if test yes = "$allow_libtool_libs_with_static_runtimes"; then - case " $predeps $postdeps " in - *" $i "*) - func_append newdeplibs " $i" - i= - ;; - esac - fi - if test -n "$i"; then - libname=`eval "\\$ECHO \"$libname_spec\""` - deplib_matches=`eval "\\$ECHO \"$library_names_spec\""` - set dummy $deplib_matches; shift - deplib_match=$1 - if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then - func_append newdeplibs " $i" - else - droppeddeps=yes - echo - $ECHO "*** Warning: dynamic linker does not accept needed library $i." - echo "*** I have the capability to make that library automatically link in when" - echo "*** you link to this library. But I can only do this if you have a" - echo "*** shared version of the library, which I believe you do not have" - echo "*** because a test_compile did reveal that the linker did not use it for" - echo "*** its dynamic dependency list that programs get resolved with at runtime." - fi - fi - ;; - *) - func_append newdeplibs " $i" - ;; - esac - done - else - # Error occurred in the first compile. Let's try to salvage - # the situation: Compile a separate program for each library. - for i in $deplibs; do - case $i in - -l*) - func_stripname -l '' "$i" - name=$func_stripname_result - $opt_dry_run || $RM conftest - if $LTCC $LTCFLAGS -o conftest conftest.c $i; then - ldd_output=`ldd conftest` - if test yes = "$allow_libtool_libs_with_static_runtimes"; then - case " $predeps $postdeps " in - *" $i "*) - func_append newdeplibs " $i" - i= - ;; - esac - fi - if test -n "$i"; then - libname=`eval "\\$ECHO \"$libname_spec\""` - deplib_matches=`eval "\\$ECHO \"$library_names_spec\""` - set dummy $deplib_matches; shift - deplib_match=$1 - if test `expr "$ldd_output" : ".*$deplib_match"` -ne 0; then - func_append newdeplibs " $i" - else - droppeddeps=yes - echo - $ECHO "*** Warning: dynamic linker does not accept needed library $i." - echo "*** I have the capability to make that library automatically link in when" - echo "*** you link to this library. But I can only do this if you have a" - echo "*** shared version of the library, which you do not appear to have" - echo "*** because a test_compile did reveal that the linker did not use this one" - echo "*** as a dynamic dependency that programs can get resolved with at runtime." - fi - fi - else - droppeddeps=yes - echo - $ECHO "*** Warning! Library $i is needed by this library but I was not able to" - echo "*** make it link in! You will probably need to install it or some" - echo "*** library that it depends on before this library will be fully" - echo "*** functional. Installing it before continuing would be even better." - fi - ;; - *) - func_append newdeplibs " $i" - ;; - esac - done - fi - ;; file_magic*) set dummy $deplibs_check_method; shift file_magic_regex=`expr "$deplibs_check_method" : "$1 \(.*\)"` @@ -9390,17 +9567,16 @@ EOF fi if test -n "$a_deplib"; then droppeddeps=yes - echo - $ECHO "*** Warning: linker path does not have real file for library $a_deplib." - echo "*** I have the capability to make that library automatically link in when" - echo "*** you link to this library. But I can only do this if you have a" - echo "*** shared version of the library, which you do not appear to have" - echo "*** because I did check the linker path looking for a file starting" + func_warning "Linker path does not have real file for library $a_deplib." + func_warning "I have the capability to make that library automatically link in when" + func_warning "you link to this library. But I can only do this if you have a" + func_warning "shared version of the library, which you do not appear to have" + func_warning "because I did check the linker path looking for a file starting" if test -z "$potlib"; then - $ECHO "*** with $libname but no candidates were found. (...for file magic test)" + func_warning "with $libname but no candidates were found. (...for file magic test)" else - $ECHO "*** with $libname and none of the candidates passed a file format test" - $ECHO "*** using a file magic. Last file checked: $potlib" + func_warning "with $libname and none of the candidates passed a file format test" + func_warning "using a file magic. Last file checked: $potlib" fi fi ;; @@ -9444,17 +9620,16 @@ EOF fi if test -n "$a_deplib"; then droppeddeps=yes - echo - $ECHO "*** Warning: linker path does not have real file for library $a_deplib." - echo "*** I have the capability to make that library automatically link in when" - echo "*** you link to this library. But I can only do this if you have a" - echo "*** shared version of the library, which you do not appear to have" - echo "*** because I did check the linker path looking for a file starting" + func_warning "Linker path does not have real file for library $a_deplib." + func_warning "I have the capability to make that library automatically link in when" + func_warning "you link to this library. But I can only do this if you have a" + func_warning "shared version of the library, which you do not appear to have" + func_warning "because I did check the linker path looking for a file starting" if test -z "$potlib"; then - $ECHO "*** with $libname but no candidates were found. (...for regex pattern test)" + func_warning "with $libname but no candidates were found. (...for regex pattern test)" else - $ECHO "*** with $libname and none of the candidates passed a file format test" - $ECHO "*** using a regex pattern. Last file checked: $potlib" + func_warning "with $libname and none of the candidates passed a file format test" + func_warning "using a regex pattern. Last file checked: $potlib" fi fi ;; @@ -9478,11 +9653,11 @@ EOF *[!\ \ ]*) echo if test none = "$deplibs_check_method"; then - echo "*** Warning: inter-library dependencies are not supported in this platform." + func_warning "Inter-library dependencies are not supported in this platform." else - echo "*** Warning: inter-library dependencies are not known to be supported." + func_warning "Inter-library dependencies are not known to be supported." fi - echo "*** All declared inter-library dependencies are being dropped." + func_warning "All declared inter-library dependencies are being dropped." droppeddeps=yes ;; esac @@ -9503,17 +9678,15 @@ EOF if test yes = "$droppeddeps"; then if test yes = "$module"; then - echo - echo "*** Warning: libtool could not satisfy all declared inter-library" - $ECHO "*** dependencies of module $libname. Therefore, libtool will create" - echo "*** a static module, that should work as long as the dlopening" - echo "*** application is linked with the -dlopen flag." + func_warning "libtool could not satisfy all declared inter-library" + func_warning "dependencies of module $libname. Therefore, libtool will create" + func_warning "a static module, that should work as long as the dlopening" + func_warning "application is linked with the -dlopen flag." if test -z "$global_symbol_pipe"; then - echo - echo "*** However, this would only work if libtool was able to extract symbol" - echo "*** lists from a program, using 'nm' or equivalent, but libtool could" - echo "*** not find such a program. So, this module is probably useless." - echo "*** 'nm' from GNU binutils and a full rebuild may help." + func_warning "However, this would only work if libtool was able to extract symbol" + func_warning "lists from a program, using 'nm' or equivalent, but libtool could" + func_warning "not find such a program. So, this module is probably useless." + func_warning "'nm' from GNU binutils and a full rebuild may help." fi if test no = "$build_old_libs"; then oldlibs=$output_objdir/$libname.$libext @@ -9688,7 +9861,7 @@ EOF orig_export_symbols= case $host_os in - cygwin* | mingw* | cegcc*) + cygwin* | mingw* | windows* | cegcc*) if test -n "$export_symbols" && test -z "$export_symbols_regex"; then # exporting using user supplied symfile func_dll_def_p "$export_symbols" || { @@ -9995,8 +10168,8 @@ EOF for cmd in $concat_cmds; do IFS=$save_ifs $opt_quiet || { - func_quote_for_expand "$cmd" - eval "func_echo $func_quote_for_expand_result" + func_quote_arg expand,pretty "$cmd" + eval "func_echo $func_quote_arg_result" } $opt_dry_run || eval "$cmd" || { lt_exit=$? @@ -10089,8 +10262,8 @@ EOF eval cmd=\"$cmd\" IFS=$save_ifs $opt_quiet || { - func_quote_for_expand "$cmd" - eval "func_echo $func_quote_for_expand_result" + func_quote_arg expand,pretty "$cmd" + eval "func_echo $func_quote_arg_result" } $opt_dry_run || eval "$cmd" || { lt_exit=$? @@ -10358,7 +10531,7 @@ EOF esac fi case $host in - *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*) + *-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-os2* | *-cegcc*) testbindir=`$ECHO "$libdir" | $SED -e 's*/lib$*/bin*'` case :$dllsearchpath: in *":$libdir:"*) ;; @@ -10436,7 +10609,7 @@ EOF # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway. wrappers_required=false ;; - *cygwin* | *mingw* ) + *cygwin* | *mingw* | *windows* ) test yes = "$build_libtool_libs" || wrappers_required=false ;; *) @@ -10564,12 +10737,13 @@ EOF elif eval var_value=\$$var; test -z "$var_value"; then relink_command="$var=; export $var; $relink_command" else - func_quote_for_eval "$var_value" - relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command" + func_quote_arg pretty "$var_value" + relink_command="$var=$func_quote_arg_result; export $var; $relink_command" fi done - func_quote "(cd `pwd`; $relink_command)" - relink_command=$func_quote_result + func_quote eval cd "`pwd`" + func_quote_arg pretty,unquoted "($func_quote_result; $relink_command)" + relink_command=$func_quote_arg_unquoted_result fi # Only actually do things if not in dry run mode. @@ -10589,7 +10763,7 @@ EOF *) exeext= ;; esac case $host in - *cygwin* | *mingw* ) + *cygwin* | *mingw* | windows* ) func_dirname_and_basename "$output" "" "." output_name=$func_basename_result output_path=$func_dirname_result @@ -10809,14 +10983,15 @@ EOF elif eval var_value=\$$var; test -z "$var_value"; then relink_command="$var=; export $var; $relink_command" else - func_quote_for_eval "$var_value" - relink_command="$var=$func_quote_for_eval_result; export $var; $relink_command" + func_quote_arg pretty,unquoted "$var_value" + relink_command="$var=$func_quote_arg_unquoted_result; export $var; $relink_command" fi done # Quote the link command for shipping. - relink_command="(cd `pwd`; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)" - func_quote "$relink_command" - relink_command=$func_quote_result + func_quote eval cd "`pwd`" + relink_command="($func_quote_result; $SHELL \"$progpath\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)" + func_quote_arg pretty,unquoted "$relink_command" + relink_command=$func_quote_arg_unquoted_result if test yes = "$hardcode_automatic"; then relink_command= fi @@ -10922,7 +11097,7 @@ EOF # tests/bindir.at for full details. tdlname=$dlname case $host,$output,$installed,$module,$dlname in - *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll) + *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *windows*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll) # If a -bindir argument was supplied, place the dll there. if test -n "$bindir"; then func_relative_path "$install_libdir" "$bindir" diff --git a/3rdparty/expat/conftools/missing b/3rdparty/expat/conftools/missing index 8d0eaad250f..1fe1611f185 100755 --- a/3rdparty/expat/conftools/missing +++ b/3rdparty/expat/conftools/missing @@ -3,7 +3,7 @@ scriptversion=2018-03-07.03; # UTC -# Copyright (C) 1996-2020 Free Software Foundation, Inc. +# Copyright (C) 1996-2021 Free Software Foundation, Inc. # Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996. # This program is free software; you can redistribute it and/or modify diff --git a/3rdparty/expat/conftools/test-driver b/3rdparty/expat/conftools/test-driver index 89dba1e075c..be73b80adf9 100755 --- a/3rdparty/expat/conftools/test-driver +++ b/3rdparty/expat/conftools/test-driver @@ -3,7 +3,7 @@ scriptversion=2018-03-07.03; # UTC -# Copyright (C) 2011-2020 Free Software Foundation, Inc. +# Copyright (C) 2011-2021 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -42,11 +42,13 @@ print_usage () { cat <<END Usage: - test-driver --test-name=NAME --log-file=PATH --trs-file=PATH - [--expect-failure={yes|no}] [--color-tests={yes|no}] - [--enable-hard-errors={yes|no}] [--] + test-driver --test-name NAME --log-file PATH --trs-file PATH + [--expect-failure {yes|no}] [--color-tests {yes|no}] + [--enable-hard-errors {yes|no}] [--] TEST-SCRIPT [TEST-SCRIPT-ARGUMENTS] + The '--test-name', '--log-file' and '--trs-file' options are mandatory. +See the GNU Automake documentation for information. END } @@ -103,8 +105,11 @@ trap "st=130; $do_exit" 2 trap "st=141; $do_exit" 13 trap "st=143; $do_exit" 15 -# Test script is run here. -"$@" >$log_file 2>&1 +# Test script is run here. We create the file first, then append to it, +# to ameliorate tests themselves also writing to the log file. Our tests +# don't, but others can (automake bug#35762). +: >"$log_file" +"$@" >>"$log_file" 2>&1 estatus=$? if test $enable_hard_errors = no && test $estatus -eq 99; then @@ -126,7 +131,7 @@ esac # know whether the test passed or failed simply by looking at the '.log' # file, without the need of also peaking into the corresponding '.trs' # file (automake bug#11814). -echo "$res $test_name (exit status: $estatus)" >>$log_file +echo "$res $test_name (exit status: $estatus)" >>"$log_file" # Report outcome to console. echo "${col}${res}${std}: $test_name" diff --git a/3rdparty/expat/doc/Makefile.am b/3rdparty/expat/doc/Makefile.am index e2f029837a4..3bea96e9aa6 100644 --- a/3rdparty/expat/doc/Makefile.am +++ b/3rdparty/expat/doc/Makefile.am @@ -6,7 +6,10 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2017 Expat development team +# Copyright (c) 2017-2024 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2017 Stephen Groat <stephen@groat.us> +# Copyright (c) 2017 Joe Orton <jorton@redhat.com> +# Copyright (c) 2024 Tomas Korbar <tkorbar@redhat.com> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -30,30 +33,27 @@ .PHONY: dist-hook # not inside conditional to avoid automake warning -if WITH_DOCBOOK +if WITH_MANPAGE dist_man_MANS = xmlwf.1 xmlwf.1: xmlwf.xml -rm -f $@ - $(DOCBOOK_TO_MAN) $< + test "x$(DOCBOOK_TO_MAN)" != x && $(DOCBOOK_TO_MAN) $< test -f $@ || mv XMLWF.1 $@ -else +endif + +if !WITH_DISTRIBUTABLE_MANPAGE dist-hook: @echo 'ERROR: Configure with --with-docbook for "make dist".' 1>&2 @false endif -# https://www.gnu.org/software/automake/manual/automake.html#What-Gets-Cleaned -.PHONY: clean-local -clean-local: clean-local-check - -.PHONY: clean-local-check -clean-local-check: - $(RM) xmlwf.1 +if !WITH_PREBUILT_MANPAGE +CLEANFILES = xmlwf.1 +endif EXTRA_DIST = \ - expat.png \ + ok.min.css \ reference.html \ style.css \ - valid-xhtml10.png \ xmlwf.xml diff --git a/3rdparty/expat/doc/Makefile.in b/3rdparty/expat/doc/Makefile.in index 94550becf39..72deb0565d9 100644 --- a/3rdparty/expat/doc/Makefile.in +++ b/3rdparty/expat/doc/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2020 Free Software Foundation, Inc. +# Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -22,7 +22,10 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2017 Expat development team +# Copyright (c) 2017-2024 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2017 Stephen Groat <stephen@groat.us> +# Copyright (c) 2017 Joe Orton <jorton@redhat.com> +# Copyright (c) 2024 Tomas Korbar <tkorbar@redhat.com> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -130,6 +133,8 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/conftools/ax-append-compile-flags.m4 \ $(top_srcdir)/conftools/ax-append-link-flags.m4 \ $(top_srcdir)/conftools/expatcfg-compiler-supports-visibility.m4 \ + $(top_srcdir)/conftools/ax-cxx-compile-stdcxx.m4 \ + $(top_srcdir)/conftools/ax-cxx-compile-stdcxx-11.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) @@ -207,8 +212,10 @@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ -CPP = @CPP@ +CMAKE_SHARED_LIBRARY_PREFIX = @CMAKE_SHARED_LIBRARY_PREFIX@ CPPFLAGS = @CPPFLAGS@ +CSCOPE = @CSCOPE@ +CTAGS = @CTAGS@ CXX = @CXX@ CXXCPP = @CXXCPP@ CXXDEPMODE = @CXXDEPMODE@ @@ -224,10 +231,20 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ +ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ +EXPAT_ATTR_INFO = @EXPAT_ATTR_INFO@ +EXPAT_CHAR_TYPE = @EXPAT_CHAR_TYPE@ +EXPAT_CONTEXT_BYTES = @EXPAT_CONTEXT_BYTES@ +EXPAT_DTD = @EXPAT_DTD@ +EXPAT_LARGE_SIZE = @EXPAT_LARGE_SIZE@ +EXPAT_MIN_SIZE = @EXPAT_MIN_SIZE@ +EXPAT_NS = @EXPAT_NS@ FGREP = @FGREP@ +FILECMD = @FILECMD@ FILEMAP = @FILEMAP@ GREP = @GREP@ +HAVE_CXX11 = @HAVE_CXX11@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -237,6 +254,8 @@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBAGE = @LIBAGE@ LIBCURRENT = @LIBCURRENT@ +LIBDIR_BASENAME = @LIBDIR_BASENAME@ +LIBM = @LIBM@ LIBOBJS = @LIBOBJS@ LIBREVISION = @LIBREVISION@ LIBS = @LIBS@ @@ -245,6 +264,7 @@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ @@ -266,9 +286,12 @@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SIZEOF_VOID_P = @SIZEOF_VOID_P@ +SO_MAJOR = @SO_MAJOR@ +SO_MINOR = @SO_MINOR@ +SO_PATCH = @SO_PATCH@ STRIP = @STRIP@ VERSION = @VERSION@ -_EXPAT_OUTPUT_NAME = @_EXPAT_OUTPUT_NAME@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ @@ -323,18 +346,18 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -@WITH_DOCBOOK_TRUE@dist_man_MANS = xmlwf.1 +@WITH_MANPAGE_TRUE@dist_man_MANS = xmlwf.1 +@WITH_PREBUILT_MANPAGE_FALSE@CLEANFILES = xmlwf.1 EXTRA_DIST = \ - expat.png \ + ok.min.css \ reference.html \ style.css \ - valid-xhtml10.png \ xmlwf.xml all: all-am .SUFFIXES: -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ @@ -358,9 +381,9 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(top_srcdir)/configure: $(am__configure_deps) +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): $(am__aclocal_m4_deps) +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): @@ -418,8 +441,7 @@ ctags CTAGS: cscope cscopelist: -@WITH_DOCBOOK_TRUE@dist-hook: - +@WITH_DISTRIBUTABLE_MANPAGE_TRUE@dist-hook: distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am @@ -485,6 +507,7 @@ install-strip: mostlyclean-generic: clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) @@ -495,7 +518,7 @@ maintainer-clean-generic: @echo "it deletes files that may require special tools to rebuild." clean: clean-am -clean-am: clean-generic clean-libtool clean-local mostlyclean-am +clean-am: clean-generic clean-libtool mostlyclean-am distclean: distclean-am -rm -f Makefile @@ -564,38 +587,31 @@ uninstall-man: uninstall-man1 .MAKE: install-am install-strip .PHONY: all all-am check check-am clean clean-generic clean-libtool \ - clean-local cscopelist-am ctags-am dist-hook distclean \ - distclean-generic distclean-libtool distdir dvi dvi-am html \ - html-am info info-am install install-am install-data \ - install-data-am install-dvi install-dvi-am install-exec \ - install-exec-am install-html install-html-am install-info \ - install-info-am install-man install-man1 install-pdf \ - install-pdf-am install-ps install-ps-am install-strip \ - installcheck installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-generic \ - mostlyclean-libtool pdf pdf-am ps ps-am tags-am uninstall \ - uninstall-am uninstall-man uninstall-man1 + cscopelist-am ctags-am dist-hook distclean distclean-generic \ + distclean-libtool distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am install-man \ + install-man1 install-pdf install-pdf-am install-ps \ + install-ps-am install-strip installcheck installcheck-am \ + installdirs maintainer-clean maintainer-clean-generic \ + mostlyclean mostlyclean-generic mostlyclean-libtool pdf pdf-am \ + ps ps-am tags-am uninstall uninstall-am uninstall-man \ + uninstall-man1 .PRECIOUS: Makefile .PHONY: dist-hook # not inside conditional to avoid automake warning -@WITH_DOCBOOK_TRUE@xmlwf.1: xmlwf.xml -@WITH_DOCBOOK_TRUE@ -rm -f $@ -@WITH_DOCBOOK_TRUE@ $(DOCBOOK_TO_MAN) $< -@WITH_DOCBOOK_TRUE@ test -f $@ || mv XMLWF.1 $@ -@WITH_DOCBOOK_FALSE@dist-hook: -@WITH_DOCBOOK_FALSE@ @echo 'ERROR: Configure with --with-docbook for "make dist".' 1>&2 -@WITH_DOCBOOK_FALSE@ @false - -# https://www.gnu.org/software/automake/manual/automake.html#What-Gets-Cleaned -.PHONY: clean-local -clean-local: clean-local-check - -.PHONY: clean-local-check -clean-local-check: - $(RM) xmlwf.1 +@WITH_MANPAGE_TRUE@xmlwf.1: xmlwf.xml +@WITH_MANPAGE_TRUE@ -rm -f $@ +@WITH_MANPAGE_TRUE@ test "x$(DOCBOOK_TO_MAN)" != x && $(DOCBOOK_TO_MAN) $< +@WITH_MANPAGE_TRUE@ test -f $@ || mv XMLWF.1 $@ + +@WITH_DISTRIBUTABLE_MANPAGE_FALSE@dist-hook: +@WITH_DISTRIBUTABLE_MANPAGE_FALSE@ @echo 'ERROR: Configure with --with-docbook for "make dist".' 1>&2 +@WITH_DISTRIBUTABLE_MANPAGE_FALSE@ @false # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/3rdparty/expat/doc/expat.png b/3rdparty/expat/doc/expat.png Binary files differdeleted file mode 100644 index 7d7c3dbaebc..00000000000 --- a/3rdparty/expat/doc/expat.png +++ /dev/null diff --git a/3rdparty/expat/doc/ok.min.css b/3rdparty/expat/doc/ok.min.css new file mode 100644 index 00000000000..d324fabb287 --- /dev/null +++ b/3rdparty/expat/doc/ok.min.css @@ -0,0 +1,2 @@ +/*! OK.css v1.2.0 | MIT License | github.com/andrewh0/okcss */@import url("https://rsms.me/inter/inter.css"); +/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */html{line-height:1.15}body{margin:0}main{display:block}h1{font-size:2em;margin:.67em 0}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;-webkit-text-decoration:underline dotted;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}img{border-style:none}button,input,optgroup,select,textarea{font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:.35em .75em .625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details{display:block}summary{display:list-item}[hidden],template{display:none}:root{--ok-sans:"Inter",system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen,Ubuntu,Cantarell,"Open Sans","Helvetica Neue","Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--ok-mono:SFMono-Regular,Menlo,Monaco,Consolas,"Ubuntu Mono","Liberation Mono","Courier New",Courier,monospace;--ok-fw-0:400;--ok-fw-1:600;--ok-fw-2:700;--ok-fw-3:700;--ok-fs-0:2.5rem;--ok-fs-1:2rem;--ok-fs-2:1.5rem;--ok-fs-3:1.25rem;--ok-fs-4:1rem;--ok-fs-5:0.75rem;--ok-br:0.25rem;--ok-s-0:0;--ok-s-1:0.25rem;--ok-s-2:0.5rem;--ok-s-3:1rem;--ok-s-4:1.5rem;--ok-s-5:2rem;--ok-s-6:2.5rem;--ok-lh-body:1.5;--ok-lh-heading:1.25;--ok-t-hl:#ffcf30;--ok-accent-0:#3e67fa;--ok-accent-1:#4788ff;--ok-tc-accent:#3173de;--ok-tc-code:#c23a30;--ok-tc-0:#000;--ok-tc-1:#747474;--ok-tc-2:#848484;--ok-bg-0:#fff;--ok-bg-1:#f0f0f0;--ok-bg-2:#ccc;--ok-b-0:1px solid #cbcbcb;--ok-b-1:1px solid #848484;--ok-down-0:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' height='8' viewBox='0 0 12 8' width='24' fill='none'%3E%3Cpath d='M6 6l4-4h1v1-1L6 7 1 2h1l4 4z' fill='%23747474'/%3E%3C/svg%3E");--ok-down-1:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' height='8' viewBox='0 0 12 8' width='24' fill='none'%3E%3Cpath d='M6 6l4-4h1v1-1L6 7 1 2h1l4 4z' fill='%23848484'/%3E%3C/svg%3E")}@media (prefers-color-scheme:dark){:root{--ok-tc-accent:#5c9aff;--ok-tc-code:#ed5853;--ok-tc-0:#fff;--ok-tc-1:#ababab;--ok-tc-2:#929292;--ok-bg-0:#000;--ok-bg-1:#212121;--ok-bg-2:#3e3e3e;--ok-b-0:1px solid #747474;--ok-b-1:1px solid #929292;--ok-down-0:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' height='8' viewBox='0 0 12 8' width='24' fill='none'%3E%3Cpath d='M6 6l4-4h1v1-1L6 7 1 2h1l4 4z' fill='%23ababab'/%3E%3C/svg%3E");--ok-down-1:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' height='8' viewBox='0 0 12 8' width='24' fill='none'%3E%3Cpath d='M6 6l4-4h1v1-1L6 7 1 2h1l4 4z' fill='%23929292'/%3E%3C/svg%3E")}}*,:after,:before{box-sizing:border-box}*{margin:0;padding:0}html{font-family:var(--ok-sans);line-sizing:normal;line-height:var(--ok-lh-body);font-weight:var(--ok-fw-0);color:var(--ok-tc-0);background-color:var(--ok-bg-0);-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;-webkit-text-size-adjust:100%;-moz-text-size-adjust:100%;-ms-text-size-adjust:100%;text-size-adjust:100%;text-rendering:optimizeLegibility;scroll-behavior:smooth}@supports (font-variation-settings:normal){html{font-family:Inter var,var(--ok-sans)}}button,input,optgroup,select,textarea{font-family:inherit;line-height:var(--ok-lh-body)}[role=button],button{cursor:pointer}audio,canvas,embed,iframe,img,input,object,select,svg,textarea,video{display:block}img,video{max-width:100%;height:auto}body{padding:var(--ok-s-3);max-width:80ch;margin:auto}article{padding-bottom:var(--ok-s-6)}h1{font-size:var(--ok-fs-0);margin:0}h2{font-size:var(--ok-fs-1)}h3{font-size:var(--ok-fs-2)}h4{font-size:var(--ok-fs-3)}h5{font-size:var(--ok-fs-4)}h6{font-size:var(--ok-fs-5);text-transform:uppercase;font-weight:var(--ok-fw-1)}h1,h2,h3,h4,h5,h6{line-height:var(--ok-lh-heading);font-weight:var(--ok-fw-3);margin-top:var(--ok-s-6);margin-bottom:var(--ok-s-3)}h1+*,h2+*,h3+*,h4+*,h5+*,h6+*,hr+*{margin-top:0}p{font-size:var(--ok-fs-4)}small{font-size:var(--ok-fs-5)}b,dt,strong{font-weight:var(--ok-fw-2)}address,article,aside,audio,blockquote,button,canvas,dd,details,dialog,div,dl,embed,fieldset,figcaption,figure,footer,form,header,hgroup,hr,iframe,img,input,main,nav,object,ol,p,pre,section,select,summary,svg,table,textarea,ul,video{margin-bottom:var(--ok-s-4)}address:last-child,article:last-child,aside:last-child,blockquote:last-child,dd:last-child,details:last-child,dialog:last-child,div:last-child,dl:last-child,dt:last-child,fieldset:last-child,figcaption:last-child,figure:last-child,footer:last-child,form:last-child,h1:last-child,h2:last-child,h3:last-child,h4:last-child,h5:last-child,h6:last-child,header:last-child,hgroup:last-child,hr:last-child,input[type=checkbox],input[type=radio],main:last-child,nav:last-child,ol:last-child,p:last-child,pre:last-child,section:last-child,table:last-child,ul:last-child{margin-bottom:0}fieldset{padding:var(--ok-s-3);border:var(--ok-b-0);border-radius:var(--ok-br)}legend{font-weight:var(--ok-fw-1);text-transform:uppercase;font-size:var(--ok-fs-5)}input,select{padding:var(--ok-s-2);background:var(--ok-bg-0);border:var(--ok-b-0);border-radius:var(--ok-br);color:var(--ok-tc-0);min-width:25ch}input:disabled,select:disabled,textarea:disabled{color:var(--ok-tc-2)}input::placeholder,textarea::placeholder{color:var(--ok-tc-2)}input::-webkit-input-placeholder,textarea::-webkit-input-placeholder{color:var(--ok-tc-2)}input::-moz-placeholder,textarea::-moz-placeholder{color:var(--ok-tc-2)}input:-ms-input-placeholder,textarea:-ms-input-placeholder{color:var(--ok-tc-2)}input::-ms-input-placeholder,textarea::-ms-input-placeholder{color:var(--ok-tc-2)}input::-webkit-clear-button,input::-webkit-inner-spin-button,input::-webkit-search-cancel-button,input::-webkit-search-results-button{display:none}input::-ms-clear,input::-ms-reveal{display:none}input:disabled,textarea:disabled{background-color:var(--ok-bg-1)}input[type=search]{-webkit-appearance:none;-moz-appearance:none;appearance:none}input[type=file]{max-width:300px}input[type=number]{-moz-appearance:textfield}input[type=checkbox],input[type=radio]{display:inline;min-width:auto}input[type=color]{height:2.5rem}input[type=date],input[type=datetime-local],input[type=month],input[type=time],input[type=week]{height:2.5rem;-webkit-appearance:none;-moz-appearance:none;appearance:none;position:relative}input[type=date]:before,input[type=datetime-local]:before,input[type=month]:before,input[type=time]:before,input[type=week]:before{position:absolute;right:0;top:0;background-image:var(--ok-down-0);background-repeat:no-repeat;background-position:right .2em top 50%;background-size:2em auto;width:2.5rem;height:calc(2.5rem - 2px);content:""}input[type=date]:disabled:before,input[type=datetime-local]:disabled:before,input[type=month]:disabled:before,input[type=time]:disabled:before,input[type=week]:disabled:before{background-image:var(--ok-down-1)}input::-webkit-calendar-picker-indicator{position:absolute;top:0;right:0;background-color:transparent;cursor:pointer;padding:0;width:2.5rem;height:calc(2.5rem - 2px);content:"";opacity:0}input[type=range]{overflow:visible;line-height:inherit;font-family:inherit;-webkit-appearance:none;-moz-appearance:none;appearance:none;margin:0;outline:none;cursor:pointer;padding:0;vertical-align:middle;border:none;min-height:2rem;background-color:transparent}input[type=range]::-webkit-slider-runnable-track{cursor:pointer;-webkit-appearance:none;border-radius:var(--ok-br);border:var(--ok-b-0);background-color:var(--ok-bg-1);background-image:linear-gradient(var(--ok-bg-1),var(--ok-bg-1));width:100%;height:.5rem;color:transparent;box-sizing:border-box;position:relative}input[type=range]::-moz-range-track{cursor:pointer;-moz-appearance:none;border-radius:var(--ok-br);border:var(--ok-b-0);background-color:var(--ok-bg-1);background-image:linear-gradient(var(--ok-bg-1),var(--ok-bg-1));width:100%;height:.5rem;color:transparent;box-sizing:border-box}input[type=range]::-ms-track{cursor:pointer;-ms-appearance:none;border-radius:var(--ok-br);border:var(--ok-b-0);background-color:var(--ok-bg-1);background-image:linear-gradient(var(--ok-bg-1),var(--ok-bg-1));width:100%;height:.5rem;color:transparent;box-sizing:border-box}input[type=range]::-ms-fill-lower{background:transparent}input[type=range]::-webkit-slider-thumb{cursor:pointer;-webkit-appearance:none;border-radius:50%;background-color:var(--ok-accent-0);width:1.5rem;height:1.5rem;margin-top:calc(-.5rem - 1px)}input[type=range]::-moz-range-thumb{cursor:pointer;-moz-appearance:none;border:none;border-radius:50%;background-color:var(--ok-accent-0);width:1.5rem;height:1.5rem}input[type=range]::-ms-thumb{cursor:pointer;-ms-appearance:none;border-radius:50%;background-color:var(--ok-accent-0);width:1.5rem;height:1.5rem;transform:translateY(.25rem)}input[type=range]:focus:not(:disabled)::-webkit-slider-thumb{background-color:var(--ok-accent-1)}input[type=range]:focus:not(:disabled)::-moz-range-thumb{background-color:var(--ok-accent-1)}input[type=range]:focus:not(:disabled)::-ms-thumb{background-color:var(--ok-accent-1)}input[type=range]:disabled{cursor:default}input[type=range]:disabled::-webkit-slider-runnable-track{cursor:default}input[type=range]:disabled::-moz-range-track{cursor:default}input[type=range]:disabled::-ms-track{cursor:default}input[type=range]:disabled::-webkit-slider-thumb{background-color:var(--ok-bg-2);cursor:default}input[type=range]:disabled::-moz-range-thumb{background-color:var(--ok-bg-2);cursor:default}input[type=range]:disabled::-ms-thumb{background-color:var(--ok-bg-2);cursor:default}select{-webkit-appearance:none;-moz-appearance:none;appearance:none;border:var(--ok-b-0);border-radius:var(--ok-br);background-color:var(--ok-bg-0);min-height:2.5rem;color:var(--ok-tc-0)}select:not([multiple]){background-image:var(--ok-down-0);background-repeat:no-repeat,repeat;background-position:right .2em top 50%;background-size:2em auto;padding-right:2.5em;height:2.5rem}select::-ms-expand{display:none}select:not([multiple]):disabled{background-image:var(--ok-down-1);background-color:var(--ok-bg-1);cursor:default}select[multiple]{border-radius:var(--ok-br)}select[multiple]:disabled{background-color:var(--ok-bg-1)}select[multiple] option{color:var(--ok-t-)}select[multiple]:disabled option{color:var(--ok-tc-2)}textarea{padding:var(--ok-s-2);resize:vertical;background:var(--ok-bg-0);border:var(--ok-b-0);border-radius:var(--ok-br);color:var(--ok-tc-0);min-height:calc(2.5rem - 2px);min-width:25ch}button,input[type=button],input[type=reset],input[type=submit]{display:inline-block;background-color:var(--ok-accent-0);border-radius:var(--ok-br);color:#fff;font-weight:var(--ok-fw-1);height:2.5rem;border:none;padding:var(--ok-s-2) var(--ok-s-3);white-space:nowrap;min-width:auto}input::-webkit-file-upload-button{display:inline-block;background-color:var(--ok-accent-0);border-radius:var(--ok-br);color:#fff;font-weight:var(--ok-fw-1);height:2.5rem;border:none;padding:var(--ok-s-2) var(--ok-s-3);white-space:nowrap}input:disabled::-webkit-file-upload-button{cursor:default;opacity:.5}button,input[type=button],input[type=reset],input[type=submit]{cursor:pointer}input:not(:disabled)::-webkit-file-upload-button{cursor:pointer}button:disabled,input[type=button]:disabled,input[type=reset]:disabled,input[type=submit]:disabled{cursor:default;opacity:.5;background-color:var(--ok-accent-0)}button:focus:not(:disabled),input[type=button]:focus:not(:disabled),input[type=reset]:focus:not(:disabled),input[type=submit]:focus:not(:disabled){background-color:var(--ok-accent-1)}input:not(:disabled):focus::-webkit-file-upload-button{background-color:var(--ok-accent-1)}table{border-collapse:collapse;display:table;margin-left:auto;margin-right:auto;white-space:nowrap}tfoot,thead{border:var(--ok-b-0)}thead{position:-webkit-sticky;position:sticky;top:0}tfoot tr,thead tr{background-color:var(--ok-bg-1);font-size:var(--ok-fs-5);text-transform:uppercase;color:var(--ok-tc-0)}td,th{border:var(--ok-b-0) 0;text-align:left;padding:.5rem}td{white-space:normal;max-width:20ch}tr{border:var(--ok-b-0)}table caption{font-size:var(--ok-fs-4);font-weight:var(--ok-fw-3);padding:.5rem}code,samp{padding:.2em .4em;color:var(--ok-tc-code)}code,pre,samp{font-family:var(--ok-mono);font-size:87.5%;line-height:var(--ok-lh-body);background-color:var(--ok-bg-1);border-radius:var(--ok-br);text-transform:none}pre{padding:var(--ok-s-3);white-space:pre;overflow-x:auto}pre,var{color:var(--ok-tc-0)}var{font-family:var(--ok-mono);font-style:normal}code pre,pre code{background:inherit;font-size:inherit;color:inherit;border:0;padding:0;margin:0}code pre{display:inline}kbd{background-color:var(--ok-bg-1);border:var(--ok-b-0);border-radius:var(--ok-br);border-bottom:2px solid var(--ok-bg-2);padding:var(--ok-s-1);font-family:var(--ok-sans);color:var(--ok-tc-0)}a{text-decoration:none;font-weight:var(--ok-fw-1)}a,a:visited,a code,a mark,a samp{color:var(--ok-tc-accent)}ol,ul{padding-left:var(--ok-s-5)}nav ul{text-decoration:none;padding-left:0}nav ul li{display:inline;margin-right:1em}li p{margin-bottom:0}li,li p+p{margin-top:.5em}audio,img,video{margin-left:auto;margin-right:auto}img{border-radius:var(--ok-br)}figure>img:not(:last-child){margin-bottom:var(--ok-s-1)}figure>figcaption{text-align:center}figcaption,time{font-size:var(--ok-fs-5);color:var(--ok-tc-1)}mark{padding:.2em .4em;background:var(--ok-t-hl);color:#000;border-radius:var(--ok-br)}iframe{border:var(--ok-b-0);border-radius:var(--ok-br);width:100%}hr{border:none;border-bottom:var(--ok-b-0)}footer{font-size:var(--ok-fs-5)}blockquote,footer{color:var(--ok-tc-1)}blockquote{position:relative;margin-left:0;margin-right:0;padding-left:var(--ok-s-5)}blockquote:before{position:absolute;height:100%;content:"";width:4px;left:0;border-radius:var(--ok-br);background-color:var(--ok-bg-1)}dd{padding-left:var(--ok-s-5)}abbr{cursor:help}@media (hover:hover){a:hover{text-decoration:underline}input:hover:not(:disabled):not(:focus):not([type=submit]):not([type=button]):not([type=reset]):not([type=range]),select:hover:not(:disabled):not(:focus),textarea:hover:not(:disabled):not(:focus){border:var(--ok-b-1)}input[type=range]:hover:not(:disabled)::-webkit-slider-runnable-track{border:var(--ok-b-1)}input[type=range]:hover:not(:disabled)::-moz-range-track{border:var(--ok-b-1)}input[type=range]:hover:not(:disabled)::-ms-track{border:var(--ok-b-1)}select:not([multiple]):not(:disabled):hover{cursor:pointer}button:hover:not(:disabled),input[type=button]:hover:not(:disabled),input[type=reset]:hover:not(:disabled),input[type=submit]:hover:not(:disabled){background-color:var(--ok-accent-1)}input:not(:disabled):hover::-webkit-file-upload-button{background-color:var(--ok-accent-1)}}
\ No newline at end of file diff --git a/3rdparty/expat/doc/reference.html b/3rdparty/expat/doc/reference.html index 1e4780ed70c..450fea84c29 100644 --- a/3rdparty/expat/doc/reference.html +++ b/3rdparty/expat/doc/reference.html @@ -3,26 +3,58 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> -<!-- Copyright 1999,2000 Clark Cooper <coopercc@netheaven.com> - All rights reserved. - This is free software. You may distribute or modify according to - the terms of the MIT/X License --> +<!-- + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2000-2004 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2002-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2017-2024 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017 Jakub Wilk <jwilk@jwilk.net> + Copyright (c) 2021 Tomas Korbar <tkorbar@redhat.com> + Copyright (c) 2021 Nicolas Cavallari <nicolas.cavallari@green-communications.fr> + Copyright (c) 2022 Thijs Schreijer <thijs@thijsschreijer.nl> + Copyright (c) 2023 Hanno Böck <hanno@gentoo.org> + Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +--> <title>Expat XML Parser</title> <meta name="author" content="Clark Cooper, coopercc@netheaven.com" /> <meta http-equiv="Content-Style-Type" content="text/css" /> + <link href="ok.min.css" rel="stylesheet" type="text/css" /> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> - <table cellspacing="0" cellpadding="0" width="100%"> - <tr> - <td class="corner"><img src="expat.png" alt="(Expat logo)" /></td> - <td class="banner"><h1>The Expat XML Parser</h1></td> - </tr> - <tr> - <td class="releaseno">Release 2.0.1</td> - <td></td> - </tr> - </table> + <div> + <h1> + The Expat XML Parser + <small>Release 2.6.4</small> + </h1> + </div> <div class="content"> <p>Expat is a library, written in C, for parsing XML documents. It's @@ -38,11 +70,11 @@ Working Group at W3C that produced the XML specification.</p> <p>This is free software, licensed under the <a href="../COPYING">MIT/X Consortium license</a>. You may download it -from <a href="http://www.libexpat.org/">the Expat home page</a>. +from <a href="https://libexpat.github.io/">the Expat home page</a>. </p> <p>The bulk of this document was originally commissioned as an article -by <a href="http://www.xml.com/">XML.com</a>. They graciously allowed +by <a href="https://www.xml.com/">XML.com</a>. They graciously allowed Clark Cooper to retain copyright and to distribute it with Expat. This version has been substantially extended to include documentation on features which have been added since the original article was @@ -120,6 +152,14 @@ interface.</p> <li><a href="#XML_GetInputContext">XML_GetInputContext</a></li> </ul> </li> + <li> + <a href="#attack-protection">Attack Protection</a> + <ul> + <li><a href="#XML_SetBillionLaughsAttackProtectionMaximumAmplification">XML_SetBillionLaughsAttackProtectionMaximumAmplification</a></li> + <li><a href="#XML_SetBillionLaughsAttackProtectionActivationThreshold">XML_SetBillionLaughsAttackProtectionActivationThreshold</a></li> + <li><a href="#XML_SetReparseDeferralEnabled">XML_SetReparseDeferralEnabled</a></li> + </ul> + </li> <li><a href="#miscellaneous">Miscellaneous Functions</a> <ul> <li><a href="#XML_SetUserData">XML_SetUserData</a></li> @@ -268,7 +308,7 @@ shoveling the document to the parser so that it can do its work.</p> <p>The Expat distribution comes as a compressed (with GNU gzip) tar file. You may download the latest version from <a href= -"http://sourceforge.net/projects/expat/" >Source Forge</a>. After +"https://sourceforge.net/projects/expat/" >Source Forge</a>. After unpacking this, cd into the directory. Then follow either the Win32 directions or Unix directions below.</p> @@ -279,7 +319,7 @@ directions in the next section. Otherwise if you have Microsoft's Developer Studio installed, you can use CMake to generate a <code>.sln</code> file, e.g. <code> -cmake -G"Visual Studio 15 2017" -DCMAKE_BUILD_TYPE=RelWithDebInfo . +cmake -G"Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=RelWithDebInfo . </code>, and build Expat using <code>msbuild /m expat.sln</code> after.</p> <p>Alternatively, you may download the Win32 binary package that @@ -316,39 +356,67 @@ library and header would get installed in <h3>Configuring Expat Using the Pre-Processor</h3> <p>Expat's feature set can be configured using a small number of -pre-processor definitions. The definition of this symbols does not -affect the set of entry points for Expat, only the behavior of the API -and the definition of character types in the case of -<code>XML_UNICODE_WCHAR_T</code>. The symbols are:</p> +pre-processor definitions. The symbols are:</p> <dl class="cpp-symbols"> -<dt>XML_DTD</dt> +<dt><a name="XML_GE">XML_GE</a></dt> +<dd> +Added in Expat 2.6.0. +Include support for +<a href="https://www.w3.org/TR/2006/REC-xml-20060816/#sec-physical-struct">general entities</a> +(syntax <code>&e1;</code> to reference and +syntax <code><!ENTITY e1 'value1'></code> (an internal general entity) or +<code><!ENTITY e2 SYSTEM 'file2'></code> (an external general entity) to declare). +With <code>XML_GE</code> enabled, general entities will be replaced by their declared replacement text; +for this to work for <em>external</em> general entities, in addition an +<code><a href="#XML_SetExternalEntityRefHandler">XML_ExternalEntityRefHandler</a></code> must be set using +<code><a href="#XML_SetExternalEntityRefHandler">XML_SetExternalEntityRefHandler</a></code>. +Also, enabling <code>XML_GE</code> makes +the functions <code><a href="#XML_SetBillionLaughsAttackProtectionMaximumAmplification"> +XML_SetBillionLaughsAttackProtectionMaximumAmplification</a></code> and <code> +<a href="#XML_SetBillionLaughsAttackProtectionActivationThreshold"> +XML_SetBillionLaughsAttackProtectionActivationThreshold</a></code> available. +<br/> +With <code>XML_GE</code> disabled, Expat has a smaller memory footprint and can be faster, but will +not load external general entities and will replace all general entities +(except the <a href="https://www.w3.org/TR/2006/REC-xml-20060816/#sec-predefined-ent">predefined five</a>: +<code>amp</code>, <code>apos</code>, <code>gt</code>, <code>lt</code>, <code>quot</code>) +with a self-reference: +for example, referencing an entity <code>e1</code> via <code>&e1;</code> will be replaced +by text <code>&e1;</code>. +</dd> + +<dt><a name="XML_DTD">XML_DTD</a></dt> <dd>Include support for using and reporting DTD-based content. If this is defined, default attribute values from an external DTD subset are reported and attribute value normalization occurs based on the type of attributes defined in the external subset. Without this, Expat has a smaller memory footprint and can be faster, but will -not load external entities or process conditional sections. This does -not affect the set of functions available in the API.</dd> - -<dt>XML_NS</dt> +not load external parameter entities or process conditional sections. If defined, makes +the functions <code><a +href="#XML_SetBillionLaughsAttackProtectionMaximumAmplification"> +XML_SetBillionLaughsAttackProtectionMaximumAmplification</a></code> and <code> +<a href="#XML_SetBillionLaughsAttackProtectionActivationThreshold"> +XML_SetBillionLaughsAttackProtectionActivationThreshold</a></code> available.</dd> + +<dt><a name="XML_NS">XML_NS</a></dt> <dd>When defined, support for the <cite><a href= -"http://www.w3.org/TR/REC-xml-names/" >Namespaces in XML</a></cite> +"https://www.w3.org/TR/REC-xml-names/" >Namespaces in XML</a></cite> specification is included.</dd> -<dt>XML_UNICODE</dt> +<dt><a name="XML_UNICODE">XML_UNICODE</a></dt> <dd>When defined, character data reported to the application is encoded in UTF-16 using wide characters of the type <code>XML_Char</code>. This is implied if <code>XML_UNICODE_WCHAR_T</code> is defined.</dd> -<dt>XML_UNICODE_WCHAR_T</dt> +<dt><a name="XML_UNICODE_WCHAR_T">XML_UNICODE_WCHAR_T</a></dt> <dd>If defined, causes the <code>XML_Char</code> character type to be defined using the <code>wchar_t</code> type; otherwise, <code>unsigned short</code> is used. Defining this implies <code>XML_UNICODE</code>.</dd> -<dt>XML_LARGE_SIZE</dt> +<dt><a name="XML_LARGE_SIZE">XML_LARGE_SIZE</a></dt> <dd>If defined, causes the <code>XML_Size</code> and <code>XML_Index</code> integer types to be at least 64 bits in size. This is intended to support processing of very large input streams, where the return values of @@ -358,23 +426,23 @@ processing of very large input streams, where the return values of could overflow. It may not be supported by all compilers, and is turned off by default.</dd> -<dt>XML_CONTEXT_BYTES</dt> +<dt><a name="XML_CONTEXT_BYTES">XML_CONTEXT_BYTES</a></dt> <dd>The number of input bytes of markup context which the parser will ensure are available for reporting via <code><a href= "#XML_GetInputContext" >XML_GetInputContext</a></code>. This is -normally set to 1024, and must be set to a positive integer. If this -is not defined, the input context will not be available and <code><a +normally set to 1024, and must be set to a positive integer to enable. +If this is set to zero, the input context will not be available and <code><a href= "#XML_GetInputContext" >XML_GetInputContext</a></code> will -always report NULL. Without this, Expat has a smaller memory +always report <code>NULL</code>. Without this, Expat has a smaller memory footprint and can be faster.</dd> -<dt>XML_STATIC</dt> +<dt><a name="XML_STATIC">XML_STATIC</a></dt> <dd>On Windows, this should be set if Expat is going to be linked statically with the code that calls it; this is required to get all the right MSVC magic annotations correct. This is ignored on other platforms.</dd> -<dt>XML_ATTR_INFO</dt> +<dt><a name="XML_ATTR_INFO">XML_ATTR_INFO</a></dt> <dd>If defined, makes the additional function <code><a href= "#XML_GetAttributeInfo" >XML_GetAttributeInfo</a></code> available for reporting attribute byte offsets.</dd> @@ -628,8 +696,9 @@ function. The StartNamespaceDeclHandler is called prior to the start tag handler and the EndNamespaceDeclHandler is called after the corresponding end tag that ends the namespace's scope. The namespace start handler gets passed the prefix and URI for the namespace. For a -default namespace declaration (xmlns='...'), the prefix will be null. -The URI will be null for the case where the default namespace is being +default namespace declaration (xmlns='...'), the prefix will be +<code>NULL</code>. +The URI will be <code>NULL</code> for the case where the default namespace is being unset. The namespace end handler just gets the prefix for the closing scope.</p> @@ -758,7 +827,7 @@ has already been passed into the parser. Applications for this include</p> <ul> - <li>Supporting the <a href= "http://www.w3.org/TR/xinclude/" + <li>Supporting the <a href= "https://www.w3.org/TR/xinclude/" >XInclude</a> specification.</li> <li>Delaying further processing until additional information is @@ -900,24 +969,30 @@ whether the parse can be resumed in the future.</p> <h3><a name="creation">Parser Creation</a></h3> -<pre class="fcndec" id="XML_ParserCreate"> +<h4 id="XML_ParserCreate">XML_ParserCreate</h4> +<pre class="fcndec"> XML_Parser XMLCALL XML_ParserCreate(const XML_Char *encoding); </pre> <div class="fcndef"> -Construct a new parser. If encoding is non-null, it specifies a +<p> +Construct a new parser. If encoding is non-<code>NULL</code>, it specifies a character encoding to use for the document. This overrides the document encoding declaration. There are four built-in encodings: +</p> <ul> <li>US-ASCII</li> <li>UTF-8</li> <li>UTF-16</li> <li>ISO-8859-1</li> </ul> +<p> Any other value will invoke a call to the UnknownEncodingHandler. +</p> </div> -<pre class="fcndec" id="XML_ParserCreateNS"> +<h4 id="XML_ParserCreateNS">XML_ParserCreateNS</h4> +<pre class="fcndec"> XML_Parser XMLCALL XML_ParserCreateNS(const XML_Char *encoding, XML_Char sep); @@ -936,7 +1011,16 @@ the local part will be concatenated without any separator - this is intended to support RDF processors. It is a programming error to use the null separator with <a href= "#XML_SetReturnNSTriplet">namespace triplets</a>.</div> -<pre class="fcndec" id="XML_ParserCreate_MM"> +<p><strong>Note:</strong> +Expat does not validate namespace URIs (beyond encoding) +against RFC 3986 today (and is not required to do so with regard to +the XML 1.0 namespaces specification) but it may start doing that +in future releases. Before that, an application using Expat must +be ready to receive namespace URIs containing non-URI characters. +</p> + +<h4 id="XML_ParserCreate_MM">XML_ParserCreate_MM</h4> +<pre class="fcndec"> XML_Parser XMLCALL XML_ParserCreate_MM(const XML_Char *encoding, const XML_Memory_Handling_Suite *ms, @@ -951,14 +1035,15 @@ typedef struct { </pre> <div class="fcndef"> <p>Construct a new parser using the suite of memory handling functions -specified in <code>ms</code>. If <code>ms</code> is NULL, then use the +specified in <code>ms</code>. If <code>ms</code> is <code>NULL</code>, then use the standard set of memory management functions. If <code>sep</code> is -non NULL, then namespace processing is enabled in the created parser +non-<code>NULL</code>, then namespace processing is enabled in the created parser and the character pointed at by sep is used as the separator between the namespace URI and the local part of the name.</p> </div> -<pre class="fcndec" id="XML_ExternalEntityParserCreate"> +<h4 id="XML_ExternalEntityParserCreate">XML_ExternalEntityParserCreate</h4> +<pre class="fcndec"> XML_Parser XMLCALL XML_ExternalEntityParserCreate(XML_Parser p, const XML_Char *context, @@ -974,7 +1059,8 @@ changing functions on this parser (unless you want it to act differently than the parent parser). </div> -<pre class="fcndec" id="XML_ParserFree"> +<h4 id="XML_ParserFree">XML_ParserFree</h4> +<pre class="fcndec"> void XMLCALL XML_ParserFree(XML_Parser p); </pre> @@ -983,7 +1069,8 @@ Free memory used by the parser. Your application is responsible for freeing any memory associated with <a href="#userdata">user data</a>. </div> -<pre class="fcndec" id="XML_ParserReset"> +<h4 id="XML_ParserReset">XML_ParserReset</h4> +<pre class="fcndec"> XML_Bool XMLCALL XML_ParserReset(XML_Parser p, const XML_Char *encoding); @@ -1014,7 +1101,7 @@ if they apply to the parser created by <code><a href= "#XML_ExternalEntityParserCreate" >XML_ExternalEntityParserCreate</a></code>.</p> -<p>Note: the <code>len</code> argument passed to these functions +<p>Note: The <code>len</code> argument passed to these functions should be considerably less than the maximum value for an integer, as it could create an integer overflow situation if the added lengths of a buffer and the unprocessed portion of the previous buffer @@ -1022,7 +1109,13 @@ exceed the maximum integer value. Input data at the end of a buffer will remain unprocessed if it is part of an XML token for which the end is not part of that buffer.</p> -<pre class="fcndec" id="XML_Parse"> +<p><a name="isFinal"></a>The application <em>must</em> make a concluding +<code><a href="#XML_Parse">XML_Parse</a></code> or +<code><a href="#XML_ParseBuffer">XML_ParseBuffer</a></code> call +with <code>isFinal</code> set to <code>XML_TRUE</code>.</p> + +<h4 id="XML_Parse">XML_Parse</h4> +<pre class="fcndec"> enum XML_Status XMLCALL XML_Parse(XML_Parser p, const char *s, @@ -1036,42 +1129,86 @@ enum XML_Status { }; </pre> <div class="fcndef"> +<p> Parse some more of the document. The string <code>s</code> is a buffer containing part (or perhaps all) of the document. The number of bytes of s that are part of the document is indicated by <code>len</code>. This means -that <code>s</code> doesn't have to be null terminated. It also means that +that <code>s</code> doesn't have to be null-terminated. It also means that if <code>len</code> is larger than the number of bytes in the block of -memory that <code>s</code> points at, then a memory fault is likely. The +memory that <code>s</code> points at, then a memory fault is likely. +Negative values for <code>len</code> are rejected since Expat 2.2.1. +The <code>isFinal</code> parameter informs the parser that this is the last piece of the document. Frequently, the last piece is empty (i.e. <code>len</code> is zero.) +</p> + +<p> If a parse error occurred, it returns <code>XML_STATUS_ERROR</code>. Otherwise it returns <code>XML_STATUS_OK</code> value. +Note that regardless of the return value, there is no guarantee that all +provided input has been parsed; only after <a href="#isFinal">the +concluding call</a> will all handler callbacks and parsing errors have +happened. +</p> + +<p> +Simplified, <code>XML_Parse</code> can be considered a convenience wrapper +that is pairing calls +to <code><a href="#XML_GetBuffer">XML_GetBuffer</a></code> +and <code><a href="#XML_ParseBuffer">XML_ParseBuffer</a></code> +(when Expat is built with macro <code>XML_CONTEXT_BYTES</code> +defined to a positive value, which is both common and default). +<code>XML_Parse</code> is then functionally equivalent to calling +<code><a href="#XML_GetBuffer">XML_GetBuffer</a></code>, +<code>memcpy</code>, and +<code><a href="#XML_ParseBuffer">XML_ParseBuffer</a></code>. +</p> + +<p> +To avoid double copying of the input, direct use of functions +<code><a href="#XML_GetBuffer">XML_GetBuffer</a></code> and +<code><a href="#XML_ParseBuffer">XML_ParseBuffer</a></code> is advised +for most production use, e.g. +if you're using <code>read</code> or similar functionality to fill your +buffers, fill directly into the buffer from +<code><a href="#XML_GetBuffer">XML_GetBuffer</a></code>, +then parse with <code><a href="#XML_ParseBuffer">XML_ParseBuffer</a></code>. +</p> </div> -<pre class="fcndec" id="XML_ParseBuffer"> +<h4 id="XML_ParseBuffer">XML_ParseBuffer</h4> +<pre class="fcndec"> enum XML_Status XMLCALL XML_ParseBuffer(XML_Parser p, int len, int isFinal); </pre> <div class="fcndef"> +<p> This is just like <code><a href= "#XML_Parse" >XML_Parse</a></code>, except in this case Expat provides the buffer. By obtaining the buffer from Expat with the <code><a href= "#XML_GetBuffer" >XML_GetBuffer</a></code> function, the application can avoid double copying of the input. +</p> + +<p> +Negative values for <code>len</code> are rejected since Expat 2.6.3. +</p> </div> -<pre class="fcndec" id="XML_GetBuffer"> +<h4 id="XML_GetBuffer">XML_GetBuffer</h4> +<pre class="fcndec"> void * XMLCALL XML_GetBuffer(XML_Parser p, int len); </pre> <div class="fcndef"> Obtain a buffer of size <code>len</code> to read a piece of the document -into. A NULL value is returned if Expat can't allocate enough memory for -this buffer. This has to be called prior to every call to +into. A <code>NULL</code> value is returned if Expat can't allocate enough memory for +this buffer. A <code>NULL</code> value may also be returned if <code>len</code> is zero. +This has to be called prior to every call to <code><a href= "#XML_ParseBuffer" >XML_ParseBuffer</a></code>. A typical use would look like this: @@ -1098,7 +1235,8 @@ for (;;) { </pre> </div> -<pre class="fcndec" id="XML_StopParser"> +<h4 id="XML_StopParser">XML_StopParser</h4> +<pre class="fcndec"> enum XML_Status XMLCALL XML_StopParser(XML_Parser p, XML_Bool resumable); @@ -1111,7 +1249,7 @@ XML_StopParser(XML_Parser p, call-back handler, except when aborting (when <code>resumable</code> is <code>XML_FALSE</code>) an already suspended parser. Some call-backs may still follow because they would otherwise get -lost, including +lost, including</p> <ul> <li> the end element handler for empty elements when stopped in the start element handler,</li> @@ -1120,7 +1258,7 @@ lost, including <li> the character data handler when stopped in the character data handler while making multiple call-backs on a contiguous chunk of characters,</li> </ul> -and possibly others.</p> +<p>and possibly others.</p> <p>This can be called from most handlers, including DTD related call-backs, except when parsing an external parameter entity and @@ -1166,7 +1304,8 @@ implementation of that handler to call <code><a href= <p>New in Expat 1.95.8.</p> </div> -<pre class="fcndec" id="XML_ResumeParser"> +<h4 id="XML_ResumeParser">XML_ResumeParser</h4> +<pre class="fcndec"> enum XML_Status XMLCALL XML_ResumeParser(XML_Parser p); </pre> @@ -1191,7 +1330,8 @@ appropriate moment.</p> <p>New in Expat 1.95.8.</p> </div> -<pre class="fcndec" id="XML_GetParsingStatus"> +<h4 id="XML_GetParsingStatus">XML_GetParsingStatus</h4> +<pre class="fcndec"> void XMLCALL XML_GetParsingStatus(XML_Parser p, XML_ParsingStatus *status); @@ -1213,7 +1353,7 @@ typedef struct { <p>Returns status of parser with respect to being initialized, parsing, finished, or suspended, and whether the final buffer is being processed. The <code>status</code> parameter <em>must not</em> be -NULL.</p> +<code>NULL</code>.</p> <p>New in Expat 1.95.8.</p> </div> @@ -1228,7 +1368,7 @@ to ignore all text not descended from a <code>para</code> element. One way it could do this is to set the character handler when a para start tag is seen, and unset it for the corresponding end tag.</p> -<p>A handler may be <em>unset</em> by providing a NULL pointer to the +<p>A handler may be <em>unset</em> by providing a <code>NULL</code> pointer to the appropriate handler setter. None of the handler setting functions have a return value.</p> @@ -1240,7 +1380,8 @@ Note that you'll receive them in this form independent of the original encoding of the document.</p> <div class="handler"> -<pre class="setter" id="XML_SetStartElementHandler"> +<h4 id="XML_SetStartElementHandler">XML_SetStartElementHandler</h4> +<pre class="setter"> void XMLCALL XML_SetStartElementHandler(XML_Parser p, XML_StartElementHandler start); @@ -1255,13 +1396,14 @@ typedef void handler as a pointer to a vector of char pointers. Each attribute seen in a start (or empty) tag occupies 2 consecutive places in this vector: the attribute name followed by the attribute value. These pairs are terminated -by a null pointer.</p> +by a <code>NULL</code> pointer.</p> <p>Note that an empty tag generates a call to both start and end handlers (in that order).</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetEndElementHandler"> +<h4 id="XML_SetEndElementHandler">XML_SetEndElementHandler</h4> +<pre class="setter"> void XMLCALL XML_SetEndElementHandler(XML_Parser p, XML_EndElementHandler); @@ -1276,7 +1418,8 @@ generates a call to both start and end handlers.</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetElementHandler"> +<h4 id="XML_SetElementHandler">XML_SetElementHandler</h4> +<pre class="setter"> void XMLCALL XML_SetElementHandler(XML_Parser p, XML_StartElementHandler start, @@ -1286,7 +1429,8 @@ XML_SetElementHandler(XML_Parser p, </div> <div class="handler"> -<pre class="setter" id="XML_SetCharacterDataHandler"> +<h4 id="XML_SetCharacterDataHandler">XML_SetCharacterDataHandler</h4> +<pre class="setter"> void XMLCALL XML_SetCharacterDataHandler(XML_Parser p, XML_CharacterDataHandler charhndl) @@ -1302,14 +1446,15 @@ is <em>NOT null-terminated</em>. You have to use the length argument to deal with the end of the string. A single block of contiguous text free of markup may still result in a sequence of calls to this handler. In other words, if you're searching for a pattern in the text, it may -be split across calls to this handler. Note: Setting this handler to NULL +be split across calls to this handler. Note: Setting this handler to <code>NULL</code> may <em>NOT immediately</em> terminate call-backs if the parser is currently processing such a single block of contiguous markup-free text, as the parser will continue calling back until the end of the block is reached.</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetProcessingInstructionHandler"> +<h4 id="XML_SetProcessingInstructionHandler">XML_SetProcessingInstructionHandler</h4> +<pre class="setter"> void XMLCALL XML_SetProcessingInstructionHandler(XML_Parser p, XML_ProcessingInstructionHandler proc) @@ -1327,7 +1472,8 @@ it after skipping all whitespace after the initial word.</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetCommentHandler"> +<h4 id="XML_SetCommentHandler">XML_SetCommentHandler</h4> +<pre class="setter"> void XMLCALL XML_SetCommentHandler(XML_Parser p, XML_CommentHandler cmnt) @@ -1342,7 +1488,8 @@ delimiters.</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetStartCdataSectionHandler"> +<h4 id="XML_SetStartCdataSectionHandler">XML_SetStartCdataSectionHandler</h4> +<pre class="setter"> void XMLCALL XML_SetStartCdataSectionHandler(XML_Parser p, XML_StartCdataSectionHandler start); @@ -1355,7 +1502,8 @@ typedef void </div> <div class="handler"> -<pre class="setter" id="XML_SetEndCdataSectionHandler"> +<h4 id="XML_SetEndCdataSectionHandler">XML_SetEndCdataSectionHandler</h4> +<pre class="setter"> void XMLCALL XML_SetEndCdataSectionHandler(XML_Parser p, XML_EndCdataSectionHandler end); @@ -1368,7 +1516,8 @@ typedef void </div> <div class="handler"> -<pre class="setter" id="XML_SetCdataSectionHandler"> +<h4 id="XML_SetCdataSectionHandler">XML_SetCdataSectionHandler</h4> +<pre class="setter"> void XMLCALL XML_SetCdataSectionHandler(XML_Parser p, XML_StartCdataSectionHandler start, @@ -1378,7 +1527,8 @@ XML_SetCdataSectionHandler(XML_Parser p, </div> <div class="handler"> -<pre class="setter" id="XML_SetDefaultHandler"> +<h4 id="XML_SetDefaultHandler">XML_SetDefaultHandler</h4> +<pre class="setter"> void XMLCALL XML_SetDefaultHandler(XML_Parser p, XML_DefaultHandler hndl) @@ -1409,7 +1559,8 @@ href="#XML_DefaultCurrent">XML_DefaultCurrent</a></code>.</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetDefaultHandlerExpand"> +<h4 id="XML_SetDefaultHandlerExpand">XML_SetDefaultHandlerExpand</h4> +<pre class="setter"> void XMLCALL XML_SetDefaultHandlerExpand(XML_Parser p, XML_DefaultHandler hndl) @@ -1429,7 +1580,8 @@ href="#XML_DefaultCurrent">XML_DefaultCurrent</a></code>.</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetExternalEntityRefHandler"> +<h4 id="XML_SetExternalEntityRefHandler">XML_SetExternalEntityRefHandler</h4> +<pre class="setter"> void XMLCALL XML_SetExternalEntityRefHandler(XML_Parser p, XML_ExternalEntityRefHandler hndl) @@ -1452,16 +1604,16 @@ the format expected by the <code>context</code> argument to <code><a href="#XML_ExternalEntityParserCreate" >XML_ExternalEntityParserCreate</a></code>. <code>code</code> is valid only until the handler returns, so if the referenced entity is -to be parsed later, it must be copied. <code>context</code> is NULL +to be parsed later, it must be copied. <code>context</code> is <code>NULL</code> only when the entity is a parameter entity, which is how one can differentiate between general and parameter entities.</p> <p>The <code>base</code> parameter is the base to use for relative system identifiers. It is set by <code><a -href="#XML_SetBase">XML_SetBase</a></code> and may be NULL. The +href="#XML_SetBase">XML_SetBase</a></code> and may be <code>NULL</code>. The <code>publicId</code> parameter is the public id given in the entity -declaration and may be NULL. <code>systemId</code> is the system -identifier specified in the entity declaration and is never NULL.</p> +declaration and may be <code>NULL</code>. <code>systemId</code> is the system +identifier specified in the entity declaration and is never <code>NULL</code>.</p> <p>There are a couple of ways in which this handler differs from others. First, this handler returns a status indicator (an @@ -1482,17 +1634,18 @@ parser, the body of the external entity can be recursively parsed.</p> information into global or static variables.</p> </div> -<pre class="fcndec" id="XML_SetExternalEntityRefHandlerArg"> +<h4 id="XML_SetExternalEntityRefHandlerArg">XML_SetExternalEntityRefHandlerArg</h4> +<pre class="fcndec"> void XMLCALL XML_SetExternalEntityRefHandlerArg(XML_Parser p, void *arg) </pre> <div class="fcndef"> <p>Set the argument passed to the ExternalEntityRefHandler. If -<code>arg</code> is not NULL, it is the new value passed to the +<code>arg</code> is not <code>NULL</code>, it is the new value passed to the handler set using <code><a href="#XML_SetExternalEntityRefHandler" >XML_SetExternalEntityRefHandler</a></code>; if <code>arg</code> is -NULL, the argument passed to the handler function will be the parser +<code>NULL</code>, the argument passed to the handler function will be the parser object itself.</p> <p><strong>Note:</strong> @@ -1508,7 +1661,8 @@ properly.</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetSkippedEntityHandler"> +<h4 id="XML_SetSkippedEntityHandler">XML_SetSkippedEntityHandler</h4> +<pre class="setter"> void XMLCALL XML_SetSkippedEntityHandler(XML_Parser p, XML_SkippedEntityHandler handler) @@ -1528,14 +1682,15 @@ typedef void has been called.</li> </ol> <p>The <code>is_parameter_entity</code> argument will be non-zero for -a parameter entity and zero for a general entity.</p> <p>Note: skipped +a parameter entity and zero for a general entity.</p> <p>Note: Skipped parameter entities in declarations and skipped general entities in attribute values cannot be reported, because the event would be out of sync with the reporting of the declarations or attribute values</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetUnknownEncodingHandler"> +<h4 id="XML_SetUnknownEncodingHandler">XML_SetUnknownEncodingHandler</h4> +<pre class="setter"> void XMLCALL XML_SetUnknownEncodingHandler(XML_Parser p, XML_UnknownEncodingHandler enchandler, @@ -1573,18 +1728,19 @@ value is -1, then that byte is invalid as the initial byte in a sequence. If the value is -n, where n is an integer > 1, then n is the number of bytes in the sequence and the actual conversion is accomplished by a call to the function pointed at by convert. This function may return -1 -if the sequence itself is invalid. The convert pointer may be null if +if the sequence itself is invalid. The convert pointer may be <code>NULL</code> if there are only single byte codes. The data parameter passed to the convert function is the data pointer from <code>XML_Encoding</code>. The string s is <em>NOT</em> null-terminated and points at the sequence of bytes to be converted.</p> <p>The function pointed at by <code>release</code> is called by the -parser when it is finished with the encoding. It may be NULL.</p> +parser when it is finished with the encoding. It may be <code>NULL</code>.</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetStartNamespaceDeclHandler"> +<h4 id="XML_SetStartNamespaceDeclHandler">XML_SetStartNamespaceDeclHandler</h4> +<pre class="setter"> void XMLCALL XML_SetStartNamespaceDeclHandler(XML_Parser p, XML_StartNamespaceDeclHandler start); @@ -1602,7 +1758,8 @@ in that start tag.</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetEndNamespaceDeclHandler"> +<h4 id="XML_SetEndNamespaceDeclHandler">XML_SetEndNamespaceDeclHandler</h4> +<pre class="setter"> void XMLCALL XML_SetEndNamespaceDeclHandler(XML_Parser p, XML_EndNamespaceDeclHandler end); @@ -1619,7 +1776,8 @@ namespace was declared.</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetNamespaceDeclHandler"> +<h4 id="XML_SetNamespaceDeclHandler">XML_SetNamespaceDeclHandler</h4> +<pre class="setter"> void XMLCALL XML_SetNamespaceDeclHandler(XML_Parser p, XML_StartNamespaceDeclHandler start, @@ -1629,7 +1787,8 @@ XML_SetNamespaceDeclHandler(XML_Parser p, </div> <div class="handler"> -<pre class="setter" id="XML_SetXmlDeclHandler"> +<h4 id="XML_SetXmlDeclHandler">XML_SetXmlDeclHandler</h4> +<pre class="setter"> void XMLCALL XML_SetXmlDeclHandler(XML_Parser p, XML_XmlDeclHandler xmldecl); @@ -1643,8 +1802,8 @@ typedef void </pre> <p>Sets a handler that is called for XML declarations and also for text declarations discovered in external entities. The way to -distinguish is that the <code>version</code> parameter will be NULL -for text declarations. The <code>encoding</code> parameter may be NULL +distinguish is that the <code>version</code> parameter will be <code>NULL</code> +for text declarations. The <code>encoding</code> parameter may be <code>NULL</code> for an XML declaration. The <code>standalone</code> argument will contain -1, 0, or 1 indicating respectively that there was no standalone parameter in the declaration, that it was given as no, or @@ -1652,7 +1811,8 @@ that it was given as yes.</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetStartDoctypeDeclHandler"> +<h4 id="XML_SetStartDoctypeDeclHandler">XML_SetStartDoctypeDeclHandler</h4> +<pre class="setter"> void XMLCALL XML_SetStartDoctypeDeclHandler(XML_Parser p, XML_StartDoctypeDeclHandler start); @@ -1667,12 +1827,13 @@ typedef void </pre> <p>Set a handler that is called at the start of a DOCTYPE declaration, before any external or internal subset is parsed. Both <code>sysid</code> -and <code>pubid</code> may be NULL. The <code>has_internal_subset</code> +and <code>pubid</code> may be <code>NULL</code>. The <code>has_internal_subset</code> will be non-zero if the DOCTYPE declaration has an internal subset.</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetEndDoctypeDeclHandler"> +<h4 id="XML_SetEndDoctypeDeclHandler">XML_SetEndDoctypeDeclHandler</h4> +<pre class="setter"> void XMLCALL XML_SetEndDoctypeDeclHandler(XML_Parser p, XML_EndDoctypeDeclHandler end); @@ -1686,7 +1847,8 @@ after parsing any external subset.</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetDoctypeDeclHandler"> +<h4 id="XML_SetDoctypeDeclHandler">XML_SetDoctypeDeclHandler</h4> +<pre class="setter"> void XMLCALL XML_SetDoctypeDeclHandler(XML_Parser p, XML_StartDoctypeDeclHandler start, @@ -1696,7 +1858,8 @@ XML_SetDoctypeDeclHandler(XML_Parser p, </div> <div class="handler"> -<pre class="setter" id="XML_SetElementDeclHandler"> +<h4 id="XML_SetElementDeclHandler">XML_SetElementDeclHandler</h4> +<pre class="setter"> void XMLCALL XML_SetElementDeclHandler(XML_Parser p, XML_ElementDeclHandler eldecl); @@ -1736,16 +1899,17 @@ struct XML_cp { </pre> <p>Sets a handler for element declarations in a DTD. The handler gets called with the name of the element in the declaration and a pointer -to a structure that contains the element model. It is the -application's responsibility to free this data structure using -<code><a href="#XML_FreeContentModel" ->XML_FreeContentModel</a></code>.</p> +to a structure that contains the element model. It's the user code's +responsibility to free model when finished with it. See <code> +<a href="#XML_FreeContentModel">XML_FreeContentModel</a></code>. +There is no need to free the model from the handler, it can be kept +around and freed at a later stage.</p> <p>The <code>model</code> argument is the root of a tree of <code>XML_Content</code> nodes. If <code>type</code> equals <code>XML_CTYPE_EMPTY</code> or <code>XML_CTYPE_ANY</code>, then <code>quant</code> will be <code>XML_CQUANT_NONE</code>, and the other -fields will be zero or NULL. If <code>type</code> is +fields will be zero or <code>NULL</code>. If <code>type</code> is <code>XML_CTYPE_MIXED</code>, then <code>quant</code> will be <code>XML_CQUANT_NONE</code> or <code>XML_CQUANT_REP</code> and <code>numchildren</code> will contain the number of elements that are @@ -1757,7 +1921,7 @@ XML_CTYPE_NAME with no quantification. Only the root node can be type <p>For type <code>XML_CTYPE_NAME</code>, the <code>name</code> field points to the name and the <code>numchildren</code> and -<code>children</code> fields will be zero and NULL. The +<code>children</code> fields will be zero and <code>NULL</code>. The <code>quant</code> field will indicate any quantifiers placed on the name.</p> @@ -1768,7 +1932,8 @@ or sequence and <code>children</code> points to the nodes.</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetAttlistDeclHandler"> +<h4 id="XML_SetAttlistDeclHandler">XML_SetAttlistDeclHandler</h4> +<pre class="setter"> void XMLCALL XML_SetAttlistDeclHandler(XML_Parser p, XML_AttlistDeclHandler attdecl); @@ -1792,16 +1957,17 @@ is in the <code>attname</code> parameter. The attribute type is in the type in the declaration with whitespace removed.</p> <p>The <code>dflt</code> parameter holds the default value. It will be -NULL in the case of "#IMPLIED" or "#REQUIRED" attributes. You can +<code>NULL</code> in the case of "#IMPLIED" or "#REQUIRED" attributes. You can distinguish these two cases by checking the <code>isrequired</code> parameter, which will be true in the case of "#REQUIRED" attributes. Attributes which are "#FIXED" will have also have a true -<code>isrequired</code>, but they will have the non-NULL fixed value +<code>isrequired</code>, but they will have the non-<code>NULL</code> fixed value in the <code>dflt</code> parameter.</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetEntityDeclHandler"> +<h4 id="XML_SetEntityDeclHandler">XML_SetEntityDeclHandler</h4> +<pre class="setter"> void XMLCALL XML_SetEntityDeclHandler(XML_Parser p, XML_EntityDeclHandler handler); @@ -1823,19 +1989,20 @@ The <code>is_parameter_entity</code> argument will be non-zero in the case of parameter entities and zero otherwise.</p> <p>For internal entities (<code><!ENTITY foo "bar"></code>), -<code>value</code> will be non-NULL and <code>systemId</code>, -<code>publicId</code>, and <code>notationName</code> will all be NULL. -The value string is <em>not</em> NULL terminated; the length is +<code>value</code> will be non-<code>NULL</code> and <code>systemId</code>, +<code>publicId</code>, and <code>notationName</code> will all be <code>NULL</code>. +The value string is <em>not</em> null-terminated; the length is provided in the <code>value_length</code> parameter. Do not use <code>value_length</code> to test for internal entities, since it is legal to have zero-length values. Instead check for whether or not -<code>value</code> is NULL.</p> <p>The <code>notationName</code> -argument will have a non-NULL value only for unparsed entity +<code>value</code> is <code>NULL</code>.</p> <p>The <code>notationName</code> +argument will have a non-<code>NULL</code> value only for unparsed entity declarations.</p> </div> <div class="handler"> -<pre class="setter" id="XML_SetUnparsedEntityDeclHandler"> +<h4 id="XML_SetUnparsedEntityDeclHandler">XML_SetUnparsedEntityDeclHandler</h4> +<pre class="setter"> void XMLCALL XML_SetUnparsedEntityDeclHandler(XML_Parser p, XML_UnparsedEntityDeclHandler h) @@ -1861,7 +2028,8 @@ compatibility. Use instead <a href= "#XML_SetEntityDeclHandler" </div> <div class="handler"> -<pre class="setter" id="XML_SetNotationDeclHandler"> +<h4 id="XML_SetNotationDeclHandler">XML_SetNotationDeclHandler</h4> +<pre class="setter"> void XMLCALL XML_SetNotationDeclHandler(XML_Parser p, XML_NotationDeclHandler h) @@ -1878,7 +2046,8 @@ typedef void </div> <div class="handler"> -<pre class="setter" id="XML_SetNotStandaloneHandler"> +<h4 id="XML_SetNotStandaloneHandler">XML_SetNotStandaloneHandler</h4> +<pre class="setter"> void XMLCALL XML_SetNotStandaloneHandler(XML_Parser p, XML_NotStandaloneHandler h) @@ -1913,7 +2082,8 @@ events.</p> DTD. In other words, they usually return bogus information when called from within a DTD declaration handler.</p> -<pre class="fcndec" id="XML_GetErrorCode"> +<h4 id="XML_GetErrorCode">XML_GetErrorCode</h4> +<pre class="fcndec"> enum XML_Error XMLCALL XML_GetErrorCode(XML_Parser p); </pre> @@ -1921,7 +2091,8 @@ XML_GetErrorCode(XML_Parser p); Return what type of error has occurred. </div> -<pre class="fcndec" id="XML_ErrorString"> +<h4 id="XML_ErrorString">XML_ErrorString</h4> +<pre class="fcndec"> const XML_LChar * XMLCALL XML_ErrorString(enum XML_Error code); </pre> @@ -1931,7 +2102,8 @@ The code should be one of the enums that can be returned from <code><a href= "#XML_GetErrorCode" >XML_GetErrorCode</a></code>. </div> -<pre class="fcndec" id="XML_GetCurrentByteIndex"> +<h4 id="XML_GetCurrentByteIndex">XML_GetCurrentByteIndex</h4> +<pre class="fcndec"> XML_Index XMLCALL XML_GetCurrentByteIndex(XML_Parser p); </pre> @@ -1942,7 +2114,8 @@ the values returned by <code><a href= "#XML_GetCurrentLineNumber" "#XML_GetCurrentColumnNumber" >XML_GetCurrentColumnNumber</a></code>. </div> -<pre class="fcndec" id="XML_GetCurrentLineNumber"> +<h4 id="XML_GetCurrentLineNumber">XML_GetCurrentLineNumber</h4> +<pre class="fcndec"> XML_Size XMLCALL XML_GetCurrentLineNumber(XML_Parser p); </pre> @@ -1951,7 +2124,8 @@ Return the line number of the position. The first line is reported as <code>1</code>. </div> -<pre class="fcndec" id="XML_GetCurrentColumnNumber"> +<h4 id="XML_GetCurrentColumnNumber">XML_GetCurrentColumnNumber</h4> +<pre class="fcndec"> XML_Size XMLCALL XML_GetCurrentColumnNumber(XML_Parser p); </pre> @@ -1960,7 +2134,8 @@ Return the offset, from the beginning of the current line, of the position. </div> -<pre class="fcndec" id="XML_GetCurrentByteCount"> +<h4 id="XML_GetCurrentByteCount">XML_GetCurrentByteCount</h4> +<pre class="fcndec"> int XMLCALL XML_GetCurrentByteCount(XML_Parser p); </pre> @@ -1972,7 +2147,8 @@ be used to distinguish empty-element tags from empty elements using separate start and end tags). </div> -<pre class="fcndec" id="XML_GetInputContext"> +<h4 id="XML_GetInputContext">XML_GetInputContext</h4> +<pre class="fcndec"> const char * XMLCALL XML_GetInputContext(XML_Parser p, int *offset, @@ -1994,8 +2170,117 @@ untranslated bytes of the input.</p> triggering a call spans over a very large amount of input, the actual parse position may be before the beginning of the buffer.</p> -<p>If <code>XML_CONTEXT_BYTES</code> is not defined, this will always -return NULL.</p> +<p>If <code>XML_CONTEXT_BYTES</code> is zero, this will always +return <code>NULL</code>.</p> +</div> + +<h3><a name="attack-protection">Attack Protection</a><a name="billion-laughs"></a></h3> + +<h4 id="XML_SetBillionLaughsAttackProtectionMaximumAmplification">XML_SetBillionLaughsAttackProtectionMaximumAmplification</h4> +<pre class="fcndec"> +/* Added in Expat 2.4.0. */ +XML_Bool XMLCALL +XML_SetBillionLaughsAttackProtectionMaximumAmplification(XML_Parser p, + float maximumAmplificationFactor); +</pre> +<div class="fcndef"> + <p> + Sets the maximum tolerated amplification factor + for protection against + <a href="https://en.wikipedia.org/wiki/Billion_laughs_attack">billion laughs attacks</a> + (default: <code>100.0</code>) + of parser <code>p</code> to <code>maximumAmplificationFactor</code>, and + returns <code>XML_TRUE</code> upon success and <code>XML_FALSE</code> upon error. + </p> + + The amplification factor is calculated as .. + <pre> + amplification := (direct + indirect) / direct + </pre> + .. while parsing, whereas + <code>direct</code> is the number of bytes read from the primary document in parsing and + <code>indirect</code> is the number of bytes added by expanding entities and reading of external DTD files, combined. + + <p>For a call to <code>XML_SetBillionLaughsAttackProtectionMaximumAmplification</code> to succeed:</p> + <ul> + <li>parser <code>p</code> must be a non-<code>NULL</code> root parser (without any parent parsers) and</li> + <li><code>maximumAmplificationFactor</code> must be non-<code>NaN</code> and greater than or equal to <code>1.0</code>.</li> + </ul> + + <p> + <strong>Note:</strong> + If you ever need to increase this value for non-attack payload, + please <a href="https://github.com/libexpat/libexpat/issues">file a bug report</a>. + </p> + + <p> + <strong>Note:</strong> + Peak amplifications + of factor 15,000 for the entire payload and + of factor 30,000 in the middle of parsing + have been observed with small benign files in practice. + + So if you do reduce the maximum allowed amplification, + please make sure that the activation threshold is still big enough + to not end up with undesired false positives (i.e. benign files being rejected). + </p> +</div> + +<h4 id="XML_SetBillionLaughsAttackProtectionActivationThreshold">XML_SetBillionLaughsAttackProtectionActivationThreshold</h4> +<pre class="fcndec"> +/* Added in Expat 2.4.0. */ +XML_Bool XMLCALL +XML_SetBillionLaughsAttackProtectionActivationThreshold(XML_Parser p, + unsigned long long activationThresholdBytes); +</pre> +<div class="fcndef"> + <p> + Sets number of output bytes (including amplification from entity expansion and reading DTD files) + needed to activate protection against + <a href="https://en.wikipedia.org/wiki/Billion_laughs_attack">billion laughs attacks</a> + (default: <code>8 MiB</code>) + of parser <code>p</code> to <code>activationThresholdBytes</code>, and + returns <code>XML_TRUE</code> upon success and <code>XML_FALSE</code> upon error. + </p> + + <p>For a call to <code>XML_SetBillionLaughsAttackProtectionActivationThreshold</code> to succeed:</p> + <ul> + <li>parser <code>p</code> must be a non-<code>NULL</code> root parser (without any parent parsers).</li> + </ul> + + <p> + <strong>Note:</strong> + If you ever need to increase this value for non-attack payload, + please <a href="https://github.com/libexpat/libexpat/issues">file a bug report</a>. + </p> + + <p> + <strong>Note:</strong> + Activation thresholds below 4 MiB are known to break support for + <a href="https://en.wikipedia.org/wiki/Darwin_Information_Typing_Architecture">DITA</a> 1.3 payload + and are hence not recommended. + </p> +</div> + +<h4 id="XML_SetReparseDeferralEnabled">XML_SetReparseDeferralEnabled</h4> +<pre class="fcndec"> +/* Added in Expat 2.6.0. */ +XML_Bool XMLCALL +XML_SetReparseDeferralEnabled(XML_Parser parser, XML_Bool enabled); +</pre> +<div class="fcndef"> + <p> + Large tokens may require many parse calls before enough data is available for Expat to parse it in full. + If Expat retried parsing the token on every parse call, parsing could take quadratic time. + To avoid this, Expat only retries once a significant amount of new data is available. + This function allows disabling this behavior. + </p> + <p> + The <code>enabled</code> argument should be <code>XML_TRUE</code> or <code>XML_FALSE</code>. + </p> + <p> + Returns <code>XML_TRUE</code> on success, and <code>XML_FALSE</code> on error. + </p> </div> <h3><a name="miscellaneous">Miscellaneous functions</a></h3> @@ -2003,7 +2288,8 @@ return NULL.</p> <p>The functions in this section either obtain state information from the parser or can be used to dynamically set parser options.</p> -<pre class="fcndec" id="XML_SetUserData"> +<h4 id="XML_SetUserData">XML_SetUserData</h4> +<pre class="fcndec"> void XMLCALL XML_SetUserData(XML_Parser p, void *userData); @@ -2018,7 +2304,8 @@ the memory associated with it, then you've probably just leaked memory. </div> -<pre class="fcndec" id="XML_GetUserData"> +<h4 id="XML_GetUserData">XML_GetUserData</h4> +<pre class="fcndec"> void * XMLCALL XML_GetUserData(XML_Parser p); </pre> @@ -2027,7 +2314,8 @@ This returns the user data pointer that gets passed to handlers. It is actually implemented as a macro. </div> -<pre class="fcndec" id="XML_UseParserAsHandlerArg"> +<h4 id="XML_UseParserAsHandlerArg">XML_UseParserAsHandlerArg</h4> +<pre class="fcndec"> void XMLCALL XML_UseParserAsHandlerArg(XML_Parser p); </pre> @@ -2038,7 +2326,8 @@ using the <code><a href= "#XML_GetUserData" >XML_GetUserData</a></code> function. </div> -<pre class="fcndec" id="XML_SetBase"> +<h4 id="XML_SetBase">XML_SetBase</h4> +<pre class="fcndec"> enum XML_Status XMLCALL XML_SetBase(XML_Parser p, const XML_Char *base); @@ -2050,7 +2339,8 @@ there's no memory to store base, otherwise it's <code>XML_STATUS_OK</code>. </div> -<pre class="fcndec" id="XML_GetBase"> +<h4 id="XML_GetBase">XML_GetBase</h4> +<pre class="fcndec"> const XML_Char * XMLCALL XML_GetBase(XML_Parser p); </pre> @@ -2058,7 +2348,8 @@ XML_GetBase(XML_Parser p); Return the base for resolving relative URIs. </div> -<pre class="fcndec" id="XML_GetSpecifiedAttributeCount"> +<h4 id="XML_GetSpecifiedAttributeCount">XML_GetSpecifiedAttributeCount</h4> +<pre class="fcndec"> int XMLCALL XML_GetSpecifiedAttributeCount(XML_Parser p); </pre> @@ -2074,7 +2365,8 @@ call to a start handler. If called inside a start handler, then that means the current call. </div> -<pre class="fcndec" id="XML_GetIdAttributeIndex"> +<h4 id="XML_GetIdAttributeIndex">XML_GetIdAttributeIndex</h4> +<pre class="fcndec"> int XMLCALL XML_GetIdAttributeIndex(XML_Parser p); </pre> @@ -2086,7 +2378,8 @@ attribute. If called inside a start handler, then that means the current call. </div> -<pre class="fcndec" id="XML_GetAttributeInfo"> +<h4 id="XML_GetAttributeInfo">XML_GetAttributeInfo</h4> +<pre class="fcndec"> const XML_AttrInfo * XMLCALL XML_GetAttributeInfo(XML_Parser parser); </pre> @@ -2107,14 +2400,15 @@ as 1; thus the number of entries in the array is <code>XML_GetSpecifiedAttributeCount(parser) / 2</code>. </div> -<pre class="fcndec" id="XML_SetEncoding"> +<h4 id="XML_SetEncoding">XML_SetEncoding</h4> +<pre class="fcndec"> enum XML_Status XMLCALL XML_SetEncoding(XML_Parser p, const XML_Char *encoding); </pre> <div class="fcndef"> Set the encoding to be used by the parser. It is equivalent to -passing a non-null encoding argument to the parser creation functions. +passing a non-<code>NULL</code> encoding argument to the parser creation functions. It must not be called after <code><a href= "#XML_Parse" >XML_Parse</a></code> or <code><a href= "#XML_ParseBuffer" >XML_ParseBuffer</a></code> have been called on the given parser. @@ -2122,7 +2416,8 @@ Returns <code>XML_STATUS_OK</code> on success or <code>XML_STATUS_ERROR</code> on error. </div> -<pre class="fcndec" id="XML_SetParamEntityParsing"> +<h4 id="XML_SetParamEntityParsing">XML_SetParamEntityParsing</h4> +<pre class="fcndec"> int XMLCALL XML_SetParamEntityParsing(XML_Parser p, enum XML_ParamEntityParsing code); @@ -2142,7 +2437,8 @@ The choices for <code>code</code> are: no effect and will always return 0. </div> -<pre class="fcndec" id="XML_SetHashSalt"> +<h4 id="XML_SetHashSalt">XML_SetHashSalt</h4> +<pre class="fcndec"> int XMLCALL XML_SetHashSalt(XML_Parser p, unsigned long hash_salt); @@ -2153,15 +2449,16 @@ Helps in preventing DoS attacks based on predicting hash function behavior. In order to have an effect this must be called before parsing has started. Returns 1 if successful, 0 when called after <code>XML_Parse</code> or <code>XML_ParseBuffer</code>. -<p><b>Note:</b>This call is optional, as the parser will auto-generate +<p><b>Note:</b> This call is optional, as the parser will auto-generate a new random salt value if no value has been set at the start of parsing.</p> -<p><b>Note:</b>One should not call <code>XML_SetHashSalt</code> with a +<p><b>Note:</b> One should not call <code>XML_SetHashSalt</code> with a hash salt value of 0, as this value is used as sentinel value to indicate that <code>XML_SetHashSalt</code> has <b>not</b> been called. Consequently such a call will have no effect, even if it returns 1.</p> </div> -<pre class="fcndec" id="XML_UseForeignDTD"> +<h4 id="XML_UseForeignDTD">XML_UseForeignDTD</h4> +<pre class="fcndec"> enum XML_Error XMLCALL XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD); </pre> @@ -2183,7 +2480,7 @@ called. The setting of parameter entity parsing, controlled using external entity reference handler set via <code><a href= "#XML_SetExternalEntityRefHandler" >XML_SetExternalEntityRefHandler</a></code> with both -<code>publicId</code> and <code>systemId</code> set to NULL.</p> +<code>publicId</code> and <code>systemId</code> set to <code>NULL</code>.</p> <p>If this function is called after parsing has begun, it returns <code>XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING</code> and ignores @@ -2198,7 +2495,8 @@ the document had a DTD with an external subset. This holds true even if the external entity reference handler returns without action.</p> </div> -<pre class="fcndec" id="XML_SetReturnNSTriplet"> +<h4 id="XML_SetReturnNSTriplet">XML_SetReturnNSTriplet</h4> +<pre class="fcndec"> void XMLCALL XML_SetReturnNSTriplet(XML_Parser parser, int do_nst); @@ -2220,7 +2518,8 @@ default manner, URI then local_name separated by the namespace separator.</p> </div> -<pre class="fcndec" id="XML_DefaultCurrent"> +<h4 id="XML_DefaultCurrent">XML_DefaultCurrent</h4> +<pre class="fcndec"> void XMLCALL XML_DefaultCurrent(XML_Parser parser); </pre> @@ -2234,7 +2533,8 @@ href="#XML_SetDefaultHandler" >XML_SetDefaultHandler</a></code> or not a default handler. </div> -<pre class="fcndec" id="XML_ExpatVersion"> +<h4 id="XML_ExpatVersion">XML_ExpatVersion</h4> +<pre class="fcndec"> XML_LChar * XMLCALL XML_ExpatVersion(); </pre> @@ -2242,7 +2542,8 @@ XML_ExpatVersion(); Return the library version as a string (e.g. <code>"expat_1.95.1"</code>). </div> -<pre class="fcndec" id="XML_ExpatVersionInfo"> +<h4 id="XML_ExpatVersionInfo">XML_ExpatVersionInfo</h4> +<pre class="fcndec"> struct XML_Expat_Version XMLCALL XML_ExpatVersionInfo(); </pre> @@ -2266,7 +2567,8 @@ Testing these constants is currently the best way to determine if particular parts of the Expat API are available. </div> -<pre class="fcndec" id="XML_GetFeatureList"> +<h4 id="XML_GetFeatureList">XML_GetFeatureList</h4> +<pre class="fcndec"> const XML_Feature * XMLCALL XML_GetFeatureList(); </pre> @@ -2299,7 +2601,7 @@ check these features to do so at runtime.</p> <p>The return value is an array of <code>XML_Feature</code>, terminated by a record with a <code>feature</code> of -<code>XML_FEATURE_END</code> and <code>name</code> of NULL, +<code>XML_FEATURE_END</code> and <code>name</code> of <code>NULL</code>, identifying the feature-test macros Expat was compiled with. Since an application that requires this kind of information needs to determine the type of character the <code>name</code> points to, records for the @@ -2327,7 +2629,8 @@ time, the following features have been defined to have values:</p> </dl> </div> -<pre class="fcndec" id="XML_FreeContentModel"> +<h4 id="XML_FreeContentModel">XML_FreeContentModel</h4> +<pre class="fcndec"> void XMLCALL XML_FreeContentModel(XML_Parser parser, XML_Content *model); </pre> @@ -2346,19 +2649,21 @@ applications. This can be essential when using dynamically loaded libraries which use different C standard libraries (this can happen on Windows, at least).</p> -<pre class="fcndec" id="XML_MemMalloc"> +<h4 id="XML_MemMalloc">XML_MemMalloc</h4> +<pre class="fcndec"> void * XMLCALL XML_MemMalloc(XML_Parser parser, size_t size); </pre> <div class="fcndef"> Allocate <code>size</code> bytes of memory using the allocator the <code>parser</code> object has been configured to use. Returns a -pointer to the memory or NULL on failure. Memory allocated in this +pointer to the memory or <code>NULL</code> on failure. Memory allocated in this way must be freed using <code><a href="#XML_MemFree" >XML_MemFree</a></code>. </div> -<pre class="fcndec" id="XML_MemRealloc"> +<h4 id="XML_MemRealloc">XML_MemRealloc</h4> +<pre class="fcndec"> void * XMLCALL XML_MemRealloc(XML_Parser parser, void *ptr, size_t size); </pre> @@ -2367,9 +2672,9 @@ Allocate <code>size</code> bytes of memory using the allocator the <code>parser</code> object has been configured to use. <code>ptr</code> must point to a block of memory allocated by <code><a href="#XML_MemMalloc" >XML_MemMalloc</a></code> or -<code>XML_MemRealloc</code>, or be NULL. This function tries to +<code>XML_MemRealloc</code>, or be <code>NULL</code>. This function tries to expand the block pointed to by <code>ptr</code> if possible. Returns -a pointer to the memory or NULL on failure. On success, the original +a pointer to the memory or <code>NULL</code> on failure. On success, the original block has either been expanded or freed. On failure, the original block has not been freed; the caller is responsible for freeing the original block. Memory allocated in this way must be freed using @@ -2377,20 +2682,24 @@ original block. Memory allocated in this way must be freed using >XML_MemFree</a></code>. </div> -<pre class="fcndec" id="XML_MemFree"> +<h4 id="XML_MemFree">XML_MemFree</h4> +<pre class="fcndec"> void XMLCALL XML_MemFree(XML_Parser parser, void *ptr); </pre> <div class="fcndef"> Free a block of memory pointed to by <code>ptr</code>. The block must have been allocated by <code><a href="#XML_MemMalloc" ->XML_MemMalloc</a></code> or <code>XML_MemRealloc</code>, or be NULL. +>XML_MemMalloc</a></code> or <code>XML_MemRealloc</code>, or be <code>NULL</code>. </div> <hr /> -<p><a href="http://validator.w3.org/check/referer"><img - src="valid-xhtml10.png" alt="Valid XHTML 1.0!" - height="31" width="88" class="noborder" /></a></p> + + <div class="footer"> + Found a bug in the documentation? + <a href="https://github.com/libexpat/libexpat/issues">Please file a bug report.</a> + </div> + </div> </body> </html> diff --git a/3rdparty/expat/doc/style.css b/3rdparty/expat/doc/style.css index 69df30bcecb..1b8cd10dffa 100644 --- a/3rdparty/expat/doc/style.css +++ b/3rdparty/expat/doc/style.css @@ -1,101 +1,47 @@ +/* + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2000-2004 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2021 Sebastian Pipping <sebastian@pipping.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +/* Stop not using half the screen */ body { - background-color: white; - border: 0px; - margin: 0px; - padding: 0px; -} - -.corner { - width: 200px; - height: 80px; - text-align: center; -} - -.banner { - background-color: rgb(110,139,61); - color: rgb(255,236,176); - padding-left: 2em; -} - -.banner h1 { - font-size: 200%; -} - -.content { - padding: 0em 2em 1em 2em; -} - -.releaseno { - background-color: rgb(110,139,61); - color: rgb(255,236,176); - padding-bottom: 0.3em; - padding-top: 0.5em; - text-align: center; - font-weight: bold; -} - -.noborder { - border-width: 0px; -} - -.eg { - padding-left: 1em; - padding-top: .5em; - padding-bottom: .5em; - border: solid thin; - margin: 1em 0; - background-color: tan; - margin-left: 2em; - margin-right: 10%; -} - -.pseudocode { - padding-left: 1em; - padding-top: .5em; - padding-bottom: .5em; - border: solid thin; - margin: 1em 0; - background-color: rgb(250,220,180); - margin-left: 2em; - margin-right: 10%; -} - -.handler { - width: 100%; - border-top-width: thin; - margin-bottom: 1em; -} - -.handler p { - margin-left: 2em; -} - -.setter { - font-weight: bold; -} - -.signature { - color: navy; -} - -.fcndec { - width: 100%; - border-top-width: thin; - font-weight: bold; -} - -.fcndef { - margin-left: 2em; - margin-bottom: 2em; -} - -dd { - margin-bottom: 2em; + max-width: none; /* was: 80ch */ } .cpp-symbols dt { font-family: monospace; } -.cpp-symbols dd { - margin-bottom: 1em; + +/* Resemble style of <footer> which is not part of xhtml1-strict */ +.footer { + font-size: var(--ok-fs-5); + color: var(--ok-tc-1); } diff --git a/3rdparty/expat/doc/valid-xhtml10.png b/3rdparty/expat/doc/valid-xhtml10.png Binary files differdeleted file mode 100644 index 8b5f1baeaa0..00000000000 --- a/3rdparty/expat/doc/valid-xhtml10.png +++ /dev/null diff --git a/3rdparty/expat/doc/xmlwf.1 b/3rdparty/expat/doc/xmlwf.1 index ca56bf97650..61b302581ce 100644 --- a/3rdparty/expat/doc/xmlwf.1 +++ b/3rdparty/expat/doc/xmlwf.1 @@ -5,7 +5,7 @@ \\$2 \(la\\$1\(ra\\$3 .. .if \n(.g .mso www.tmac -.TH XMLWF 1 "March 11, 2016" "" "" +.TH XMLWF 1 "November 6, 2024" "" "" .SH NAME xmlwf \- Determines if an XML document is well-formed .SH SYNOPSIS @@ -15,7 +15,27 @@ xmlwf \- Determines if an XML document is well-formed \fBxmlwf\fR \kx .if (\nx>(\n(.l/2)) .nr x (\n(.l/5) 'in \n(.iu+\nxu -[\fB-s\fR] [\fB-n\fR] [\fB-p\fR] [\fB-x\fR] [\fB-e \fIencoding\fB\fR] [\fB-w\fR] [\fB-d \fIoutput-dir\fB\fR] [\fB-c\fR] [\fB-m\fR] [\fB-r\fR] [\fB-t\fR] [\fB-N\fR] [\fB-v\fR] [file ...] +[\fIOPTIONS\fR] [\fIFILE\fR ...] +'in \n(.iu-\nxu +.ad b +'hy +'nh +.fi +.ad l +\fBxmlwf\fR \kx +.if (\nx>(\n(.l/2)) .nr x (\n(.l/5) +'in \n(.iu+\nxu +\fB-h\fR | \fB--help\fR +'in \n(.iu-\nxu +.ad b +'hy +'nh +.fi +.ad l +\fBxmlwf\fR \kx +.if (\nx>(\n(.l/2)) .nr x (\n(.l/5) +'in \n(.iu+\nxu +\fB-v\fR | \fB--version\fR 'in \n(.iu-\nxu .ad b 'hy @@ -34,7 +54,7 @@ following rules: \(bu The file begins with an XML declaration. For instance, \*(T<<?xml version="1.0" standalone="yes"?>\*(T>. -\fINOTE:\fR +\fINOTE\fR: \fBxmlwf\fR does not currently check for a valid XML declaration. .TP 0.2i @@ -62,10 +82,42 @@ it does not check the DTD. However, it does support external entities (see the \*(T<\fB\-x\fR\*(T> option). .SH OPTIONS When an option includes an argument, you may specify the argument either -separately ("\*(T<\fB\-d\fR\*(T> output") or concatenated with the -option ("\*(T<\fB\-d\fR\*(T>output"). \fBxmlwf\fR +separately ("\*(T<\fB\-d\fR\*(T> \fIoutput\fR") or concatenated with the +option ("\*(T<\fB\-d\fR\*(T>\fIoutput\fR"). \fBxmlwf\fR supports both. .TP +\*(T<\fB\-a\fR\*(T> \fIfactor\fR +Sets the maximum tolerated amplification factor +for protection against billion laughs attacks (default: 100.0). +The amplification factor is calculated as .. + +.nf + + amplification := (direct + indirect) / direct + +.fi + +\&.. while parsing, whereas +<direct> is the number of bytes read +from the primary document in parsing and +<indirect> is the number of bytes +added by expanding entities and reading of external DTD files, +combined. + +\fINOTE\fR: +If you ever need to increase this value for non-attack payload, +please file a bug report. +.TP +\*(T<\fB\-b\fR\*(T> \fIbytes\fR +Sets the number of output bytes (including amplification) +needed to activate protection against billion laughs attacks +(default: 8 MiB). +This can be thought of as an "activation threshold". + +\fINOTE\fR: +If you ever need to increase this value for non-attack payload, +please file a bug report. +.TP \*(T<\fB\-c\fR\*(T> If the input file is well-formed and \fBxmlwf\fR doesn't encounter any errors, the input file is simply copied to @@ -73,7 +125,7 @@ the output directory unchanged. This implies no namespaces (turns off \*(T<\fB\-n\fR\*(T>) and requires \*(T<\fB\-d\fR\*(T> to specify an output directory. .TP -\*(T<\fB\-d output\-dir\fR\*(T> +\*(T<\fB\-d\fR\*(T> \fIoutput-dir\fR Specifies a directory to contain transformed representations of the input files. By default, \*(T<\fB\-d\fR\*(T> outputs a canonical representation @@ -96,7 +148,7 @@ is treated equivalently to data. More on canonical XML can be found at http://www.jclark.com/xml/canonxml.html . .TP -\*(T<\fB\-e encoding\fR\*(T> +\*(T<\fB\-e\fR\*(T> \fIencoding\fR Specifies the character encoding for the document, overriding any document encoding declaration. \fBxmlwf\fR supports four built-in encodings: @@ -106,6 +158,25 @@ supports four built-in encodings: \*(T<ISO\-8859\-1\*(T>. Also see the \*(T<\fB\-w\fR\*(T> option. .TP +\*(T<\fB\-g\fR\*(T> \fIbytes\fR +Sets the buffer size to request per call pair to +\*(T<\fBXML_GetBuffer\fR\*(T> and \*(T<\fBread\fR\*(T> +(default: 8 KiB). +.TP +\*(T<\fB\-h\fR\*(T>, \*(T<\fB\-\-help\fR\*(T> +Prints short usage information on command \fBxmlwf\fR, +and then exits. +Similar to this man page but more concise. +.TP +\*(T<\fB\-k\fR\*(T> +When processing multiple files, \fBxmlwf\fR +by default halts after the the first file with an error. +This tells \fBxmlwf\fR to report the error +but to keep processing. +This can be useful, for example, when testing a filter that converts +many files to XML and you want to quickly find out which conversions +failed. +.TP \*(T<\fB\-m\fR\*(T> Outputs some strange sort of XML file that completely describes the input file, including character positions. @@ -121,13 +192,17 @@ This matches the example output used by the formal XML test cases. Requires \*(T<\fB\-d\fR\*(T> to specify an output file. .TP \*(T<\fB\-p\fR\*(T> -Tells xmlwf to process external DTDs and parameter +Tells \fBxmlwf\fR to process external DTDs and parameter entities. Normally \fBxmlwf\fR never parses parameter entities. \*(T<\fB\-p\fR\*(T> tells it to always parse them. \*(T<\fB\-p\fR\*(T> implies \*(T<\fB\-x\fR\*(T>. .TP +\*(T<\fB\-q\fR\*(T> +Disable reparse deferral, and allow quadratic parse runtime +on large tokens (default: reparse deferral enabled). +.TP \*(T<\fB\-r\fR\*(T> Normally \fBxmlwf\fR memory-maps the XML file before parsing; this can result in faster parsing on many @@ -156,7 +231,7 @@ without client overhead. \*(T<\fB\-t\fR\*(T> turns off most of the output options (\*(T<\fB\-d\fR\*(T>, \*(T<\fB\-m\fR\*(T>, \*(T<\fB\-c\fR\*(T>, ...). .TP -\*(T<\fB\-v\fR\*(T> +\*(T<\fB\-v\fR\*(T>, \*(T<\fB\-\-version\fR\*(T> Prints the version of the Expat library being used, including some information on the compile-time configuration of the library, and then exits. @@ -165,7 +240,7 @@ then exits. Enables support for Windows code pages. Normally, \fBxmlwf\fR will throw an error if it runs across an encoding that it is not equipped to handle itself. With -\*(T<\fB\-w\fR\*(T>, xmlwf will try to use a Windows code +\*(T<\fB\-w\fR\*(T>, \fBxmlwf\fR will try to use a Windows code page. See also \*(T<\fB\-e\fR\*(T>. .TP \*(T<\fB\-x\fR\*(T> @@ -210,24 +285,32 @@ will run \fBxmlwf\fR on the file Older versions of \fBxmlwf\fR do not support reading from standard input. .SH OUTPUT -If an input file is not well-formed, -\fBxmlwf\fR prints a single line describing -the problem to standard output. If a file is well formed, -\fBxmlwf\fR outputs nothing. +\fBxmlwf\fR outputs nothing for files which are problem-free. +If any input file is not well-formed, or if the output for any +input file cannot be opened, \fBxmlwf\fR prints a single +line describing the problem to standard output. +.PP +If the \*(T<\fB\-k\fR\*(T> option is not provided, \fBxmlwf\fR +halts upon encountering a well-formedness or output-file error. +If \*(T<\fB\-k\fR\*(T> is provided, \fBxmlwf\fR continues +processing the remaining input files, describing problems found with any of them. .SH "EXIT STATUS" -For option \*(T<\fB\-v\fR\*(T> or \*(T<\fB\-h\fR\*(T>, \fBxmlwf\fR always exits with status code 0. For other cases, the following exit status codes are returned: +For options \*(T<\fB\-v\fR\*(T>|\*(T<\fB\-\-version\fR\*(T> or \*(T<\fB\-h\fR\*(T>|\*(T<\fB\-\-help\fR\*(T>, \fBxmlwf\fR always exits with status code 0. For other cases, the following exit status codes are returned: .TP \*(T<\fB0\fR\*(T> -The input files are well-formed. +The input files are well-formed and the output (if requested) was written successfully. .TP \*(T<\fB1\fR\*(T> An internal error occurred. .TP \*(T<\fB2\fR\*(T> -An input file was not well-formed or could not be parsed. +One or more input files were not well-formed or could not be parsed. .TP \*(T<\fB3\fR\*(T> If using the \*(T<\fB\-d\fR\*(T> option, an error occurred opening an output file. +.TP +\*(T<\fB4\fR\*(T> +There was a command-line argument error in how \fBxmlwf\fR was invoked. .SH BUGS The errors should go to standard error, not standard output. .PP @@ -239,24 +322,16 @@ I have no idea why anyone would want to use the \*(T<\fB\-d\fR\*(T>, \*(T<\fB\-c\fR\*(T>, and \*(T<\fB\-m\fR\*(T> options. If someone could explain it to me, I'd like to add this information to this manpage. -.SH ALTERNATIVES -Here are some XML validators on the web: - -.nf - -http://www.hcrc.ed.ac.uk/~richard/xml\-check.html -http://www.stg.brown.edu/service/xmlvalid/ -http://www.scripting.com/frontier5/xml/code/xmlValidator.html -http://www.xml.com/pub/a/tools/ruwf/check.html -.fi .SH "SEE ALSO" .nf -The Expat home page: http://www.libexpat.org/ -The W3 XML specification: http://www.w3.org/TR/REC\-xml +The Expat home page: https://libexpat.github.io/ +The W3 XML 1.0 specification (fourth edition): https://www.w3.org/TR/2006/REC\-xml\-20060816/ +Billion laughs attack: https://en.wikipedia.org/wiki/Billion_laughs_attack .fi .SH AUTHOR -This manual page was written by Scott Bronson <\*(T<bronson@rinspin.com\*(T>> for +This manual page was originally written by Scott Bronson <\*(T<bronson@rinspin.com\*(T>> +in December 2001 for the Debian GNU/Linux system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation diff --git a/3rdparty/expat/doc/xmlwf.xml b/3rdparty/expat/doc/xmlwf.xml index 654466cef62..cf6d984af46 100644 --- a/3rdparty/expat/doc/xmlwf.xml +++ b/3rdparty/expat/doc/xmlwf.xml @@ -1,11 +1,28 @@ -<!DOCTYPE refentry [ - <!-- Fill in your name for FIRSTNAME and SURNAME. --> +<!-- + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001 Scott Bronson <bronson@rinspin.com> + Copyright (c) 2002-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2009 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2016 Ardo van Rangelrooij <ardo@debian.org> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2020 Joe Orton <jorton@redhat.com> + Copyright (c) 2021 Tim Bray <tbray@textuality.com> + Unlike most of Expat, + this file is copyrighted under the GNU Free Documentation License 1.1. +--> +<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" + "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [ <!ENTITY dhfirstname "<firstname>Scott</firstname>"> <!ENTITY dhsurname "<surname>Bronson</surname>"> - <!-- Please adjust the date whenever revising the manpage. --> - <!ENTITY dhdate "<date>March 11, 2016</date>"> - <!-- SECTION should be 1-8, maybe w/ subsection other parameters are - allowed: see man(7), man(1). --> + <!ENTITY dhdate "<date>November 6, 2024</date>"> + <!-- Please adjust this^^ date whenever cutting a new release. --> <!ENTITY dhsection "<manvolnum>1</manvolnum>"> <!ENTITY dhemail "<email>bronson@rinspin.com</email>"> <!ENTITY dhusername "Scott Bronson"> @@ -44,25 +61,22 @@ <refsynopsisdiv> <cmdsynopsis> <command>&dhpackage;</command> - <arg><option>-s</option></arg> - <arg><option>-n</option></arg> - <arg><option>-p</option></arg> - <arg><option>-x</option></arg> - - <arg><option>-e <replaceable>encoding</replaceable></option></arg> - <arg><option>-w</option></arg> - - <arg><option>-d <replaceable>output-dir</replaceable></option></arg> - <arg><option>-c</option></arg> - <arg><option>-m</option></arg> - - <arg><option>-r</option></arg> - <arg><option>-t</option></arg> - <arg><option>-N</option></arg> - - <arg><option>-v</option></arg> - - <arg>file ...</arg> + <arg><replaceable>OPTIONS</replaceable></arg> + <arg><replaceable>FILE</replaceable> ...</arg> + </cmdsynopsis> + <cmdsynopsis> + <command>&dhpackage;</command> + <group choice="plain"> + <arg><option>-h</option></arg> + <arg><option>--help</option></arg> + </group> + </cmdsynopsis> + <cmdsynopsis> + <command>&dhpackage;</command> + <group choice="plain"> + <arg><option>-v</option></arg> + <arg><option>--version</option></arg> + </group> </cmdsynopsis> </refsynopsisdiv> @@ -95,7 +109,7 @@ <listitem><para> The file begins with an XML declaration. For instance, <literal><?xml version="1.0" standalone="yes"?></literal>. - <emphasis>NOTE:</emphasis> + <emphasis>NOTE</emphasis>: <command>&dhpackage;</command> does not currently check for a valid XML declaration. </para></listitem> @@ -132,14 +146,58 @@ <para> When an option includes an argument, you may specify the argument either -separately ("<option>-d</option> output") or concatenated with the -option ("<option>-d</option>output"). <command>&dhpackage;</command> +separately ("<option>-d</option> <replaceable>output</replaceable>") or concatenated with the +option ("<option>-d</option><replaceable>output</replaceable>"). <command>&dhpackage;</command> supports both. </para> <variablelist> <varlistentry> + <term><option>-a</option> <replaceable>factor</replaceable></term> + <listitem> + <para> + Sets the maximum tolerated amplification factor + for protection against billion laughs attacks (default: 100.0). + The amplification factor is calculated as .. + </para> + <literallayout> + amplification := (direct + indirect) / direct + </literallayout> + <para> + .. while parsing, whereas + <direct> is the number of bytes read + from the primary document in parsing and + <indirect> is the number of bytes + added by expanding entities and reading of external DTD files, + combined. + </para> + <para> + <emphasis>NOTE</emphasis>: + If you ever need to increase this value for non-attack payload, + please file a bug report. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><option>-b</option> <replaceable>bytes</replaceable></term> + <listitem> + <para> + Sets the number of output bytes (including amplification) + needed to activate protection against billion laughs attacks + (default: 8 MiB). + This can be thought of as an "activation threshold". + </para> + <para> + <emphasis>NOTE</emphasis>: + If you ever need to increase this value for non-attack payload, + please file a bug report. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><option>-c</option></term> <listitem> <para> @@ -153,7 +211,7 @@ supports both. </varlistentry> <varlistentry> - <term><option>-d output-dir</option></term> + <term><option>-d</option> <replaceable>output-dir</replaceable></term> <listitem> <para> Specifies a directory to contain transformed @@ -184,7 +242,7 @@ supports both. </varlistentry> <varlistentry> - <term><option>-e encoding</option></term> + <term><option>-e</option> <replaceable>encoding</replaceable></term> <listitem> <para> Specifies the character encoding for the document, overriding @@ -200,6 +258,44 @@ supports both. </varlistentry> <varlistentry> + <term><option>-g</option> <replaceable>bytes</replaceable></term> + <listitem> + <para> + Sets the buffer size to request per call pair to + <function>XML_GetBuffer</function> and <function>read</function> + (default: 8 KiB). + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><option>-h</option></term> + <term><option>--help</option></term> + <listitem> + <para> + Prints short usage information on command <command>&dhpackage;</command>, + and then exits. + Similar to this man page but more concise. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <term><option>-k</option></term> + <listitem> + <para> + When processing multiple files, <command>&dhpackage;</command> + by default halts after the the first file with an error. + This tells <command>&dhpackage;</command> to report the error + but to keep processing. + This can be useful, for example, when testing a filter that converts + many files to XML and you want to quickly find out which conversions + failed. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><option>-m</option></term> <listitem> <para> @@ -235,7 +331,7 @@ supports both. <term><option>-p</option></term> <listitem> <para> - Tells xmlwf to process external DTDs and parameter + Tells <command>&dhpackage;</command> to process external DTDs and parameter entities. </para> <para> @@ -247,6 +343,16 @@ supports both. </varlistentry> <varlistentry> + <term><option>-q</option></term> + <listitem> + <para> + Disable reparse deferral, and allow quadratic parse runtime + on large tokens (default: reparse deferral enabled). + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><option>-r</option></term> <listitem> <para> @@ -292,9 +398,10 @@ supports both. </para> </listitem> </varlistentry> - + <varlistentry> <term><option>-v</option></term> + <term><option>--version</option></term> <listitem> <para> Prints the version of the Expat library being used, including some @@ -311,7 +418,7 @@ supports both. Enables support for Windows code pages. Normally, <command>&dhpackage;</command> will throw an error if it runs across an encoding that it is not equipped to handle itself. With - <option>-w</option>, &dhpackage; will try to use a Windows code + <option>-w</option>, <command>&dhpackage;</command> will try to use a Windows code page. See also <option>-e</option>. </para> </listitem> @@ -379,20 +486,26 @@ supports both. <refsect1> <title>OUTPUT</title> <para> - If an input file is not well-formed, - <command>&dhpackage;</command> prints a single line describing - the problem to standard output. If a file is well formed, - <command>&dhpackage;</command> outputs nothing. - </para> + <command>&dhpackage;</command> outputs nothing for files which are problem-free. + If any input file is not well-formed, or if the output for any + input file cannot be opened, <command>&dhpackage;</command> prints a single + line describing the problem to standard output. + </para> + <para> + If the <option>-k</option> option is not provided, <command>&dhpackage;</command> + halts upon encountering a well-formedness or output-file error. + If <option>-k</option> is provided, <command>&dhpackage;</command> continues + processing the remaining input files, describing problems found with any of them. + </para> </refsect1> <refsect1> <title>EXIT STATUS</title> - <para>For option <option>-v</option> or <option>-h</option>, <command>&dhpackage;</command> always exits with status code 0. For other cases, the following exit status codes are returned: + <para>For options <option>-v</option>|<option>--version</option> or <option>-h</option>|<option>--help</option>, <command>&dhpackage;</command> always exits with status code 0. For other cases, the following exit status codes are returned: <variablelist> <varlistentry> <term><option>0</option></term> - <listitem><para>The input files are well-formed.</para> + <listitem><para>The input files are well-formed and the output (if requested) was written successfully.</para> </listitem> </varlistentry> <varlistentry> @@ -402,7 +515,7 @@ supports both. </varlistentry> <varlistentry> <term><option>2</option></term> - <listitem><para>An input file was not well-formed or could not be parsed.</para> + <listitem><para>One or more input files were not well-formed or could not be parsed.</para> </listitem> </varlistentry> <varlistentry> @@ -410,6 +523,11 @@ supports both. <listitem><para>If using the <option>-d</option> option, an error occurred opening an output file.</para> </listitem> </varlistentry> + <varlistentry> + <term><option>4</option></term> + <listitem><para>There was a command-line argument error in how <command>&dhpackage;</command> was invoked.</para> + </listitem> + </varlistentry> </variablelist> </para> </refsect1> @@ -434,27 +552,13 @@ supports both. </refsect1> <refsect1> - <title>ALTERNATIVES</title> - <para> - Here are some XML validators on the web: - -<literallayout> -http://www.hcrc.ed.ac.uk/~richard/xml-check.html -http://www.stg.brown.edu/service/xmlvalid/ -http://www.scripting.com/frontier5/xml/code/xmlValidator.html -http://www.xml.com/pub/a/tools/ruwf/check.html -</literallayout> - - </para> - </refsect1> - - <refsect1> <title>SEE ALSO</title> <para> <literallayout> -The Expat home page: http://www.libexpat.org/ -The W3 XML specification: http://www.w3.org/TR/REC-xml +The Expat home page: https://libexpat.github.io/ +The W3 XML 1.0 specification (fourth edition): https://www.w3.org/TR/2006/REC-xml-20060816/ +Billion laughs attack: https://en.wikipedia.org/wiki/Billion_laughs_attack </literallayout> </para> @@ -463,7 +567,8 @@ The W3 XML specification: http://www.w3.org/TR/REC-xml <refsect1> <title>AUTHOR</title> <para> - This manual page was written by &dhusername; &dhemail; for + This manual page was originally written by &dhusername; &dhemail; + in December 2001 for the &debian; system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the <acronym>GNU</acronym> Free Documentation diff --git a/3rdparty/expat/examples/Makefile.am b/3rdparty/expat/examples/Makefile.am index c3b1f7bedbf..e2e22bce8f6 100644 --- a/3rdparty/expat/examples/Makefile.am +++ b/3rdparty/expat/examples/Makefile.am @@ -6,7 +6,8 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2017 Expat development team +# Copyright (c) 2017-2022 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2020 Jeffrey Walton <noloader@gmail.com> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -30,7 +31,10 @@ AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(srcdir)/../lib -noinst_PROGRAMS = elements outline +noinst_PROGRAMS = element_declarations elements outline + +element_declarations_SOURCES = element_declarations.c +element_declarations_LDADD = ../lib/libexpat.la elements_SOURCES = elements.c elements_LDADD = ../lib/libexpat.la diff --git a/3rdparty/expat/examples/Makefile.in b/3rdparty/expat/examples/Makefile.in index 7c4a296ba2b..044c9089c56 100644 --- a/3rdparty/expat/examples/Makefile.in +++ b/3rdparty/expat/examples/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2020 Free Software Foundation, Inc. +# Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -22,7 +22,8 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2017 Expat development team +# Copyright (c) 2017-2022 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2020 Jeffrey Walton <noloader@gmail.com> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -118,7 +119,8 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -noinst_PROGRAMS = elements$(EXEEXT) outline$(EXEEXT) +noinst_PROGRAMS = element_declarations$(EXEEXT) elements$(EXEEXT) \ + outline$(EXEEXT) subdir = examples ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ @@ -132,6 +134,8 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/conftools/ax-append-compile-flags.m4 \ $(top_srcdir)/conftools/ax-append-link-flags.m4 \ $(top_srcdir)/conftools/expatcfg-compiler-supports-visibility.m4 \ + $(top_srcdir)/conftools/ax-cxx-compile-stdcxx.m4 \ + $(top_srcdir)/conftools/ax-cxx-compile-stdcxx-11.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) @@ -141,13 +145,16 @@ CONFIG_HEADER = $(top_builddir)/expat_config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = PROGRAMS = $(noinst_PROGRAMS) -am_elements_OBJECTS = elements.$(OBJEXT) -elements_OBJECTS = $(am_elements_OBJECTS) -elements_DEPENDENCIES = ../lib/libexpat.la +am_element_declarations_OBJECTS = element_declarations.$(OBJEXT) +element_declarations_OBJECTS = $(am_element_declarations_OBJECTS) +element_declarations_DEPENDENCIES = ../lib/libexpat.la AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = +am_elements_OBJECTS = elements.$(OBJEXT) +elements_OBJECTS = $(am_elements_OBJECTS) +elements_DEPENDENCIES = ../lib/libexpat.la am_outline_OBJECTS = outline.$(OBJEXT) outline_OBJECTS = $(am_outline_OBJECTS) outline_DEPENDENCIES = ../lib/libexpat.la @@ -166,7 +173,8 @@ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/conftools/depcomp am__maybe_remake_depfiles = depfiles -am__depfiles_remade = ./$(DEPDIR)/elements.Po ./$(DEPDIR)/outline.Po +am__depfiles_remade = ./$(DEPDIR)/element_declarations.Po \ + ./$(DEPDIR)/elements.Po ./$(DEPDIR)/outline.Po am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -186,8 +194,10 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = -SOURCES = $(elements_SOURCES) $(outline_SOURCES) -DIST_SOURCES = $(elements_SOURCES) $(outline_SOURCES) +SOURCES = $(element_declarations_SOURCES) $(elements_SOURCES) \ + $(outline_SOURCES) +DIST_SOURCES = $(element_declarations_SOURCES) $(elements_SOURCES) \ + $(outline_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -210,8 +220,6 @@ am__define_uniq_tagged_files = \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` -ETAGS = etags -CTAGS = ctags am__DIST_COMMON = $(srcdir)/Makefile.in \ $(top_srcdir)/conftools/depcomp DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -231,8 +239,10 @@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ -CPP = @CPP@ +CMAKE_SHARED_LIBRARY_PREFIX = @CMAKE_SHARED_LIBRARY_PREFIX@ CPPFLAGS = @CPPFLAGS@ +CSCOPE = @CSCOPE@ +CTAGS = @CTAGS@ CXX = @CXX@ CXXCPP = @CXXCPP@ CXXDEPMODE = @CXXDEPMODE@ @@ -248,10 +258,20 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ +ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ +EXPAT_ATTR_INFO = @EXPAT_ATTR_INFO@ +EXPAT_CHAR_TYPE = @EXPAT_CHAR_TYPE@ +EXPAT_CONTEXT_BYTES = @EXPAT_CONTEXT_BYTES@ +EXPAT_DTD = @EXPAT_DTD@ +EXPAT_LARGE_SIZE = @EXPAT_LARGE_SIZE@ +EXPAT_MIN_SIZE = @EXPAT_MIN_SIZE@ +EXPAT_NS = @EXPAT_NS@ FGREP = @FGREP@ +FILECMD = @FILECMD@ FILEMAP = @FILEMAP@ GREP = @GREP@ +HAVE_CXX11 = @HAVE_CXX11@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -261,6 +281,8 @@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBAGE = @LIBAGE@ LIBCURRENT = @LIBCURRENT@ +LIBDIR_BASENAME = @LIBDIR_BASENAME@ +LIBM = @LIBM@ LIBOBJS = @LIBOBJS@ LIBREVISION = @LIBREVISION@ LIBS = @LIBS@ @@ -269,6 +291,7 @@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ @@ -290,9 +313,12 @@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SIZEOF_VOID_P = @SIZEOF_VOID_P@ +SO_MAJOR = @SO_MAJOR@ +SO_MINOR = @SO_MINOR@ +SO_PATCH = @SO_PATCH@ STRIP = @STRIP@ VERSION = @VERSION@ -_EXPAT_OUTPUT_NAME = @_EXPAT_OUTPUT_NAME@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ @@ -347,6 +373,8 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ +element_declarations_SOURCES = element_declarations.c +element_declarations_LDADD = ../lib/libexpat.la elements_SOURCES = elements.c elements_LDADD = ../lib/libexpat.la outline_SOURCES = outline.c @@ -355,7 +383,7 @@ all: all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ @@ -379,9 +407,9 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(top_srcdir)/configure: $(am__configure_deps) +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): $(am__aclocal_m4_deps) +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): @@ -394,6 +422,10 @@ clean-noinstPROGRAMS: echo " rm -f" $$list; \ rm -f $$list +element_declarations$(EXEEXT): $(element_declarations_OBJECTS) $(element_declarations_DEPENDENCIES) $(EXTRA_element_declarations_DEPENDENCIES) + @rm -f element_declarations$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(element_declarations_OBJECTS) $(element_declarations_LDADD) $(LIBS) + elements$(EXEEXT): $(elements_OBJECTS) $(elements_DEPENDENCIES) $(EXTRA_elements_DEPENDENCIES) @rm -f elements$(EXEEXT) $(AM_V_CCLD)$(LINK) $(elements_OBJECTS) $(elements_LDADD) $(LIBS) @@ -408,6 +440,7 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/element_declarations.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elements.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/outline.Po@am__quote@ # am--include-marker @@ -495,7 +528,6 @@ cscopelist-am: $(am__tagged_files) distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am @@ -569,7 +601,8 @@ clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \ mostlyclean-am distclean: distclean-am - -rm -f ./$(DEPDIR)/elements.Po + -rm -f ./$(DEPDIR)/element_declarations.Po + -rm -f ./$(DEPDIR)/elements.Po -rm -f ./$(DEPDIR)/outline.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ @@ -616,7 +649,8 @@ install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am - -rm -f ./$(DEPDIR)/elements.Po + -rm -f ./$(DEPDIR)/element_declarations.Po + -rm -f ./$(DEPDIR)/elements.Po -rm -f ./$(DEPDIR)/outline.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic diff --git a/3rdparty/expat/examples/element_declarations.c b/3rdparty/expat/examples/element_declarations.c new file mode 100644 index 00000000000..d644b2ffa5e --- /dev/null +++ b/3rdparty/expat/examples/element_declarations.c @@ -0,0 +1,235 @@ +/* Read an XML document from standard input and print + element declarations (if any) to standard output. + It must be used with Expat compiled for UTF-8 output. + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 1997-2000 Thai Open Source Software Center Ltd + Copyright (c) 2001-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2004-2006 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2019 Zhongyuan Zhou <zhouzhongyuan@huawei.com> + Copyright (c) 2024 Hanno Böck <hanno@gentoo.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <expat.h> + +#ifdef XML_LARGE_SIZE +# define XML_FMT_INT_MOD "ll" +#else +# define XML_FMT_INT_MOD "l" +#endif + +#ifdef XML_UNICODE_WCHAR_T +# define XML_FMT_STR "ls" +#else +# define XML_FMT_STR "s" +#endif + +// While traversing the XML_Content tree, we avoid recursion +// to not be vulnerable to a denial of service attack. +typedef struct StackStruct { + const XML_Content *model; + unsigned level; + struct StackStruct *prev; +} Stack; + +static Stack * +stackPushMalloc(Stack *stackTop, const XML_Content *model, unsigned level) { + Stack *const newStackTop = malloc(sizeof(Stack)); + if (! newStackTop) { + return NULL; + } + newStackTop->model = model; + newStackTop->level = level; + newStackTop->prev = stackTop; + return newStackTop; +} + +static Stack * +stackPopFree(Stack *stackTop) { + Stack *const newStackTop = stackTop->prev; + free(stackTop); + return newStackTop; +} + +static char * +contentTypeName(enum XML_Content_Type contentType) { + switch (contentType) { + case XML_CTYPE_EMPTY: + return "EMPTY"; + case XML_CTYPE_ANY: + return "ANY"; + case XML_CTYPE_MIXED: + return "MIXED"; + case XML_CTYPE_NAME: + return "NAME"; + case XML_CTYPE_CHOICE: + return "CHOICE"; + case XML_CTYPE_SEQ: + return "SEQ"; + default: + return "???"; + } +} + +static char * +contentQuantName(enum XML_Content_Quant contentQuant) { + switch (contentQuant) { + case XML_CQUANT_NONE: + return "NONE"; + case XML_CQUANT_OPT: + return "OPT"; + case XML_CQUANT_REP: + return "REP"; + case XML_CQUANT_PLUS: + return "PLUS"; + default: + return "???"; + } +} + +static void +dumpContentModelElement(const XML_Content *model, unsigned level, + const XML_Content *root) { + // Indent + unsigned u = 0; + for (; u < level; u++) { + printf(" "); + } + + // Node + printf("[%u] type=%s(%u), quant=%s(%u)", (unsigned)(model - root), + contentTypeName(model->type), (unsigned int)model->type, + contentQuantName(model->quant), (unsigned int)model->quant); + if (model->name) { + printf(", name=\"%" XML_FMT_STR "\"", model->name); + } else { + printf(", name=NULL"); + } + printf(", numchildren=%u", model->numchildren); + printf("\n"); +} + +static bool +dumpContentModel(const XML_Char *name, const XML_Content *root) { + printf("Element \"%" XML_FMT_STR "\":\n", name); + Stack *stackTop = stackPushMalloc(NULL, root, 1); + if (! stackTop) { + return false; + } + + while (stackTop) { + const XML_Content *const model = stackTop->model; + const unsigned level = stackTop->level; + + dumpContentModelElement(model, level, root); + + stackTop = stackPopFree(stackTop); + + for (size_t u = model->numchildren; u >= 1; u--) { + Stack *const newStackTop + = stackPushMalloc(stackTop, model->children + (u - 1), level + 1); + if (! newStackTop) { + // We ran out of memory, so let's free all memory allocated + // earlier in this function, to be leak-clean: + while (stackTop != NULL) { + stackTop = stackPopFree(stackTop); + } + return false; + } + stackTop = newStackTop; + } + } + + printf("\n"); + return true; +} + +static void XMLCALL +handleElementDeclaration(void *userData, const XML_Char *name, + XML_Content *model) { + XML_Parser parser = (XML_Parser)userData; + const bool success = dumpContentModel(name, model); + XML_FreeContentModel(parser, model); + if (! success) { + XML_StopParser(parser, /* resumable= */ XML_FALSE); + } +} + +int +main(void) { + XML_Parser parser = XML_ParserCreate(NULL); + int done; + + if (! parser) { + fprintf(stderr, "Couldn't allocate memory for parser\n"); + return 1; + } + + XML_SetUserData(parser, parser); + XML_SetElementDeclHandler(parser, handleElementDeclaration); + + do { + void *const buf = XML_GetBuffer(parser, BUFSIZ); + if (! buf) { + fprintf(stderr, "Couldn't allocate memory for buffer\n"); + XML_ParserFree(parser); + return 1; + } + + const size_t len = fread(buf, 1, BUFSIZ, stdin); + + if (ferror(stdin)) { + fprintf(stderr, "Read error\n"); + XML_ParserFree(parser); + return 1; + } + + done = feof(stdin); + + if (XML_ParseBuffer(parser, (int)len, done) == XML_STATUS_ERROR) { + enum XML_Error errorCode = XML_GetErrorCode(parser); + if (errorCode == XML_ERROR_ABORTED) { + errorCode = XML_ERROR_NO_MEMORY; + } + fprintf(stderr, + "Parse error at line %" XML_FMT_INT_MOD "u:\n%" XML_FMT_STR "\n", + XML_GetCurrentLineNumber(parser), XML_ErrorString(errorCode)); + XML_ParserFree(parser); + return 1; + } + } while (! done); + + XML_ParserFree(parser); + return 0; +} diff --git a/3rdparty/expat/examples/elements.c b/3rdparty/expat/examples/elements.c index eb0c729bff1..e5fb850d501 100644 --- a/3rdparty/expat/examples/elements.c +++ b/3rdparty/expat/examples/elements.c @@ -11,7 +11,12 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2001-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2004-2006 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2019 Zhongyuan Zhou <zhouzhongyuan@huawei.com> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -44,7 +49,6 @@ #endif #ifdef XML_UNICODE_WCHAR_T -# include <wchar.h> # define XML_FMT_STR "ls" #else # define XML_FMT_STR "s" @@ -53,7 +57,7 @@ static void XMLCALL startElement(void *userData, const XML_Char *name, const XML_Char **atts) { int i; - int *depthPtr = (int *)userData; + int *const depthPtr = (int *)userData; (void)atts; for (i = 0; i < *depthPtr; i++) @@ -64,34 +68,54 @@ startElement(void *userData, const XML_Char *name, const XML_Char **atts) { static void XMLCALL endElement(void *userData, const XML_Char *name) { - int *depthPtr = (int *)userData; + int *const depthPtr = (int *)userData; (void)name; *depthPtr -= 1; } int -main(int argc, char *argv[]) { - char buf[BUFSIZ]; +main(void) { XML_Parser parser = XML_ParserCreate(NULL); int done; int depth = 0; - (void)argc; - (void)argv; + + if (! parser) { + fprintf(stderr, "Couldn't allocate memory for parser\n"); + return 1; + } XML_SetUserData(parser, &depth); XML_SetElementHandler(parser, startElement, endElement); + do { - size_t len = fread(buf, 1, sizeof(buf), stdin); - done = len < sizeof(buf); - if (XML_Parse(parser, buf, (int)len, done) == XML_STATUS_ERROR) { - fprintf(stderr, "%" XML_FMT_STR " at line %" XML_FMT_INT_MOD "u\n", - XML_ErrorString(XML_GetErrorCode(parser)), - XML_GetCurrentLineNumber(parser)); + void *const buf = XML_GetBuffer(parser, BUFSIZ); + if (! buf) { + fprintf(stderr, "Couldn't allocate memory for buffer\n"); + XML_ParserFree(parser); + return 1; + } + + const size_t len = fread(buf, 1, BUFSIZ, stdin); + + if (ferror(stdin)) { + fprintf(stderr, "Read error\n"); + XML_ParserFree(parser); + return 1; + } + + done = feof(stdin); + + if (XML_ParseBuffer(parser, (int)len, done) == XML_STATUS_ERROR) { + fprintf(stderr, + "Parse error at line %" XML_FMT_INT_MOD "u:\n%" XML_FMT_STR "\n", + XML_GetCurrentLineNumber(parser), + XML_ErrorString(XML_GetErrorCode(parser))); XML_ParserFree(parser); return 1; } } while (! done); + XML_ParserFree(parser); return 0; } diff --git a/3rdparty/expat/examples/outline.c b/3rdparty/expat/examples/outline.c index d996b8e3a8d..d2df914fedb 100644 --- a/3rdparty/expat/examples/outline.c +++ b/3rdparty/expat/examples/outline.c @@ -8,8 +8,12 @@ \___/_/\_\ .__/ \__,_|\__| |_| XML parser - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2001-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2006 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -47,73 +51,74 @@ # define XML_FMT_STR "s" #endif -#define BUFFSIZE 8192 - -char Buff[BUFFSIZE]; - -int Depth; - static void XMLCALL -start(void *data, const XML_Char *el, const XML_Char **attr) { +startElement(void *userData, const XML_Char *name, const XML_Char **atts) { int i; - (void)data; + int *const depthPtr = (int *)userData; - for (i = 0; i < Depth; i++) + for (i = 0; i < *depthPtr; i++) printf(" "); - printf("%" XML_FMT_STR, el); + printf("%" XML_FMT_STR, name); - for (i = 0; attr[i]; i += 2) { - printf(" %" XML_FMT_STR "='%" XML_FMT_STR "'", attr[i], attr[i + 1]); + for (i = 0; atts[i]; i += 2) { + printf(" %" XML_FMT_STR "='%" XML_FMT_STR "'", atts[i], atts[i + 1]); } printf("\n"); - Depth++; + *depthPtr += 1; } static void XMLCALL -end(void *data, const XML_Char *el) { - (void)data; - (void)el; +endElement(void *userData, const XML_Char *name) { + int *const depthPtr = (int *)userData; + (void)name; - Depth--; + *depthPtr -= 1; } int -main(int argc, char *argv[]) { - XML_Parser p = XML_ParserCreate(NULL); - (void)argc; - (void)argv; +main(void) { + XML_Parser parser = XML_ParserCreate(NULL); + int done; + int depth = 0; - if (! p) { + if (! parser) { fprintf(stderr, "Couldn't allocate memory for parser\n"); - exit(-1); + return 1; } - XML_SetElementHandler(p, start, end); + XML_SetUserData(parser, &depth); + XML_SetElementHandler(parser, startElement, endElement); - for (;;) { - int done; - int len; + do { + void *const buf = XML_GetBuffer(parser, BUFSIZ); + if (! buf) { + fprintf(stderr, "Couldn't allocate memory for buffer\n"); + XML_ParserFree(parser); + return 1; + } + + const size_t len = fread(buf, 1, BUFSIZ, stdin); - len = (int)fread(Buff, 1, BUFFSIZE, stdin); if (ferror(stdin)) { fprintf(stderr, "Read error\n"); - exit(-1); + XML_ParserFree(parser); + return 1; } + done = feof(stdin); - if (XML_Parse(p, Buff, len, done) == XML_STATUS_ERROR) { + if (XML_ParseBuffer(parser, (int)len, done) == XML_STATUS_ERROR) { fprintf(stderr, "Parse error at line %" XML_FMT_INT_MOD "u:\n%" XML_FMT_STR "\n", - XML_GetCurrentLineNumber(p), - XML_ErrorString(XML_GetErrorCode(p))); - exit(-1); + XML_GetCurrentLineNumber(parser), + XML_ErrorString(XML_GetErrorCode(parser))); + XML_ParserFree(parser); + return 1; } + } while (! done); - if (done) - break; - } - XML_ParserFree(p); + XML_ParserFree(parser); return 0; } diff --git a/3rdparty/expat/expat.pc.cmake b/3rdparty/expat/expat.pc.cmake new file mode 100644 index 00000000000..56da413791e --- /dev/null +++ b/3rdparty/expat/expat.pc.cmake @@ -0,0 +1,13 @@ +prefix=$<TARGET_PROPERTY:expat,pkgconfig_prefix> +exec_prefix=$<TARGET_PROPERTY:expat,pkgconfig_exec_prefix> +libdir=$<TARGET_PROPERTY:expat,pkgconfig_libdir> +includedir=$<TARGET_PROPERTY:expat,pkgconfig_includedir> + +Name: $<TARGET_PROPERTY:expat,pkgconfig_$<LOWER_CASE:$<CONFIG>>_name> +Version: $<TARGET_PROPERTY:expat,pkgconfig_version> +Description: expat XML parser +URL: https://libexpat.github.io/ +Libs: -L${libdir} -l$<TARGET_PROPERTY:expat,pkgconfig_$<LOWER_CASE:$<CONFIG>>_output_name> +Libs.private: $<TARGET_PROPERTY:expat,pkgconfig_libm> +Cflags: -I${includedir} +Cflags.private: -DXML_STATIC diff --git a/3rdparty/expat/expat.pc.in b/3rdparty/expat/expat.pc.in index bdfa47f8457..a53ab118729 100644 --- a/3rdparty/expat/expat.pc.in +++ b/3rdparty/expat/expat.pc.in @@ -3,9 +3,11 @@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ -Name: @_EXPAT_OUTPUT_NAME@ +Name: @PACKAGE_NAME@ Version: @PACKAGE_VERSION@ Description: expat XML parser -URL: http://www.libexpat.org -Libs: -L${libdir} -l@_EXPAT_OUTPUT_NAME@ +URL: https://libexpat.github.io/ +Libs: -L${libdir} -l@PACKAGE_NAME@ +Libs.private: @LIBM@ Cflags: -I${includedir} +Cflags.private: -DXML_STATIC diff --git a/3rdparty/expat/expat_config.h.cmake b/3rdparty/expat/expat_config.h.cmake index 173fed168c1..43df67aefde 100644 --- a/3rdparty/expat/expat_config.h.cmake +++ b/3rdparty/expat/expat_config.h.cmake @@ -1,5 +1,8 @@ /* expat_config.h.cmake. Based upon generated expat_config.h.in. */ +#ifndef EXPAT_CONFIG_H +#define EXPAT_CONFIG_H 1 + /* 1234 = LIL_ENDIAN, 4321 = BIGENDIAN */ #cmakedefine BYTEORDER @BYTEORDER@ @@ -79,7 +82,9 @@ #cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@" /* Define to 1 if you have the ANSI C header files. */ +#ifndef STDC_HEADERS #cmakedefine STDC_HEADERS +#endif /* whether byteorder is bigendian */ #cmakedefine WORDS_BIGENDIAN @@ -89,17 +94,20 @@ #cmakedefine XML_ATTR_INFO /* Define to specify how much context to retain around the current parse - point. */ -#cmakedefine XML_CONTEXT_BYTES @XML_CONTEXT_BYTES@ + point, 0 to disable. */ +#define XML_CONTEXT_BYTES @XML_CONTEXT_BYTES@ #if ! defined(_WIN32) /* Define to include code reading entropy from `/dev/urandom'. */ - #cmakedefine XML_DEV_URANDOM +#cmakedefine XML_DEV_URANDOM #endif /* Define to make parameter entity parsing functionality available. */ #cmakedefine XML_DTD +/* Define as 1/0 to enable/disable support for general entities. */ +#define XML_GE @XML_GE@ + /* Define to make XML Namespaces functionality available. */ #cmakedefine XML_NS @@ -109,7 +117,6 @@ #endif /* Define to `long' if <sys/types.h> does not define. */ -#cmakedefine off_t @OFF_T@ +#cmakedefine off_t @off_t@ -/* Define to `unsigned' if <sys/types.h> does not define. */ -#cmakedefine size_t @SIZE_T@ +#endif // ndef EXPAT_CONFIG_H diff --git a/3rdparty/expat/expat_config.h.in b/3rdparty/expat/expat_config.h.in index 59207b42e41..67ef89c7171 100644 --- a/3rdparty/expat/expat_config.h.in +++ b/3rdparty/expat/expat_config.h.in @@ -1,5 +1,8 @@ /* expat_config.h.in. Generated from configure.ac by autoheader. */ +#ifndef EXPAT_CONFIG_H +#define EXPAT_CONFIG_H 1 + /* Define if building universal (internal helper macro) */ #undef AC_APPLE_UNIVERSAL_BUILD @@ -12,6 +15,9 @@ /* Define to 1 if you have the `arc4random_buf' function. */ #undef HAVE_ARC4RANDOM_BUF +/* define if the compiler supports basic C++11 syntax */ +#undef HAVE_CXX11 + /* Define to 1 if you have the <dlfcn.h> header file. */ #undef HAVE_DLFCN_H @@ -30,15 +36,15 @@ /* Define to 1 if you have the `bsd' library (-lbsd). */ #undef HAVE_LIBBSD -/* Define to 1 if you have the <memory.h> header file. */ -#undef HAVE_MEMORY_H - /* Define to 1 if you have a working `mmap' system call. */ #undef HAVE_MMAP /* Define to 1 if you have the <stdint.h> header file. */ #undef HAVE_STDINT_H +/* Define to 1 if you have the <stdio.h> header file. */ +#undef HAVE_STDIO_H + /* Define to 1 if you have the <stdlib.h> header file. */ #undef HAVE_STDLIB_H @@ -87,7 +93,9 @@ /* Define to the version of this package. */ #undef PACKAGE_VERSION -/* Define to 1 if you have the ANSI C header files. */ +/* Define to 1 if all of the C90 standard headers exist (not just the ones + required in a freestanding environment). This macro is provided for + backward compatibility; new code need not use it. */ #undef STDC_HEADERS /* Version number of package */ @@ -110,7 +118,7 @@ #undef XML_ATTR_INFO /* Define to specify how much context to retain around the current parse - point. */ + point, 0 to disable. */ #undef XML_CONTEXT_BYTES /* Define to include code reading entropy from `/dev/urandom'. */ @@ -119,6 +127,9 @@ /* Define to make parameter entity parsing functionality available. */ #undef XML_DTD +/* Define as 1/0 to enable/disable support for general entities. */ +#undef XML_GE + /* Define to make XML Namespaces functionality available. */ #undef XML_NS @@ -128,5 +139,4 @@ /* Define to `long int' if <sys/types.h> does not define. */ #undef off_t -/* Define to `unsigned int' if <sys/types.h> does not define. */ -#undef size_t +#endif // ndef EXPAT_CONFIG_H diff --git a/3rdparty/expat/fix-xmltest-log.sh b/3rdparty/expat/fix-xmltest-log.sh index c143e93cf20..18cc6f642d2 100755 --- a/3rdparty/expat/fix-xmltest-log.sh +++ b/3rdparty/expat/fix-xmltest-log.sh @@ -6,7 +6,8 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2019 Expat development team +# Copyright (c) 2019-2022 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2024 Dag-Erling Smørgrav <des@des.dev> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -32,17 +33,18 @@ set -e filename="${1:-tests/xmltest.log}" -dos2unix "${filename}" - -tempfile="$(mktemp)" -sed \ +sed -i.bak \ + -e '# convert DOS line endings to Unix without resorting to dos2unix' \ + -e $'s/\r//' \ + \ -e 's/^wine: Call .* msvcrt\.dll\._wperror, aborting$/ibm49i02.dtd: No such file or directory/' \ \ -e '/^wine: /d' \ -e '/^Application tried to create a window, but no driver could be loaded.$/d' \ -e '/^Make sure that your X server is running and that $DISPLAY is set correctly.$/d' \ -e '/^err:systray:initialize_systray Could not create tray window$/d' \ + -e '/^[0-9a-f]\+:err:/d' \ + -e '/^wine client error:/d' \ -e '/^In ibm\/invalid\/P49\/: Unhandled exception: unimplemented .\+/d' \ \ - "${filename}" > "${tempfile}" -mv "${tempfile}" "${filename}" + "${filename}" diff --git a/3rdparty/expat/fuzz/xml_parse_fuzzer.c b/3rdparty/expat/fuzz/xml_parse_fuzzer.c new file mode 100644 index 00000000000..a7e8414ce35 --- /dev/null +++ b/3rdparty/expat/fuzz/xml_parse_fuzzer.c @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <assert.h> +#include <stdint.h> + +#include "expat.h" +#include "siphash.h" + +// Macros to convert preprocessor macros to string literals. See +// https://gcc.gnu.org/onlinedocs/gcc-3.4.3/cpp/Stringification.html +#define xstr(s) str(s) +#define str(s) #s + +// The encoder type that we wish to fuzz should come from the compile-time +// definition `ENCODING_FOR_FUZZING`. This allows us to have a separate fuzzer +// binary for +#ifndef ENCODING_FOR_FUZZING +# error "ENCODING_FOR_FUZZING was not provided to this fuzz target." +#endif + +// 16-byte deterministic hash key. +static unsigned char hash_key[16] = "FUZZING IS FUN!"; + +static void XMLCALL +start(void *userData, const XML_Char *name, const XML_Char **atts) { + (void)userData; + (void)name; + (void)atts; +} +static void XMLCALL +end(void *userData, const XML_Char *name) { + (void)userData; + (void)name; +} + +static void XMLCALL +may_stop_character_handler(void *userData, const XML_Char *s, int len) { + XML_Parser parser = (XML_Parser)userData; + if (len > 1 && s[0] == 's') { + XML_StopParser(parser, s[1] == 'r' ? XML_FALSE : XML_TRUE); + } +} + +static void +ParseOneInput(XML_Parser p, const uint8_t *data, size_t size) { + // Set the hash salt using siphash to generate a deterministic hash. + struct sipkey *key = sip_keyof(hash_key); + XML_SetHashSalt(p, (unsigned long)siphash24(data, size, key)); + (void)sip24_valid; + + XML_SetUserData(p, p); + XML_SetElementHandler(p, start, end); + XML_SetCharacterDataHandler(p, may_stop_character_handler); + XML_Parse(p, (const XML_Char *)data, size, 0); + if (XML_Parse(p, (const XML_Char *)data, size, 1) == XML_STATUS_ERROR) { + XML_ErrorString(XML_GetErrorCode(p)); + } + XML_GetCurrentLineNumber(p); + if (size % 2) { + XML_ParserReset(p, NULL); + } +} + +int +LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + XML_Parser parentParser = XML_ParserCreate(xstr(ENCODING_FOR_FUZZING)); + assert(parentParser); + ParseOneInput(parentParser, data, size); + // not freed yet, but used later and freed then + + XML_Parser namespaceParser = XML_ParserCreateNS(NULL, '!'); + assert(namespaceParser); + ParseOneInput(namespaceParser, data, size); + XML_ParserFree(namespaceParser); + + XML_Parser externalEntityParser + = XML_ExternalEntityParserCreate(parentParser, "e1", NULL); + assert(externalEntityParser); + ParseOneInput(externalEntityParser, data, size); + XML_ParserFree(externalEntityParser); + + XML_Parser externalDtdParser + = XML_ExternalEntityParserCreate(parentParser, NULL, NULL); + assert(externalDtdParser); + ParseOneInput(externalDtdParser, data, size); + XML_ParserFree(externalDtdParser); + + // finally frees this parser which served as parent + XML_ParserFree(parentParser); + return 0; +} diff --git a/3rdparty/expat/fuzz/xml_parsebuffer_fuzzer.c b/3rdparty/expat/fuzz/xml_parsebuffer_fuzzer.c new file mode 100644 index 00000000000..0327aa9f952 --- /dev/null +++ b/3rdparty/expat/fuzz/xml_parsebuffer_fuzzer.c @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <assert.h> +#include <stdint.h> +#include <string.h> + +#include "expat.h" +#include "siphash.h" + +// Macros to convert preprocessor macros to string literals. See +// https://gcc.gnu.org/onlinedocs/gcc-3.4.3/cpp/Stringification.html +#define xstr(s) str(s) +#define str(s) #s + +// The encoder type that we wish to fuzz should come from the compile-time +// definition `ENCODING_FOR_FUZZING`. This allows us to have a separate fuzzer +// binary for +#ifndef ENCODING_FOR_FUZZING +# error "ENCODING_FOR_FUZZING was not provided to this fuzz target." +#endif + +// 16-byte deterministic hash key. +static unsigned char hash_key[16] = "FUZZING IS FUN!"; + +static void XMLCALL +start(void *userData, const XML_Char *name, const XML_Char **atts) { + (void)userData; + (void)name; + (void)atts; +} +static void XMLCALL +end(void *userData, const XML_Char *name) { + (void)userData; + (void)name; +} + +static void XMLCALL +may_stop_character_handler(void *userData, const XML_Char *s, int len) { + XML_Parser parser = (XML_Parser)userData; + if (len > 1 && s[0] == 's') { + XML_StopParser(parser, s[1] == 'r' ? XML_FALSE : XML_TRUE); + } +} + +static void +ParseOneInput(XML_Parser p, const uint8_t *data, size_t size) { + // Set the hash salt using siphash to generate a deterministic hash. + struct sipkey *key = sip_keyof(hash_key); + XML_SetHashSalt(p, (unsigned long)siphash24(data, size, key)); + (void)sip24_valid; + + XML_SetUserData(p, p); + XML_SetElementHandler(p, start, end); + XML_SetCharacterDataHandler(p, may_stop_character_handler); + void *buf = XML_GetBuffer(p, size); + assert(buf); + memcpy(buf, data, size); + XML_ParseBuffer(p, size, 0); + buf = XML_GetBuffer(p, size); + if (buf == NULL) { + return; + } + memcpy(buf, data, size); + if (XML_ParseBuffer(p, size, 1) == XML_STATUS_ERROR) { + XML_ErrorString(XML_GetErrorCode(p)); + } + XML_GetCurrentLineNumber(p); + if (size % 2) { + XML_ParserReset(p, NULL); + } +} + +int +LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + if (size == 0) + return 0; + + XML_Parser parentParser = XML_ParserCreate(xstr(ENCODING_FOR_FUZZING)); + assert(parentParser); + ParseOneInput(parentParser, data, size); + // not freed yet, but used later and freed then + + XML_Parser namespaceParser = XML_ParserCreateNS(NULL, '!'); + assert(namespaceParser); + ParseOneInput(namespaceParser, data, size); + XML_ParserFree(namespaceParser); + + XML_Parser externalEntityParser + = XML_ExternalEntityParserCreate(parentParser, "e1", NULL); + assert(externalEntityParser); + ParseOneInput(externalEntityParser, data, size); + XML_ParserFree(externalEntityParser); + + XML_Parser externalDtdParser + = XML_ExternalEntityParserCreate(parentParser, NULL, NULL); + assert(externalDtdParser); + ParseOneInput(externalDtdParser, data, size); + XML_ParserFree(externalDtdParser); + + // finally frees this parser which served as parent + XML_ParserFree(parentParser); + return 0; +} diff --git a/3rdparty/expat/lib/Makefile.am b/3rdparty/expat/lib/Makefile.am index 05343e235d8..1958f322f31 100644 --- a/3rdparty/expat/lib/Makefile.am +++ b/3rdparty/expat/lib/Makefile.am @@ -6,7 +6,9 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2017 Expat development team +# Copyright (c) 2017-2024 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2017 Tomasz KÅ‚oczko <kloczek@fedoraproject.org> +# Copyright (c) 2019 David Loffredo <loffredo@steptools.com> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -34,9 +36,13 @@ include_HEADERS = \ expat_external.h lib_LTLIBRARIES = libexpat.la +if WITH_TESTS +noinst_LTLIBRARIES = libtestpat.la +endif libexpat_la_LDFLAGS = \ @AM_LDFLAGS@ \ + @LIBM@ \ -no-undefined \ -version-info @LIBCURRENT@:@LIBREVISION@:@LIBAGE@ @@ -45,6 +51,12 @@ libexpat_la_SOURCES = \ xmltok.c \ xmlrole.c +if WITH_TESTS +libtestpat_la_CPPFLAGS = -DXML_TESTING + +libtestpat_la_SOURCES = $(libexpat_la_SOURCES) +endif + doc_DATA = \ ../AUTHORS \ ../Changes @@ -63,8 +75,7 @@ EXTRA_DIST = \ iasciitab.h \ internal.h \ latin1tab.h \ - libexpat.def \ - libexpatw.def \ + libexpat.def.cmake \ nametab.h \ siphash.h \ utf8tab.h \ diff --git a/3rdparty/expat/lib/Makefile.in b/3rdparty/expat/lib/Makefile.in index 10f20d5533d..1a97e85fc41 100644 --- a/3rdparty/expat/lib/Makefile.in +++ b/3rdparty/expat/lib/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2020 Free Software Foundation, Inc. +# Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -22,7 +22,9 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2017 Expat development team +# Copyright (c) 2017-2024 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2017 Tomasz KÅ‚oczko <kloczek@fedoraproject.org> +# Copyright (c) 2019 David Loffredo <loffredo@steptools.com> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -133,6 +135,8 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/conftools/ax-append-compile-flags.m4 \ $(top_srcdir)/conftools/ax-append-link-flags.m4 \ $(top_srcdir)/conftools/expatcfg-compiler-supports-visibility.m4 \ + $(top_srcdir)/conftools/ax-cxx-compile-stdcxx.m4 \ + $(top_srcdir)/conftools/ax-cxx-compile-stdcxx-11.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) @@ -171,7 +175,7 @@ am__uninstall_files_from_dir = { \ } am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(docdir)" \ "$(DESTDIR)$(includedir)" -LTLIBRARIES = $(lib_LTLIBRARIES) +LTLIBRARIES = $(lib_LTLIBRARIES) $(noinst_LTLIBRARIES) libexpat_la_LIBADD = am_libexpat_la_OBJECTS = xmlparse.lo xmltok.lo xmlrole.lo libexpat_la_OBJECTS = $(am_libexpat_la_OBJECTS) @@ -182,6 +186,13 @@ am__v_lt_1 = libexpat_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(libexpat_la_LDFLAGS) $(LDFLAGS) -o $@ +libtestpat_la_LIBADD = +am__libtestpat_la_SOURCES_DIST = xmlparse.c xmltok.c xmlrole.c +am__objects_1 = libtestpat_la-xmlparse.lo libtestpat_la-xmltok.lo \ + libtestpat_la-xmlrole.lo +@WITH_TESTS_TRUE@am_libtestpat_la_OBJECTS = $(am__objects_1) +libtestpat_la_OBJECTS = $(am_libtestpat_la_OBJECTS) +@WITH_TESTS_TRUE@am_libtestpat_la_rpath = AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -197,8 +208,10 @@ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/conftools/depcomp am__maybe_remake_depfiles = depfiles -am__depfiles_remade = ./$(DEPDIR)/xmlparse.Plo ./$(DEPDIR)/xmlrole.Plo \ - ./$(DEPDIR)/xmltok.Plo +am__depfiles_remade = ./$(DEPDIR)/libtestpat_la-xmlparse.Plo \ + ./$(DEPDIR)/libtestpat_la-xmlrole.Plo \ + ./$(DEPDIR)/libtestpat_la-xmltok.Plo ./$(DEPDIR)/xmlparse.Plo \ + ./$(DEPDIR)/xmlrole.Plo ./$(DEPDIR)/xmltok.Plo am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -218,8 +231,9 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = -SOURCES = $(libexpat_la_SOURCES) -DIST_SOURCES = $(libexpat_la_SOURCES) +SOURCES = $(libexpat_la_SOURCES) $(libtestpat_la_SOURCES) +DIST_SOURCES = $(libexpat_la_SOURCES) \ + $(am__libtestpat_la_SOURCES_DIST) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -244,8 +258,6 @@ am__define_uniq_tagged_files = \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` -ETAGS = etags -CTAGS = ctags am__DIST_COMMON = $(srcdir)/Makefile.in \ $(top_srcdir)/conftools/depcomp DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -265,8 +277,10 @@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ -CPP = @CPP@ +CMAKE_SHARED_LIBRARY_PREFIX = @CMAKE_SHARED_LIBRARY_PREFIX@ CPPFLAGS = @CPPFLAGS@ +CSCOPE = @CSCOPE@ +CTAGS = @CTAGS@ CXX = @CXX@ CXXCPP = @CXXCPP@ CXXDEPMODE = @CXXDEPMODE@ @@ -282,10 +296,20 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ +ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ +EXPAT_ATTR_INFO = @EXPAT_ATTR_INFO@ +EXPAT_CHAR_TYPE = @EXPAT_CHAR_TYPE@ +EXPAT_CONTEXT_BYTES = @EXPAT_CONTEXT_BYTES@ +EXPAT_DTD = @EXPAT_DTD@ +EXPAT_LARGE_SIZE = @EXPAT_LARGE_SIZE@ +EXPAT_MIN_SIZE = @EXPAT_MIN_SIZE@ +EXPAT_NS = @EXPAT_NS@ FGREP = @FGREP@ +FILECMD = @FILECMD@ FILEMAP = @FILEMAP@ GREP = @GREP@ +HAVE_CXX11 = @HAVE_CXX11@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -295,6 +319,8 @@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBAGE = @LIBAGE@ LIBCURRENT = @LIBCURRENT@ +LIBDIR_BASENAME = @LIBDIR_BASENAME@ +LIBM = @LIBM@ LIBOBJS = @LIBOBJS@ LIBREVISION = @LIBREVISION@ LIBS = @LIBS@ @@ -303,6 +329,7 @@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ @@ -324,9 +351,12 @@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SIZEOF_VOID_P = @SIZEOF_VOID_P@ +SO_MAJOR = @SO_MAJOR@ +SO_MINOR = @SO_MINOR@ +SO_PATCH = @SO_PATCH@ STRIP = @STRIP@ VERSION = @VERSION@ -_EXPAT_OUTPUT_NAME = @_EXPAT_OUTPUT_NAME@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ @@ -387,8 +417,10 @@ include_HEADERS = \ expat_external.h lib_LTLIBRARIES = libexpat.la +@WITH_TESTS_TRUE@noinst_LTLIBRARIES = libtestpat.la libexpat_la_LDFLAGS = \ @AM_LDFLAGS@ \ + @LIBM@ \ -no-undefined \ -version-info @LIBCURRENT@:@LIBREVISION@:@LIBAGE@ @@ -397,6 +429,8 @@ libexpat_la_SOURCES = \ xmltok.c \ xmlrole.c +@WITH_TESTS_TRUE@libtestpat_la_CPPFLAGS = -DXML_TESTING +@WITH_TESTS_TRUE@libtestpat_la_SOURCES = $(libexpat_la_SOURCES) doc_DATA = \ ../AUTHORS \ ../Changes @@ -409,8 +443,7 @@ EXTRA_DIST = \ iasciitab.h \ internal.h \ latin1tab.h \ - libexpat.def \ - libexpatw.def \ + libexpat.def.cmake \ nametab.h \ siphash.h \ utf8tab.h \ @@ -425,7 +458,7 @@ all: all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ @@ -449,9 +482,9 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(top_srcdir)/configure: $(am__configure_deps) +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): $(am__aclocal_m4_deps) +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): @@ -490,15 +523,32 @@ clean-libLTLIBRARIES: rm -f $${locs}; \ } +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; \ + locs=`for p in $$list; do echo $$p; done | \ + sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ + sort -u`; \ + test -z "$$locs" || { \ + echo rm -f $${locs}; \ + rm -f $${locs}; \ + } + libexpat.la: $(libexpat_la_OBJECTS) $(libexpat_la_DEPENDENCIES) $(EXTRA_libexpat_la_DEPENDENCIES) $(AM_V_CCLD)$(libexpat_la_LINK) -rpath $(libdir) $(libexpat_la_OBJECTS) $(libexpat_la_LIBADD) $(LIBS) +libtestpat.la: $(libtestpat_la_OBJECTS) $(libtestpat_la_DEPENDENCIES) $(EXTRA_libtestpat_la_DEPENDENCIES) + $(AM_V_CCLD)$(LINK) $(am_libtestpat_la_rpath) $(libtestpat_la_OBJECTS) $(libtestpat_la_LIBADD) $(LIBS) + mostlyclean-compile: -rm -f *.$(OBJEXT) distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtestpat_la-xmlparse.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtestpat_la-xmlrole.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libtestpat_la-xmltok.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlparse.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmlrole.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmltok.Plo@am__quote@ # am--include-marker @@ -530,6 +580,27 @@ am--depfiles: $(am__depfiles_remade) @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< +libtestpat_la-xmlparse.lo: xmlparse.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtestpat_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libtestpat_la-xmlparse.lo -MD -MP -MF $(DEPDIR)/libtestpat_la-xmlparse.Tpo -c -o libtestpat_la-xmlparse.lo `test -f 'xmlparse.c' || echo '$(srcdir)/'`xmlparse.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libtestpat_la-xmlparse.Tpo $(DEPDIR)/libtestpat_la-xmlparse.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='xmlparse.c' object='libtestpat_la-xmlparse.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtestpat_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libtestpat_la-xmlparse.lo `test -f 'xmlparse.c' || echo '$(srcdir)/'`xmlparse.c + +libtestpat_la-xmltok.lo: xmltok.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtestpat_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libtestpat_la-xmltok.lo -MD -MP -MF $(DEPDIR)/libtestpat_la-xmltok.Tpo -c -o libtestpat_la-xmltok.lo `test -f 'xmltok.c' || echo '$(srcdir)/'`xmltok.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libtestpat_la-xmltok.Tpo $(DEPDIR)/libtestpat_la-xmltok.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='xmltok.c' object='libtestpat_la-xmltok.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtestpat_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libtestpat_la-xmltok.lo `test -f 'xmltok.c' || echo '$(srcdir)/'`xmltok.c + +libtestpat_la-xmlrole.lo: xmlrole.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtestpat_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libtestpat_la-xmlrole.lo -MD -MP -MF $(DEPDIR)/libtestpat_la-xmlrole.Tpo -c -o libtestpat_la-xmlrole.lo `test -f 'xmlrole.c' || echo '$(srcdir)/'`xmlrole.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libtestpat_la-xmlrole.Tpo $(DEPDIR)/libtestpat_la-xmlrole.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='xmlrole.c' object='libtestpat_la-xmlrole.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libtestpat_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libtestpat_la-xmlrole.lo `test -f 'xmlrole.c' || echo '$(srcdir)/'`xmlrole.c + mostlyclean-libtool: -rm -f *.lo @@ -629,7 +700,6 @@ cscopelist-am: $(am__tagged_files) distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am @@ -703,10 +773,13 @@ maintainer-clean-generic: clean: clean-am clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ - mostlyclean-am + clean-noinstLTLIBRARIES mostlyclean-am distclean: distclean-am - -rm -f ./$(DEPDIR)/xmlparse.Plo + -rm -f ./$(DEPDIR)/libtestpat_la-xmlparse.Plo + -rm -f ./$(DEPDIR)/libtestpat_la-xmlrole.Plo + -rm -f ./$(DEPDIR)/libtestpat_la-xmltok.Plo + -rm -f ./$(DEPDIR)/xmlparse.Plo -rm -f ./$(DEPDIR)/xmlrole.Plo -rm -f ./$(DEPDIR)/xmltok.Plo -rm -f Makefile @@ -755,7 +828,10 @@ install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-am - -rm -f ./$(DEPDIR)/xmlparse.Plo + -rm -f ./$(DEPDIR)/libtestpat_la-xmlparse.Plo + -rm -f ./$(DEPDIR)/libtestpat_la-xmlrole.Plo + -rm -f ./$(DEPDIR)/libtestpat_la-xmltok.Plo + -rm -f ./$(DEPDIR)/xmlparse.Plo -rm -f ./$(DEPDIR)/xmlrole.Plo -rm -f ./$(DEPDIR)/xmltok.Plo -rm -f Makefile @@ -780,16 +856,17 @@ uninstall-am: uninstall-docDATA uninstall-includeHEADERS \ .MAKE: install-am install-data-am install-strip .PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ - clean-generic clean-libLTLIBRARIES clean-libtool cscopelist-am \ - ctags ctags-am distclean distclean-compile distclean-generic \ - distclean-libtool distclean-tags distdir dvi dvi-am html \ - html-am info info-am install install-am install-data \ - install-data-am install-data-hook install-docDATA install-dvi \ - install-dvi-am install-exec install-exec-am install-html \ - install-html-am install-includeHEADERS install-info \ - install-info-am install-libLTLIBRARIES install-man install-pdf \ - install-pdf-am install-ps install-ps-am install-strip \ - installcheck installcheck-am installdirs maintainer-clean \ + clean-generic clean-libLTLIBRARIES clean-libtool \ + clean-noinstLTLIBRARIES cscopelist-am ctags ctags-am distclean \ + distclean-compile distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am html html-am info info-am \ + install install-am install-data install-data-am \ + install-data-hook install-docDATA install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-includeHEADERS install-info install-info-am \ + install-libLTLIBRARIES install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags tags-am uninstall uninstall-am uninstall-docDATA \ diff --git a/3rdparty/expat/lib/ascii.h b/3rdparty/expat/lib/ascii.h index c3587e57332..1f594d2e54b 100644 --- a/3rdparty/expat/lib/ascii.h +++ b/3rdparty/expat/lib/ascii.h @@ -6,8 +6,11 @@ \___/_/\_\ .__/ \__,_|\__| |_| XML parser - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 1999-2000 Thai Open Source Software Center Ltd + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2007 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/lib/asciitab.h b/3rdparty/expat/lib/asciitab.h index 63b1d1b4482..af766fb2478 100644 --- a/3rdparty/expat/lib/asciitab.h +++ b/3rdparty/expat/lib/asciitab.h @@ -7,7 +7,9 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/lib/expat.h b/3rdparty/expat/lib/expat.h index cb828db155f..c2c75ef4f05 100644 --- a/3rdparty/expat/lib/expat.h +++ b/3rdparty/expat/lib/expat.h @@ -7,7 +7,18 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2000-2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2001-2002 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2002-2016 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2016 Cristian Rodríguez <crrodriguez@opensuse.org> + Copyright (c) 2016 Thomas Beutlich <tc@tbeu.de> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2022 Thijs Schreijer <thijs@thijsschreijer.nl> + Copyright (c) 2023 Hanno Böck <hanno@gentoo.org> + Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com> + Copyright (c) 2024 Taichi Haradaguchi <20001722@ymail.ne.jp> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -115,7 +126,13 @@ enum XML_Error { XML_ERROR_RESERVED_PREFIX_XMLNS, XML_ERROR_RESERVED_NAMESPACE_URI, /* Added in 2.2.1. */ - XML_ERROR_INVALID_ARGUMENT + XML_ERROR_INVALID_ARGUMENT, + /* Added in 2.3.0. */ + XML_ERROR_NO_BUFFER, + /* Added in 2.4.0. */ + XML_ERROR_AMPLIFICATION_LIMIT_BREACH, + /* Added in 2.6.4. */ + XML_ERROR_NOT_STARTED, }; enum XML_Content_Type { @@ -163,8 +180,10 @@ struct XML_cp { }; /* This is called for an element declaration. See above for - description of the model argument. It's the caller's responsibility - to free model when finished with it. + description of the model argument. It's the user code's responsibility + to free model when finished with it. See XML_FreeContentModel. + There is no need to free the model from the handler, it can be kept + around and freed at a later stage. */ typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData, const XML_Char *name, @@ -226,6 +245,17 @@ XML_ParserCreate(const XML_Char *encoding); and the local part will be concatenated without any separator. It is a programming error to use the separator '\0' with namespace triplets (see XML_SetReturnNSTriplet). + If a namespace separator is chosen that can be part of a URI or + part of an XML name, splitting an expanded name back into its + 1, 2 or 3 original parts on application level in the element handler + may end up vulnerable, so these are advised against; sane choices for + a namespace separator are e.g. '\n' (line feed) and '|' (pipe). + + Note that Expat does not validate namespace URIs (beyond encoding) + against RFC 3986 today (and is not required to do so with regard to + the XML 1.0 namespaces specification) but it may start doing that + in future releases. Before that, an application using Expat must + be ready to receive namespace URIs containing non-URI characters. */ XMLPARSEAPI(XML_Parser) XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator); @@ -244,7 +274,7 @@ XML_ParserCreate_MM(const XML_Char *encoding, const XML_Memory_Handling_Suite *memsuite, const XML_Char *namespaceSeparator); -/* Prepare a parser object to be re-used. This is particularly +/* Prepare a parser object to be reused. This is particularly valuable when memory allocation overhead is disproportionately high, such as when a large number of small documnents need to be parsed. All handlers are cleared from the parser, except for the @@ -306,7 +336,7 @@ typedef void(XMLCALL *XML_StartDoctypeDeclHandler)(void *userData, const XML_Char *pubid, int has_internal_subset); -/* This is called for the start of the DOCTYPE declaration when the +/* This is called for the end of the DOCTYPE declaration when the closing > is encountered, but after processing any external subset. */ @@ -513,7 +543,7 @@ typedef struct { Otherwise it must return XML_STATUS_ERROR. If info does not describe a suitable encoding, then the parser will - return an XML_UNKNOWN_ENCODING error. + return an XML_ERROR_UNKNOWN_ENCODING error. */ typedef int(XMLCALL *XML_UnknownEncodingHandler)(void *encodingHandlerData, const XML_Char *name, @@ -926,7 +956,7 @@ XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser); XMLPARSEAPI(int) XML_GetCurrentByteCount(XML_Parser parser); -/* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets +/* If XML_CONTEXT_BYTES is >=1, returns the input buffer, sets the integer pointed to by offset to the offset within this buffer of the current parse position, and sets the integer pointed to by size to the size of this buffer (the number of input bytes). Otherwise @@ -997,7 +1027,12 @@ enum XML_FeatureEnum { XML_FEATURE_SIZEOF_XML_LCHAR, XML_FEATURE_NS, XML_FEATURE_LARGE_SIZE, - XML_FEATURE_ATTR_INFO + XML_FEATURE_ATTR_INFO, + /* Added in Expat 2.4.0. */ + XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT, + XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT, + /* Added in Expat 2.6.0. */ + XML_FEATURE_GE /* Additional features must be added to the end of this enum. */ }; @@ -1010,12 +1045,30 @@ typedef struct { XMLPARSEAPI(const XML_Feature *) XML_GetFeatureList(void); +#if defined(XML_DTD) || (defined(XML_GE) && XML_GE == 1) +/* Added in Expat 2.4.0 for XML_DTD defined and + * added in Expat 2.6.0 for XML_GE == 1. */ +XMLPARSEAPI(XML_Bool) +XML_SetBillionLaughsAttackProtectionMaximumAmplification( + XML_Parser parser, float maximumAmplificationFactor); + +/* Added in Expat 2.4.0 for XML_DTD defined and + * added in Expat 2.6.0 for XML_GE == 1. */ +XMLPARSEAPI(XML_Bool) +XML_SetBillionLaughsAttackProtectionActivationThreshold( + XML_Parser parser, unsigned long long activationThresholdBytes); +#endif + +/* Added in Expat 2.6.0. */ +XMLPARSEAPI(XML_Bool) +XML_SetReparseDeferralEnabled(XML_Parser parser, XML_Bool enabled); + /* Expat follows the semantic versioning convention. - See http://semver.org. + See https://semver.org */ #define XML_MAJOR_VERSION 2 -#define XML_MINOR_VERSION 2 -#define XML_MICRO_VERSION 10 +#define XML_MINOR_VERSION 6 +#define XML_MICRO_VERSION 4 #ifdef __cplusplus } diff --git a/3rdparty/expat/lib/expat_external.h b/3rdparty/expat/lib/expat_external.h index b3b6e74d9d2..162e2bd0ec8 100644 --- a/3rdparty/expat/lib/expat_external.h +++ b/3rdparty/expat/lib/expat_external.h @@ -7,7 +7,14 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2000-2004 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2001-2002 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2002-2006 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016 Cristian Rodríguez <crrodriguez@opensuse.org> + Copyright (c) 2016-2019 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2018 Yury Gribov <tetra2005@gmail.com> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/lib/iasciitab.h b/3rdparty/expat/lib/iasciitab.h index ea97cfcf678..5d8646f2a31 100644 --- a/3rdparty/expat/lib/iasciitab.h +++ b/3rdparty/expat/lib/iasciitab.h @@ -7,7 +7,9 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/lib/internal.h b/3rdparty/expat/lib/internal.h index 60913dab762..167ec36804a 100644 --- a/3rdparty/expat/lib/internal.h +++ b/3rdparty/expat/lib/internal.h @@ -25,8 +25,14 @@ \___/_/\_\ .__/ \__,_|\__| |_| XML parser - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2002-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2002-2006 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2018 Yury Gribov <tetra2005@gmail.com> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild@sony.com> + Copyright (c) 2024 Taichi Haradaguchi <20001722@ymail.ne.jp> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -101,22 +107,69 @@ # endif #endif +#include <limits.h> // ULONG_MAX + +#if defined(_WIN32) \ + && (! defined(__USE_MINGW_ANSI_STDIO) \ + || (1 - __USE_MINGW_ANSI_STDIO - 1 == 0)) +# define EXPAT_FMT_ULL(midpart) "%" midpart "I64u" +# if defined(_WIN64) // Note: modifiers "td" and "zu" do not work for MinGW +# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "I64d" +# define EXPAT_FMT_SIZE_T(midpart) "%" midpart "I64u" +# else +# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d" +# define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u" +# endif +#else +# define EXPAT_FMT_ULL(midpart) "%" midpart "llu" +# if ! defined(ULONG_MAX) +# error Compiler did not define ULONG_MAX for us +# elif ULONG_MAX == 18446744073709551615u // 2^64-1 +# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "ld" +# define EXPAT_FMT_SIZE_T(midpart) "%" midpart "lu" +# else +# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d" +# define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u" +# endif +#endif + #ifndef UNUSED_P # define UNUSED_P(p) (void)p #endif +/* NOTE BEGIN If you ever patch these defaults to greater values + for non-attack XML payload in your environment, + please file a bug report with libexpat. Thank you! +*/ +#define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT \ + 100.0f +#define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT \ + 8388608 // 8 MiB, 2^23 +/* NOTE END */ + +#include "expat.h" // so we can use type XML_Parser below + #ifdef __cplusplus extern "C" { #endif -#ifdef XML_ENABLE_VISIBILITY -# if XML_ENABLE_VISIBILITY -__attribute__((visibility("default"))) -# endif +void _INTERNAL_trim_to_complete_utf8_characters(const char *from, + const char **fromLimRef); + +#if defined(XML_GE) && XML_GE == 1 +unsigned long long testingAccountingGetCountBytesDirect(XML_Parser parser); +unsigned long long testingAccountingGetCountBytesIndirect(XML_Parser parser); +const char *unsignedCharToPrintable(unsigned char c); +#endif + +extern +#if ! defined(XML_TESTING) + const +#endif + XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c +#if defined(XML_TESTING) +extern unsigned int g_bytesScanned; // used for testing only #endif -void -_INTERNAL_trim_to_complete_utf8_characters(const char *from, - const char **fromLimRef); #ifdef __cplusplus } diff --git a/3rdparty/expat/lib/latin1tab.h b/3rdparty/expat/lib/latin1tab.h index 6f916041355..b681d278af6 100644 --- a/3rdparty/expat/lib/latin1tab.h +++ b/3rdparty/expat/lib/latin1tab.h @@ -7,7 +7,9 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/lib/libexpat.def b/3rdparty/expat/lib/libexpat.def deleted file mode 100644 index 16faf5955e7..00000000000 --- a/3rdparty/expat/lib/libexpat.def +++ /dev/null @@ -1,78 +0,0 @@ -; DEF file for MS VC++ - -LIBRARY -EXPORTS - XML_DefaultCurrent @1 - XML_ErrorString @2 - XML_ExpatVersion @3 - XML_ExpatVersionInfo @4 - XML_ExternalEntityParserCreate @5 - XML_GetBase @6 - XML_GetBuffer @7 - XML_GetCurrentByteCount @8 - XML_GetCurrentByteIndex @9 - XML_GetCurrentColumnNumber @10 - XML_GetCurrentLineNumber @11 - XML_GetErrorCode @12 - XML_GetIdAttributeIndex @13 - XML_GetInputContext @14 - XML_GetSpecifiedAttributeCount @15 - XML_Parse @16 - XML_ParseBuffer @17 - XML_ParserCreate @18 - XML_ParserCreateNS @19 - XML_ParserCreate_MM @20 - XML_ParserFree @21 - XML_SetAttlistDeclHandler @22 - XML_SetBase @23 - XML_SetCdataSectionHandler @24 - XML_SetCharacterDataHandler @25 - XML_SetCommentHandler @26 - XML_SetDefaultHandler @27 - XML_SetDefaultHandlerExpand @28 - XML_SetDoctypeDeclHandler @29 - XML_SetElementDeclHandler @30 - XML_SetElementHandler @31 - XML_SetEncoding @32 - XML_SetEndCdataSectionHandler @33 - XML_SetEndDoctypeDeclHandler @34 - XML_SetEndElementHandler @35 - XML_SetEndNamespaceDeclHandler @36 - XML_SetEntityDeclHandler @37 - XML_SetExternalEntityRefHandler @38 - XML_SetExternalEntityRefHandlerArg @39 - XML_SetNamespaceDeclHandler @40 - XML_SetNotStandaloneHandler @41 - XML_SetNotationDeclHandler @42 - XML_SetParamEntityParsing @43 - XML_SetProcessingInstructionHandler @44 - XML_SetReturnNSTriplet @45 - XML_SetStartCdataSectionHandler @46 - XML_SetStartDoctypeDeclHandler @47 - XML_SetStartElementHandler @48 - XML_SetStartNamespaceDeclHandler @49 - XML_SetUnknownEncodingHandler @50 - XML_SetUnparsedEntityDeclHandler @51 - XML_SetUserData @52 - XML_SetXmlDeclHandler @53 - XML_UseParserAsHandlerArg @54 -; added with version 1.95.3 - XML_ParserReset @55 - XML_SetSkippedEntityHandler @56 -; added with version 1.95.5 - XML_GetFeatureList @57 - XML_UseForeignDTD @58 -; added with version 1.95.6 - XML_FreeContentModel @59 - XML_MemMalloc @60 - XML_MemRealloc @61 - XML_MemFree @62 -; added with version 1.95.8 - XML_StopParser @63 - XML_ResumeParser @64 - XML_GetParsingStatus @65 -; added with version 2.1.1 -; XML_GetAttributeInfo @66 - XML_SetHashSalt @67 -; added with version 2.2.5 - _INTERNAL_trim_to_complete_utf8_characters @68 diff --git a/3rdparty/expat/lib/libexpatw.def b/3rdparty/expat/lib/libexpat.def.cmake index 16faf5955e7..10ee9cd6f99 100644 --- a/3rdparty/expat/lib/libexpatw.def +++ b/3rdparty/expat/lib/libexpat.def.cmake @@ -1,6 +1,5 @@ ; DEF file for MS VC++ -LIBRARY EXPORTS XML_DefaultCurrent @1 XML_ErrorString @2 @@ -72,7 +71,11 @@ EXPORTS XML_ResumeParser @64 XML_GetParsingStatus @65 ; added with version 2.1.1 -; XML_GetAttributeInfo @66 +@_EXPAT_COMMENT_ATTR_INFO@ XML_GetAttributeInfo @66 XML_SetHashSalt @67 -; added with version 2.2.5 - _INTERNAL_trim_to_complete_utf8_characters @68 +; internal @68 removed with version 2.3.1 +; added with version 2.4.0 +@_EXPAT_COMMENT_DTD_OR_GE@ XML_SetBillionLaughsAttackProtectionActivationThreshold @69 +@_EXPAT_COMMENT_DTD_OR_GE@ XML_SetBillionLaughsAttackProtectionMaximumAmplification @70 +; added with version 2.6.0 + XML_SetReparseDeferralEnabled @71 diff --git a/3rdparty/expat/lib/nametab.h b/3rdparty/expat/lib/nametab.h index 3681df348ee..63485446b96 100644 --- a/3rdparty/expat/lib/nametab.h +++ b/3rdparty/expat/lib/nametab.h @@ -6,8 +6,8 @@ \___/_/\_\ .__/ \__,_|\__| |_| XML parser - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/lib/siphash.h b/3rdparty/expat/lib/siphash.h index bfee65a332f..04f6f74585b 100644 --- a/3rdparty/expat/lib/siphash.h +++ b/3rdparty/expat/lib/siphash.h @@ -11,6 +11,9 @@ * -------------------------------------------------------------------------- * HISTORY: * + * 2020-10-03 (Sebastian Pipping) + * - Drop support for Visual Studio 9.0/2008 and earlier + * * 2019-08-03 (Sebastian Pipping) * - Mark part of sip24_valid as to be excluded from clang-format * - Re-format code using clang-format 9 @@ -96,22 +99,14 @@ #define SIPHASH_H #include <stddef.h> /* size_t */ - -#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER < 1600) -/* For vs2003/7.1 up to vs2008/9.0; _MSC_VER 1600 is vs2010/10.0 */ -typedef unsigned __int8 uint8_t; -typedef unsigned __int32 uint32_t; -typedef unsigned __int64 uint64_t; -#else -# include <stdint.h> /* uint64_t uint32_t uint8_t */ -#endif +#include <stdint.h> /* uint64_t uint32_t uint8_t */ /* * Workaround to not require a C++11 compiler for using ULL suffix * if this code is included and compiled as C++; related GCC warning is: * warning: use of C++11 long long integer constant [-Wlong-long] */ -#define _SIP_ULL(high, low) (((uint64_t)high << 32) | low) +#define SIP_ULL(high, low) ((((uint64_t)high) << 32) | (low)) #define SIP_ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b)))) @@ -131,8 +126,7 @@ typedef unsigned __int64 uint64_t; | ((uint64_t)((p)[4]) << 32) | ((uint64_t)((p)[5]) << 40) \ | ((uint64_t)((p)[6]) << 48) | ((uint64_t)((p)[7]) << 56)) -#define SIPHASH_INITIALIZER \ - { 0, 0, 0, 0, {0}, 0, 0 } +#define SIPHASH_INITIALIZER {0, 0, 0, 0, {0}, 0, 0} struct siphash { uint64_t v0, v1, v2, v3; @@ -195,10 +189,10 @@ sip_round(struct siphash *H, const int rounds) { static struct siphash * sip24_init(struct siphash *H, const struct sipkey *key) { - H->v0 = _SIP_ULL(0x736f6d65U, 0x70736575U) ^ key->k[0]; - H->v1 = _SIP_ULL(0x646f7261U, 0x6e646f6dU) ^ key->k[1]; - H->v2 = _SIP_ULL(0x6c796765U, 0x6e657261U) ^ key->k[0]; - H->v3 = _SIP_ULL(0x74656462U, 0x79746573U) ^ key->k[1]; + H->v0 = SIP_ULL(0x736f6d65U, 0x70736575U) ^ key->k[0]; + H->v1 = SIP_ULL(0x646f7261U, 0x6e646f6dU) ^ key->k[1]; + H->v2 = SIP_ULL(0x6c796765U, 0x6e657261U) ^ key->k[0]; + H->v3 = SIP_ULL(0x74656462U, 0x79746573U) ^ key->k[1]; H->p = H->buf; H->c = 0; diff --git a/3rdparty/expat/lib/utf8tab.h b/3rdparty/expat/lib/utf8tab.h index a22986acbb9..88efcf91cc1 100644 --- a/3rdparty/expat/lib/utf8tab.h +++ b/3rdparty/expat/lib/utf8tab.h @@ -7,7 +7,9 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/lib/winconfig.h b/3rdparty/expat/lib/winconfig.h index 562a4a82dc1..05805514ec7 100644 --- a/3rdparty/expat/lib/winconfig.h +++ b/3rdparty/expat/lib/winconfig.h @@ -6,8 +6,11 @@ \___/_/\_\ .__/ \__,_|\__| |_| XML parser - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2023 Orgad Shaneh <orgad.shaneh@audiocodes.com> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -33,24 +36,13 @@ #ifndef WINCONFIG_H #define WINCONFIG_H -#define WIN32_LEAN_AND_MEAN +#ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif #include <windows.h> #undef WIN32_LEAN_AND_MEAN #include <memory.h> #include <string.h> -#if defined(HAVE_EXPAT_CONFIG_H) /* e.g. MinGW */ -# include <expat_config.h> -#else /* !defined(HAVE_EXPAT_CONFIG_H) */ - -# define XML_NS 1 -# define XML_DTD 1 -# define XML_CONTEXT_BYTES 1024 - -/* we will assume all Windows platforms are little endian */ -# define BYTEORDER 1234 - -#endif /* !defined(HAVE_EXPAT_CONFIG_H) */ - #endif /* ndef WINCONFIG_H */ diff --git a/3rdparty/expat/lib/xmlparse.c b/3rdparty/expat/lib/xmlparse.c index dfc316ca36c..503d318abba 100644 --- a/3rdparty/expat/lib/xmlparse.c +++ b/3rdparty/expat/lib/xmlparse.c @@ -1,4 +1,4 @@ -/* 5cd169f2942b85c05e0b1b96f9990f91ac3d07e470ad7ce906ac8590c8ed4f35 (2.2.10+) +/* c5625880f4bf417c1463deee4eb92d86ff413f802048621c57e25fe483eb59e4 (2.6.4+) __ __ _ ___\ \/ /_ __ __ _| |_ / _ \\ /| '_ \ / _` | __| @@ -7,7 +7,40 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2000-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2001-2002 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2002-2016 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2005-2009 Steven Solie <steven@solie.ca> + Copyright (c) 2016 Eric Rahm <erahm@mozilla.com> + Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2016 Gaurav <g.gupta@samsung.com> + Copyright (c) 2016 Thomas Beutlich <tc@tbeu.de> + Copyright (c) 2016 Gustavo Grieco <gustavo.grieco@imag.fr> + Copyright (c) 2016 Pascal Cuoq <cuoq@trust-in-soft.com> + Copyright (c) 2016 Ed Schouten <ed@nuxi.nl> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Václav Slavík <vaclav@slavik.io> + Copyright (c) 2017 Viktor Szakats <commit@vsz.me> + Copyright (c) 2017 Chanho Park <chanho61.park@samsung.com> + Copyright (c) 2017 Rolf Eike Beer <eike@sf-mail.de> + Copyright (c) 2017 Hans Wennborg <hans@chromium.org> + Copyright (c) 2018 Anton Maklakov <antmak.pub@gmail.com> + Copyright (c) 2018 Benjamin Peterson <benjamin@python.org> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2018 Mariusz Zaborski <oshogbo@vexillium.org> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2019-2020 Ben Wagner <bungeman@chromium.org> + Copyright (c) 2019 Vadim Zeitlin <vadim@zeitlins.org> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Copyright (c) 2022 Samanta Navarro <ferivoz@riseup.net> + Copyright (c) 2022 Jeffrey Walton <noloader@gmail.com> + Copyright (c) 2022 Jann Horn <jannh@google.com> + Copyright (c) 2022 Sean McBride <sean@rogue-research.com> + Copyright (c) 2023 Owain Davies <owaind@bath.edu> + Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild@sony.com> + Copyright (c) 2024 Berkay Eren Ürün <berkay.ueruen@siemens.com> + Copyright (c) 2024 Hanno Böck <hanno@gentoo.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -30,8 +63,27 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#if ! defined(_GNU_SOURCE) -# define _GNU_SOURCE 1 /* syscall prototype */ +#define XML_BUILDING_EXPAT 1 + +#include "expat_config.h" + +#if ! defined(XML_GE) || (1 - XML_GE - 1 == 2) || (XML_GE < 0) || (XML_GE > 1) +# error XML_GE (for general entities) must be defined, non-empty, either 1 or 0 (0 to disable, 1 to enable; 1 is a common default) +#endif + +#if defined(XML_DTD) && XML_GE == 0 +# error Either undefine XML_DTD or define XML_GE to 1. +#endif + +#if ! defined(XML_CONTEXT_BYTES) || (1 - XML_CONTEXT_BYTES - 1 == 2) \ + || (XML_CONTEXT_BYTES + 0 < 0) +# error XML_CONTEXT_BYTES must be defined, non-empty and >=0 (0 to disable, >=1 to enable; 1024 is a common default) +#endif + +#if defined(HAVE_SYSCALL_GETRANDOM) +# if ! defined(_GNU_SOURCE) +# define _GNU_SOURCE 1 /* syscall prototype */ +# endif #endif #ifdef _WIN32 @@ -41,23 +93,15 @@ # endif #endif +#include <stdbool.h> #include <stddef.h> #include <string.h> /* memset(), memcpy() */ #include <assert.h> #include <limits.h> /* UINT_MAX */ #include <stdio.h> /* fprintf */ #include <stdlib.h> /* getenv, rand_s */ - -#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER < 1600) -/* vs2008/9.0 and earlier lack stdint.h; _MSC_VER 1600 is vs2010/10.0 */ -# if defined(_WIN64) -typedef unsigned __int64 uintptr_t; -# else -typedef unsigned __int32 uintptr_t; -# endif -#else -# include <stdint.h> /* uintptr_t */ -#endif +#include <stdint.h> /* uintptr_t */ +#include <math.h> /* isnan */ #ifdef _WIN32 # define getpid GetCurrentProcessId @@ -69,13 +113,9 @@ typedef unsigned __int32 uintptr_t; # include <errno.h> #endif -#define XML_BUILDING_EXPAT 1 - #ifdef _WIN32 # include "winconfig.h" -#elif defined(HAVE_EXPAT_CONFIG_H) -# include <expat_config.h> -#endif /* ndef _WIN32 */ +#endif #include "ascii.h" #include "expat.h" @@ -112,11 +152,11 @@ typedef unsigned __int32 uintptr_t; Your options include: \ * Linux >=3.17 + glibc >=2.25 (getrandom): HAVE_GETRANDOM, \ * Linux >=3.17 + glibc (including <2.25) (syscall SYS_getrandom): HAVE_SYSCALL_GETRANDOM, \ - * BSD / macOS >=10.7 (arc4random_buf): HAVE_ARC4RANDOM_BUF, \ - * BSD / macOS (including <10.7) (arc4random): HAVE_ARC4RANDOM, \ + * BSD / macOS >=10.7 / glibc >=2.36 (arc4random_buf): HAVE_ARC4RANDOM_BUF, \ + * BSD / macOS (including <10.7) / glibc >=2.36 (arc4random): HAVE_ARC4RANDOM, \ * libbsd (arc4random_buf): HAVE_ARC4RANDOM_BUF + HAVE_LIBBSD, \ * libbsd (arc4random): HAVE_ARC4RANDOM + HAVE_LIBBSD, \ - * Linux (including <3.17) / BSD / macOS (including <10.7) (/dev/urandom): XML_DEV_URANDOM, \ + * Linux (including <3.17) / BSD / macOS (including <10.7) / Solaris >=8 (/dev/urandom): XML_DEV_URANDOM, \ * Windows >=Vista (rand_s): _WIN32. \ \ If insist on not using any of these, bypass this error by defining \ @@ -172,11 +212,13 @@ typedef char ICHAR; #endif /* Round up n to be a multiple of sz, where sz is a power of 2. */ -#define ROUND_UP(n, sz) (((n) + ((sz)-1)) & ~((sz)-1)) +#define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1)) /* Do safe (NULL-aware) pointer arithmetic */ #define EXPAT_SAFE_PTR_DIFF(p, q) (((p) && (q)) ? ((p) - (q)) : 0) +#define EXPAT_MIN(a, b) (((a) < (b)) ? (a) : (b)) + #include "internal.h" #include "xmltok.h" #include "xmlrole.h" @@ -208,7 +250,7 @@ static void copy_salt_to_sipkey(XML_Parser parser, struct sipkey *key); it odd, since odd numbers are always relative prime to a power of 2. */ #define SECOND_HASH(hash, mask, power) \ - ((((hash) & ~(mask)) >> ((power)-1)) & ((mask) >> 2)) + ((((hash) & ~(mask)) >> ((power) - 1)) & ((mask) >> 2)) #define PROBE_STEP(hash, mask, power) \ ((unsigned char)((SECOND_HASH(hash, mask, power)) | 1)) @@ -254,13 +296,13 @@ typedef struct { The name of the element is stored in both the document and API encodings. The memory buffer 'buf' is a separately-allocated memory area which stores the name. During the XML_Parse()/ - XMLParseBuffer() when the element is open, the memory for the 'raw' + XML_ParseBuffer() when the element is open, the memory for the 'raw' version of the name (in the document encoding) is shared with the document buffer. If the element is open across calls to XML_Parse()/XML_ParseBuffer(), the buffer is re-allocated to contain the 'raw' name as well. - A parser re-uses these structures, maintaining a list of allocated + A parser reuses these structures, maintaining a list of allocated TAG objects in a free list. */ typedef struct tag { @@ -382,6 +424,31 @@ typedef struct open_internal_entity { XML_Bool betweenDecl; /* WFC: PE Between Declarations */ } OPEN_INTERNAL_ENTITY; +enum XML_Account { + XML_ACCOUNT_DIRECT, /* bytes directly passed to the Expat parser */ + XML_ACCOUNT_ENTITY_EXPANSION, /* intermediate bytes produced during entity + expansion */ + XML_ACCOUNT_NONE /* i.e. do not account, was accounted already */ +}; + +#if XML_GE == 1 +typedef unsigned long long XmlBigCount; +typedef struct accounting { + XmlBigCount countBytesDirect; + XmlBigCount countBytesIndirect; + unsigned long debugLevel; + float maximumAmplificationFactor; // >=1.0 + unsigned long long activationThresholdBytes; +} ACCOUNTING; + +typedef struct entity_stats { + unsigned int countEverOpened; + unsigned int currentDepth; + unsigned int maximumDepthSeen; + unsigned long debugLevel; +} ENTITY_STATS; +#endif /* XML_GE == 1 */ + typedef enum XML_Error PTRCALL Processor(XML_Parser parser, const char *start, const char *end, const char **endPtr); @@ -412,43 +479,55 @@ static enum XML_Error initializeEncoding(XML_Parser parser); static enum XML_Error doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, int tok, const char *next, const char **nextPtr, - XML_Bool haveMore, XML_Bool allowClosingDoctype); + XML_Bool haveMore, XML_Bool allowClosingDoctype, + enum XML_Account account); static enum XML_Error processInternalEntity(XML_Parser parser, ENTITY *entity, XML_Bool betweenDecl); static enum XML_Error doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, const char *start, const char *end, const char **endPtr, - XML_Bool haveMore); -static enum XML_Error doCdataSection(XML_Parser parser, const ENCODING *, + XML_Bool haveMore, enum XML_Account account); +static enum XML_Error doCdataSection(XML_Parser parser, const ENCODING *enc, const char **startPtr, const char *end, - const char **nextPtr, XML_Bool haveMore); + const char **nextPtr, XML_Bool haveMore, + enum XML_Account account); #ifdef XML_DTD -static enum XML_Error doIgnoreSection(XML_Parser parser, const ENCODING *, +static enum XML_Error doIgnoreSection(XML_Parser parser, const ENCODING *enc, const char **startPtr, const char *end, const char **nextPtr, XML_Bool haveMore); #endif /* XML_DTD */ static void freeBindings(XML_Parser parser, BINDING *bindings); -static enum XML_Error storeAtts(XML_Parser parser, const ENCODING *, - const char *s, TAG_NAME *tagNamePtr, - BINDING **bindingsPtr); +static enum XML_Error storeAtts(XML_Parser parser, const ENCODING *enc, + const char *attStr, TAG_NAME *tagNamePtr, + BINDING **bindingsPtr, + enum XML_Account account); static enum XML_Error addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, const XML_Char *uri, BINDING **bindingsPtr); -static int defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *, XML_Bool isCdata, - XML_Bool isId, const XML_Char *dfltValue, - XML_Parser parser); -static enum XML_Error storeAttributeValue(XML_Parser parser, const ENCODING *, - XML_Bool isCdata, const char *, - const char *, STRING_POOL *); -static enum XML_Error appendAttributeValue(XML_Parser parser, const ENCODING *, - XML_Bool isCdata, const char *, - const char *, STRING_POOL *); +static int defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, + XML_Bool isCdata, XML_Bool isId, + const XML_Char *value, XML_Parser parser); +static enum XML_Error storeAttributeValue(XML_Parser parser, + const ENCODING *enc, XML_Bool isCdata, + const char *ptr, const char *end, + STRING_POOL *pool, + enum XML_Account account); +static enum XML_Error appendAttributeValue(XML_Parser parser, + const ENCODING *enc, + XML_Bool isCdata, const char *ptr, + const char *end, STRING_POOL *pool, + enum XML_Account account); static ATTRIBUTE_ID *getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start, const char *end); -static int setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *); +static int setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *elementType); +#if XML_GE == 1 static enum XML_Error storeEntityValue(XML_Parser parser, const ENCODING *enc, - const char *start, const char *end); + const char *start, const char *end, + enum XML_Account account); +#else +static enum XML_Error storeSelfEntityValue(XML_Parser parser, ENTITY *entity); +#endif static int reportProcessingInstruction(XML_Parser parser, const ENCODING *enc, const char *start, const char *end); static int reportComment(XML_Parser parser, const ENCODING *enc, @@ -468,21 +547,22 @@ static void dtdDestroy(DTD *p, XML_Bool isDocEntity, const XML_Memory_Handling_Suite *ms); static int dtdCopy(XML_Parser oldParser, DTD *newDtd, const DTD *oldDtd, const XML_Memory_Handling_Suite *ms); -static int copyEntityTable(XML_Parser oldParser, HASH_TABLE *, STRING_POOL *, - const HASH_TABLE *); +static int copyEntityTable(XML_Parser oldParser, HASH_TABLE *newTable, + STRING_POOL *newPool, const HASH_TABLE *oldTable); static NAMED *lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize); -static void FASTCALL hashTableInit(HASH_TABLE *, +static void FASTCALL hashTableInit(HASH_TABLE *table, const XML_Memory_Handling_Suite *ms); -static void FASTCALL hashTableClear(HASH_TABLE *); -static void FASTCALL hashTableDestroy(HASH_TABLE *); -static void FASTCALL hashTableIterInit(HASH_TABLE_ITER *, const HASH_TABLE *); -static NAMED *FASTCALL hashTableIterNext(HASH_TABLE_ITER *); +static void FASTCALL hashTableClear(HASH_TABLE *table); +static void FASTCALL hashTableDestroy(HASH_TABLE *table); +static void FASTCALL hashTableIterInit(HASH_TABLE_ITER *iter, + const HASH_TABLE *table); +static NAMED *FASTCALL hashTableIterNext(HASH_TABLE_ITER *iter); -static void FASTCALL poolInit(STRING_POOL *, +static void FASTCALL poolInit(STRING_POOL *pool, const XML_Memory_Handling_Suite *ms); -static void FASTCALL poolClear(STRING_POOL *); -static void FASTCALL poolDestroy(STRING_POOL *); +static void FASTCALL poolClear(STRING_POOL *pool); +static void FASTCALL poolDestroy(STRING_POOL *pool); static XML_Char *poolAppend(STRING_POOL *pool, const ENCODING *enc, const char *ptr, const char *end); static XML_Char *poolStoreString(STRING_POOL *pool, const ENCODING *enc, @@ -512,8 +592,35 @@ static XML_Parser parserCreate(const XML_Char *encodingName, static void parserInit(XML_Parser parser, const XML_Char *encodingName); +#if XML_GE == 1 +static float accountingGetCurrentAmplification(XML_Parser rootParser); +static void accountingReportStats(XML_Parser originParser, const char *epilog); +static void accountingOnAbort(XML_Parser originParser); +static void accountingReportDiff(XML_Parser rootParser, + unsigned int levelsAwayFromRootParser, + const char *before, const char *after, + ptrdiff_t bytesMore, int source_line, + enum XML_Account account); +static XML_Bool accountingDiffTolerated(XML_Parser originParser, int tok, + const char *before, const char *after, + int source_line, + enum XML_Account account); + +static void entityTrackingReportStats(XML_Parser parser, ENTITY *entity, + const char *action, int sourceLine); +static void entityTrackingOnOpen(XML_Parser parser, ENTITY *entity, + int sourceLine); +static void entityTrackingOnClose(XML_Parser parser, ENTITY *entity, + int sourceLine); + +static XML_Parser getRootParserOf(XML_Parser parser, + unsigned int *outLevelDiff); +#endif /* XML_GE == 1 */ + +static unsigned long getDebugLevel(const char *variableName, + unsigned long defaultDebugLevel); + #define poolStart(pool) ((pool)->start) -#define poolEnd(pool) ((pool)->ptr) #define poolLength(pool) ((pool)->ptr - (pool)->start) #define poolChop(pool) ((void)--(pool->ptr)) #define poolLastChar(pool) (((pool)->ptr)[-1]) @@ -524,21 +631,41 @@ static void parserInit(XML_Parser parser, const XML_Char *encodingName); ? 0 \ : ((*((pool)->ptr)++ = c), 1)) +#if ! defined(XML_TESTING) +const +#endif + XML_Bool g_reparseDeferralEnabledDefault + = XML_TRUE; // write ONLY in runtests.c +#if defined(XML_TESTING) +unsigned int g_bytesScanned = 0; // used for testing only +#endif + struct XML_ParserStruct { /* The first member must be m_userData so that the XML_GetUserData macro works. */ void *m_userData; void *m_handlerArg; - char *m_buffer; + + // How the four parse buffer pointers below relate in time and space: + // + // m_buffer <= m_bufferPtr <= m_bufferEnd <= m_bufferLim + // | | | | + // <--parsed-->| | | + // <---parsing--->| | + // <--unoccupied-->| + // <---------total-malloced/realloced-------->| + + char *m_buffer; // malloc/realloc base pointer of parse buffer const XML_Memory_Handling_Suite m_mem; - /* first character to be parsed */ - const char *m_bufferPtr; - /* past last character to be parsed */ - char *m_bufferEnd; - /* allocated end of m_buffer */ - const char *m_bufferLim; + const char *m_bufferPtr; // first character to be parsed + char *m_bufferEnd; // past last character to be parsed + const char *m_bufferLim; // allocated end of m_buffer + XML_Index m_parseEndByteIndex; const char *m_parseEndPtr; + size_t m_partialTokenBytesBefore; /* used in heuristic to avoid O(n^2) */ + XML_Bool m_reparseDeferralEnabled; + int m_lastBufferRequestSize; XML_Char *m_dataBuf; XML_Char *m_dataBufEnd; XML_StartElementHandler m_startElementHandler; @@ -625,6 +752,10 @@ struct XML_ParserStruct { enum XML_ParamEntityParsing m_paramEntityParsing; #endif unsigned long m_hash_secret_salt; +#if XML_GE == 1 + ACCOUNTING m_accounting; + ENTITY_STATS m_entity_stats; +#endif }; #define MALLOC(parser, s) (parser->m_mem.malloc_fcn((s))) @@ -638,11 +769,11 @@ XML_ParserCreate(const XML_Char *encodingName) { XML_Parser XMLCALL XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep) { - XML_Char tmp[2]; - *tmp = nsSep; + XML_Char tmp[2] = {nsSep, 0}; return XML_ParserCreate_MM(encodingName, NULL, tmp); } +// "xml=http://www.w3.org/XML/1998/namespace" static const XML_Char implicitContext[] = {ASCII_x, ASCII_m, ASCII_l, ASCII_EQUALS, ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, @@ -809,9 +940,8 @@ gather_time_entropy(void) { static unsigned long ENTROPY_DEBUG(const char *label, unsigned long entropy) { - const char *const EXPAT_ENTROPY_DEBUG = getenv("EXPAT_ENTROPY_DEBUG"); - if (EXPAT_ENTROPY_DEBUG && ! strcmp(EXPAT_ENTROPY_DEBUG, "1")) { - fprintf(stderr, "Entropy: %s --> 0x%0*lx (%lu bytes)\n", label, + if (getDebugLevel("EXPAT_ENTROPY_DEBUG", 0) >= 1u) { + fprintf(stderr, "expat: Entropy: %s --> 0x%0*lx (%lu bytes)\n", label, (int)sizeof(entropy) * 2, entropy, (unsigned long)sizeof(entropy)); } return entropy; @@ -867,6 +997,49 @@ get_hash_secret_salt(XML_Parser parser) { return parser->m_hash_secret_salt; } +static enum XML_Error +callProcessor(XML_Parser parser, const char *start, const char *end, + const char **endPtr) { + const size_t have_now = EXPAT_SAFE_PTR_DIFF(end, start); + + if (parser->m_reparseDeferralEnabled + && ! parser->m_parsingStatus.finalBuffer) { + // Heuristic: don't try to parse a partial token again until the amount of + // available data has increased significantly. + const size_t had_before = parser->m_partialTokenBytesBefore; + // ...but *do* try anyway if we're close to causing a reallocation. + size_t available_buffer + = EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer); +#if XML_CONTEXT_BYTES > 0 + available_buffer -= EXPAT_MIN(available_buffer, XML_CONTEXT_BYTES); +#endif + available_buffer + += EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_bufferEnd); + // m_lastBufferRequestSize is never assigned a value < 0, so the cast is ok + const bool enough + = (have_now >= 2 * had_before) + || ((size_t)parser->m_lastBufferRequestSize > available_buffer); + + if (! enough) { + *endPtr = start; // callers may expect this to be set + return XML_ERROR_NONE; + } + } +#if defined(XML_TESTING) + g_bytesScanned += (unsigned)have_now; +#endif + const enum XML_Error ret = parser->m_processor(parser, start, end, endPtr); + if (ret == XML_ERROR_NONE) { + // if we consumed nothing, remember what we had on this parse attempt. + if (*endPtr == start) { + parser->m_partialTokenBytesBefore = have_now; + } else { + parser->m_partialTokenBytesBefore = 0; + } + } + return ret; +} + static XML_Bool /* only valid for root parser */ startParsing(XML_Parser parser) { /* hash functions must be initialized before setContext() is called */ @@ -896,7 +1069,7 @@ parserCreate(const XML_Char *encodingName, if (memsuite) { XML_Memory_Handling_Suite *mtemp; - parser = (XML_Parser)memsuite->malloc_fcn(sizeof(struct XML_ParserStruct)); + parser = memsuite->malloc_fcn(sizeof(struct XML_ParserStruct)); if (parser != NULL) { mtemp = (XML_Memory_Handling_Suite *)&(parser->m_mem); mtemp->malloc_fcn = memsuite->malloc_fcn; @@ -988,6 +1161,14 @@ parserCreate(const XML_Char *encodingName, parserInit(parser, encodingName); if (encodingName && ! parser->m_protocolEncodingName) { + if (dtd) { + // We need to stop the upcoming call to XML_ParserFree from happily + // destroying parser->m_dtd because the DTD is shared with the parent + // parser and the only guard that keeps XML_ParserFree from destroying + // parser->m_dtd is parser->m_isParamEntity but it will be set to + // XML_TRUE only later in XML_ExternalEntityParserCreate (or not at all). + parser->m_dtd = NULL; + } XML_ParserFree(parser); return NULL; } @@ -1040,6 +1221,9 @@ parserInit(XML_Parser parser, const XML_Char *encodingName) { parser->m_bufferEnd = parser->m_buffer; parser->m_parseEndByteIndex = 0; parser->m_parseEndPtr = NULL; + parser->m_partialTokenBytesBefore = 0; + parser->m_reparseDeferralEnabled = g_reparseDeferralEnabledDefault; + parser->m_lastBufferRequestSize = 0; parser->m_declElementType = NULL; parser->m_declAttributeId = NULL; parser->m_declEntity = NULL; @@ -1073,6 +1257,18 @@ parserInit(XML_Parser parser, const XML_Char *encodingName) { parser->m_paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; #endif parser->m_hash_secret_salt = 0; + +#if XML_GE == 1 + memset(&parser->m_accounting, 0, sizeof(ACCOUNTING)); + parser->m_accounting.debugLevel = getDebugLevel("EXPAT_ACCOUNTING_DEBUG", 0u); + parser->m_accounting.maximumAmplificationFactor + = EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT; + parser->m_accounting.activationThresholdBytes + = EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT; + + memset(&parser->m_entity_stats, 0, sizeof(ENTITY_STATS)); + parser->m_entity_stats.debugLevel = getDebugLevel("EXPAT_ENTITY_DEBUG", 0u); +#endif } /* moves list of bindings to m_freeBindingList */ @@ -1197,6 +1393,7 @@ XML_ExternalEntityParserCreate(XML_Parser oldParser, const XML_Char *context, to worry which hash secrets each table has. */ unsigned long oldhash_secret_salt; + XML_Bool oldReparseDeferralEnabled; /* Validate the oldParser parameter before we pull everything out of it */ if (oldParser == NULL) @@ -1241,6 +1438,7 @@ XML_ExternalEntityParserCreate(XML_Parser oldParser, const XML_Char *context, to worry which hash secrets each table has. */ oldhash_secret_salt = parser->m_hash_secret_salt; + oldReparseDeferralEnabled = parser->m_reparseDeferralEnabled; #ifdef XML_DTD if (! context) @@ -1253,8 +1451,7 @@ XML_ExternalEntityParserCreate(XML_Parser oldParser, const XML_Char *context, would be otherwise. */ if (parser->m_ns) { - XML_Char tmp[2]; - *tmp = parser->m_namespaceSeparator; + XML_Char tmp[2] = {parser->m_namespaceSeparator, 0}; parser = parserCreate(encodingName, &parser->m_mem, tmp, newDtd); } else { parser = parserCreate(encodingName, &parser->m_mem, NULL, newDtd); @@ -1294,6 +1491,7 @@ XML_ExternalEntityParserCreate(XML_Parser oldParser, const XML_Char *context, parser->m_defaultExpandInternalEntities = oldDefaultExpandInternalEntities; parser->m_ns_triplets = oldns_triplets; parser->m_hash_secret_salt = oldhash_secret_salt; + parser->m_reparseDeferralEnabled = oldReparseDeferralEnabled; parser->m_parentParser = oldParser; #ifdef XML_DTD parser->m_paramEntityParsing = oldParamEntityParsing; @@ -1748,55 +1946,8 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) { parser->m_parsingStatus.parsing = XML_PARSING; } - if (len == 0) { - parser->m_parsingStatus.finalBuffer = (XML_Bool)isFinal; - if (! isFinal) - return XML_STATUS_OK; - parser->m_positionPtr = parser->m_bufferPtr; - parser->m_parseEndPtr = parser->m_bufferEnd; - - /* If data are left over from last buffer, and we now know that these - data are the final chunk of input, then we have to check them again - to detect errors based on that fact. - */ - parser->m_errorCode - = parser->m_processor(parser, parser->m_bufferPtr, - parser->m_parseEndPtr, &parser->m_bufferPtr); - - if (parser->m_errorCode == XML_ERROR_NONE) { - switch (parser->m_parsingStatus.parsing) { - case XML_SUSPENDED: - /* It is hard to be certain, but it seems that this case - * cannot occur. This code is cleaning up a previous parse - * with no new data (since len == 0). Changing the parsing - * state requires getting to execute a handler function, and - * there doesn't seem to be an opportunity for that while in - * this circumstance. - * - * Given the uncertainty, we retain the code but exclude it - * from coverage tests. - * - * LCOV_EXCL_START - */ - XmlUpdatePosition(parser->m_encoding, parser->m_positionPtr, - parser->m_bufferPtr, &parser->m_position); - parser->m_positionPtr = parser->m_bufferPtr; - return XML_STATUS_SUSPENDED; - /* LCOV_EXCL_STOP */ - case XML_INITIALIZED: - case XML_PARSING: - parser->m_parsingStatus.parsing = XML_FINISHED; - /* fall through */ - default: - return XML_STATUS_OK; - } - } - parser->m_eventEndPtr = parser->m_eventPtr; - parser->m_processor = errorProcessor; - return XML_STATUS_ERROR; - } -#ifndef XML_CONTEXT_BYTES - else if (parser->m_bufferPtr == parser->m_bufferEnd) { +#if XML_CONTEXT_BYTES == 0 + if (parser->m_bufferPtr == parser->m_bufferEnd) { const char *end; int nLeftOver; enum XML_Status result; @@ -1807,12 +1958,15 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) { parser->m_processor = errorProcessor; return XML_STATUS_ERROR; } + // though this isn't a buffer request, we assume that `len` is the app's + // preferred buffer fill size, and therefore save it here. + parser->m_lastBufferRequestSize = len; parser->m_parseEndByteIndex += len; parser->m_positionPtr = s; parser->m_parsingStatus.finalBuffer = (XML_Bool)isFinal; parser->m_errorCode - = parser->m_processor(parser, s, parser->m_parseEndPtr = s + len, &end); + = callProcessor(parser, s, parser->m_parseEndPtr = s + len, &end); if (parser->m_errorCode != XML_ERROR_NONE) { parser->m_eventEndPtr = parser->m_eventPtr; @@ -1839,23 +1993,25 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) { &parser->m_position); nLeftOver = s + len - end; if (nLeftOver) { - if (parser->m_buffer == NULL - || nLeftOver > parser->m_bufferLim - parser->m_buffer) { - /* avoid _signed_ integer overflow */ - char *temp = NULL; - const int bytesToAllocate = (int)((unsigned)len * 2U); - if (bytesToAllocate > 0) { - temp = (char *)REALLOC(parser, parser->m_buffer, bytesToAllocate); - } - if (temp == NULL) { - parser->m_errorCode = XML_ERROR_NO_MEMORY; - parser->m_eventPtr = parser->m_eventEndPtr = NULL; - parser->m_processor = errorProcessor; - return XML_STATUS_ERROR; - } - parser->m_buffer = temp; - parser->m_bufferLim = parser->m_buffer + bytesToAllocate; + // Back up and restore the parsing status to avoid XML_ERROR_SUSPENDED + // (and XML_ERROR_FINISHED) from XML_GetBuffer. + const enum XML_Parsing originalStatus = parser->m_parsingStatus.parsing; + parser->m_parsingStatus.parsing = XML_PARSING; + void *const temp = XML_GetBuffer(parser, nLeftOver); + parser->m_parsingStatus.parsing = originalStatus; + // GetBuffer may have overwritten this, but we want to remember what the + // app requested, not how many bytes were left over after parsing. + parser->m_lastBufferRequestSize = len; + if (temp == NULL) { + // NOTE: parser->m_errorCode has already been set by XML_GetBuffer(). + parser->m_eventPtr = parser->m_eventEndPtr = NULL; + parser->m_processor = errorProcessor; + return XML_STATUS_ERROR; } + // Since we know that the buffer was empty and XML_CONTEXT_BYTES is 0, we + // don't have any data to preserve, and can copy straight into the start + // of the buffer rather than the GetBuffer return pointer (which may be + // pointing further into the allocated buffer). memcpy(parser->m_buffer, end, nLeftOver); } parser->m_bufferPtr = parser->m_buffer; @@ -1866,16 +2022,15 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) { parser->m_eventEndPtr = parser->m_bufferPtr; return result; } -#endif /* not defined XML_CONTEXT_BYTES */ - else { - void *buff = XML_GetBuffer(parser, len); - if (buff == NULL) - return XML_STATUS_ERROR; - else { - memcpy(buff, s, len); - return XML_ParseBuffer(parser, len, isFinal); - } +#endif /* XML_CONTEXT_BYTES == 0 */ + void *buff = XML_GetBuffer(parser, len); + if (buff == NULL) + return XML_STATUS_ERROR; + if (len > 0) { + assert(s != NULL); // make sure s==NULL && len!=0 was rejected above + memcpy(buff, s, len); } + return XML_ParseBuffer(parser, len, isFinal); } enum XML_Status XMLCALL @@ -1885,6 +2040,12 @@ XML_ParseBuffer(XML_Parser parser, int len, int isFinal) { if (parser == NULL) return XML_STATUS_ERROR; + + if (len < 0) { + parser->m_errorCode = XML_ERROR_INVALID_ARGUMENT; + return XML_STATUS_ERROR; + } + switch (parser->m_parsingStatus.parsing) { case XML_SUSPENDED: parser->m_errorCode = XML_ERROR_SUSPENDED; @@ -1893,6 +2054,12 @@ XML_ParseBuffer(XML_Parser parser, int len, int isFinal) { parser->m_errorCode = XML_ERROR_FINISHED; return XML_STATUS_ERROR; case XML_INITIALIZED: + /* Has someone called XML_GetBuffer successfully before? */ + if (! parser->m_bufferPtr) { + parser->m_errorCode = XML_ERROR_NO_BUFFER; + return XML_STATUS_ERROR; + } + if (parser->m_parentParser == NULL && ! startParsing(parser)) { parser->m_errorCode = XML_ERROR_NO_MEMORY; return XML_STATUS_ERROR; @@ -1909,8 +2076,8 @@ XML_ParseBuffer(XML_Parser parser, int len, int isFinal) { parser->m_parseEndByteIndex += len; parser->m_parsingStatus.finalBuffer = (XML_Bool)isFinal; - parser->m_errorCode = parser->m_processor( - parser, start, parser->m_parseEndPtr, &parser->m_bufferPtr); + parser->m_errorCode = callProcessor(parser, start, parser->m_parseEndPtr, + &parser->m_bufferPtr); if (parser->m_errorCode != XML_ERROR_NONE) { parser->m_eventEndPtr = parser->m_eventPtr; @@ -1955,10 +2122,14 @@ XML_GetBuffer(XML_Parser parser, int len) { default:; } - if (len > EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_bufferEnd)) { -#ifdef XML_CONTEXT_BYTES + // whether or not the request succeeds, `len` seems to be the app's preferred + // buffer fill size; remember it. + parser->m_lastBufferRequestSize = len; + if (len > EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_bufferEnd) + || parser->m_buffer == NULL) { +#if XML_CONTEXT_BYTES > 0 int keep; -#endif /* defined XML_CONTEXT_BYTES */ +#endif /* XML_CONTEXT_BYTES > 0 */ /* Do not invoke signed arithmetic overflow: */ int neededSize = (int)((unsigned)len + (unsigned)EXPAT_SAFE_PTR_DIFF( @@ -1967,15 +2138,21 @@ XML_GetBuffer(XML_Parser parser, int len) { parser->m_errorCode = XML_ERROR_NO_MEMORY; return NULL; } -#ifdef XML_CONTEXT_BYTES +#if XML_CONTEXT_BYTES > 0 keep = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer); if (keep > XML_CONTEXT_BYTES) keep = XML_CONTEXT_BYTES; + /* Detect and prevent integer overflow */ + if (keep > INT_MAX - neededSize) { + parser->m_errorCode = XML_ERROR_NO_MEMORY; + return NULL; + } neededSize += keep; -#endif /* defined XML_CONTEXT_BYTES */ - if (neededSize - <= EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_buffer)) { -#ifdef XML_CONTEXT_BYTES +#endif /* XML_CONTEXT_BYTES > 0 */ + if (parser->m_buffer && parser->m_bufferPtr + && neededSize + <= EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_buffer)) { +#if XML_CONTEXT_BYTES > 0 if (keep < EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer)) { int offset = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferPtr, parser->m_buffer) @@ -1988,19 +2165,17 @@ XML_GetBuffer(XML_Parser parser, int len) { parser->m_bufferPtr -= offset; } #else - if (parser->m_buffer && parser->m_bufferPtr) { - memmove(parser->m_buffer, parser->m_bufferPtr, - EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr)); - parser->m_bufferEnd - = parser->m_buffer - + EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr); - parser->m_bufferPtr = parser->m_buffer; - } -#endif /* not defined XML_CONTEXT_BYTES */ + memmove(parser->m_buffer, parser->m_bufferPtr, + EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr)); + parser->m_bufferEnd + = parser->m_buffer + + EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr); + parser->m_bufferPtr = parser->m_buffer; +#endif /* XML_CONTEXT_BYTES > 0 */ } else { char *newBuf; int bufferSize - = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_bufferPtr); + = (int)EXPAT_SAFE_PTR_DIFF(parser->m_bufferLim, parser->m_buffer); if (bufferSize == 0) bufferSize = INIT_BUFFER_SIZE; do { @@ -2017,7 +2192,7 @@ XML_GetBuffer(XML_Parser parser, int len) { return NULL; } parser->m_bufferLim = newBuf + bufferSize; -#ifdef XML_CONTEXT_BYTES +#if XML_CONTEXT_BYTES > 0 if (parser->m_bufferPtr) { memcpy(newBuf, &parser->m_bufferPtr[-keep], EXPAT_SAFE_PTR_DIFF(parser->m_bufferEnd, parser->m_bufferPtr) @@ -2047,7 +2222,7 @@ XML_GetBuffer(XML_Parser parser, int len) { parser->m_bufferEnd = newBuf; } parser->m_bufferPtr = parser->m_buffer = newBuf; -#endif /* not defined XML_CONTEXT_BYTES */ +#endif /* XML_CONTEXT_BYTES > 0 */ } parser->m_eventPtr = parser->m_eventEndPtr = NULL; parser->m_positionPtr = NULL; @@ -2060,6 +2235,9 @@ XML_StopParser(XML_Parser parser, XML_Bool resumable) { if (parser == NULL) return XML_STATUS_ERROR; switch (parser->m_parsingStatus.parsing) { + case XML_INITIALIZED: + parser->m_errorCode = XML_ERROR_NOT_STARTED; + return XML_STATUS_ERROR; case XML_SUSPENDED: if (resumable) { parser->m_errorCode = XML_ERROR_SUSPENDED; @@ -2070,7 +2248,7 @@ XML_StopParser(XML_Parser parser, XML_Bool resumable) { case XML_FINISHED: parser->m_errorCode = XML_ERROR_FINISHED; return XML_STATUS_ERROR; - default: + case XML_PARSING: if (resumable) { #ifdef XML_DTD if (parser->m_isParamEntity) { @@ -2081,6 +2259,9 @@ XML_StopParser(XML_Parser parser, XML_Bool resumable) { parser->m_parsingStatus.parsing = XML_SUSPENDED; } else parser->m_parsingStatus.parsing = XML_FINISHED; + break; + default: + assert(0); } return XML_STATUS_OK; } @@ -2097,7 +2278,7 @@ XML_ResumeParser(XML_Parser parser) { } parser->m_parsingStatus.parsing = XML_PARSING; - parser->m_errorCode = parser->m_processor( + parser->m_errorCode = callProcessor( parser, parser->m_bufferPtr, parser->m_parseEndPtr, &parser->m_bufferPtr); if (parser->m_errorCode != XML_ERROR_NONE) { @@ -2161,7 +2342,7 @@ XML_GetCurrentByteCount(XML_Parser parser) { const char *XMLCALL XML_GetInputContext(XML_Parser parser, int *offset, int *size) { -#ifdef XML_CONTEXT_BYTES +#if XML_CONTEXT_BYTES > 0 if (parser == NULL) return NULL; if (parser->m_eventPtr && parser->m_buffer) { @@ -2175,7 +2356,7 @@ XML_GetInputContext(XML_Parser parser, int *offset, int *size) { (void)parser; (void)offset; (void)size; -#endif /* defined XML_CONTEXT_BYTES */ +#endif /* XML_CONTEXT_BYTES > 0 */ return (const char *)0; } @@ -2337,6 +2518,17 @@ XML_ErrorString(enum XML_Error code) { /* Added in 2.2.5. */ case XML_ERROR_INVALID_ARGUMENT: /* Constant added in 2.2.1, already */ return XML_L("invalid argument"); + /* Added in 2.3.0. */ + case XML_ERROR_NO_BUFFER: + return XML_L( + "a successful prior call to function XML_GetBuffer is required"); + /* Added in 2.4.0. */ + case XML_ERROR_AMPLIFICATION_LIMIT_BREACH: + return XML_L( + "limit on input amplification factor (from DTD and entities) breached"); + /* Added in 2.6.4. */ + case XML_ERROR_NOT_STARTED: + return XML_L("parser not started"); } return NULL; } @@ -2373,41 +2565,87 @@ XML_ExpatVersionInfo(void) { const XML_Feature *XMLCALL XML_GetFeatureList(void) { - static const XML_Feature features[] - = {{XML_FEATURE_SIZEOF_XML_CHAR, XML_L("sizeof(XML_Char)"), - sizeof(XML_Char)}, - {XML_FEATURE_SIZEOF_XML_LCHAR, XML_L("sizeof(XML_LChar)"), - sizeof(XML_LChar)}, + static const XML_Feature features[] = { + {XML_FEATURE_SIZEOF_XML_CHAR, XML_L("sizeof(XML_Char)"), + sizeof(XML_Char)}, + {XML_FEATURE_SIZEOF_XML_LCHAR, XML_L("sizeof(XML_LChar)"), + sizeof(XML_LChar)}, #ifdef XML_UNICODE - {XML_FEATURE_UNICODE, XML_L("XML_UNICODE"), 0}, + {XML_FEATURE_UNICODE, XML_L("XML_UNICODE"), 0}, #endif #ifdef XML_UNICODE_WCHAR_T - {XML_FEATURE_UNICODE_WCHAR_T, XML_L("XML_UNICODE_WCHAR_T"), 0}, + {XML_FEATURE_UNICODE_WCHAR_T, XML_L("XML_UNICODE_WCHAR_T"), 0}, #endif #ifdef XML_DTD - {XML_FEATURE_DTD, XML_L("XML_DTD"), 0}, + {XML_FEATURE_DTD, XML_L("XML_DTD"), 0}, #endif -#ifdef XML_CONTEXT_BYTES - {XML_FEATURE_CONTEXT_BYTES, XML_L("XML_CONTEXT_BYTES"), - XML_CONTEXT_BYTES}, +#if XML_CONTEXT_BYTES > 0 + {XML_FEATURE_CONTEXT_BYTES, XML_L("XML_CONTEXT_BYTES"), + XML_CONTEXT_BYTES}, #endif #ifdef XML_MIN_SIZE - {XML_FEATURE_MIN_SIZE, XML_L("XML_MIN_SIZE"), 0}, + {XML_FEATURE_MIN_SIZE, XML_L("XML_MIN_SIZE"), 0}, #endif #ifdef XML_NS - {XML_FEATURE_NS, XML_L("XML_NS"), 0}, + {XML_FEATURE_NS, XML_L("XML_NS"), 0}, #endif #ifdef XML_LARGE_SIZE - {XML_FEATURE_LARGE_SIZE, XML_L("XML_LARGE_SIZE"), 0}, + {XML_FEATURE_LARGE_SIZE, XML_L("XML_LARGE_SIZE"), 0}, #endif #ifdef XML_ATTR_INFO - {XML_FEATURE_ATTR_INFO, XML_L("XML_ATTR_INFO"), 0}, + {XML_FEATURE_ATTR_INFO, XML_L("XML_ATTR_INFO"), 0}, +#endif +#if XML_GE == 1 + /* Added in Expat 2.4.0 for XML_DTD defined and + * added in Expat 2.6.0 for XML_GE == 1. */ + {XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT, + XML_L("XML_BLAP_MAX_AMP"), + (long int) + EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT}, + {XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT, + XML_L("XML_BLAP_ACT_THRES"), + EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT}, + /* Added in Expat 2.6.0. */ + {XML_FEATURE_GE, XML_L("XML_GE"), 0}, #endif - {XML_FEATURE_END, NULL, 0}}; + {XML_FEATURE_END, NULL, 0}}; return features; } +#if XML_GE == 1 +XML_Bool XMLCALL +XML_SetBillionLaughsAttackProtectionMaximumAmplification( + XML_Parser parser, float maximumAmplificationFactor) { + if ((parser == NULL) || (parser->m_parentParser != NULL) + || isnan(maximumAmplificationFactor) + || (maximumAmplificationFactor < 1.0f)) { + return XML_FALSE; + } + parser->m_accounting.maximumAmplificationFactor = maximumAmplificationFactor; + return XML_TRUE; +} + +XML_Bool XMLCALL +XML_SetBillionLaughsAttackProtectionActivationThreshold( + XML_Parser parser, unsigned long long activationThresholdBytes) { + if ((parser == NULL) || (parser->m_parentParser != NULL)) { + return XML_FALSE; + } + parser->m_accounting.activationThresholdBytes = activationThresholdBytes; + return XML_TRUE; +} +#endif /* XML_GE == 1 */ + +XML_Bool XMLCALL +XML_SetReparseDeferralEnabled(XML_Parser parser, XML_Bool enabled) { + if (parser != NULL && (enabled == XML_TRUE || enabled == XML_FALSE)) { + parser->m_reparseDeferralEnabled = enabled; + return XML_TRUE; + } + return XML_FALSE; +} + /* Initially tag->rawName always points into the parse buffer; for those TAG instances opened while the current parse buffer was processed, and not yet closed, we need to store tag->rawName in a more @@ -2419,6 +2657,7 @@ storeRawNames(XML_Parser parser) { while (tag) { int bufSize; int nameLen = sizeof(XML_Char) * (tag->name.strLen + 1); + size_t rawNameLen; char *rawNameBuf = tag->buf + nameLen; /* Stop if already stored. Since m_tagStack is a stack, we can stop at the first entry that has already been copied; everything @@ -2427,10 +2666,14 @@ storeRawNames(XML_Parser parser) { */ if (tag->rawName == rawNameBuf) break; - /* For re-use purposes we need to ensure that the + /* For reuse purposes we need to ensure that the size of tag->buf is a multiple of sizeof(XML_Char). */ - bufSize = nameLen + ROUND_UP(tag->rawNameLength, sizeof(XML_Char)); + rawNameLen = ROUND_UP(tag->rawNameLength, sizeof(XML_Char)); + /* Detect and prevent integer overflow. */ + if (rawNameLen > (size_t)INT_MAX - nameLen) + return XML_FALSE; + bufSize = nameLen + (int)rawNameLen; if (bufSize > tag->bufEnd - tag->buf) { char *temp = (char *)REALLOC(parser, tag->buf, bufSize); if (temp == NULL) @@ -2460,9 +2703,9 @@ storeRawNames(XML_Parser parser) { static enum XML_Error PTRCALL contentProcessor(XML_Parser parser, const char *start, const char *end, const char **endPtr) { - enum XML_Error result - = doContent(parser, 0, parser->m_encoding, start, end, endPtr, - (XML_Bool)! parser->m_parsingStatus.finalBuffer); + enum XML_Error result = doContent( + parser, 0, parser->m_encoding, start, end, endPtr, + (XML_Bool)! parser->m_parsingStatus.finalBuffer, XML_ACCOUNT_DIRECT); if (result == XML_ERROR_NONE) { if (! storeRawNames(parser)) return XML_ERROR_NO_MEMORY; @@ -2487,6 +2730,14 @@ externalEntityInitProcessor2(XML_Parser parser, const char *start, int tok = XmlContentTok(parser->m_encoding, start, end, &next); switch (tok) { case XML_TOK_BOM: +#if XML_GE == 1 + if (! accountingDiffTolerated(parser, tok, start, next, __LINE__, + XML_ACCOUNT_DIRECT)) { + accountingOnAbort(parser); + return XML_ERROR_AMPLIFICATION_LIMIT_BREACH; + } +#endif /* XML_GE == 1 */ + /* If we are at the end of the buffer, this would cause the next stage, i.e. externalEntityInitProcessor3, to pass control directly to doContent (by detecting XML_TOK_NONE) without processing any xml text @@ -2524,6 +2775,10 @@ externalEntityInitProcessor3(XML_Parser parser, const char *start, const char *next = start; /* XmlContentTok doesn't always set the last arg */ parser->m_eventPtr = start; tok = XmlContentTok(parser->m_encoding, start, end, &next); + /* Note: These bytes are accounted later in: + - processXmlDecl + - externalEntityContentProcessor + */ parser->m_eventEndPtr = next; switch (tok) { @@ -2565,7 +2820,8 @@ externalEntityContentProcessor(XML_Parser parser, const char *start, const char *end, const char **endPtr) { enum XML_Error result = doContent(parser, 1, parser->m_encoding, start, end, endPtr, - (XML_Bool)! parser->m_parsingStatus.finalBuffer); + (XML_Bool)! parser->m_parsingStatus.finalBuffer, + XML_ACCOUNT_ENTITY_EXPANSION); if (result == XML_ERROR_NONE) { if (! storeRawNames(parser)) return XML_ERROR_NO_MEMORY; @@ -2576,7 +2832,7 @@ externalEntityContentProcessor(XML_Parser parser, const char *start, static enum XML_Error doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, const char *s, const char *end, const char **nextPtr, - XML_Bool haveMore) { + XML_Bool haveMore, enum XML_Account account) { /* save one level of indirection */ DTD *const dtd = parser->m_dtd; @@ -2594,6 +2850,17 @@ doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, for (;;) { const char *next = s; /* XmlContentTok doesn't always set the last arg */ int tok = XmlContentTok(enc, s, end, &next); +#if XML_GE == 1 + const char *accountAfter + = ((tok == XML_TOK_TRAILING_RSQB) || (tok == XML_TOK_TRAILING_CR)) + ? (haveMore ? s /* i.e. 0 bytes */ : end) + : next; + if (! accountingDiffTolerated(parser, tok, s, accountAfter, __LINE__, + account)) { + accountingOnAbort(parser); + return XML_ERROR_AMPLIFICATION_LIMIT_BREACH; + } +#endif *eventEndPP = next; switch (tok) { case XML_TOK_TRAILING_CR: @@ -2649,6 +2916,14 @@ doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, XML_Char ch = (XML_Char)XmlPredefinedEntityName( enc, s + enc->minBytesPerChar, next - enc->minBytesPerChar); if (ch) { +#if XML_GE == 1 + /* NOTE: We are replacing 4-6 characters original input for 1 character + * so there is no amplification and hence recording without + * protection. */ + accountingDiffTolerated(parser, tok, (char *)&ch, + ((char *)&ch) + sizeof(XML_Char), __LINE__, + XML_ACCOUNT_ENTITY_EXPANSION); +#endif /* XML_GE == 1 */ if (parser->m_characterDataHandler) parser->m_characterDataHandler(parser->m_handlerArg, &ch, 1); else if (parser->m_defaultHandler) @@ -2767,7 +3042,8 @@ doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, } tag->name.str = (XML_Char *)tag->buf; *toPtr = XML_T('\0'); - result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings)); + result + = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings), account); if (result) return result; if (parser->m_startElementHandler) @@ -2791,7 +3067,8 @@ doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, if (! name.str) return XML_ERROR_NO_MEMORY; poolFinish(&parser->m_tempPool); - result = storeAtts(parser, enc, s, &name, &bindings); + result = storeAtts(parser, enc, s, &name, &bindings, + XML_ACCOUNT_NONE /* token spans whole start tag */); if (result != XML_ERROR_NONE) { freeBindings(parser, bindings); return result; @@ -2828,9 +3105,6 @@ doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, int len; const char *rawName; TAG *tag = parser->m_tagStack; - parser->m_tagStack = tag->parent; - tag->parent = parser->m_freeTagList; - parser->m_freeTagList = tag; rawName = s + enc->minBytesPerChar * 2; len = XmlNameLength(enc, rawName); if (len != tag->rawNameLength @@ -2838,6 +3112,9 @@ doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, *eventPP = rawName; return XML_ERROR_TAG_MISMATCH; } + parser->m_tagStack = tag->parent; + tag->parent = parser->m_freeTagList; + parser->m_freeTagList = tag; --parser->m_tagLevel; if (parser->m_endElementHandler) { const XML_Char *localPart; @@ -2847,13 +3124,13 @@ doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, if (parser->m_ns && localPart) { /* localPart and prefix may have been overwritten in tag->name.str, since this points to the binding->uri - buffer which gets re-used; so we have to add them again + buffer which gets reused; so we have to add them again */ uri = (XML_Char *)tag->name.str + tag->name.uriLen; /* don't need to check for space - already done in storeAtts() */ while (*localPart) *uri++ = *localPart++; - prefix = (XML_Char *)tag->name.prefix; + prefix = tag->name.prefix; if (parser->m_ns_triplets && prefix) { *uri++ = parser->m_namespaceSeparator; while (*prefix) @@ -2920,13 +3197,14 @@ doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, However, now we have a start/endCdataSectionHandler, so it seems easier to let the user deal with this. */ - else if (0 && parser->m_characterDataHandler) + else if ((0) && parser->m_characterDataHandler) parser->m_characterDataHandler(parser->m_handlerArg, parser->m_dataBuf, 0); /* END disabled code */ else if (parser->m_defaultHandler) reportDefault(parser, enc, s, next); - result = doCdataSection(parser, enc, &next, end, nextPtr, haveMore); + result + = doCdataSection(parser, enc, &next, end, nextPtr, haveMore, account); if (result != XML_ERROR_NONE) return result; else if (! next) { @@ -2948,8 +3226,8 @@ doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, (int)(dataPtr - (ICHAR *)parser->m_dataBuf)); } else parser->m_characterDataHandler( - parser->m_handlerArg, (XML_Char *)s, - (int)((XML_Char *)end - (XML_Char *)s)); + parser->m_handlerArg, (const XML_Char *)s, + (int)((const XML_Char *)end - (const XML_Char *)s)); } else if (parser->m_defaultHandler) reportDefault(parser, enc, s, end); /* We are at the end of the final buffer, should we check for @@ -2982,8 +3260,8 @@ doContent(XML_Parser parser, int startTagLevel, const ENCODING *enc, *eventPP = s; } } else - charDataHandler(parser->m_handlerArg, (XML_Char *)s, - (int)((XML_Char *)next - (XML_Char *)s)); + charDataHandler(parser->m_handlerArg, (const XML_Char *)s, + (int)((const XML_Char *)next - (const XML_Char *)s)); } else if (parser->m_defaultHandler) reportDefault(parser, enc, s, next); } break; @@ -3055,7 +3333,8 @@ freeBindings(XML_Parser parser, BINDING *bindings) { */ static enum XML_Error storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr, - TAG_NAME *tagNamePtr, BINDING **bindingsPtr) { + TAG_NAME *tagNamePtr, BINDING **bindingsPtr, + enum XML_Account account) { DTD *const dtd = parser->m_dtd; /* save one level of indirection */ ELEMENT_TYPE *elementType; int nDefaultAtts; @@ -3087,13 +3366,38 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr, /* get the attributes from the tokenizer */ n = XmlGetAttributes(enc, attStr, parser->m_attsSize, parser->m_atts); + + /* Detect and prevent integer overflow */ + if (n > INT_MAX - nDefaultAtts) { + return XML_ERROR_NO_MEMORY; + } + if (n + nDefaultAtts > parser->m_attsSize) { int oldAttsSize = parser->m_attsSize; ATTRIBUTE *temp; #ifdef XML_ATTR_INFO XML_AttrInfo *temp2; #endif + + /* Detect and prevent integer overflow */ + if ((nDefaultAtts > INT_MAX - INIT_ATTS_SIZE) + || (n > INT_MAX - (nDefaultAtts + INIT_ATTS_SIZE))) { + return XML_ERROR_NO_MEMORY; + } + parser->m_attsSize = n + nDefaultAtts + INIT_ATTS_SIZE; + + /* Detect and prevent integer overflow. + * The preprocessor guard addresses the "always false" warning + * from -Wtype-limits on platforms where + * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */ +#if UINT_MAX >= SIZE_MAX + if ((unsigned)parser->m_attsSize > (size_t)(-1) / sizeof(ATTRIBUTE)) { + parser->m_attsSize = oldAttsSize; + return XML_ERROR_NO_MEMORY; + } +#endif + temp = (ATTRIBUTE *)REALLOC(parser, (void *)parser->m_atts, parser->m_attsSize * sizeof(ATTRIBUTE)); if (temp == NULL) { @@ -3102,6 +3406,17 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr, } parser->m_atts = temp; #ifdef XML_ATTR_INFO + /* Detect and prevent integer overflow. + * The preprocessor guard addresses the "always false" warning + * from -Wtype-limits on platforms where + * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */ +# if UINT_MAX >= SIZE_MAX + if ((unsigned)parser->m_attsSize > (size_t)(-1) / sizeof(XML_AttrInfo)) { + parser->m_attsSize = oldAttsSize; + return XML_ERROR_NO_MEMORY; + } +# endif + temp2 = (XML_AttrInfo *)REALLOC(parser, (void *)parser->m_attInfo, parser->m_attsSize * sizeof(XML_AttrInfo)); if (temp2 == NULL) { @@ -3165,7 +3480,7 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr, /* normalize the attribute value */ result = storeAttributeValue( parser, enc, isCdata, parser->m_atts[i].valuePtr, - parser->m_atts[i].valueEnd, &parser->m_tempPool); + parser->m_atts[i].valueEnd, &parser->m_tempPool, account); if (result) return result; appAtts[attIndex] = poolStart(&parser->m_tempPool); @@ -3240,7 +3555,13 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr, if (nPrefixes) { int j; /* hash table index */ unsigned long version = parser->m_nsAttsVersion; - int nsAttsSize = (int)1 << parser->m_nsAttsPower; + + /* Detect and prevent invalid shift */ + if (parser->m_nsAttsPower >= sizeof(unsigned int) * 8 /* bits per byte */) { + return XML_ERROR_NO_MEMORY; + } + + unsigned int nsAttsSize = 1u << parser->m_nsAttsPower; unsigned char oldNsAttsPower = parser->m_nsAttsPower; /* size of hash table must be at least 2 * (# of prefixed attributes) */ if ((nPrefixes << 1) @@ -3251,7 +3572,28 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr, ; if (parser->m_nsAttsPower < 3) parser->m_nsAttsPower = 3; - nsAttsSize = (int)1 << parser->m_nsAttsPower; + + /* Detect and prevent invalid shift */ + if (parser->m_nsAttsPower >= sizeof(nsAttsSize) * 8 /* bits per byte */) { + /* Restore actual size of memory in m_nsAtts */ + parser->m_nsAttsPower = oldNsAttsPower; + return XML_ERROR_NO_MEMORY; + } + + nsAttsSize = 1u << parser->m_nsAttsPower; + + /* Detect and prevent integer overflow. + * The preprocessor guard addresses the "always false" warning + * from -Wtype-limits on platforms where + * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */ +#if UINT_MAX >= SIZE_MAX + if (nsAttsSize > (size_t)(-1) / sizeof(NS_ATT)) { + /* Restore actual size of memory in m_nsAtts */ + parser->m_nsAttsPower = oldNsAttsPower; + return XML_ERROR_NO_MEMORY; + } +#endif + temp = (NS_ATT *)REALLOC(parser, parser->m_nsAtts, nsAttsSize * sizeof(NS_ATT)); if (! temp) { @@ -3409,9 +3751,31 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr, tagNamePtr->prefixLen = prefixLen; for (i = 0; localPart[i++];) ; /* i includes null terminator */ + + /* Detect and prevent integer overflow */ + if (binding->uriLen > INT_MAX - prefixLen + || i > INT_MAX - (binding->uriLen + prefixLen)) { + return XML_ERROR_NO_MEMORY; + } + n = i + binding->uriLen + prefixLen; if (n > binding->uriAlloc) { TAG *p; + + /* Detect and prevent integer overflow */ + if (n > INT_MAX - EXPAND_SPARE) { + return XML_ERROR_NO_MEMORY; + } + /* Detect and prevent integer overflow. + * The preprocessor guard addresses the "always false" warning + * from -Wtype-limits on platforms where + * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */ +#if UINT_MAX >= SIZE_MAX + if ((unsigned)(n + EXPAND_SPARE) > (size_t)(-1) / sizeof(XML_Char)) { + return XML_ERROR_NO_MEMORY; + } +#endif + uri = (XML_Char *)MALLOC(parser, (n + EXPAND_SPARE) * sizeof(XML_Char)); if (! uri) return XML_ERROR_NO_MEMORY; @@ -3436,12 +3800,124 @@ storeAtts(XML_Parser parser, const ENCODING *enc, const char *attStr, return XML_ERROR_NONE; } +static XML_Bool +is_rfc3986_uri_char(XML_Char candidate) { + // For the RFC 3986 ANBF grammar see + // https://datatracker.ietf.org/doc/html/rfc3986#appendix-A + + switch (candidate) { + // From rule "ALPHA" (uppercase half) + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + + // From rule "ALPHA" (lowercase half) + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': + + // From rule "DIGIT" + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + + // From rule "pct-encoded" + case '%': + + // From rule "unreserved" + case '-': + case '.': + case '_': + case '~': + + // From rule "gen-delims" + case ':': + case '/': + case '?': + case '#': + case '[': + case ']': + case '@': + + // From rule "sub-delims" + case '!': + case '$': + case '&': + case '\'': + case '(': + case ')': + case '*': + case '+': + case ',': + case ';': + case '=': + return XML_TRUE; + + default: + return XML_FALSE; + } +} + /* addBinding() overwrites the value of prefix->binding without checking. Therefore one must keep track of the old value outside of addBinding(). */ static enum XML_Error addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, const XML_Char *uri, BINDING **bindingsPtr) { + // "http://www.w3.org/XML/1998/namespace" static const XML_Char xmlNamespace[] = {ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w, @@ -3452,6 +3928,7 @@ addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, ASCII_e, ASCII_s, ASCII_p, ASCII_a, ASCII_c, ASCII_e, '\0'}; static const int xmlLen = (int)sizeof(xmlNamespace) / sizeof(XML_Char) - 1; + // "http://www.w3.org/2000/xmlns/" static const XML_Char xmlnsNamespace[] = {ASCII_h, ASCII_t, ASCII_t, ASCII_p, ASCII_COLON, ASCII_SLASH, ASCII_SLASH, ASCII_w, ASCII_w, ASCII_w, ASCII_PERIOD, ASCII_w, @@ -3491,6 +3968,29 @@ addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, if (! mustBeXML && isXMLNS && (len > xmlnsLen || uri[len] != xmlnsNamespace[len])) isXMLNS = XML_FALSE; + + // NOTE: While Expat does not validate namespace URIs against RFC 3986 + // today (and is not REQUIRED to do so with regard to the XML 1.0 + // namespaces specification) we have to at least make sure, that + // the application on top of Expat (that is likely splitting expanded + // element names ("qualified names") of form + // "[uri sep] local [sep prefix] '\0'" back into 1, 2 or 3 pieces + // in its element handler code) cannot be confused by an attacker + // putting additional namespace separator characters into namespace + // declarations. That would be ambiguous and not to be expected. + // + // While the HTML API docs of function XML_ParserCreateNS have been + // advising against use of a namespace separator character that can + // appear in a URI for >20 years now, some widespread applications + // are using URI characters (':' (colon) in particular) for a + // namespace separator, in practice. To keep these applications + // functional, we only reject namespaces URIs containing the + // application-chosen namespace separator if the chosen separator + // is a non-URI character with regard to RFC 3986. + if (parser->m_ns && (uri[len] == parser->m_namespaceSeparator) + && ! is_rfc3986_uri_char(uri[len])) { + return XML_ERROR_SYNTAX; + } } isXML = isXML && len == xmlLen; isXMLNS = isXMLNS && len == xmlnsLen; @@ -3507,6 +4007,21 @@ addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, if (parser->m_freeBindingList) { b = parser->m_freeBindingList; if (len > b->uriAlloc) { + /* Detect and prevent integer overflow */ + if (len > INT_MAX - EXPAND_SPARE) { + return XML_ERROR_NO_MEMORY; + } + + /* Detect and prevent integer overflow. + * The preprocessor guard addresses the "always false" warning + * from -Wtype-limits on platforms where + * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */ +#if UINT_MAX >= SIZE_MAX + if ((unsigned)(len + EXPAND_SPARE) > (size_t)(-1) / sizeof(XML_Char)) { + return XML_ERROR_NO_MEMORY; + } +#endif + XML_Char *temp = (XML_Char *)REALLOC( parser, b->uri, sizeof(XML_Char) * (len + EXPAND_SPARE)); if (temp == NULL) @@ -3519,6 +4034,21 @@ addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, b = (BINDING *)MALLOC(parser, sizeof(BINDING)); if (! b) return XML_ERROR_NO_MEMORY; + + /* Detect and prevent integer overflow */ + if (len > INT_MAX - EXPAND_SPARE) { + return XML_ERROR_NO_MEMORY; + } + /* Detect and prevent integer overflow. + * The preprocessor guard addresses the "always false" warning + * from -Wtype-limits on platforms where + * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */ +#if UINT_MAX >= SIZE_MAX + if ((unsigned)(len + EXPAND_SPARE) > (size_t)(-1) / sizeof(XML_Char)) { + return XML_ERROR_NO_MEMORY; + } +#endif + b->uri = (XML_Char *)MALLOC(parser, sizeof(XML_Char) * (len + EXPAND_SPARE)); if (! b->uri) { @@ -3554,9 +4084,9 @@ addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, static enum XML_Error PTRCALL cdataSectionProcessor(XML_Parser parser, const char *start, const char *end, const char **endPtr) { - enum XML_Error result - = doCdataSection(parser, parser->m_encoding, &start, end, endPtr, - (XML_Bool)! parser->m_parsingStatus.finalBuffer); + enum XML_Error result = doCdataSection( + parser, parser->m_encoding, &start, end, endPtr, + (XML_Bool)! parser->m_parsingStatus.finalBuffer, XML_ACCOUNT_DIRECT); if (result != XML_ERROR_NONE) return result; if (start) { @@ -3576,7 +4106,8 @@ cdataSectionProcessor(XML_Parser parser, const char *start, const char *end, */ static enum XML_Error doCdataSection(XML_Parser parser, const ENCODING *enc, const char **startPtr, - const char *end, const char **nextPtr, XML_Bool haveMore) { + const char *end, const char **nextPtr, XML_Bool haveMore, + enum XML_Account account) { const char *s = *startPtr; const char **eventPP; const char **eventEndPP; @@ -3594,6 +4125,14 @@ doCdataSection(XML_Parser parser, const ENCODING *enc, const char **startPtr, for (;;) { const char *next = s; /* in case of XML_TOK_NONE or XML_TOK_PARTIAL */ int tok = XmlCdataSectionTok(enc, s, end, &next); +#if XML_GE == 1 + if (! accountingDiffTolerated(parser, tok, s, next, __LINE__, account)) { + accountingOnAbort(parser); + return XML_ERROR_AMPLIFICATION_LIMIT_BREACH; + } +#else + UNUSED_P(account); +#endif *eventEndPP = next; switch (tok) { case XML_TOK_CDATA_SECT_CLOSE: @@ -3601,7 +4140,7 @@ doCdataSection(XML_Parser parser, const ENCODING *enc, const char **startPtr, parser->m_endCdataSectionHandler(parser->m_handlerArg); /* BEGIN disabled code */ /* see comment under XML_TOK_CDATA_SECT_OPEN */ - else if (0 && parser->m_characterDataHandler) + else if ((0) && parser->m_characterDataHandler) parser->m_characterDataHandler(parser->m_handlerArg, parser->m_dataBuf, 0); /* END disabled code */ @@ -3637,8 +4176,8 @@ doCdataSection(XML_Parser parser, const ENCODING *enc, const char **startPtr, *eventPP = s; } } else - charDataHandler(parser->m_handlerArg, (XML_Char *)s, - (int)((XML_Char *)next - (XML_Char *)s)); + charDataHandler(parser->m_handlerArg, (const XML_Char *)s, + (int)((const XML_Char *)next - (const XML_Char *)s)); } else if (parser->m_defaultHandler) reportDefault(parser, enc, s, next); } break; @@ -3738,6 +4277,13 @@ doIgnoreSection(XML_Parser parser, const ENCODING *enc, const char **startPtr, *eventPP = s; *startPtr = NULL; tok = XmlIgnoreSectionTok(enc, s, end, &next); +# if XML_GE == 1 + if (! accountingDiffTolerated(parser, tok, s, next, __LINE__, + XML_ACCOUNT_DIRECT)) { + accountingOnAbort(parser); + return XML_ERROR_AMPLIFICATION_LIMIT_BREACH; + } +# endif *eventEndPP = next; switch (tok) { case XML_TOK_IGNORE_SECT: @@ -3787,7 +4333,7 @@ initializeEncoding(XML_Parser parser) { const char *s; #ifdef XML_UNICODE char encodingBuf[128]; - /* See comments abount `protoclEncodingName` in parserInit() */ + /* See comments about `protocolEncodingName` in parserInit() */ if (! parser->m_protocolEncodingName) s = NULL; else { @@ -3819,9 +4365,18 @@ processXmlDecl(XML_Parser parser, int isGeneralTextEntity, const char *s, const XML_Char *storedEncName = NULL; const ENCODING *newEncoding = NULL; const char *version = NULL; - const char *versionend; + const char *versionend = NULL; const XML_Char *storedversion = NULL; int standalone = -1; + +#if XML_GE == 1 + if (! accountingDiffTolerated(parser, XML_TOK_XML_DECL, s, next, __LINE__, + XML_ACCOUNT_DIRECT)) { + accountingOnAbort(parser); + return XML_ERROR_AMPLIFICATION_LIMIT_BREACH; + } +#endif + if (! (parser->m_ns ? XmlParseXmlDeclNS : XmlParseXmlDecl)( isGeneralTextEntity, parser->m_encoding, s, next, &parser->m_eventPtr, &version, &versionend, &encodingName, &newEncoding, &standalone)) { @@ -3971,6 +4526,10 @@ entityValueInitProcessor(XML_Parser parser, const char *s, const char *end, for (;;) { tok = XmlPrologTok(parser->m_encoding, start, end, &next); + /* Note: Except for XML_TOK_BOM below, these bytes are accounted later in: + - storeEntityValue + - processXmlDecl + */ parser->m_eventEndPtr = next; if (tok <= 0) { if (! parser->m_parsingStatus.finalBuffer && tok != XML_TOK_INVALID) { @@ -3989,7 +4548,8 @@ entityValueInitProcessor(XML_Parser parser, const char *s, const char *end, break; } /* found end of entity value - can store it now */ - return storeEntityValue(parser, parser->m_encoding, s, end); + return storeEntityValue(parser, parser->m_encoding, s, end, + XML_ACCOUNT_DIRECT); } else if (tok == XML_TOK_XML_DECL) { enum XML_Error result; result = processXmlDecl(parser, 0, start, next); @@ -4007,17 +4567,25 @@ entityValueInitProcessor(XML_Parser parser, const char *s, const char *end, parser->m_processor = entityValueProcessor; return entityValueProcessor(parser, next, end, nextPtr); } - /* If we are at the end of the buffer, this would cause XmlPrologTok to - return XML_TOK_NONE on the next call, which would then cause the - function to exit with *nextPtr set to s - that is what we want for other - tokens, but not for the BOM - we would rather like to skip it; - then, when this routine is entered the next time, XmlPrologTok will - return XML_TOK_INVALID, since the BOM is still in the buffer + /* XmlPrologTok has now set the encoding based on the BOM it found, and we + must move s and nextPtr forward to consume the BOM. + + If we didn't, and got XML_TOK_NONE from the next XmlPrologTok call, we + would leave the BOM in the buffer and return. On the next call to this + function, our XmlPrologTok call would return XML_TOK_INVALID, since it + is not valid to have multiple BOMs. */ - else if (tok == XML_TOK_BOM && next == end - && ! parser->m_parsingStatus.finalBuffer) { + else if (tok == XML_TOK_BOM) { +# if XML_GE == 1 + if (! accountingDiffTolerated(parser, tok, s, next, __LINE__, + XML_ACCOUNT_DIRECT)) { + accountingOnAbort(parser); + return XML_ERROR_AMPLIFICATION_LIMIT_BREACH; + } +# endif + *nextPtr = next; - return XML_ERROR_NONE; + s = next; } /* If we get this token, we have the start of what might be a normal tag, but not a declaration (i.e. it doesn't begin with @@ -4058,16 +4626,24 @@ externalParEntProcessor(XML_Parser parser, const char *s, const char *end, } /* This would cause the next stage, i.e. doProlog to be passed XML_TOK_BOM. However, when parsing an external subset, doProlog will not accept a BOM - as valid, and report a syntax error, so we have to skip the BOM + as valid, and report a syntax error, so we have to skip the BOM, and + account for the BOM bytes. */ else if (tok == XML_TOK_BOM) { + if (! accountingDiffTolerated(parser, tok, s, next, __LINE__, + XML_ACCOUNT_DIRECT)) { + accountingOnAbort(parser); + return XML_ERROR_AMPLIFICATION_LIMIT_BREACH; + } + s = next; tok = XmlPrologTok(parser->m_encoding, s, end, &next); } parser->m_processor = prologProcessor; return doProlog(parser, parser->m_encoding, s, end, tok, next, nextPtr, - (XML_Bool)! parser->m_parsingStatus.finalBuffer, XML_TRUE); + (XML_Bool)! parser->m_parsingStatus.finalBuffer, XML_TRUE, + XML_ACCOUNT_DIRECT); } static enum XML_Error PTRCALL @@ -4080,6 +4656,9 @@ entityValueProcessor(XML_Parser parser, const char *s, const char *end, for (;;) { tok = XmlPrologTok(enc, start, end, &next); + /* Note: These bytes are accounted later in: + - storeEntityValue + */ if (tok <= 0) { if (! parser->m_parsingStatus.finalBuffer && tok != XML_TOK_INVALID) { *nextPtr = s; @@ -4097,7 +4676,7 @@ entityValueProcessor(XML_Parser parser, const char *s, const char *end, break; } /* found end of entity value - can store it now */ - return storeEntityValue(parser, enc, s, end); + return storeEntityValue(parser, enc, s, end, XML_ACCOUNT_DIRECT); } start = next; } @@ -4111,13 +4690,14 @@ prologProcessor(XML_Parser parser, const char *s, const char *end, const char *next = s; int tok = XmlPrologTok(parser->m_encoding, s, end, &next); return doProlog(parser, parser->m_encoding, s, end, tok, next, nextPtr, - (XML_Bool)! parser->m_parsingStatus.finalBuffer, XML_TRUE); + (XML_Bool)! parser->m_parsingStatus.finalBuffer, XML_TRUE, + XML_ACCOUNT_DIRECT); } static enum XML_Error doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, int tok, const char *next, const char **nextPtr, XML_Bool haveMore, - XML_Bool allowClosingDoctype) { + XML_Bool allowClosingDoctype, enum XML_Account account) { #ifdef XML_DTD static const XML_Char externalSubsetName[] = {ASCII_HASH, '\0'}; #endif /* XML_DTD */ @@ -4144,6 +4724,10 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, static const XML_Char enumValueSep[] = {ASCII_PIPE, '\0'}; static const XML_Char enumValueStart[] = {ASCII_LPAREN, '\0'}; +#ifndef XML_DTD + UNUSED_P(account); +#endif + /* save one level of indirection */ DTD *const dtd = parser->m_dtd; @@ -4208,6 +4792,21 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, } } role = XmlTokenRole(&parser->m_prologState, tok, s, next, enc); +#if XML_GE == 1 + switch (role) { + case XML_ROLE_INSTANCE_START: // bytes accounted in contentProcessor + case XML_ROLE_XML_DECL: // bytes accounted in processXmlDecl +# ifdef XML_DTD + case XML_ROLE_TEXT_DECL: // bytes accounted in processXmlDecl +# endif + break; + default: + if (! accountingDiffTolerated(parser, tok, s, next, __LINE__, account)) { + accountingOnAbort(parser); + return XML_ERROR_AMPLIFICATION_LIMIT_BREACH; + } + } +#endif switch (role) { case XML_ROLE_XML_DECL: { enum XML_Error result = processXmlDecl(parser, 0, s, next); @@ -4472,10 +5071,10 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, parser->m_handlerArg, parser->m_declElementType->name, parser->m_declAttributeId->name, parser->m_declAttributeType, 0, role == XML_ROLE_REQUIRED_ATTRIBUTE_VALUE); - poolClear(&parser->m_tempPool); handleDefault = XML_FALSE; } } + poolClear(&parser->m_tempPool); break; case XML_ROLE_DEFAULT_ATTRIBUTE_VALUE: case XML_ROLE_FIXED_ATTRIBUTE_VALUE: @@ -4483,7 +5082,8 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, const XML_Char *attVal; enum XML_Error result = storeAttributeValue( parser, enc, parser->m_declAttributeIsCdata, - s + enc->minBytesPerChar, next - enc->minBytesPerChar, &dtd->pool); + s + enc->minBytesPerChar, next - enc->minBytesPerChar, &dtd->pool, + XML_ACCOUNT_NONE); if (result) return result; attVal = poolStart(&dtd->pool); @@ -4516,8 +5116,12 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, break; case XML_ROLE_ENTITY_VALUE: if (dtd->keepProcessing) { - enum XML_Error result = storeEntityValue( - parser, enc, s + enc->minBytesPerChar, next - enc->minBytesPerChar); +#if XML_GE == 1 + // This will store the given replacement text in + // parser->m_declEntity->textPtr. + enum XML_Error result + = storeEntityValue(parser, enc, s + enc->minBytesPerChar, + next - enc->minBytesPerChar, XML_ACCOUNT_NONE); if (parser->m_declEntity) { parser->m_declEntity->textPtr = poolStart(&dtd->entityValuePool); parser->m_declEntity->textLen @@ -4535,6 +5139,25 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, poolDiscard(&dtd->entityValuePool); if (result != XML_ERROR_NONE) return result; +#else + // This will store "&entity123;" in parser->m_declEntity->textPtr + // to end up as "&entity123;" in the handler. + if (parser->m_declEntity != NULL) { + const enum XML_Error result + = storeSelfEntityValue(parser, parser->m_declEntity); + if (result != XML_ERROR_NONE) + return result; + + if (parser->m_entityDeclHandler) { + *eventEndPP = s; + parser->m_entityDeclHandler( + parser->m_handlerArg, parser->m_declEntity->name, + parser->m_declEntity->is_param, parser->m_declEntity->textPtr, + parser->m_declEntity->textLen, parser->m_curBase, 0, 0, 0); + handleDefault = XML_FALSE; + } + } +#endif } break; case XML_ROLE_DOCTYPE_SYSTEM_ID: @@ -4593,6 +5216,16 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, } break; case XML_ROLE_ENTITY_COMPLETE: +#if XML_GE == 0 + // This will store "&entity123;" in entity->textPtr + // to end up as "&entity123;" in the handler. + if (parser->m_declEntity != NULL) { + const enum XML_Error result + = storeSelfEntityValue(parser, parser->m_declEntity); + if (result != XML_ERROR_NONE) + return result; + } +#endif if (dtd->keepProcessing && parser->m_declEntity && parser->m_entityDeclHandler) { *eventEndPP = s; @@ -4776,6 +5409,11 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, if (parser->m_prologState.level >= parser->m_groupSize) { if (parser->m_groupSize) { { + /* Detect and prevent integer overflow */ + if (parser->m_groupSize > (unsigned int)(-1) / 2u) { + return XML_ERROR_NO_MEMORY; + } + char *const new_connector = (char *)REALLOC( parser, parser->m_groupConnector, parser->m_groupSize *= 2); if (new_connector == NULL) { @@ -4786,6 +5424,16 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, } if (dtd->scaffIndex) { + /* Detect and prevent integer overflow. + * The preprocessor guard addresses the "always false" warning + * from -Wtype-limits on platforms where + * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */ +#if UINT_MAX >= SIZE_MAX + if (parser->m_groupSize > (size_t)(-1) / sizeof(int)) { + return XML_ERROR_NO_MEMORY; + } +#endif + int *const new_scaff_index = (int *)REALLOC( parser, dtd->scaffIndex, parser->m_groupSize * sizeof(int)); if (new_scaff_index == NULL) @@ -4866,7 +5514,7 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, * * If 'standalone' is false, the DTD must have no * parameter entities or we wouldn't have passed the outer - * 'if' statement. That measn the only entity in the hash + * 'if' statement. That means the only entity in the hash * table is the external subset name "#" which cannot be * given as a parameter entity name in XML syntax, so the * lookup must have returned NULL and we don't even reach @@ -4907,12 +5555,15 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, if (parser->m_externalEntityRefHandler) { dtd->paramEntityRead = XML_FALSE; entity->open = XML_TRUE; + entityTrackingOnOpen(parser, entity, __LINE__); if (! parser->m_externalEntityRefHandler( parser->m_externalEntityRefHandlerArg, 0, entity->base, entity->systemId, entity->publicId)) { + entityTrackingOnClose(parser, entity, __LINE__); entity->open = XML_FALSE; return XML_ERROR_EXTERNAL_ENTITY_HANDLING; } + entityTrackingOnClose(parser, entity, __LINE__); entity->open = XML_FALSE; handleDefault = XML_FALSE; if (! dtd->paramEntityRead) { @@ -4991,7 +5642,7 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, if (dtd->in_eldecl) { ELEMENT_TYPE *el; const XML_Char *name; - int nameLen; + size_t nameLen; const char *nxt = (quant == XML_CQUANT_NONE ? next : next - enc->minBytesPerChar); int myindex = nextScaffoldPart(parser); @@ -5007,7 +5658,13 @@ doProlog(XML_Parser parser, const ENCODING *enc, const char *s, const char *end, nameLen = 0; for (; name[nameLen++];) ; - dtd->contentStringLen += nameLen; + + /* Detect and prevent integer overflow */ + if (nameLen > UINT_MAX - dtd->contentStringLen) { + return XML_ERROR_NO_MEMORY; + } + + dtd->contentStringLen += (unsigned)nameLen; if (parser->m_elementDeclHandler) handleDefault = XML_FALSE; } @@ -5110,6 +5767,13 @@ epilogProcessor(XML_Parser parser, const char *s, const char *end, for (;;) { const char *next = NULL; int tok = XmlPrologTok(parser->m_encoding, s, end, &next); +#if XML_GE == 1 + if (! accountingDiffTolerated(parser, tok, s, next, __LINE__, + XML_ACCOUNT_DIRECT)) { + accountingOnAbort(parser); + return XML_ERROR_AMPLIFICATION_LIMIT_BREACH; + } +#endif parser->m_eventEndPtr = next; switch (tok) { /* report partial linebreak - it might be the last token */ @@ -5183,6 +5847,9 @@ processInternalEntity(XML_Parser parser, ENTITY *entity, XML_Bool betweenDecl) { return XML_ERROR_NO_MEMORY; } entity->open = XML_TRUE; +#if XML_GE == 1 + entityTrackingOnOpen(parser, entity, __LINE__); +#endif entity->processed = 0; openEntity->next = parser->m_openInternalEntities; parser->m_openInternalEntities = openEntity; @@ -5196,22 +5863,26 @@ processInternalEntity(XML_Parser parser, ENTITY *entity, XML_Bool betweenDecl) { /* Set a safe default value in case 'next' does not get set */ next = textStart; -#ifdef XML_DTD if (entity->is_param) { int tok = XmlPrologTok(parser->m_internalEncoding, textStart, textEnd, &next); result = doProlog(parser, parser->m_internalEncoding, textStart, textEnd, - tok, next, &next, XML_FALSE, XML_FALSE); - } else -#endif /* XML_DTD */ + tok, next, &next, XML_FALSE, XML_FALSE, + XML_ACCOUNT_ENTITY_EXPANSION); + } else { result = doContent(parser, parser->m_tagLevel, parser->m_internalEncoding, - textStart, textEnd, &next, XML_FALSE); + textStart, textEnd, &next, XML_FALSE, + XML_ACCOUNT_ENTITY_EXPANSION); + } if (result == XML_ERROR_NONE) { if (textEnd != next && parser->m_parsingStatus.parsing == XML_SUSPENDED) { entity->processed = (int)(next - textStart); parser->m_processor = internalEntityProcessor; - } else { + } else if (parser->m_openInternalEntities->entity == entity) { +#if XML_GE == 1 + entityTrackingOnClose(parser, entity, __LINE__); +#endif /* XML_GE == 1 */ entity->open = XML_FALSE; parser->m_openInternalEntities = openEntity->next; /* put openEntity back in list of free instances */ @@ -5239,47 +5910,62 @@ internalEntityProcessor(XML_Parser parser, const char *s, const char *end, /* Set a safe default value in case 'next' does not get set */ next = textStart; -#ifdef XML_DTD if (entity->is_param) { int tok = XmlPrologTok(parser->m_internalEncoding, textStart, textEnd, &next); result = doProlog(parser, parser->m_internalEncoding, textStart, textEnd, - tok, next, &next, XML_FALSE, XML_TRUE); - } else -#endif /* XML_DTD */ + tok, next, &next, XML_FALSE, XML_TRUE, + XML_ACCOUNT_ENTITY_EXPANSION); + } else { result = doContent(parser, openEntity->startTagLevel, parser->m_internalEncoding, textStart, textEnd, &next, - XML_FALSE); + XML_FALSE, XML_ACCOUNT_ENTITY_EXPANSION); + } if (result != XML_ERROR_NONE) return result; - else if (textEnd != next - && parser->m_parsingStatus.parsing == XML_SUSPENDED) { + + if (textEnd != next && parser->m_parsingStatus.parsing == XML_SUSPENDED) { entity->processed = (int)(next - (const char *)entity->textPtr); return result; - } else { - entity->open = XML_FALSE; - parser->m_openInternalEntities = openEntity->next; - /* put openEntity back in list of free instances */ - openEntity->next = parser->m_freeInternalEntities; - parser->m_freeInternalEntities = openEntity; } -#ifdef XML_DTD +#if XML_GE == 1 + entityTrackingOnClose(parser, entity, __LINE__); +#endif + entity->open = XML_FALSE; + parser->m_openInternalEntities = openEntity->next; + /* put openEntity back in list of free instances */ + openEntity->next = parser->m_freeInternalEntities; + parser->m_freeInternalEntities = openEntity; + + // If there are more open entities we want to stop right here and have the + // upcoming call to XML_ResumeParser continue with entity content, or it would + // be ignored altogether. + if (parser->m_openInternalEntities != NULL + && parser->m_parsingStatus.parsing == XML_SUSPENDED) { + return XML_ERROR_NONE; + } + if (entity->is_param) { int tok; parser->m_processor = prologProcessor; tok = XmlPrologTok(parser->m_encoding, s, end, &next); return doProlog(parser, parser->m_encoding, s, end, tok, next, nextPtr, - (XML_Bool)! parser->m_parsingStatus.finalBuffer, XML_TRUE); - } else -#endif /* XML_DTD */ - { + (XML_Bool)! parser->m_parsingStatus.finalBuffer, XML_TRUE, + XML_ACCOUNT_DIRECT); + } else { parser->m_processor = contentProcessor; /* see externalEntityContentProcessor vs contentProcessor */ - return doContent(parser, parser->m_parentParser ? 1 : 0, parser->m_encoding, - s, end, nextPtr, - (XML_Bool)! parser->m_parsingStatus.finalBuffer); + result = doContent(parser, parser->m_parentParser ? 1 : 0, + parser->m_encoding, s, end, nextPtr, + (XML_Bool)! parser->m_parsingStatus.finalBuffer, + XML_ACCOUNT_DIRECT); + if (result == XML_ERROR_NONE) { + if (! storeRawNames(parser)) + return XML_ERROR_NO_MEMORY; + } + return result; } } @@ -5294,9 +5980,10 @@ errorProcessor(XML_Parser parser, const char *s, const char *end, static enum XML_Error storeAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, - const char *ptr, const char *end, STRING_POOL *pool) { + const char *ptr, const char *end, STRING_POOL *pool, + enum XML_Account account) { enum XML_Error result - = appendAttributeValue(parser, enc, isCdata, ptr, end, pool); + = appendAttributeValue(parser, enc, isCdata, ptr, end, pool, account); if (result) return result; if (! isCdata && poolLength(pool) && poolLastChar(pool) == 0x20) @@ -5308,11 +5995,23 @@ storeAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, static enum XML_Error appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, - const char *ptr, const char *end, STRING_POOL *pool) { + const char *ptr, const char *end, STRING_POOL *pool, + enum XML_Account account) { DTD *const dtd = parser->m_dtd; /* save one level of indirection */ +#ifndef XML_DTD + UNUSED_P(account); +#endif + for (;;) { - const char *next; + const char *next + = ptr; /* XmlAttributeValueTok doesn't always set the last arg */ int tok = XmlAttributeValueTok(enc, ptr, end, &next); +#if XML_GE == 1 + if (! accountingDiffTolerated(parser, tok, ptr, next, __LINE__, account)) { + accountingOnAbort(parser); + return XML_ERROR_AMPLIFICATION_LIMIT_BREACH; + } +#endif switch (tok) { case XML_TOK_NONE: return XML_ERROR_NONE; @@ -5372,6 +6071,14 @@ appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, XML_Char ch = (XML_Char)XmlPredefinedEntityName( enc, ptr + enc->minBytesPerChar, next - enc->minBytesPerChar); if (ch) { +#if XML_GE == 1 + /* NOTE: We are replacing 4-6 characters original input for 1 character + * so there is no amplification and hence recording without + * protection. */ + accountingDiffTolerated(parser, tok, (char *)&ch, + ((char *)&ch) + sizeof(XML_Char), __LINE__, + XML_ACCOUNT_ENTITY_EXPANSION); +#endif /* XML_GE == 1 */ if (! poolAppendChar(pool, ch)) return XML_ERROR_NO_MEMORY; break; @@ -5449,9 +6156,16 @@ appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, enum XML_Error result; const XML_Char *textEnd = entity->textPtr + entity->textLen; entity->open = XML_TRUE; +#if XML_GE == 1 + entityTrackingOnOpen(parser, entity, __LINE__); +#endif result = appendAttributeValue(parser, parser->m_internalEncoding, isCdata, (const char *)entity->textPtr, - (const char *)textEnd, pool); + (const char *)textEnd, pool, + XML_ACCOUNT_ENTITY_EXPANSION); +#if XML_GE == 1 + entityTrackingOnClose(parser, entity, __LINE__); +#endif entity->open = XML_FALSE; if (result) return result; @@ -5479,16 +6193,20 @@ appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, /* not reached */ } +#if XML_GE == 1 static enum XML_Error storeEntityValue(XML_Parser parser, const ENCODING *enc, - const char *entityTextPtr, const char *entityTextEnd) { + const char *entityTextPtr, const char *entityTextEnd, + enum XML_Account account) { DTD *const dtd = parser->m_dtd; /* save one level of indirection */ STRING_POOL *pool = &(dtd->entityValuePool); enum XML_Error result = XML_ERROR_NONE; -#ifdef XML_DTD +# ifdef XML_DTD int oldInEntityValue = parser->m_prologState.inEntityValue; parser->m_prologState.inEntityValue = 1; -#endif /* XML_DTD */ +# else + UNUSED_P(account); +# endif /* XML_DTD */ /* never return Null for the value argument in EntityDeclHandler, since this would indicate an external entity; therefore we have to make sure that entityValuePool.start is not null */ @@ -5498,11 +6216,20 @@ storeEntityValue(XML_Parser parser, const ENCODING *enc, } for (;;) { - const char *next; + const char *next + = entityTextPtr; /* XmlEntityValueTok doesn't always set the last arg */ int tok = XmlEntityValueTok(enc, entityTextPtr, entityTextEnd, &next); + + if (! accountingDiffTolerated(parser, tok, entityTextPtr, next, __LINE__, + account)) { + accountingOnAbort(parser); + result = XML_ERROR_AMPLIFICATION_LIMIT_BREACH; + goto endEntityValue; + } + switch (tok) { case XML_TOK_PARAM_ENTITY_REF: -#ifdef XML_DTD +# ifdef XML_DTD if (parser->m_isParamEntity || enc != parser->m_encoding) { const XML_Char *name; ENTITY *entity; @@ -5525,7 +6252,7 @@ storeEntityValue(XML_Parser parser, const ENCODING *enc, dtd->keepProcessing = dtd->standalone; goto endEntityValue; } - if (entity->open) { + if (entity->open || (entity == parser->m_declEntity)) { if (enc == parser->m_encoding) parser->m_eventPtr = entityTextPtr; result = XML_ERROR_RECURSIVE_ENTITY_REF; @@ -5535,13 +6262,16 @@ storeEntityValue(XML_Parser parser, const ENCODING *enc, if (parser->m_externalEntityRefHandler) { dtd->paramEntityRead = XML_FALSE; entity->open = XML_TRUE; + entityTrackingOnOpen(parser, entity, __LINE__); if (! parser->m_externalEntityRefHandler( parser->m_externalEntityRefHandlerArg, 0, entity->base, entity->systemId, entity->publicId)) { + entityTrackingOnClose(parser, entity, __LINE__); entity->open = XML_FALSE; result = XML_ERROR_EXTERNAL_ENTITY_HANDLING; goto endEntityValue; } + entityTrackingOnClose(parser, entity, __LINE__); entity->open = XML_FALSE; if (! dtd->paramEntityRead) dtd->keepProcessing = dtd->standalone; @@ -5549,16 +6279,19 @@ storeEntityValue(XML_Parser parser, const ENCODING *enc, dtd->keepProcessing = dtd->standalone; } else { entity->open = XML_TRUE; + entityTrackingOnOpen(parser, entity, __LINE__); result = storeEntityValue( parser, parser->m_internalEncoding, (const char *)entity->textPtr, - (const char *)(entity->textPtr + entity->textLen)); + (const char *)(entity->textPtr + entity->textLen), + XML_ACCOUNT_ENTITY_EXPANSION); + entityTrackingOnClose(parser, entity, __LINE__); entity->open = XML_FALSE; if (result) goto endEntityValue; } break; } -#endif /* XML_DTD */ +# endif /* XML_DTD */ /* In the internal subset, PE references are not legal within markup declarations, e.g entity values in this case. */ parser->m_eventPtr = entityTextPtr; @@ -5639,12 +6372,38 @@ storeEntityValue(XML_Parser parser, const ENCODING *enc, entityTextPtr = next; } endEntityValue: -#ifdef XML_DTD +# ifdef XML_DTD parser->m_prologState.inEntityValue = oldInEntityValue; -#endif /* XML_DTD */ +# endif /* XML_DTD */ return result; } +#else /* XML_GE == 0 */ + +static enum XML_Error +storeSelfEntityValue(XML_Parser parser, ENTITY *entity) { + // This will store "&entity123;" in entity->textPtr + // to end up as "&entity123;" in the handler. + const char *const entity_start = "&"; + const char *const entity_end = ";"; + + STRING_POOL *const pool = &(parser->m_dtd->entityValuePool); + if (! poolAppendString(pool, entity_start) + || ! poolAppendString(pool, entity->name) + || ! poolAppendString(pool, entity_end)) { + poolDiscard(pool); + return XML_ERROR_NO_MEMORY; + } + + entity->textPtr = poolStart(pool); + entity->textLen = (int)(poolLength(pool)); + poolFinish(pool); + + return XML_ERROR_NONE; +} + +#endif /* XML_GE == 0 */ + static void FASTCALL normalizeLines(XML_Char *s) { XML_Char *p; @@ -5755,8 +6514,9 @@ reportDefault(XML_Parser parser, const ENCODING *enc, const char *s, } while ((convert_res != XML_CONVERT_COMPLETED) && (convert_res != XML_CONVERT_INPUT_INCOMPLETE)); } else - parser->m_defaultHandler(parser->m_handlerArg, (XML_Char *)s, - (int)((XML_Char *)end - (XML_Char *)s)); + parser->m_defaultHandler( + parser->m_handlerArg, (const XML_Char *)s, + (int)((const XML_Char *)end - (const XML_Char *)s)); } static int @@ -5784,7 +6544,24 @@ defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, XML_Bool isCdata, } } else { DEFAULT_ATTRIBUTE *temp; + + /* Detect and prevent integer overflow */ + if (type->allocDefaultAtts > INT_MAX / 2) { + return 0; + } + int count = type->allocDefaultAtts * 2; + + /* Detect and prevent integer overflow. + * The preprocessor guard addresses the "always false" warning + * from -Wtype-limits on platforms where + * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */ +#if UINT_MAX >= SIZE_MAX + if ((unsigned)count > (size_t)(-1) / sizeof(DEFAULT_ATTRIBUTE)) { + return 0; + } +#endif + temp = (DEFAULT_ATTRIBUTE *)REALLOC(parser, type->defaultAtts, (count * sizeof(DEFAULT_ATTRIBUTE))); if (temp == NULL) @@ -5843,7 +6620,7 @@ getAttributeId(XML_Parser parser, const ENCODING *enc, const char *start, name = poolStoreString(&dtd->pool, enc, start, end); if (! name) return NULL; - /* skip quotation mark - its storage will be re-used (like in name[-1]) */ + /* skip quotation mark - its storage will be reused (like in name[-1]) */ ++name; id = (ATTRIBUTE_ID *)lookup(parser, &dtd->attributeIds, name, sizeof(ATTRIBUTE_ID)); @@ -5993,6 +6770,10 @@ getContext(XML_Parser parser) { static XML_Bool setContext(XML_Parser parser, const XML_Char *context) { + if (context == NULL) { + return XML_FALSE; + } + DTD *const dtd = parser->m_dtd; /* save one level of indirection */ const XML_Char *s = context; @@ -6074,7 +6855,7 @@ normalizePublicId(XML_Char *publicId) { static DTD * dtdCreate(const XML_Memory_Handling_Suite *ms) { - DTD *p = (DTD *)ms->malloc_fcn(sizeof(DTD)); + DTD *p = ms->malloc_fcn(sizeof(DTD)); if (p == NULL) return p; poolInit(&(p->pool), ms); @@ -6247,8 +7028,18 @@ dtdCopy(XML_Parser oldParser, DTD *newDtd, const DTD *oldDtd, if (! newE) return 0; if (oldE->nDefaultAtts) { - newE->defaultAtts = (DEFAULT_ATTRIBUTE *)ms->malloc_fcn( - oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); + /* Detect and prevent integer overflow. + * The preprocessor guard addresses the "always false" warning + * from -Wtype-limits on platforms where + * sizeof(int) < sizeof(size_t), e.g. on x86_64. */ +#if UINT_MAX >= SIZE_MAX + if ((size_t)oldE->nDefaultAtts + > ((size_t)(-1) / sizeof(DEFAULT_ATTRIBUTE))) { + return 0; + } +#endif + newE->defaultAtts + = ms->malloc_fcn(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); if (! newE->defaultAtts) { return 0; } @@ -6410,7 +7201,7 @@ lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize) { /* table->size is a power of 2 */ table->size = (size_t)1 << INIT_POWER; tsize = table->size * sizeof(NAMED *); - table->v = (NAMED **)table->mem->malloc_fcn(tsize); + table->v = table->mem->malloc_fcn(tsize); if (! table->v) { table->size = 0; return NULL; @@ -6435,10 +7226,22 @@ lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize) { /* check for overflow (table is half full) */ if (table->used >> (table->power - 1)) { unsigned char newPower = table->power + 1; + + /* Detect and prevent invalid shift */ + if (newPower >= sizeof(unsigned long) * 8 /* bits per byte */) { + return NULL; + } + size_t newSize = (size_t)1 << newPower; unsigned long newMask = (unsigned long)newSize - 1; + + /* Detect and prevent integer overflow */ + if (newSize > (size_t)(-1) / sizeof(NAMED *)) { + return NULL; + } + size_t tsize = newSize * sizeof(NAMED *); - NAMED **newV = (NAMED **)table->mem->malloc_fcn(tsize); + NAMED **newV = table->mem->malloc_fcn(tsize); if (! newV) return NULL; memset(newV, 0, tsize); @@ -6467,7 +7270,7 @@ lookup(XML_Parser parser, HASH_TABLE *table, KEY name, size_t createSize) { } } } - table->v[i] = (NAMED *)table->mem->malloc_fcn(createSize); + table->v[i] = table->mem->malloc_fcn(createSize); if (! table->v[i]) return NULL; memset(table->v[i], 0, createSize); @@ -6571,7 +7374,7 @@ poolAppend(STRING_POOL *pool, const ENCODING *enc, const char *ptr, return NULL; for (;;) { const enum XML_Convert_Result convert_res = XmlConvert( - enc, &ptr, end, (ICHAR **)&(pool->ptr), (ICHAR *)pool->end); + enc, &ptr, end, (ICHAR **)&(pool->ptr), (const ICHAR *)pool->end); if ((convert_res == XML_CONVERT_COMPLETED) || (convert_res == XML_CONVERT_INPUT_INCOMPLETE)) break; @@ -6755,7 +7558,7 @@ poolGrow(STRING_POOL *pool) { if (bytesToAllocate == 0) return XML_FALSE; - tem = (BLOCK *)pool->mem->malloc_fcn(bytesToAllocate); + tem = pool->mem->malloc_fcn(bytesToAllocate); if (! tem) return XML_FALSE; tem->size = blockSize; @@ -6777,6 +7580,15 @@ nextScaffoldPart(XML_Parser parser) { int next; if (! dtd->scaffIndex) { + /* Detect and prevent integer overflow. + * The preprocessor guard addresses the "always false" warning + * from -Wtype-limits on platforms where + * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */ +#if UINT_MAX >= SIZE_MAX + if (parser->m_groupSize > ((size_t)(-1) / sizeof(int))) { + return -1; + } +#endif dtd->scaffIndex = (int *)MALLOC(parser, parser->m_groupSize * sizeof(int)); if (! dtd->scaffIndex) return -1; @@ -6786,6 +7598,20 @@ nextScaffoldPart(XML_Parser parser) { if (dtd->scaffCount >= dtd->scaffSize) { CONTENT_SCAFFOLD *temp; if (dtd->scaffold) { + /* Detect and prevent integer overflow */ + if (dtd->scaffSize > UINT_MAX / 2u) { + return -1; + } + /* Detect and prevent integer overflow. + * The preprocessor guard addresses the "always false" warning + * from -Wtype-limits on platforms where + * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */ +#if UINT_MAX >= SIZE_MAX + if (dtd->scaffSize > (size_t)(-1) / 2u / sizeof(CONTENT_SCAFFOLD)) { + return -1; + } +#endif + temp = (CONTENT_SCAFFOLD *)REALLOC( parser, dtd->scaffold, dtd->scaffSize * 2 * sizeof(CONTENT_SCAFFOLD)); if (temp == NULL) @@ -6817,55 +7643,130 @@ nextScaffoldPart(XML_Parser parser) { return next; } -static void -build_node(XML_Parser parser, int src_node, XML_Content *dest, - XML_Content **contpos, XML_Char **strpos) { - DTD *const dtd = parser->m_dtd; /* save one level of indirection */ - dest->type = dtd->scaffold[src_node].type; - dest->quant = dtd->scaffold[src_node].quant; - if (dest->type == XML_CTYPE_NAME) { - const XML_Char *src; - dest->name = *strpos; - src = dtd->scaffold[src_node].name; - for (;;) { - *(*strpos)++ = *src; - if (! *src) - break; - src++; - } - dest->numchildren = 0; - dest->children = NULL; - } else { - unsigned int i; - int cn; - dest->numchildren = dtd->scaffold[src_node].childcnt; - dest->children = *contpos; - *contpos += dest->numchildren; - for (i = 0, cn = dtd->scaffold[src_node].firstchild; i < dest->numchildren; - i++, cn = dtd->scaffold[cn].nextsib) { - build_node(parser, cn, &(dest->children[i]), contpos, strpos); - } - dest->name = NULL; - } -} - static XML_Content * build_model(XML_Parser parser) { + /* Function build_model transforms the existing parser->m_dtd->scaffold + * array of CONTENT_SCAFFOLD tree nodes into a new array of + * XML_Content tree nodes followed by a gapless list of zero-terminated + * strings. */ DTD *const dtd = parser->m_dtd; /* save one level of indirection */ XML_Content *ret; - XML_Content *cpos; - XML_Char *str; - int allocsize = (dtd->scaffCount * sizeof(XML_Content) - + (dtd->contentStringLen * sizeof(XML_Char))); + XML_Char *str; /* the current string writing location */ + + /* Detect and prevent integer overflow. + * The preprocessor guard addresses the "always false" warning + * from -Wtype-limits on platforms where + * sizeof(unsigned int) < sizeof(size_t), e.g. on x86_64. */ +#if UINT_MAX >= SIZE_MAX + if (dtd->scaffCount > (size_t)(-1) / sizeof(XML_Content)) { + return NULL; + } + if (dtd->contentStringLen > (size_t)(-1) / sizeof(XML_Char)) { + return NULL; + } +#endif + if (dtd->scaffCount * sizeof(XML_Content) + > (size_t)(-1) - dtd->contentStringLen * sizeof(XML_Char)) { + return NULL; + } + + const size_t allocsize = (dtd->scaffCount * sizeof(XML_Content) + + (dtd->contentStringLen * sizeof(XML_Char))); ret = (XML_Content *)MALLOC(parser, allocsize); if (! ret) return NULL; - str = (XML_Char *)(&ret[dtd->scaffCount]); - cpos = &ret[1]; + /* What follows is an iterative implementation (of what was previously done + * recursively in a dedicated function called "build_node". The old recursive + * build_node could be forced into stack exhaustion from input as small as a + * few megabyte, and so that was a security issue. Hence, a function call + * stack is avoided now by resolving recursion.) + * + * The iterative approach works as follows: + * + * - We have two writing pointers, both walking up the result array; one does + * the work, the other creates "jobs" for its colleague to do, and leads + * the way: + * + * - The faster one, pointer jobDest, always leads and writes "what job + * to do" by the other, once they reach that place in the + * array: leader "jobDest" stores the source node array index (relative + * to array dtd->scaffold) in field "numchildren". + * + * - The slower one, pointer dest, looks at the value stored in the + * "numchildren" field (which actually holds a source node array index + * at that time) and puts the real data from dtd->scaffold in. + * + * - Before the loop starts, jobDest writes source array index 0 + * (where the root node is located) so that dest will have something to do + * when it starts operation. + * + * - Whenever nodes with children are encountered, jobDest appends + * them as new jobs, in order. As a result, tree node siblings are + * adjacent in the resulting array, for example: + * + * [0] root, has two children + * [1] first child of 0, has three children + * [3] first child of 1, does not have children + * [4] second child of 1, does not have children + * [5] third child of 1, does not have children + * [2] second child of 0, does not have children + * + * Or (the same data) presented in flat array view: + * + * [0] root, has two children + * + * [1] first child of 0, has three children + * [2] second child of 0, does not have children + * + * [3] first child of 1, does not have children + * [4] second child of 1, does not have children + * [5] third child of 1, does not have children + * + * - The algorithm repeats until all target array indices have been processed. + */ + XML_Content *dest = ret; /* tree node writing location, moves upwards */ + XML_Content *const destLimit = &ret[dtd->scaffCount]; + XML_Content *jobDest = ret; /* next free writing location in target array */ + str = (XML_Char *)&ret[dtd->scaffCount]; + + /* Add the starting job, the root node (index 0) of the source tree */ + (jobDest++)->numchildren = 0; + + for (; dest < destLimit; dest++) { + /* Retrieve source tree array index from job storage */ + const int src_node = (int)dest->numchildren; + + /* Convert item */ + dest->type = dtd->scaffold[src_node].type; + dest->quant = dtd->scaffold[src_node].quant; + if (dest->type == XML_CTYPE_NAME) { + const XML_Char *src; + dest->name = str; + src = dtd->scaffold[src_node].name; + for (;;) { + *str++ = *src; + if (! *src) + break; + src++; + } + dest->numchildren = 0; + dest->children = NULL; + } else { + unsigned int i; + int cn; + dest->name = NULL; + dest->numchildren = dtd->scaffold[src_node].childcnt; + dest->children = jobDest; + + /* Append scaffold indices of children to array */ + for (i = 0, cn = dtd->scaffold[src_node].firstchild; + i < dest->numchildren; i++, cn = dtd->scaffold[cn].nextsib) + (jobDest++)->numchildren = (unsigned int)cn; + } + } - build_node(parser, 0, ret, &cpos, &str); return ret; } @@ -6894,7 +7795,7 @@ getElementType(XML_Parser parser, const ENCODING *enc, const char *ptr, static XML_Char * copyString(const XML_Char *s, const XML_Memory_Handling_Suite *memsuite) { - int charsRequired = 0; + size_t charsRequired = 0; XML_Char *result; /* First determine how long the string is */ @@ -6912,3 +7813,759 @@ copyString(const XML_Char *s, const XML_Memory_Handling_Suite *memsuite) { memcpy(result, s, charsRequired * sizeof(XML_Char)); return result; } + +#if XML_GE == 1 + +static float +accountingGetCurrentAmplification(XML_Parser rootParser) { + // 1.........1.........12 => 22 + const size_t lenOfShortestInclude = sizeof("<!ENTITY a SYSTEM 'b'>") - 1; + const XmlBigCount countBytesOutput + = rootParser->m_accounting.countBytesDirect + + rootParser->m_accounting.countBytesIndirect; + const float amplificationFactor + = rootParser->m_accounting.countBytesDirect + ? (countBytesOutput + / (float)(rootParser->m_accounting.countBytesDirect)) + : ((lenOfShortestInclude + + rootParser->m_accounting.countBytesIndirect) + / (float)lenOfShortestInclude); + assert(! rootParser->m_parentParser); + return amplificationFactor; +} + +static void +accountingReportStats(XML_Parser originParser, const char *epilog) { + const XML_Parser rootParser = getRootParserOf(originParser, NULL); + assert(! rootParser->m_parentParser); + + if (rootParser->m_accounting.debugLevel == 0u) { + return; + } + + const float amplificationFactor + = accountingGetCurrentAmplification(rootParser); + fprintf(stderr, + "expat: Accounting(%p): Direct " EXPAT_FMT_ULL( + "10") ", indirect " EXPAT_FMT_ULL("10") ", amplification %8.2f%s", + (void *)rootParser, rootParser->m_accounting.countBytesDirect, + rootParser->m_accounting.countBytesIndirect, + (double)amplificationFactor, epilog); +} + +static void +accountingOnAbort(XML_Parser originParser) { + accountingReportStats(originParser, " ABORTING\n"); +} + +static void +accountingReportDiff(XML_Parser rootParser, + unsigned int levelsAwayFromRootParser, const char *before, + const char *after, ptrdiff_t bytesMore, int source_line, + enum XML_Account account) { + assert(! rootParser->m_parentParser); + + fprintf(stderr, + " (+" EXPAT_FMT_PTRDIFF_T("6") " bytes %s|%u, xmlparse.c:%d) %*s\"", + bytesMore, (account == XML_ACCOUNT_DIRECT) ? "DIR" : "EXP", + levelsAwayFromRootParser, source_line, 10, ""); + + const char ellipis[] = "[..]"; + const size_t ellipsisLength = sizeof(ellipis) /* because compile-time */ - 1; + const unsigned int contextLength = 10; + + /* Note: Performance is of no concern here */ + const char *walker = before; + if ((rootParser->m_accounting.debugLevel >= 3u) + || (after - before) + <= (ptrdiff_t)(contextLength + ellipsisLength + contextLength)) { + for (; walker < after; walker++) { + fprintf(stderr, "%s", unsignedCharToPrintable(walker[0])); + } + } else { + for (; walker < before + contextLength; walker++) { + fprintf(stderr, "%s", unsignedCharToPrintable(walker[0])); + } + fprintf(stderr, ellipis); + walker = after - contextLength; + for (; walker < after; walker++) { + fprintf(stderr, "%s", unsignedCharToPrintable(walker[0])); + } + } + fprintf(stderr, "\"\n"); +} + +static XML_Bool +accountingDiffTolerated(XML_Parser originParser, int tok, const char *before, + const char *after, int source_line, + enum XML_Account account) { + /* Note: We need to check the token type *first* to be sure that + * we can even access variable <after>, safely. + * E.g. for XML_TOK_NONE <after> may hold an invalid pointer. */ + switch (tok) { + case XML_TOK_INVALID: + case XML_TOK_PARTIAL: + case XML_TOK_PARTIAL_CHAR: + case XML_TOK_NONE: + return XML_TRUE; + } + + if (account == XML_ACCOUNT_NONE) + return XML_TRUE; /* because these bytes have been accounted for, already */ + + unsigned int levelsAwayFromRootParser; + const XML_Parser rootParser + = getRootParserOf(originParser, &levelsAwayFromRootParser); + assert(! rootParser->m_parentParser); + + const int isDirect + = (account == XML_ACCOUNT_DIRECT) && (originParser == rootParser); + const ptrdiff_t bytesMore = after - before; + + XmlBigCount *const additionTarget + = isDirect ? &rootParser->m_accounting.countBytesDirect + : &rootParser->m_accounting.countBytesIndirect; + + /* Detect and avoid integer overflow */ + if (*additionTarget > (XmlBigCount)(-1) - (XmlBigCount)bytesMore) + return XML_FALSE; + *additionTarget += bytesMore; + + const XmlBigCount countBytesOutput + = rootParser->m_accounting.countBytesDirect + + rootParser->m_accounting.countBytesIndirect; + const float amplificationFactor + = accountingGetCurrentAmplification(rootParser); + const XML_Bool tolerated + = (countBytesOutput < rootParser->m_accounting.activationThresholdBytes) + || (amplificationFactor + <= rootParser->m_accounting.maximumAmplificationFactor); + + if (rootParser->m_accounting.debugLevel >= 2u) { + accountingReportStats(rootParser, ""); + accountingReportDiff(rootParser, levelsAwayFromRootParser, before, after, + bytesMore, source_line, account); + } + + return tolerated; +} + +unsigned long long +testingAccountingGetCountBytesDirect(XML_Parser parser) { + if (! parser) + return 0; + return parser->m_accounting.countBytesDirect; +} + +unsigned long long +testingAccountingGetCountBytesIndirect(XML_Parser parser) { + if (! parser) + return 0; + return parser->m_accounting.countBytesIndirect; +} + +static void +entityTrackingReportStats(XML_Parser rootParser, ENTITY *entity, + const char *action, int sourceLine) { + assert(! rootParser->m_parentParser); + if (rootParser->m_entity_stats.debugLevel == 0u) + return; + +# if defined(XML_UNICODE) + const char *const entityName = "[..]"; +# else + const char *const entityName = entity->name; +# endif + + fprintf( + stderr, + "expat: Entities(%p): Count %9u, depth %2u/%2u %*s%s%s; %s length %d (xmlparse.c:%d)\n", + (void *)rootParser, rootParser->m_entity_stats.countEverOpened, + rootParser->m_entity_stats.currentDepth, + rootParser->m_entity_stats.maximumDepthSeen, + (rootParser->m_entity_stats.currentDepth - 1) * 2, "", + entity->is_param ? "%" : "&", entityName, action, entity->textLen, + sourceLine); +} + +static void +entityTrackingOnOpen(XML_Parser originParser, ENTITY *entity, int sourceLine) { + const XML_Parser rootParser = getRootParserOf(originParser, NULL); + assert(! rootParser->m_parentParser); + + rootParser->m_entity_stats.countEverOpened++; + rootParser->m_entity_stats.currentDepth++; + if (rootParser->m_entity_stats.currentDepth + > rootParser->m_entity_stats.maximumDepthSeen) { + rootParser->m_entity_stats.maximumDepthSeen++; + } + + entityTrackingReportStats(rootParser, entity, "OPEN ", sourceLine); +} + +static void +entityTrackingOnClose(XML_Parser originParser, ENTITY *entity, int sourceLine) { + const XML_Parser rootParser = getRootParserOf(originParser, NULL); + assert(! rootParser->m_parentParser); + + entityTrackingReportStats(rootParser, entity, "CLOSE", sourceLine); + rootParser->m_entity_stats.currentDepth--; +} + +static XML_Parser +getRootParserOf(XML_Parser parser, unsigned int *outLevelDiff) { + XML_Parser rootParser = parser; + unsigned int stepsTakenUpwards = 0; + while (rootParser->m_parentParser) { + rootParser = rootParser->m_parentParser; + stepsTakenUpwards++; + } + assert(! rootParser->m_parentParser); + if (outLevelDiff != NULL) { + *outLevelDiff = stepsTakenUpwards; + } + return rootParser; +} + +const char * +unsignedCharToPrintable(unsigned char c) { + switch (c) { + case 0: + return "\\0"; + case 1: + return "\\x1"; + case 2: + return "\\x2"; + case 3: + return "\\x3"; + case 4: + return "\\x4"; + case 5: + return "\\x5"; + case 6: + return "\\x6"; + case 7: + return "\\x7"; + case 8: + return "\\x8"; + case 9: + return "\\t"; + case 10: + return "\\n"; + case 11: + return "\\xB"; + case 12: + return "\\xC"; + case 13: + return "\\r"; + case 14: + return "\\xE"; + case 15: + return "\\xF"; + case 16: + return "\\x10"; + case 17: + return "\\x11"; + case 18: + return "\\x12"; + case 19: + return "\\x13"; + case 20: + return "\\x14"; + case 21: + return "\\x15"; + case 22: + return "\\x16"; + case 23: + return "\\x17"; + case 24: + return "\\x18"; + case 25: + return "\\x19"; + case 26: + return "\\x1A"; + case 27: + return "\\x1B"; + case 28: + return "\\x1C"; + case 29: + return "\\x1D"; + case 30: + return "\\x1E"; + case 31: + return "\\x1F"; + case 32: + return " "; + case 33: + return "!"; + case 34: + return "\\\""; + case 35: + return "#"; + case 36: + return "$"; + case 37: + return "%"; + case 38: + return "&"; + case 39: + return "'"; + case 40: + return "("; + case 41: + return ")"; + case 42: + return "*"; + case 43: + return "+"; + case 44: + return ","; + case 45: + return "-"; + case 46: + return "."; + case 47: + return "/"; + case 48: + return "0"; + case 49: + return "1"; + case 50: + return "2"; + case 51: + return "3"; + case 52: + return "4"; + case 53: + return "5"; + case 54: + return "6"; + case 55: + return "7"; + case 56: + return "8"; + case 57: + return "9"; + case 58: + return ":"; + case 59: + return ";"; + case 60: + return "<"; + case 61: + return "="; + case 62: + return ">"; + case 63: + return "?"; + case 64: + return "@"; + case 65: + return "A"; + case 66: + return "B"; + case 67: + return "C"; + case 68: + return "D"; + case 69: + return "E"; + case 70: + return "F"; + case 71: + return "G"; + case 72: + return "H"; + case 73: + return "I"; + case 74: + return "J"; + case 75: + return "K"; + case 76: + return "L"; + case 77: + return "M"; + case 78: + return "N"; + case 79: + return "O"; + case 80: + return "P"; + case 81: + return "Q"; + case 82: + return "R"; + case 83: + return "S"; + case 84: + return "T"; + case 85: + return "U"; + case 86: + return "V"; + case 87: + return "W"; + case 88: + return "X"; + case 89: + return "Y"; + case 90: + return "Z"; + case 91: + return "["; + case 92: + return "\\\\"; + case 93: + return "]"; + case 94: + return "^"; + case 95: + return "_"; + case 96: + return "`"; + case 97: + return "a"; + case 98: + return "b"; + case 99: + return "c"; + case 100: + return "d"; + case 101: + return "e"; + case 102: + return "f"; + case 103: + return "g"; + case 104: + return "h"; + case 105: + return "i"; + case 106: + return "j"; + case 107: + return "k"; + case 108: + return "l"; + case 109: + return "m"; + case 110: + return "n"; + case 111: + return "o"; + case 112: + return "p"; + case 113: + return "q"; + case 114: + return "r"; + case 115: + return "s"; + case 116: + return "t"; + case 117: + return "u"; + case 118: + return "v"; + case 119: + return "w"; + case 120: + return "x"; + case 121: + return "y"; + case 122: + return "z"; + case 123: + return "{"; + case 124: + return "|"; + case 125: + return "}"; + case 126: + return "~"; + case 127: + return "\\x7F"; + case 128: + return "\\x80"; + case 129: + return "\\x81"; + case 130: + return "\\x82"; + case 131: + return "\\x83"; + case 132: + return "\\x84"; + case 133: + return "\\x85"; + case 134: + return "\\x86"; + case 135: + return "\\x87"; + case 136: + return "\\x88"; + case 137: + return "\\x89"; + case 138: + return "\\x8A"; + case 139: + return "\\x8B"; + case 140: + return "\\x8C"; + case 141: + return "\\x8D"; + case 142: + return "\\x8E"; + case 143: + return "\\x8F"; + case 144: + return "\\x90"; + case 145: + return "\\x91"; + case 146: + return "\\x92"; + case 147: + return "\\x93"; + case 148: + return "\\x94"; + case 149: + return "\\x95"; + case 150: + return "\\x96"; + case 151: + return "\\x97"; + case 152: + return "\\x98"; + case 153: + return "\\x99"; + case 154: + return "\\x9A"; + case 155: + return "\\x9B"; + case 156: + return "\\x9C"; + case 157: + return "\\x9D"; + case 158: + return "\\x9E"; + case 159: + return "\\x9F"; + case 160: + return "\\xA0"; + case 161: + return "\\xA1"; + case 162: + return "\\xA2"; + case 163: + return "\\xA3"; + case 164: + return "\\xA4"; + case 165: + return "\\xA5"; + case 166: + return "\\xA6"; + case 167: + return "\\xA7"; + case 168: + return "\\xA8"; + case 169: + return "\\xA9"; + case 170: + return "\\xAA"; + case 171: + return "\\xAB"; + case 172: + return "\\xAC"; + case 173: + return "\\xAD"; + case 174: + return "\\xAE"; + case 175: + return "\\xAF"; + case 176: + return "\\xB0"; + case 177: + return "\\xB1"; + case 178: + return "\\xB2"; + case 179: + return "\\xB3"; + case 180: + return "\\xB4"; + case 181: + return "\\xB5"; + case 182: + return "\\xB6"; + case 183: + return "\\xB7"; + case 184: + return "\\xB8"; + case 185: + return "\\xB9"; + case 186: + return "\\xBA"; + case 187: + return "\\xBB"; + case 188: + return "\\xBC"; + case 189: + return "\\xBD"; + case 190: + return "\\xBE"; + case 191: + return "\\xBF"; + case 192: + return "\\xC0"; + case 193: + return "\\xC1"; + case 194: + return "\\xC2"; + case 195: + return "\\xC3"; + case 196: + return "\\xC4"; + case 197: + return "\\xC5"; + case 198: + return "\\xC6"; + case 199: + return "\\xC7"; + case 200: + return "\\xC8"; + case 201: + return "\\xC9"; + case 202: + return "\\xCA"; + case 203: + return "\\xCB"; + case 204: + return "\\xCC"; + case 205: + return "\\xCD"; + case 206: + return "\\xCE"; + case 207: + return "\\xCF"; + case 208: + return "\\xD0"; + case 209: + return "\\xD1"; + case 210: + return "\\xD2"; + case 211: + return "\\xD3"; + case 212: + return "\\xD4"; + case 213: + return "\\xD5"; + case 214: + return "\\xD6"; + case 215: + return "\\xD7"; + case 216: + return "\\xD8"; + case 217: + return "\\xD9"; + case 218: + return "\\xDA"; + case 219: + return "\\xDB"; + case 220: + return "\\xDC"; + case 221: + return "\\xDD"; + case 222: + return "\\xDE"; + case 223: + return "\\xDF"; + case 224: + return "\\xE0"; + case 225: + return "\\xE1"; + case 226: + return "\\xE2"; + case 227: + return "\\xE3"; + case 228: + return "\\xE4"; + case 229: + return "\\xE5"; + case 230: + return "\\xE6"; + case 231: + return "\\xE7"; + case 232: + return "\\xE8"; + case 233: + return "\\xE9"; + case 234: + return "\\xEA"; + case 235: + return "\\xEB"; + case 236: + return "\\xEC"; + case 237: + return "\\xED"; + case 238: + return "\\xEE"; + case 239: + return "\\xEF"; + case 240: + return "\\xF0"; + case 241: + return "\\xF1"; + case 242: + return "\\xF2"; + case 243: + return "\\xF3"; + case 244: + return "\\xF4"; + case 245: + return "\\xF5"; + case 246: + return "\\xF6"; + case 247: + return "\\xF7"; + case 248: + return "\\xF8"; + case 249: + return "\\xF9"; + case 250: + return "\\xFA"; + case 251: + return "\\xFB"; + case 252: + return "\\xFC"; + case 253: + return "\\xFD"; + case 254: + return "\\xFE"; + case 255: + return "\\xFF"; + default: + assert(0); /* never gets here */ + return "dead code"; + } + assert(0); /* never gets here */ +} + +#endif /* XML_GE == 1 */ + +static unsigned long +getDebugLevel(const char *variableName, unsigned long defaultDebugLevel) { + const char *const valueOrNull = getenv(variableName); + if (valueOrNull == NULL) { + return defaultDebugLevel; + } + const char *const value = valueOrNull; + + errno = 0; + char *afterValue = NULL; + unsigned long debugLevel = strtoul(value, &afterValue, 10); + if ((errno != 0) || (afterValue == value) || (afterValue[0] != '\0')) { + errno = 0; + return defaultDebugLevel; + } + + return debugLevel; +} diff --git a/3rdparty/expat/lib/xmlrole.c b/3rdparty/expat/lib/xmlrole.c index 3b676a415d8..2c48bf40867 100644 --- a/3rdparty/expat/lib/xmlrole.c +++ b/3rdparty/expat/lib/xmlrole.c @@ -7,7 +7,15 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2002-2006 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2002-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2005-2009 Steven Solie <steven@solie.ca> + Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -30,15 +38,13 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "expat_config.h" + #include <stddef.h> #ifdef _WIN32 # include "winconfig.h" -#else -# ifdef HAVE_EXPAT_CONFIG_H -# include <expat_config.h> -# endif -#endif /* ndef _WIN32 */ +#endif #include "expat_external.h" #include "internal.h" diff --git a/3rdparty/expat/lib/xmlrole.h b/3rdparty/expat/lib/xmlrole.h index 036aba64fd2..a7904274c91 100644 --- a/3rdparty/expat/lib/xmlrole.h +++ b/3rdparty/expat/lib/xmlrole.h @@ -7,7 +7,10 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2017-2024 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -124,9 +127,9 @@ typedef struct prolog_state { #endif /* XML_DTD */ } PROLOG_STATE; -void XmlPrologStateInit(PROLOG_STATE *); +void XmlPrologStateInit(PROLOG_STATE *state); #ifdef XML_DTD -void XmlPrologStateInitExternalEntity(PROLOG_STATE *); +void XmlPrologStateInitExternalEntity(PROLOG_STATE *state); #endif /* XML_DTD */ #define XmlTokenRole(state, tok, ptr, end, enc) \ diff --git a/3rdparty/expat/lib/xmltok.c b/3rdparty/expat/lib/xmltok.c index c4f9897f7dc..3864b9e6676 100644 --- a/3rdparty/expat/lib/xmltok.c +++ b/3rdparty/expat/lib/xmltok.c @@ -7,7 +7,23 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2001-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2002 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2002-2016 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2005-2009 Steven Solie <steven@solie.ca> + Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2016 Pascal Cuoq <cuoq@trust-in-soft.com> + Copyright (c) 2016 Don Lewis <truckman@apache.org> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Alexander Bluhm <alexander.bluhm@gmx.net> + Copyright (c) 2017 Benbuck Nason <bnason@netflix.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Copyright (c) 2022 Martin Ettl <ettl.martin78@googlemail.com> + Copyright (c) 2022 Sean McBride <sean@rogue-research.com> + Copyright (c) 2023 Hanno Böck <hanno@gentoo.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -30,25 +46,15 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "expat_config.h" + #include <stddef.h> #include <string.h> /* memcpy */ - -#if defined(_MSC_VER) && (_MSC_VER <= 1700) -/* for vs2012/11.0/1700 and earlier Visual Studio compilers */ -# define bool int -# define false 0 -# define true 1 -#else -# include <stdbool.h> -#endif +#include <stdbool.h> #ifdef _WIN32 # include "winconfig.h" -#else -# ifdef HAVE_EXPAT_CONFIG_H -# include <expat_config.h> -# endif -#endif /* ndef _WIN32 */ +#endif #include "expat_external.h" #include "internal.h" @@ -72,7 +78,7 @@ #define VTABLE VTABLE1, PREFIX(toUtf8), PREFIX(toUtf16) #define UCS2_GET_NAMING(pages, hi, lo) \ - (namingBitmap[(pages[hi] << 3) + ((lo) >> 5)] & (1u << ((lo)&0x1F))) + (namingBitmap[(pages[hi] << 3) + ((lo) >> 5)] & (1u << ((lo) & 0x1F))) /* A 2 byte UTF-8 representation splits the characters 11 bits between the bottom 5 and 6 bits of the bytes. We need 8 bits to index into @@ -95,13 +101,8 @@ + ((((byte)[1]) & 3) << 1) + ((((byte)[2]) >> 5) & 1)] \ & (1u << (((byte)[2]) & 0x1F))) -#define UTF8_GET_NAMING(pages, p, n) \ - ((n) == 2 \ - ? UTF8_GET_NAMING2(pages, (const unsigned char *)(p)) \ - : ((n) == 3 ? UTF8_GET_NAMING3(pages, (const unsigned char *)(p)) : 0)) - /* Detection of invalid UTF-8 sequences is based on Table 3.1B - of Unicode 3.2: http://www.unicode.org/unicode/reports/tr28/ + of Unicode 3.2: https://www.unicode.org/unicode/reports/tr28/ with the additional restriction of not allowing the Unicode code points 0xFFFF and 0xFFFE (sequences EF,BF,BF and EF,BF,BE). Implementation details: @@ -226,7 +227,7 @@ struct normal_encoding { /* isNmstrt2 */ NULL, /* isNmstrt3 */ NULL, /* isNmstrt4 */ NULL, \ /* isInvalid2 */ NULL, /* isInvalid3 */ NULL, /* isInvalid4 */ NULL -static int FASTCALL checkCharRefNumber(int); +static int FASTCALL checkCharRefNumber(int result); #include "xmltok_impl.h" #include "ascii.h" @@ -244,7 +245,7 @@ static int FASTCALL checkCharRefNumber(int); #endif #define SB_BYTE_TYPE(enc, p) \ - (((struct normal_encoding *)(enc))->type[(unsigned char)*(p)]) + (((const struct normal_encoding *)(enc))->type[(unsigned char)*(p)]) #ifdef XML_MIN_SIZE static int PTRFASTCALL @@ -269,8 +270,14 @@ sb_byteToAscii(const ENCODING *enc, const char *p) { #define IS_NAME_CHAR(enc, p, n) (AS_NORMAL_ENCODING(enc)->isName##n(enc, p)) #define IS_NMSTRT_CHAR(enc, p, n) (AS_NORMAL_ENCODING(enc)->isNmstrt##n(enc, p)) -#define IS_INVALID_CHAR(enc, p, n) \ - (AS_NORMAL_ENCODING(enc)->isInvalid##n(enc, p)) +#ifdef XML_MIN_SIZE +# define IS_INVALID_CHAR(enc, p, n) \ + (AS_NORMAL_ENCODING(enc)->isInvalid##n \ + && AS_NORMAL_ENCODING(enc)->isInvalid##n(enc, p)) +#else +# define IS_INVALID_CHAR(enc, p, n) \ + (AS_NORMAL_ENCODING(enc)->isInvalid##n(enc, p)) +#endif #ifdef XML_MIN_SIZE # define IS_NAME_CHAR_MINBPC(enc, p) \ @@ -292,7 +299,7 @@ sb_charMatches(const ENCODING *enc, const char *p, int c) { } #else /* c is an ASCII character */ -# define CHAR_MATCHES(enc, p, c) (*(p) == c) +# define CHAR_MATCHES(enc, p, c) (*(p) == (c)) #endif #define PREFIX(ident) normal_##ident @@ -402,7 +409,7 @@ utf8_toUtf16(const ENCODING *enc, const char **fromP, const char *fromLim, unsigned short *to = *toP; const char *from = *fromP; while (from < fromLim && to < toLim) { - switch (((struct normal_encoding *)enc)->type[(unsigned char)*from]) { + switch (SB_BYTE_TYPE(enc, from)) { case BT_LEAD2: if (fromLim - from < 2) { res = XML_CONVERT_INPUT_INCOMPLETE; @@ -710,33 +717,28 @@ unicode_byte_type(char hi, char lo) { return res; \ } -#define SET2(ptr, ch) (((ptr)[0] = ((ch)&0xff)), ((ptr)[1] = ((ch) >> 8))) #define GET_LO(ptr) ((unsigned char)(ptr)[0]) #define GET_HI(ptr) ((unsigned char)(ptr)[1]) DEFINE_UTF16_TO_UTF8(little2_) DEFINE_UTF16_TO_UTF16(little2_) -#undef SET2 #undef GET_LO #undef GET_HI -#define SET2(ptr, ch) (((ptr)[0] = ((ch) >> 8)), ((ptr)[1] = ((ch)&0xFF))) #define GET_LO(ptr) ((unsigned char)(ptr)[1]) #define GET_HI(ptr) ((unsigned char)(ptr)[0]) DEFINE_UTF16_TO_UTF8(big2_) DEFINE_UTF16_TO_UTF16(big2_) -#undef SET2 #undef GET_LO #undef GET_HI #define LITTLE2_BYTE_TYPE(enc, p) \ - ((p)[1] == 0 ? ((struct normal_encoding *)(enc))->type[(unsigned char)*(p)] \ - : unicode_byte_type((p)[1], (p)[0])) + ((p)[1] == 0 ? SB_BYTE_TYPE(enc, p) : unicode_byte_type((p)[1], (p)[0])) #define LITTLE2_BYTE_TO_ASCII(p) ((p)[1] == 0 ? (p)[0] : -1) -#define LITTLE2_CHAR_MATCHES(p, c) ((p)[1] == 0 && (p)[0] == c) +#define LITTLE2_CHAR_MATCHES(p, c) ((p)[1] == 0 && (p)[0] == (c)) #define LITTLE2_IS_NAME_CHAR_MINBPC(p) \ UCS2_GET_NAMING(namePages, (unsigned char)p[1], (unsigned char)p[0]) #define LITTLE2_IS_NMSTRT_CHAR_MINBPC(p) \ @@ -867,11 +869,9 @@ static const struct normal_encoding internal_little2_encoding #endif #define BIG2_BYTE_TYPE(enc, p) \ - ((p)[0] == 0 \ - ? ((struct normal_encoding *)(enc))->type[(unsigned char)(p)[1]] \ - : unicode_byte_type((p)[0], (p)[1])) + ((p)[0] == 0 ? SB_BYTE_TYPE(enc, p + 1) : unicode_byte_type((p)[0], (p)[1])) #define BIG2_BYTE_TO_ASCII(p) ((p)[0] == 0 ? (p)[1] : -1) -#define BIG2_CHAR_MATCHES(p, c) ((p)[0] == 0 && (p)[1] == c) +#define BIG2_CHAR_MATCHES(p, c) ((p)[0] == 0 && (p)[1] == (c)) #define BIG2_IS_NAME_CHAR_MINBPC(p) \ UCS2_GET_NAMING(namePages, (unsigned char)p[0], (unsigned char)p[1]) #define BIG2_IS_NMSTRT_CHAR_MINBPC(p) \ diff --git a/3rdparty/expat/lib/xmltok.h b/3rdparty/expat/lib/xmltok.h index 2adbf5307be..c51fce1ec15 100644 --- a/3rdparty/expat/lib/xmltok.h +++ b/3rdparty/expat/lib/xmltok.h @@ -7,7 +7,11 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2002-2005 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -285,7 +289,8 @@ int XmlParseXmlDecl(int isGeneralTextEntity, const ENCODING *enc, const char **encodingNamePtr, const ENCODING **namedEncodingPtr, int *standalonePtr); -int XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name); +int XmlInitEncoding(INIT_ENCODING *p, const ENCODING **encPtr, + const char *name); const ENCODING *XmlGetUtf8InternalEncoding(void); const ENCODING *XmlGetUtf16InternalEncoding(void); int FASTCALL XmlUtf8Encode(int charNumber, char *buf); @@ -303,7 +308,8 @@ int XmlParseXmlDeclNS(int isGeneralTextEntity, const ENCODING *enc, const char **encodingNamePtr, const ENCODING **namedEncodingPtr, int *standalonePtr); -int XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name); +int XmlInitEncodingNS(INIT_ENCODING *p, const ENCODING **encPtr, + const char *name); const ENCODING *XmlGetUtf8InternalEncodingNS(void); const ENCODING *XmlGetUtf16InternalEncodingNS(void); ENCODING *XmlInitUnknownEncodingNS(void *mem, int *table, CONVERTER convert, diff --git a/3rdparty/expat/lib/xmltok_impl.c b/3rdparty/expat/lib/xmltok_impl.c index 06d5c90851f..239a2d06c45 100644 --- a/3rdparty/expat/lib/xmltok_impl.c +++ b/3rdparty/expat/lib/xmltok_impl.c @@ -1,4 +1,4 @@ -/* This file is included! +/* This file is included (from xmltok.c, 1-3 times depending on XML_MIN_SIZE)! __ __ _ ___\ \/ /_ __ __ _| |_ / _ \\ /| '_ \ / _` | __| @@ -7,7 +7,16 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2002-2016 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2018 Benjamin Peterson <benjamin@python.org> + Copyright (c) 2018 Anton Maklakov <antmak.pub@gmail.com> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Boris Kolpackov <boris@codesynthesis.com> + Copyright (c) 2022 Martin Ettl <ettl.martin78@googlemail.com> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -32,7 +41,7 @@ #ifdef XML_TOK_IMPL_C -# ifndef IS_INVALID_CHAR +# ifndef IS_INVALID_CHAR // i.e. for UTF-16 and XML_MIN_SIZE not defined # define IS_INVALID_CHAR(enc, ptr, n) (0) # endif @@ -61,7 +70,7 @@ case BT_LEAD##n: \ if (end - ptr < n) \ return XML_TOK_PARTIAL_CHAR; \ - if (! IS_NAME_CHAR(enc, ptr, n)) { \ + if (IS_INVALID_CHAR(enc, ptr, n) || ! IS_NAME_CHAR(enc, ptr, n)) { \ *nextTokPtr = ptr; \ return XML_TOK_INVALID; \ } \ @@ -88,9 +97,9 @@ # define CHECK_NMSTRT_CASE(n, enc, ptr, end, nextTokPtr) \ case BT_LEAD##n: \ - if (end - ptr < n) \ + if ((end) - (ptr) < (n)) \ return XML_TOK_PARTIAL_CHAR; \ - if (! IS_NMSTRT_CHAR(enc, ptr, n)) { \ + if (IS_INVALID_CHAR(enc, ptr, n) || ! IS_NMSTRT_CHAR(enc, ptr, n)) { \ *nextTokPtr = ptr; \ return XML_TOK_INVALID; \ } \ @@ -116,7 +125,8 @@ # define PREFIX(ident) ident # endif -# define HAS_CHARS(enc, ptr, end, count) (end - ptr >= count * MINBPC(enc)) +# define HAS_CHARS(enc, ptr, end, count) \ + ((end) - (ptr) >= ((count) * MINBPC(enc))) # define HAS_CHAR(enc, ptr, end) HAS_CHARS(enc, ptr, end, 1) @@ -1134,6 +1144,10 @@ PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end, case BT_LEAD##n: \ if (end - ptr < n) \ return XML_TOK_PARTIAL_CHAR; \ + if (IS_INVALID_CHAR(enc, ptr, n)) { \ + *nextTokPtr = ptr; \ + return XML_TOK_INVALID; \ + } \ if (IS_NMSTRT_CHAR(enc, ptr, n)) { \ ptr += n; \ tok = XML_TOK_NAME; \ @@ -1262,7 +1276,7 @@ PREFIX(attributeValueTok)(const ENCODING *enc, const char *ptr, const char *end, switch (BYTE_TYPE(enc, ptr)) { # define LEAD_CASE(n) \ case BT_LEAD##n: \ - ptr += n; \ + ptr += n; /* NOTE: The encoding has already been validated. */ \ break; LEAD_CASE(2) LEAD_CASE(3) @@ -1331,7 +1345,7 @@ PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, const char *end, switch (BYTE_TYPE(enc, ptr)) { # define LEAD_CASE(n) \ case BT_LEAD##n: \ - ptr += n; \ + ptr += n; /* NOTE: The encoding has already been validated. */ \ break; LEAD_CASE(2) LEAD_CASE(3) @@ -1510,7 +1524,7 @@ PREFIX(getAtts)(const ENCODING *enc, const char *ptr, int attsMax, state = inName; \ } # define LEAD_CASE(n) \ - case BT_LEAD##n: \ + case BT_LEAD##n: /* NOTE: The encoding has already been validated. */ \ START_NAME ptr += (n - MINBPC(enc)); \ break; LEAD_CASE(2) @@ -1722,7 +1736,7 @@ PREFIX(nameLength)(const ENCODING *enc, const char *ptr) { switch (BYTE_TYPE(enc, ptr)) { # define LEAD_CASE(n) \ case BT_LEAD##n: \ - ptr += n; \ + ptr += n; /* NOTE: The encoding has already been validated. */ \ break; LEAD_CASE(2) LEAD_CASE(3) @@ -1767,7 +1781,7 @@ PREFIX(updatePosition)(const ENCODING *enc, const char *ptr, const char *end, switch (BYTE_TYPE(enc, ptr)) { # define LEAD_CASE(n) \ case BT_LEAD##n: \ - ptr += n; \ + ptr += n; /* NOTE: The encoding has already been validated. */ \ pos->columnNumber++; \ break; LEAD_CASE(2) diff --git a/3rdparty/expat/lib/xmltok_impl.h b/3rdparty/expat/lib/xmltok_impl.h index e925dbc7e2c..3469c4ae138 100644 --- a/3rdparty/expat/lib/xmltok_impl.h +++ b/3rdparty/expat/lib/xmltok_impl.h @@ -7,7 +7,8 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2017-2019 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -44,7 +45,7 @@ enum { BT_LF, /* line feed = "\n" */ BT_GT, /* greater than = ">" */ BT_QUOT, /* quotation character = "\"" */ - BT_APOS, /* aposthrophe = "'" */ + BT_APOS, /* apostrophe = "'" */ BT_EQUALS, /* equal sign = "=" */ BT_QUEST, /* question mark = "?" */ BT_EXCL, /* exclamation mark = "!" */ diff --git a/3rdparty/expat/lib/xmltok_ns.c b/3rdparty/expat/lib/xmltok_ns.c index 919c74e9f97..fbdd3e3c7b7 100644 --- a/3rdparty/expat/lib/xmltok_ns.c +++ b/3rdparty/expat/lib/xmltok_ns.c @@ -7,7 +7,11 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2002-2006 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2017-2021 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -89,7 +93,7 @@ NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr, static const ENCODING * NS(findEncoding)(const ENCODING *enc, const char *ptr, const char *end) { # define ENCODING_MAX 128 - char buf[ENCODING_MAX]; + char buf[ENCODING_MAX] = ""; char *p = buf; int i; XmlUtf8Convert(enc, &ptr, end, &p, p + ENCODING_MAX - 1); diff --git a/3rdparty/expat/m4/libtool.m4 b/3rdparty/expat/m4/libtool.m4 index ae7c9061329..fcfc1c836ea 100644 --- a/3rdparty/expat/m4/libtool.m4 +++ b/3rdparty/expat/m4/libtool.m4 @@ -1,6 +1,7 @@ # libtool.m4 - Configure libtool for the host system. -*-Autoconf-*- # -# Copyright (C) 1996-2001, 2003-2015 Free Software Foundation, Inc. +# Copyright (C) 1996-2001, 2003-2019, 2021-2024 Free Software +# Foundation, Inc. # Written by Gordon Matzigkeit, 1996 # # This file is free software; the Free Software Foundation gives @@ -8,13 +9,13 @@ # modifications, as long as this notice is preserved. m4_define([_LT_COPYING], [dnl -# Copyright (C) 2014 Free Software Foundation, Inc. +# Copyright (C) 2024 Free Software Foundation, Inc. # This is free software; see the source for copying conditions. There is NO # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # GNU Libtool is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of of the License, or +# the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # As a special exception to the GNU General Public License, if you @@ -31,7 +32,7 @@ m4_define([_LT_COPYING], [dnl # along with this program. If not, see <http://www.gnu.org/licenses/>. ]) -# serial 58 LT_INIT +# serial 62 LT_INIT # LT_PREREQ(VERSION) @@ -59,7 +60,7 @@ esac # LT_INIT([OPTIONS]) # ------------------ AC_DEFUN([LT_INIT], -[AC_PREREQ([2.62])dnl We use AC_PATH_PROGS_FEATURE_CHECK +[AC_PREREQ([2.64])dnl We use AC_PATH_PROGS_FEATURE_CHECK AC_REQUIRE([AC_CONFIG_AUX_DIR_DEFAULT])dnl AC_BEFORE([$0], [LT_LANG])dnl AC_BEFORE([$0], [LT_OUTPUT])dnl @@ -181,6 +182,7 @@ m4_require([_LT_FILEUTILS_DEFAULTS])dnl m4_require([_LT_CHECK_SHELL_FEATURES])dnl m4_require([_LT_PATH_CONVERSION_FUNCTIONS])dnl m4_require([_LT_CMD_RELOAD])dnl +m4_require([_LT_DECL_FILECMD])dnl m4_require([_LT_CHECK_MAGIC_METHOD])dnl m4_require([_LT_CHECK_SHAREDLIB_FROM_LINKLIB])dnl m4_require([_LT_CMD_OLD_ARCHIVE])dnl @@ -219,8 +221,8 @@ esac ofile=libtool can_build_shared=yes -# All known linkers require a '.a' archive for static linking (except MSVC, -# which needs '.lib'). +# All known linkers require a '.a' archive for static linking (except MSVC and +# ICC, which need '.lib'). libext=a with_gnu_ld=$lt_cv_prog_gnu_ld @@ -614,7 +616,7 @@ m4_popdef([AS_MESSAGE_LOG_FD])])])# _LT_GENERATED_FILE_INIT # LT_OUTPUT # --------- # This macro allows early generation of the libtool script (before -# AC_OUTPUT is called), incase it is used in configure for compilation +# AC_OUTPUT is called), in case it is used in configure for compilation # tests. AC_DEFUN([LT_OUTPUT], [: ${CONFIG_LT=./config.lt} @@ -649,9 +651,9 @@ m4_ifset([AC_PACKAGE_NAME], [AC_PACKAGE_NAME ])config.lt[]dnl m4_ifset([AC_PACKAGE_VERSION], [ AC_PACKAGE_VERSION]) configured by $[0], generated by m4_PACKAGE_STRING. -Copyright (C) 2011 Free Software Foundation, Inc. +Copyright (C) 2024 Free Software Foundation, Inc. This config.lt script is free software; the Free Software Foundation -gives unlimited permision to copy, distribute and modify it." +gives unlimited permission to copy, distribute and modify it." while test 0 != $[#] do @@ -728,7 +730,6 @@ _LT_CONFIG_SAVE_COMMANDS([ cat <<_LT_EOF >> "$cfgfile" #! $SHELL # Generated automatically by $as_me ($PACKAGE) $VERSION -# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`: # NOTE: Changes made to this file will be lost: look at ltmain.sh. # Provide generalized library-building support services. @@ -778,7 +779,7 @@ _LT_EOF # if finds mixed CR/LF and LF-only lines. Since sed operates in # text mode, it properly converts lines to CR/LF. This bash problem # is reportedly fixed, but why not run on old versions too? - sed '$q' "$ltmain" >> "$cfgfile" \ + $SED '$q' "$ltmain" >> "$cfgfile" \ || (rm -f "$cfgfile"; exit 1) mv -f "$cfgfile" "$ofile" || @@ -973,6 +974,7 @@ _lt_linker_boilerplate=`cat conftest.err` $RM -r conftest* ])# _LT_LINKER_BOILERPLATE + # _LT_REQUIRED_DARWIN_CHECKS # ------------------------- m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[ @@ -1023,6 +1025,21 @@ m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[ rm -f conftest.* fi]) + # Feature test to disable chained fixups since it is not + # compatible with '-undefined dynamic_lookup' + AC_CACHE_CHECK([for -no_fixup_chains linker flag], + [lt_cv_support_no_fixup_chains], + [ save_LDFLAGS=$LDFLAGS + LDFLAGS="$LDFLAGS -Wl,-no_fixup_chains" + AC_LINK_IFELSE( + [AC_LANG_PROGRAM([],[])], + lt_cv_support_no_fixup_chains=yes, + lt_cv_support_no_fixup_chains=no + ) + LDFLAGS=$save_LDFLAGS + ] + ) + AC_CACHE_CHECK([for -exported_symbols_list linker flag], [lt_cv_ld_exported_symbols_list], [lt_cv_ld_exported_symbols_list=no @@ -1042,12 +1059,12 @@ int forced_loaded() { return 2;} _LT_EOF echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&AS_MESSAGE_LOG_FD $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&AS_MESSAGE_LOG_FD - echo "$AR cru libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD - $AR cru libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD + echo "$AR $AR_FLAGS libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD + $AR $AR_FLAGS libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD echo "$RANLIB libconftest.a" >&AS_MESSAGE_LOG_FD $RANLIB libconftest.a 2>&AS_MESSAGE_LOG_FD cat > conftest.c << _LT_EOF -int main() { return 0;} +int main(void) { return 0;} _LT_EOF echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&AS_MESSAGE_LOG_FD $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err @@ -1067,17 +1084,16 @@ _LT_EOF _lt_dar_allow_undefined='$wl-undefined ${wl}suppress' ;; darwin1.*) _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; - darwin*) # darwin 5.x on - # if running on 10.5 or later, the deployment target defaults - # to the OS version, if on x86, and 10.4, the deployment - # target defaults to 10.4. Don't you love it? - case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in - 10.0,*86*-darwin8*|10.0,*-darwin[[91]]*) - _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; - 10.[[012]][[,.]]*) - _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; - 10.*) - _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;; + darwin*) + case $MACOSX_DEPLOYMENT_TARGET,$host in + 10.[[012]],*|,*powerpc*-darwin[[5-8]]*) + _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined ${wl}suppress' ;; + *) + _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' + if test yes = "$lt_cv_support_no_fixup_chains"; then + AS_VAR_APPEND([_lt_dar_allow_undefined], [' $wl-no_fixup_chains']) + fi + ;; esac ;; esac @@ -1126,12 +1142,12 @@ m4_defun([_LT_DARWIN_LINKER_FEATURES], output_verbose_link_cmd=func_echo_all _LT_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dsymutil" _LT_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dsymutil" - _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" - _LT_TAGVAR(module_expsym_cmds, $1)="sed -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" + _LT_TAGVAR(archive_expsym_cmds, $1)="$SED 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod$_lt_dar_export_syms$_lt_dsymutil" + _LT_TAGVAR(module_expsym_cmds, $1)="$SED -e 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags$_lt_dar_export_syms$_lt_dsymutil" m4_if([$1], [CXX], [ if test yes != "$lt_cv_apple_cc_single_mod"; then _LT_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dsymutil" - _LT_TAGVAR(archive_expsym_cmds, $1)="sed 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dar_export_syms$_lt_dsymutil" + _LT_TAGVAR(archive_expsym_cmds, $1)="$SED 's|^|_|' < \$export_symbols > \$output_objdir/\$libname-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \$lib-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$lib-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring$_lt_dar_export_syms$_lt_dsymutil" fi ],[]) else @@ -1245,7 +1261,8 @@ _LT_DECL([], [ECHO], [1], [An echo program that protects backslashes]) # _LT_WITH_SYSROOT # ---------------- AC_DEFUN([_LT_WITH_SYSROOT], -[AC_MSG_CHECKING([for sysroot]) +[m4_require([_LT_DECL_SED])dnl +AC_MSG_CHECKING([for sysroot]) AC_ARG_WITH([sysroot], [AS_HELP_STRING([--with-sysroot@<:@=DIR@:>@], [Search for dependent libraries within DIR (or the compiler's sysroot @@ -1258,11 +1275,13 @@ lt_sysroot= case $with_sysroot in #( yes) if test yes = "$GCC"; then - lt_sysroot=`$CC --print-sysroot 2>/dev/null` + # Trim trailing / since we'll always append absolute paths and we want + # to avoid //, if only for less confusing output for the user. + lt_sysroot=`$CC --print-sysroot 2>/dev/null | $SED 's:/\+$::'` fi ;; #( /*) - lt_sysroot=`echo "$with_sysroot" | sed -e "$sed_quote_subst"` + lt_sysroot=`echo "$with_sysroot" | $SED -e "$sed_quote_subst"` ;; #( no|'') ;; #( @@ -1292,7 +1311,7 @@ ia64-*-hpux*) # options accordingly. echo 'int i;' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then - case `/usr/bin/file conftest.$ac_objext` in + case `$FILECMD conftest.$ac_objext` in *ELF-32*) HPUX_IA64_MODE=32 ;; @@ -1309,7 +1328,7 @@ ia64-*-hpux*) echo '[#]line '$LINENO' "configure"' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then if test yes = "$lt_cv_prog_gnu_ld"; then - case `/usr/bin/file conftest.$ac_objext` in + case `$FILECMD conftest.$ac_objext` in *32-bit*) LD="${LD-ld} -melf32bsmip" ;; @@ -1321,7 +1340,7 @@ ia64-*-hpux*) ;; esac else - case `/usr/bin/file conftest.$ac_objext` in + case `$FILECMD conftest.$ac_objext` in *32-bit*) LD="${LD-ld} -32" ;; @@ -1343,7 +1362,7 @@ mips64*-*linux*) echo '[#]line '$LINENO' "configure"' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then emul=elf - case `/usr/bin/file conftest.$ac_objext` in + case `$FILECMD conftest.$ac_objext` in *32-bit*) emul="${emul}32" ;; @@ -1351,7 +1370,7 @@ mips64*-*linux*) emul="${emul}64" ;; esac - case `/usr/bin/file conftest.$ac_objext` in + case `$FILECMD conftest.$ac_objext` in *MSB*) emul="${emul}btsmip" ;; @@ -1359,7 +1378,7 @@ mips64*-*linux*) emul="${emul}ltsmip" ;; esac - case `/usr/bin/file conftest.$ac_objext` in + case `$FILECMD conftest.$ac_objext` in *N32*) emul="${emul}n32" ;; @@ -1370,7 +1389,7 @@ mips64*-*linux*) ;; x86_64-*kfreebsd*-gnu|x86_64-*linux*|powerpc*-*linux*| \ -s390*-*linux*|s390*-*tpf*|sparc*-*linux*) +s390*-*linux*|s390*-*tpf*|sparc*-*linux*|x86_64-gnu*) # Find out what ABI is being produced by ac_compile, and set linker # options accordingly. Note that the listed cases only cover the # situations where additional linker options are needed (such as when @@ -1379,14 +1398,14 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) # not appear in the list. echo 'int i;' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then - case `/usr/bin/file conftest.o` in + case `$FILECMD conftest.o` in *32-bit*) case $host in x86_64-*kfreebsd*-gnu) LD="${LD-ld} -m elf_i386_fbsd" ;; - x86_64-*linux*) - case `/usr/bin/file conftest.o` in + x86_64-*linux*|x86_64-gnu*) + case `$FILECMD conftest.o` in *x86-64*) LD="${LD-ld} -m elf32_x86_64" ;; @@ -1414,7 +1433,7 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) x86_64-*kfreebsd*-gnu) LD="${LD-ld} -m elf_x86_64_fbsd" ;; - x86_64-*linux*) + x86_64-*linux*|x86_64-gnu*) LD="${LD-ld} -m elf_x86_64" ;; powerpcle-*linux*|powerpc64le-*linux*) @@ -1454,7 +1473,7 @@ s390*-*linux*|s390*-*tpf*|sparc*-*linux*) # options accordingly. echo 'int i;' > conftest.$ac_ext if AC_TRY_EVAL(ac_compile); then - case `/usr/bin/file conftest.o` in + case `$FILECMD conftest.o` in *64-bit*) case $lt_cv_prog_gnu_ld in yes*) @@ -1493,9 +1512,22 @@ need_locks=$enable_libtool_lock m4_defun([_LT_PROG_AR], [AC_CHECK_TOOLS(AR, [ar], false) : ${AR=ar} -: ${AR_FLAGS=cru} _LT_DECL([], [AR], [1], [The archiver]) -_LT_DECL([], [AR_FLAGS], [1], [Flags to create an archive]) + +# Use ARFLAGS variable as AR's operation code to sync the variable naming with +# Automake. If both AR_FLAGS and ARFLAGS are specified, AR_FLAGS should have +# higher priority because that's what people were doing historically (setting +# ARFLAGS for automake and AR_FLAGS for libtool). FIXME: Make the AR_FLAGS +# variable obsoleted/removed. + +test ${AR_FLAGS+y} || AR_FLAGS=${ARFLAGS-cr} +lt_ar_flags=$AR_FLAGS +_LT_DECL([], [lt_ar_flags], [0], [Flags to create an archive (by configure)]) + +# Make AR_FLAGS overridable by 'make ARFLAGS='. Don't try to run-time override +# by AR_FLAGS because that was never working and AR_FLAGS is about to die. +_LT_DECL([], [AR_FLAGS], [\@S|@{ARFLAGS-"\@S|@lt_ar_flags"}], + [Flags to create an archive]) AC_CACHE_CHECK([for archiver @FILE support], [lt_cv_ar_at_file], [lt_cv_ar_at_file=no @@ -1534,7 +1566,7 @@ AC_CHECK_TOOL(STRIP, strip, :) test -z "$STRIP" && STRIP=: _LT_DECL([], [STRIP], [1], [A symbol stripping program]) -AC_CHECK_TOOL(RANLIB, ranlib, :) +AC_REQUIRE([AC_PROG_RANLIB]) test -z "$RANLIB" && RANLIB=: _LT_DECL([], [RANLIB], [1], [Commands used to install an old-style archive]) @@ -1545,15 +1577,8 @@ old_postinstall_cmds='chmod 644 $oldlib' old_postuninstall_cmds= if test -n "$RANLIB"; then - case $host_os in - bitrig* | openbsd*) - old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$tool_oldlib" - ;; - *) - old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib" - ;; - esac old_archive_cmds="$old_archive_cmds~\$RANLIB \$tool_oldlib" + old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$tool_oldlib" fi case $host_os in @@ -1692,7 +1717,7 @@ AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl lt_cv_sys_max_cmd_len=-1; ;; - cygwin* | mingw* | cegcc*) + cygwin* | mingw* | windows* | cegcc*) # On Win9x/ME, this test blows up -- it succeeds, but takes # about 5 minutes as the teststring grows exponentially. # Worse, since 9x/ME are not pre-emptively multitasking, @@ -1708,18 +1733,13 @@ AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl lt_cv_sys_max_cmd_len=8192; ;; - mint*) - # On MiNT this can take a long time and run out of memory. - lt_cv_sys_max_cmd_len=8192; - ;; - amigaos*) # On AmigaOS with pdksh, this test takes hours, literally. # So we just punt and use a minimum line length of 8192. lt_cv_sys_max_cmd_len=8192; ;; - bitrig* | darwin* | dragonfly* | freebsd* | netbsd* | openbsd*) + darwin* | dragonfly* | freebsd* | midnightbsd* | netbsd* | openbsd*) # This has been around since 386BSD, at least. Likely further. if test -x /sbin/sysctl; then lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax` @@ -1762,7 +1782,7 @@ AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl sysv5* | sco5v6* | sysv4.2uw2*) kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null` if test -n "$kargmax"; then - lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[ ]]//'` + lt_cv_sys_max_cmd_len=`echo $kargmax | $SED 's/.*[[ ]]//'` else lt_cv_sys_max_cmd_len=32768 fi @@ -1879,11 +1899,11 @@ else /* When -fvisibility=hidden is used, assume the code has been annotated correspondingly for the symbols needed. */ #if defined __GNUC__ && (((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ > 3)) -int fnord () __attribute__((visibility("default"))); +int fnord (void) __attribute__((visibility("default"))); #endif -int fnord () { return 42; } -int main () +int fnord (void) { return 42; } +int main (void) { void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW); int status = $lt_dlunknown; @@ -1940,7 +1960,7 @@ else lt_cv_dlopen_self=yes ;; - mingw* | pw32* | cegcc*) + mingw* | windows* | pw32* | cegcc*) lt_cv_dlopen=LoadLibrary lt_cv_dlopen_libs= ;; @@ -2212,26 +2232,35 @@ m4_defun([_LT_CMD_STRIPLIB], striplib= old_striplib= AC_MSG_CHECKING([whether stripping libraries is possible]) -if test -n "$STRIP" && $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then - test -z "$old_striplib" && old_striplib="$STRIP --strip-debug" - test -z "$striplib" && striplib="$STRIP --strip-unneeded" - AC_MSG_RESULT([yes]) +if test -z "$STRIP"; then + AC_MSG_RESULT([no]) else -# FIXME - insert some real tests, host_os isn't really good enough - case $host_os in - darwin*) - if test -n "$STRIP"; then + if $STRIP -V 2>&1 | $GREP "GNU strip" >/dev/null; then + old_striplib="$STRIP --strip-debug" + striplib="$STRIP --strip-unneeded" + AC_MSG_RESULT([yes]) + else + case $host_os in + darwin*) + # FIXME - insert some real tests, host_os isn't really good enough striplib="$STRIP -x" old_striplib="$STRIP -S" AC_MSG_RESULT([yes]) - else + ;; + freebsd*) + if $STRIP -V 2>&1 | $GREP "elftoolchain" >/dev/null; then + old_striplib="$STRIP --strip-debug" + striplib="$STRIP --strip-unneeded" + AC_MSG_RESULT([yes]) + else + AC_MSG_RESULT([no]) + fi + ;; + *) AC_MSG_RESULT([no]) - fi - ;; - *) - AC_MSG_RESULT([no]) - ;; - esac + ;; + esac + fi fi _LT_DECL([], [old_striplib], [1], [Commands to strip libraries]) _LT_DECL([], [striplib], [1]) @@ -2299,7 +2328,7 @@ if test yes = "$GCC"; then *) lt_awk_arg='/^libraries:/' ;; esac case $host_os in - mingw* | cegcc*) lt_sed_strip_eq='s|=\([[A-Za-z]]:\)|\1|g' ;; + mingw* | windows* | cegcc*) lt_sed_strip_eq='s|=\([[A-Za-z]]:\)|\1|g' ;; *) lt_sed_strip_eq='s|=/|/|g' ;; esac lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e $lt_sed_strip_eq` @@ -2357,7 +2386,7 @@ BEGIN {RS = " "; FS = "/|\n";} { # AWK program above erroneously prepends '/' to C:/dos/paths # for these hosts. case $host_os in - mingw* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\ + mingw* | windows* | cegcc*) lt_search_path_spec=`$ECHO "$lt_search_path_spec" |\ $SED 's|/\([[A-Za-z]]:\)|\1|g'` ;; esac sys_lib_search_path_spec=`$ECHO "$lt_search_path_spec" | $lt_NL2SP` @@ -2432,7 +2461,7 @@ aix[[4-9]]*) # Unfortunately, runtime linking may impact performance, so we do # not want this to be the default eventually. Also, we use the # versioned .so libs for executables only if there is the -brtl - # linker flag in LDFLAGS as well, or --with-aix-soname=svr4 only. + # linker flag in LDFLAGS as well, or --enable-aix-soname=svr4 only. # To allow for filename-based versioning support, we need to create # libNAME.so.V as an archive file, containing: # *) an Import File, referring to the versioned filename of the @@ -2526,7 +2555,7 @@ bsdi[[45]]*) # libtool to hard-code these into programs ;; -cygwin* | mingw* | pw32* | cegcc*) +cygwin* | mingw* | windows* | pw32* | cegcc*) version_type=windows shrext_cmds=.dll need_version=no @@ -2537,6 +2566,19 @@ cygwin* | mingw* | pw32* | cegcc*) # gcc library_names_spec='$libname.dll.a' # DLL is installed to $(libdir)/../bin by postinstall_cmds + # If user builds GCC with mulitlibs enabled, + # it should just install on $(libdir) + # not on $(libdir)/../bin or 32 bits dlls would override 64 bit ones. + if test yes = $multilib; then + postinstall_cmds='base_file=`basename \$file`~ + dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ + dldir=$destdir/`dirname \$dlpath`~ + $install_prog $dir/$dlname $destdir/$dlname~ + chmod a+x $destdir/$dlname~ + if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then + eval '\''$striplib $destdir/$dlname'\'' || exit \$?; + fi' + else postinstall_cmds='base_file=`basename \$file`~ dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\$base_file'\''i; echo \$dlname'\''`~ dldir=$destdir/`dirname \$dlpath`~ @@ -2546,6 +2588,7 @@ cygwin* | mingw* | pw32* | cegcc*) if test -n '\''$stripme'\'' && test -n '\''$striplib'\''; then eval '\''$striplib \$dldir/$dlname'\'' || exit \$?; fi' + fi postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~ dlpath=$dir/\$dldll~ $RM \$dlpath' @@ -2554,30 +2597,30 @@ cygwin* | mingw* | pw32* | cegcc*) case $host_os in cygwin*) # Cygwin DLLs use 'cyg' prefix rather than 'lib' - soname_spec='`echo $libname | sed -e 's/^lib/cyg/'``echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' + soname_spec='`echo $libname | $SED -e 's/^lib/cyg/'``echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' m4_if([$1], [],[ sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/lib/w32api"]) ;; - mingw* | cegcc*) + mingw* | windows* | cegcc*) # MinGW DLLs use traditional 'lib' prefix soname_spec='$libname`echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' ;; pw32*) # pw32 DLLs use 'pw' prefix rather than 'lib' - library_names_spec='`echo $libname | sed -e 's/^lib/pw/'``echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' + library_names_spec='`echo $libname | $SED -e 's/^lib/pw/'``echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' ;; esac dynamic_linker='Win32 ld.exe' ;; - *,cl*) - # Native MSVC + *,cl* | *,icl*) + # Native MSVC or ICC libname_spec='$name' soname_spec='$libname`echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext' library_names_spec='$libname.dll.lib' case $build_os in - mingw*) + mingw* | windows*) sys_lib_search_path_spec= lt_save_ifs=$IFS IFS=';' @@ -2590,7 +2633,7 @@ m4_if([$1], [],[ done IFS=$lt_save_ifs # Convert to MSYS style. - sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | sed -e 's|\\\\|/|g' -e 's| \\([[a-zA-Z]]\\):| /\\1|g' -e 's|^ ||'` + sys_lib_search_path_spec=`$ECHO "$sys_lib_search_path_spec" | $SED -e 's|\\\\|/|g' -e 's| \\([[a-zA-Z]]\\):| /\\1|g' -e 's|^ ||'` ;; cygwin*) # Convert to unix form, then to dos form, then back to unix form @@ -2627,7 +2670,7 @@ m4_if([$1], [],[ ;; *) - # Assume MSVC wrapper + # Assume MSVC and ICC wrapper library_names_spec='$libname`echo $release | $SED -e 's/[[.]]/-/g'`$versuffix$shared_ext $libname.lib' dynamic_linker='Win32 ld.exe' ;; @@ -2660,7 +2703,7 @@ dgux*) shlibpath_var=LD_LIBRARY_PATH ;; -freebsd* | dragonfly*) +freebsd* | dragonfly* | midnightbsd*) # DragonFly does not have aout. When/if they implement a new # versioning mechanism, adjust this. if test -x /usr/bin/objformat; then @@ -2697,7 +2740,21 @@ freebsd* | dragonfly*) need_version=no ;; esac - shlibpath_var=LD_LIBRARY_PATH + case $host_cpu in + powerpc64) + # On FreeBSD bi-arch platforms, a different variable is used for 32-bit + # binaries. See <https://man.freebsd.org/cgi/man.cgi?query=ld.so>. + AC_COMPILE_IFELSE( + [AC_LANG_SOURCE( + [[int test_pointer_size[sizeof (void *) - 5]; + ]])], + [shlibpath_var=LD_LIBRARY_PATH], + [shlibpath_var=LD_32_LIBRARY_PATH]) + ;; + *) + shlibpath_var=LD_LIBRARY_PATH + ;; + esac case $host_os in freebsd2.*) shlibpath_overrides_runpath=yes @@ -2838,7 +2895,7 @@ linux*android*) version_type=none # Android doesn't support versioned libraries. need_lib_prefix=no need_version=no - library_names_spec='$libname$release$shared_ext' + library_names_spec='$libname$release$shared_ext $libname$shared_ext' soname_spec='$libname$release$shared_ext' finish_cmds= shlibpath_var=LD_LIBRARY_PATH @@ -2850,8 +2907,9 @@ linux*android*) hardcode_into_libs=yes dynamic_linker='Android linker' - # Don't embed -rpath directories since the linker doesn't support them. - _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' + # -rpath works at least for libraries that are not overridden by + # libraries installed in system locations. + _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-rpath $wl$libdir' ;; # This must be glibc/ELF. @@ -2885,7 +2943,7 @@ linux* | k*bsd*-gnu | kopensolaris*-gnu | gnu*) # before this can be enabled. hardcode_into_libs=yes - # Ideally, we could use ldconfig to report *all* directores which are + # Ideally, we could use ldconfig to report *all* directories which are # searched for libraries, however this is still not possible. Aside from not # being certain /sbin/ldconfig is available, command # 'ldconfig -N -X -v | grep ^/' on 64bit Fedora does not report /usr/lib64, @@ -2942,7 +3000,7 @@ newsos6) dynamic_linker='ldqnx.so' ;; -openbsd* | bitrig*) +openbsd*) version_type=sunos sys_lib_dlsearch_path_spec=/usr/lib need_lib_prefix=no @@ -3274,7 +3332,7 @@ if test yes = "$GCC"; then # Check if gcc -print-prog-name=ld gives a path. AC_MSG_CHECKING([for ld used by $CC]) case $host in - *-*-mingw*) + *-*-mingw* | *-*-windows*) # gcc leaves a trailing carriage return, which upsets mingw ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;; *) @@ -3383,7 +3441,7 @@ case $reload_flag in esac reload_cmds='$LD$reload_flag -o $output$reload_objs' case $host_os in - cygwin* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | windows* | pw32* | cegcc*) if test yes != "$GCC"; then reload_cmds=false fi @@ -3455,7 +3513,6 @@ lt_cv_deplibs_check_method='unknown' # 'none' -- dependencies not supported. # 'unknown' -- same as none, but documents that we really don't know. # 'pass_all' -- all dependencies passed with no checks. -# 'test_compile' -- check by making test program. # 'file_magic [[regex]]' -- check by looking for files in library path # that responds to the $file_magic_cmd with a given extended regex. # If you have 'file' or equivalent on your system and you're not sure @@ -3472,7 +3529,7 @@ beos*) bsdi[[45]]*) lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib)' - lt_cv_file_magic_cmd='/usr/bin/file -L' + lt_cv_file_magic_cmd='$FILECMD -L' lt_cv_file_magic_test_file=/shlib/libc.so ;; @@ -3482,7 +3539,7 @@ cygwin*) lt_cv_file_magic_cmd='func_win32_libid' ;; -mingw* | pw32*) +mingw* | windows* | pw32*) # Base MSYS/MinGW do not provide the 'file' command needed by # func_win32_libid shell function, so use a weaker test based on 'objdump', # unless we find 'file', for example because we are cross-compiling. @@ -3491,7 +3548,7 @@ mingw* | pw32*) lt_cv_file_magic_cmd='func_win32_libid' else # Keep this pattern in sync with the one in func_win32_libid. - lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' + lt_cv_deplibs_check_method='file_magic file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64|pe-aarch64)' lt_cv_file_magic_cmd='$OBJDUMP -f' fi ;; @@ -3506,14 +3563,14 @@ darwin* | rhapsody*) lt_cv_deplibs_check_method=pass_all ;; -freebsd* | dragonfly*) +freebsd* | dragonfly* | midnightbsd*) if echo __ELF__ | $CC -E - | $GREP __ELF__ > /dev/null; then case $host_cpu in i*86 ) # Not sure whether the presence of OpenBSD here was a mistake. # Let's accept both of them until this is cleared up. lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library' - lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_cmd=$FILECMD lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*` ;; esac @@ -3527,7 +3584,7 @@ haiku*) ;; hpux10.20* | hpux11*) - lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_cmd=$FILECMD case $host_cpu in ia64*) lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64' @@ -3574,7 +3631,7 @@ netbsd*) newos6*) lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)' - lt_cv_file_magic_cmd=/usr/bin/file + lt_cv_file_magic_cmd=$FILECMD lt_cv_file_magic_test_file=/usr/lib/libnls.so ;; @@ -3582,7 +3639,7 @@ newos6*) lt_cv_deplibs_check_method=pass_all ;; -openbsd* | bitrig*) +openbsd*) if test -z "`echo __ELF__ | $CC -E - | $GREP __ELF__`"; then lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$' else @@ -3646,7 +3703,7 @@ file_magic_glob= want_nocaseglob=no if test "$build" = "$host"; then case $host_os in - mingw* | pw32*) + mingw* | windows* | pw32*) if ( shopt | grep nocaseglob ) >/dev/null 2>&1; then want_nocaseglob=yes else @@ -3698,16 +3755,16 @@ else # Tru64's nm complains that /dev/null is an invalid object file # MSYS converts /dev/null to NUL, MinGW nm treats NUL as empty case $build_os in - mingw*) lt_bad_file=conftest.nm/nofile ;; + mingw* | windows*) lt_bad_file=conftest.nm/nofile ;; *) lt_bad_file=/dev/null ;; esac - case `"$tmp_nm" -B $lt_bad_file 2>&1 | sed '1q'` in + case `"$tmp_nm" -B $lt_bad_file 2>&1 | $SED '1q'` in *$lt_bad_file* | *'Invalid file or object type'*) lt_cv_path_NM="$tmp_nm -B" break 2 ;; *) - case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in + case `"$tmp_nm" -p /dev/null 2>&1 | $SED '1q'` in */dev/null*) lt_cv_path_NM="$tmp_nm -p" break 2 @@ -3733,7 +3790,7 @@ else # Let the user override the test. else AC_CHECK_TOOLS(DUMPBIN, [dumpbin "link -dump"], :) - case `$DUMPBIN -symbols -headers /dev/null 2>&1 | sed '1q'` in + case `$DUMPBIN -symbols -headers /dev/null 2>&1 | $SED '1q'` in *COFF*) DUMPBIN="$DUMPBIN -symbols -headers" ;; @@ -3789,7 +3846,7 @@ lt_cv_sharedlib_from_linklib_cmd, [lt_cv_sharedlib_from_linklib_cmd='unknown' case $host_os in -cygwin* | mingw* | pw32* | cegcc*) +cygwin* | mingw* | windows* | pw32* | cegcc*) # two different shell functions defined in ltmain.sh; # decide which one to use based on capabilities of $DLLTOOL case `$DLLTOOL --help 2>&1` in @@ -3821,16 +3878,16 @@ _LT_DECL([], [sharedlib_from_linklib_cmd], [1], m4_defun([_LT_PATH_MANIFEST_TOOL], [AC_CHECK_TOOL(MANIFEST_TOOL, mt, :) test -z "$MANIFEST_TOOL" && MANIFEST_TOOL=mt -AC_CACHE_CHECK([if $MANIFEST_TOOL is a manifest tool], [lt_cv_path_mainfest_tool], - [lt_cv_path_mainfest_tool=no +AC_CACHE_CHECK([if $MANIFEST_TOOL is a manifest tool], [lt_cv_path_manifest_tool], + [lt_cv_path_manifest_tool=no echo "$as_me:$LINENO: $MANIFEST_TOOL '-?'" >&AS_MESSAGE_LOG_FD $MANIFEST_TOOL '-?' 2>conftest.err > conftest.out cat conftest.err >&AS_MESSAGE_LOG_FD if $GREP 'Manifest Tool' conftest.out > /dev/null; then - lt_cv_path_mainfest_tool=yes + lt_cv_path_manifest_tool=yes fi rm -f conftest*]) -if test yes != "$lt_cv_path_mainfest_tool"; then +if test yes != "$lt_cv_path_manifest_tool"; then MANIFEST_TOOL=: fi _LT_DECL([], [MANIFEST_TOOL], [1], [Manifest tool])dnl @@ -3859,7 +3916,7 @@ AC_DEFUN([LT_LIB_M], [AC_REQUIRE([AC_CANONICAL_HOST])dnl LIBM= case $host in -*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-pw32* | *-*-darwin*) +*-*-beos* | *-*-cegcc* | *-*-cygwin* | *-*-haiku* | *-*-mingw* | *-*-pw32* | *-*-darwin*) # These system don't have libm, or don't need it ;; *-ncr-sysv4.3*) @@ -3934,7 +3991,7 @@ case $host_os in aix*) symcode='[[BCDT]]' ;; -cygwin* | mingw* | pw32* | cegcc*) +cygwin* | mingw* | windows* | pw32* | cegcc*) symcode='[[ABCDGISTW]]' ;; hpux*) @@ -3949,7 +4006,7 @@ osf*) symcode='[[BCDEGQRST]]' ;; solaris*) - symcode='[[BDRT]]' + symcode='[[BCDRT]]' ;; sco3.2v5*) symcode='[[DT]]' @@ -3973,7 +4030,7 @@ esac if test "$lt_cv_nm_interface" = "MS dumpbin"; then # Gets list of data symbols to import. - lt_cv_sys_global_symbol_to_import="sed -n -e 's/^I .* \(.*\)$/\1/p'" + lt_cv_sys_global_symbol_to_import="$SED -n -e 's/^I .* \(.*\)$/\1/p'" # Adjust the below global symbol transforms to fixup imported variables. lt_cdecl_hook=" -e 's/^I .* \(.*\)$/extern __declspec(dllimport) char \1;/p'" lt_c_name_hook=" -e 's/^I .* \(.*\)$/ {\"\1\", (void *) 0},/p'" @@ -3991,20 +4048,20 @@ fi # Transform an extracted symbol line into a proper C declaration. # Some systems (esp. on ia64) link data and code symbols differently, # so use this general approach. -lt_cv_sys_global_symbol_to_cdecl="sed -n"\ +lt_cv_sys_global_symbol_to_cdecl="$SED -n"\ $lt_cdecl_hook\ " -e 's/^T .* \(.*\)$/extern int \1();/p'"\ " -e 's/^$symcode$symcode* .* \(.*\)$/extern char \1;/p'" # Transform an extracted symbol line into symbol name and symbol address -lt_cv_sys_global_symbol_to_c_name_address="sed -n"\ +lt_cv_sys_global_symbol_to_c_name_address="$SED -n"\ $lt_c_name_hook\ " -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ " -e 's/^$symcode$symcode* .* \(.*\)$/ {\"\1\", (void *) \&\1},/p'" # Transform an extracted symbol line into symbol name with lib prefix and # symbol address. -lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="sed -n"\ +lt_cv_sys_global_symbol_to_c_name_address_lib_prefix="$SED -n"\ $lt_c_name_lib_hook\ " -e 's/^: \(.*\) .*$/ {\"\1\", (void *) 0},/p'"\ " -e 's/^$symcode$symcode* .* \(lib.*\)$/ {\"\1\", (void *) \&\1},/p'"\ @@ -4013,7 +4070,7 @@ $lt_c_name_lib_hook\ # Handle CRLF in mingw tool chain opt_cr= case $build_os in -mingw*) +mingw* | windows*) opt_cr=`$ECHO 'x\{0,1\}' | tr x '\015'` # option cr in regexp ;; esac @@ -4028,7 +4085,7 @@ for ac_symprfx in "" "_"; do if test "$lt_cv_nm_interface" = "MS dumpbin"; then # Fake it for dumpbin and say T for any non-static function, # D for any global variable and I for any imported variable. - # Also find C++ and __fastcall symbols from MSVC++, + # Also find C++ and __fastcall symbols from MSVC++ or ICC, # which start with @ or ?. lt_cv_sys_global_symbol_pipe="$AWK ['"\ " {last_section=section; section=\$ 3};"\ @@ -4046,9 +4103,9 @@ for ac_symprfx in "" "_"; do " s[1]~prfx {split(s[1],t,\"@\"); print f,t[1],substr(t[1],length(prfx))}"\ " ' prfx=^$ac_symprfx]" else - lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[ ]]\($symcode$symcode*\)[[ ]][[ ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" + lt_cv_sys_global_symbol_pipe="$SED -n -e 's/^.*[[ ]]\($symcode$symcode*\)[[ ]][[ ]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'" fi - lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | sed '/ __gnu_lto/d'" + lt_cv_sys_global_symbol_pipe="$lt_cv_sys_global_symbol_pipe | $SED '/ __gnu_lto/d'" # Check to see that the pipe works correctly. pipe_works=no @@ -4064,7 +4121,7 @@ void nm_test_func(void){} #ifdef __cplusplus } #endif -int main(){nm_test_var='a';nm_test_func();return(0);} +int main(void){nm_test_var='a';nm_test_func();return(0);} _LT_EOF if AC_TRY_EVAL(ac_compile); then @@ -4240,7 +4297,7 @@ m4_if([$1], [CXX], [ beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*) # PIC is the default for these OSes. ;; - mingw* | cygwin* | os2* | pw32* | cegcc*) + mingw* | windows* | cygwin* | os2* | pw32* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). # Although the cygwin gcc ignores -fPIC, still need this for old-style @@ -4316,7 +4373,7 @@ m4_if([$1], [CXX], [ ;; esac ;; - mingw* | cygwin* | os2* | pw32* | cegcc*) + mingw* | windows* | cygwin* | os2* | pw32* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). m4_if([$1], [GCJ], [], @@ -4335,7 +4392,7 @@ m4_if([$1], [CXX], [ ;; esac ;; - freebsd* | dragonfly*) + freebsd* | dragonfly* | midnightbsd*) # FreeBSD uses GNU C++ ;; hpux9* | hpux10* | hpux11*) @@ -4418,7 +4475,7 @@ m4_if([$1], [CXX], [ _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' ;; *) - case `$CC -V 2>&1 | sed 5q` in + case `$CC -V 2>&1 | $SED 5q` in *Sun\ C*) # Sun C++ 5.9 _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' @@ -4564,7 +4621,7 @@ m4_if([$1], [CXX], [ # PIC is the default for these OSes. ;; - mingw* | cygwin* | pw32* | os2* | cegcc*) + mingw* | windows* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). # Although the cygwin gcc ignores -fPIC, still need this for old-style @@ -4668,7 +4725,7 @@ m4_if([$1], [CXX], [ esac ;; - mingw* | cygwin* | pw32* | os2* | cegcc*) + mingw* | windows* | cygwin* | pw32* | os2* | cegcc*) # This hack is so that the source file can tell whether it is being # built for inclusion in a dll (and should export symbols for example). m4_if([$1], [GCJ], [], @@ -4710,6 +4767,12 @@ m4_if([$1], [CXX], [ _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' ;; + *flang* | ftn) + # Flang compiler. + _LT_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,' + _LT_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC' + _LT_TAGVAR(lt_prog_compiler_static, $1)='-static' + ;; # icc used to be incompatible with GCC. # ICC 10 doesn't accept -KPIC any more. icc* | ifort*) @@ -4754,7 +4817,7 @@ m4_if([$1], [CXX], [ _LT_TAGVAR(lt_prog_compiler_static, $1)='-qstaticlink' ;; *) - case `$CC -V 2>&1 | sed 5q` in + case `$CC -V 2>&1 | $SED 5q` in *Sun\ Ceres\ Fortran* | *Sun*Fortran*\ [[1-7]].* | *Sun*Fortran*\ 8.[[0-3]]*) # Sun Fortran 8.3 passes all unrecognized flags to the linker _LT_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC' @@ -4937,15 +5000,15 @@ m4_if([$1], [CXX], [ if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' else - _LT_TAGVAR(export_symbols_cmds, $1)='`func_echo_all $NM | $SED -e '\''s/B\([[^B]]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && ([substr](\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + _LT_TAGVAR(export_symbols_cmds, $1)='`func_echo_all $NM | $SED -e '\''s/B\([[^B]]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "L") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && ([substr](\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' fi ;; pw32*) _LT_TAGVAR(export_symbols_cmds, $1)=$ltdll_cmds ;; - cygwin* | mingw* | cegcc*) + cygwin* | mingw* | windows* | cegcc*) case $cc_basename in - cl*) + cl* | icl*) _LT_TAGVAR(exclude_expsyms, $1)='_NULL_IMPORT_DESCRIPTOR|_IMPORT_DESCRIPTOR_.*' ;; *) @@ -5001,19 +5064,19 @@ dnl Note also adjust exclude_expsyms for C++ above. extract_expsyms_cmds= case $host_os in - cygwin* | mingw* | pw32* | cegcc*) - # FIXME: the MSVC++ port hasn't been tested in a loooong time + cygwin* | mingw* | windows* | pw32* | cegcc*) + # FIXME: the MSVC++ and ICC port hasn't been tested in a loooong time # When not using gcc, we currently assume that we are using - # Microsoft Visual C++. + # Microsoft Visual C++ or Intel C++ Compiler. if test yes != "$GCC"; then with_gnu_ld=no fi ;; interix*) - # we just hope/assume this is gcc and not c89 (= MSVC++) + # we just hope/assume this is gcc and not c89 (= MSVC++ or ICC) with_gnu_ld=yes ;; - openbsd* | bitrig*) + openbsd*) with_gnu_ld=no ;; esac @@ -5062,7 +5125,7 @@ dnl Note also adjust exclude_expsyms for C++ above. _LT_TAGVAR(whole_archive_flag_spec, $1)= fi supports_anon_versioning=no - case `$LD -v | $SED -e 's/([^)]\+)\s\+//' 2>&1` in + case `$LD -v | $SED -e 's/([[^)]]\+)\s\+//' 2>&1` in *GNU\ gold*) supports_anon_versioning=yes ;; *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11 *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ... @@ -5116,7 +5179,7 @@ _LT_EOF fi ;; - cygwin* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | windows* | pw32* | cegcc*) # _LT_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless, # as there is no search path for DLLs. _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir' @@ -5172,8 +5235,9 @@ _LT_EOF cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ emximp -o $lib $output_objdir/$libname.def' - _LT_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='@' ;; interix[[3-9]]*) @@ -5188,7 +5252,7 @@ _LT_EOF # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link # time. Moving up from 0x10000000 also allows more sbrk(2) space. _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' - _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$SED "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' ;; gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) @@ -5231,7 +5295,7 @@ _LT_EOF _LT_TAGVAR(compiler_needs_object, $1)=yes ;; esac - case `$CC -V 2>&1 | sed 5q` in + case `$CC -V 2>&1 | $SED 5q` in *Sun\ C*) # Sun C 5.9 _LT_TAGVAR(whole_archive_flag_spec, $1)='$wl--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; func_echo_all \"$new_convenience\"` $wl--no-whole-archive' _LT_TAGVAR(compiler_needs_object, $1)=yes @@ -5243,7 +5307,7 @@ _LT_EOF if test yes = "$supports_anon_versioning"; then _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ - cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' fi @@ -5259,7 +5323,7 @@ _LT_EOF _LT_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $linker_flags -soname $soname -o $lib' if test yes = "$supports_anon_versioning"; then _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ - cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $LD -shared $libobjs $deplibs $linker_flags -soname $soname -version-script $output_objdir/$libname.ver -o $lib' fi @@ -5391,7 +5455,7 @@ _LT_EOF if $NM -V 2>&1 | $GREP 'GNU' > /dev/null; then _LT_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W")) && ([substr](\$ 3,1,1) != ".")) { if (\$ 2 == "W") { print \$ 3 " weak" } else { print \$ 3 } } }'\'' | sort -u > $export_symbols' else - _LT_TAGVAR(export_symbols_cmds, $1)='`func_echo_all $NM | $SED -e '\''s/B\([[^B]]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && ([substr](\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' + _LT_TAGVAR(export_symbols_cmds, $1)='`func_echo_all $NM | $SED -e '\''s/B\([[^B]]*\)$/P\1/'\''` -PCpgl $libobjs $convenience | awk '\''{ if (((\$ 2 == "T") || (\$ 2 == "D") || (\$ 2 == "B") || (\$ 2 == "L") || (\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) && ([substr](\$ 1,1,1) != ".")) { if ((\$ 2 == "W") || (\$ 2 == "V") || (\$ 2 == "Z")) { print \$ 1 " weak" } else { print \$ 1 } } }'\'' | sort -u > $export_symbols' fi aix_use_runtimelinking=no @@ -5572,14 +5636,14 @@ _LT_EOF _LT_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic ;; - cygwin* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | windows* | pw32* | cegcc*) # When not using gcc, we currently assume that we are using - # Microsoft Visual C++. + # Microsoft Visual C++ or Intel C++ Compiler. # hardcode_libdir_flag_spec is actually meaningless, as there is # no search path for DLLs. case $cc_basename in - cl*) - # Native MSVC + cl* | icl*) + # Native MSVC or ICC _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' _LT_TAGVAR(allow_undefined_flag, $1)=unsupported _LT_TAGVAR(always_export_symbols, $1)=yes @@ -5589,14 +5653,14 @@ _LT_EOF # Tell ltmain to make .dll files, not .so files. shrext_cmds=.dll # FIXME: Setting linknames here is a bad hack. - _LT_TAGVAR(archive_cmds, $1)='$CC -o $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' + _LT_TAGVAR(archive_cmds, $1)='$CC -Fe $output_objdir/$soname $libobjs $compiler_flags $deplibs -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~linknames=' _LT_TAGVAR(archive_expsym_cmds, $1)='if _LT_DLL_DEF_P([$export_symbols]); then cp "$export_symbols" "$output_objdir/$soname.def"; echo "$tool_output_objdir$soname.def" > "$output_objdir/$soname.exp"; else $SED -e '\''s/^/-link -EXPORT:/'\'' < $export_symbols > $output_objdir/$soname.exp; fi~ - $CC -o $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ + $CC -Fe $tool_output_objdir$soname $libobjs $compiler_flags $deplibs "@$tool_output_objdir$soname.exp" -Wl,-DLL,-IMPLIB:"$tool_output_objdir$libname.dll.lib"~ linknames=' # The linker will not automatically build a static lib if we build a DLL. # _LT_TAGVAR(old_archive_from_new_cmds, $1)='true' @@ -5620,7 +5684,7 @@ _LT_EOF fi' ;; *) - # Assume MSVC wrapper + # Assume MSVC and ICC wrapper _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' _LT_TAGVAR(allow_undefined_flag, $1)=unsupported # Tell ltmain to make .lib files, not .a files. @@ -5668,7 +5732,7 @@ _LT_EOF ;; # FreeBSD 3 and greater uses gcc -shared to do shared libraries. - freebsd* | dragonfly*) + freebsd* | dragonfly* | midnightbsd*) _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags' _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir' _LT_TAGVAR(hardcode_direct, $1)=yes @@ -5834,7 +5898,7 @@ _LT_EOF *nto* | *qnx*) ;; - openbsd* | bitrig*) + openbsd*) if test -f /usr/libexec/ld.so; then _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no @@ -5877,8 +5941,9 @@ _LT_EOF cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ emximp -o $lib $output_objdir/$libname.def' - _LT_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='@' ;; osf3*) @@ -6170,7 +6235,7 @@ _LT_TAGDECL([], [hardcode_direct], [0], _LT_TAGDECL([], [hardcode_direct_absolute], [0], [Set to "yes" if using DIR/libNAME$shared_ext during linking hardcodes DIR into the resulting binary and the resulting library dependency is - "absolute", i.e impossible to change by setting $shlibpath_var if the + "absolute", i.e. impossible to change by setting $shlibpath_var if the library is relocated]) _LT_TAGDECL([], [hardcode_minus_L], [0], [Set to "yes" if using the -LDIR flag during linking hardcodes DIR @@ -6228,7 +6293,7 @@ _LT_TAGVAR(objext, $1)=$objext lt_simple_compile_test_code="int some_variable = 0;" # Code to be used in simple link tests -lt_simple_link_test_code='int main(){return(0);}' +lt_simple_link_test_code='int main(void){return(0);}' _LT_TAG_COMPILER # Save the default compiler, since it gets overwritten when the other @@ -6417,8 +6482,7 @@ if test yes != "$_lt_caught_CXX_error"; then wlarc='$wl' # ancient GNU ld didn't support --whole-archive et. al. - if eval "`$CC -print-prog-name=ld` --help 2>&1" | - $GREP 'no-whole-archive' > /dev/null; then + if $LD --help 2>&1 | $GREP 'no-whole-archive' > /dev/null; then _LT_TAGVAR(whole_archive_flag_spec, $1)=$wlarc'--whole-archive$convenience '$wlarc'--no-whole-archive' else _LT_TAGVAR(whole_archive_flag_spec, $1)= @@ -6438,7 +6502,7 @@ if test yes != "$_lt_caught_CXX_error"; then # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "[[-]]L"' else GXX=no @@ -6647,10 +6711,10 @@ if test yes != "$_lt_caught_CXX_error"; then esac ;; - cygwin* | mingw* | pw32* | cegcc*) + cygwin* | mingw* | windows* | pw32* | cegcc*) case $GXX,$cc_basename in - ,cl* | no,cl*) - # Native MSVC + ,cl* | no,cl* | ,icl* | no,icl*) + # Native MSVC or ICC # hardcode_libdir_flag_spec is actually meaningless, as there is # no search path for DLLs. _LT_TAGVAR(hardcode_libdir_flag_spec, $1)=' ' @@ -6746,8 +6810,9 @@ if test yes != "$_lt_caught_CXX_error"; then cat $export_symbols | $prefix_cmds >> $output_objdir/$libname.def~ $CC -Zdll -Zcrtdll -o $output_objdir/$soname $libobjs $deplibs $compiler_flags $output_objdir/$libname.def~ emximp -o $lib $output_objdir/$libname.def' - _LT_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' + _LT_TAGVAR(old_archive_from_new_cmds, $1)='emximp -o $output_objdir/${libname}_dll.a $output_objdir/$libname.def' _LT_TAGVAR(enable_shared_with_static_runtimes, $1)=yes + _LT_TAGVAR(file_list_spec, $1)='@' ;; dgux*) @@ -6778,7 +6843,7 @@ if test yes != "$_lt_caught_CXX_error"; then _LT_TAGVAR(archive_cmds_need_lc, $1)=no ;; - freebsd* | dragonfly*) + freebsd* | dragonfly* | midnightbsd*) # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF # conventions _LT_TAGVAR(ld_shlibs, $1)=yes @@ -6813,7 +6878,7 @@ if test yes != "$_lt_caught_CXX_error"; then # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. - output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $EGREP "[[-]]L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then @@ -6878,7 +6943,7 @@ if test yes != "$_lt_caught_CXX_error"; then # explicitly linking system object files so we need to strip them # from the output so that they don't get included in the library # dependencies. - output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "\-L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' + output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | $GREP "[[-]]L"`; list= ; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; func_echo_all "$list"' ;; *) if test yes = "$GXX"; then @@ -6915,7 +6980,7 @@ if test yes != "$_lt_caught_CXX_error"; then # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link # time. Moving up from 0x10000000 also allows more sbrk(2) space. _LT_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' - _LT_TAGVAR(archive_expsym_cmds, $1)='sed "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' + _LT_TAGVAR(archive_expsym_cmds, $1)='$SED "s|^|_|" $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags $wl-h,$soname $wl--retain-symbols-file,$output_objdir/$soname.expsym $wl--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib' ;; irix5* | irix6*) case $cc_basename in @@ -7055,13 +7120,13 @@ if test yes != "$_lt_caught_CXX_error"; then _LT_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname -o $lib' if test yes = "$supports_anon_versioning"; then _LT_TAGVAR(archive_expsym_cmds, $1)='echo "{ global:" > $output_objdir/$libname.ver~ - cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ + cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~ echo "local: *; };" >> $output_objdir/$libname.ver~ $CC -qmkshrobj $libobjs $deplibs $compiler_flags $wl-soname $wl$soname $wl-version-script $wl$output_objdir/$libname.ver -o $lib' fi ;; *) - case `$CC -V 2>&1 | sed 5q` in + case `$CC -V 2>&1 | $SED 5q` in *Sun\ C*) # Sun C++ 5.9 _LT_TAGVAR(no_undefined_flag, $1)=' -zdefs' @@ -7126,7 +7191,7 @@ if test yes != "$_lt_caught_CXX_error"; then _LT_TAGVAR(ld_shlibs, $1)=yes ;; - openbsd* | bitrig*) + openbsd*) if test -f /usr/libexec/ld.so; then _LT_TAGVAR(hardcode_direct, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=no @@ -7217,7 +7282,7 @@ if test yes != "$_lt_caught_CXX_error"; then # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "[[-]]L"' else # FIXME: insert proper C++ library support @@ -7301,7 +7366,7 @@ if test yes != "$_lt_caught_CXX_error"; then # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "[[-]]L"' else # g++ 2.7 appears to require '-G' NOT '-shared' on this # platform. @@ -7312,7 +7377,7 @@ if test yes != "$_lt_caught_CXX_error"; then # Commands to make compiler produce verbose output that lists # what "hidden" libraries, object files and flags are used when # linking a shared library. - output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "\-L"' + output_verbose_link_cmd='$CC -G $CFLAGS -v conftest.$objext 2>&1 | $GREP -v "^Configured with:" | $GREP "[[-]]L"' fi _LT_TAGVAR(hardcode_libdir_flag_spec, $1)='$wl-R $wl$libdir' @@ -7550,10 +7615,11 @@ if AC_TRY_EVAL(ac_compile); then case $prev$p in -L* | -R* | -l*) - # Some compilers place space between "-{L,R}" and the path. + # Some compilers place space between "-{L,R,l}" and the path. # Remove the space. - if test x-L = "$p" || - test x-R = "$p"; then + if test x-L = x"$p" || + test x-R = x"$p" || + test x-l = x"$p"; then prev=$p continue fi @@ -8207,6 +8273,14 @@ _LT_DECL([], [DLLTOOL], [1], [DLL creation program]) AC_SUBST([DLLTOOL]) ]) +# _LT_DECL_FILECMD +# ---------------- +# Check for a file(cmd) program that can be used to detect file type and magic +m4_defun([_LT_DECL_FILECMD], +[AC_CHECK_PROG([FILECMD], [file], [file], [:]) +_LT_DECL([], [FILECMD], [1], [A file(cmd) program that detects file types]) +])# _LD_DECL_FILECMD + # _LT_DECL_SED # ------------ # Check for a fully-functional sed program, that truncates @@ -8219,73 +8293,6 @@ _LT_DECL([], [SED], [1], [A sed program that does not truncate output]) _LT_DECL([], [Xsed], ["\$SED -e 1s/^X//"], [Sed that helps us avoid accidentally triggering echo(1) options like -n]) ])# _LT_DECL_SED - -m4_ifndef([AC_PROG_SED], [ -############################################################ -# NOTE: This macro has been submitted for inclusion into # -# GNU Autoconf as AC_PROG_SED. When it is available in # -# a released version of Autoconf we should remove this # -# macro and use it instead. # -############################################################ - -m4_defun([AC_PROG_SED], -[AC_MSG_CHECKING([for a sed that does not truncate output]) -AC_CACHE_VAL(lt_cv_path_SED, -[# Loop through the user's path and test for sed and gsed. -# Then use that list of sed's as ones to test for truncation. -as_save_IFS=$IFS; IFS=$PATH_SEPARATOR -for as_dir in $PATH -do - IFS=$as_save_IFS - test -z "$as_dir" && as_dir=. - for lt_ac_prog in sed gsed; do - for ac_exec_ext in '' $ac_executable_extensions; do - if $as_executable_p "$as_dir/$lt_ac_prog$ac_exec_ext"; then - lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext" - fi - done - done -done -IFS=$as_save_IFS -lt_ac_max=0 -lt_ac_count=0 -# Add /usr/xpg4/bin/sed as it is typically found on Solaris -# along with /bin/sed that truncates output. -for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do - test ! -f "$lt_ac_sed" && continue - cat /dev/null > conftest.in - lt_ac_count=0 - echo $ECHO_N "0123456789$ECHO_C" >conftest.in - # Check for GNU sed and select it if it is found. - if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then - lt_cv_path_SED=$lt_ac_sed - break - fi - while true; do - cat conftest.in conftest.in >conftest.tmp - mv conftest.tmp conftest.in - cp conftest.in conftest.nl - echo >>conftest.nl - $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break - cmp -s conftest.out conftest.nl || break - # 10000 chars as input seems more than enough - test 10 -lt "$lt_ac_count" && break - lt_ac_count=`expr $lt_ac_count + 1` - if test "$lt_ac_count" -gt "$lt_ac_max"; then - lt_ac_max=$lt_ac_count - lt_cv_path_SED=$lt_ac_sed - fi - done -done -]) -SED=$lt_cv_path_SED -AC_SUBST([SED]) -AC_MSG_RESULT([$SED]) -])#AC_PROG_SED -])#m4_ifndef - -# Old name: -AU_ALIAS([LT_AC_PROG_SED], [AC_PROG_SED]) dnl aclocal-1.4 backwards compatibility: dnl AC_DEFUN([LT_AC_PROG_SED], []) @@ -8332,7 +8339,7 @@ AC_CACHE_VAL(lt_cv_to_host_file_cmd, [case $host in *-*-mingw* ) case $build in - *-*-mingw* ) # actually msys + *-*-mingw* | *-*-windows* ) # actually msys lt_cv_to_host_file_cmd=func_convert_file_msys_to_w32 ;; *-*-cygwin* ) @@ -8345,7 +8352,7 @@ AC_CACHE_VAL(lt_cv_to_host_file_cmd, ;; *-*-cygwin* ) case $build in - *-*-mingw* ) # actually msys + *-*-mingw* | *-*-windows* ) # actually msys lt_cv_to_host_file_cmd=func_convert_file_msys_to_cygwin ;; *-*-cygwin* ) @@ -8371,9 +8378,9 @@ AC_CACHE_VAL(lt_cv_to_tool_file_cmd, [#assume ordinary cross tools, or native build. lt_cv_to_tool_file_cmd=func_convert_file_noop case $host in - *-*-mingw* ) + *-*-mingw* | *-*-windows* ) case $build in - *-*-mingw* ) # actually msys + *-*-mingw* | *-*-windows* ) # actually msys lt_cv_to_tool_file_cmd=func_convert_file_msys_to_w32 ;; esac diff --git a/3rdparty/expat/m4/ltoptions.m4 b/3rdparty/expat/m4/ltoptions.m4 index 94b08297666..25caa890298 100644 --- a/3rdparty/expat/m4/ltoptions.m4 +++ b/3rdparty/expat/m4/ltoptions.m4 @@ -1,14 +1,14 @@ # Helper functions for option handling. -*- Autoconf -*- # -# Copyright (C) 2004-2005, 2007-2009, 2011-2015 Free Software -# Foundation, Inc. +# Copyright (C) 2004-2005, 2007-2009, 2011-2019, 2021-2024 Free +# Software Foundation, Inc. # Written by Gary V. Vaughan, 2004 # # This file is free software; the Free Software Foundation gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. -# serial 8 ltoptions.m4 +# serial 10 ltoptions.m4 # This is to help aclocal find these macros, as it can't see m4_define. AC_DEFUN([LTOPTIONS_VERSION], [m4_if([1])]) @@ -128,7 +128,7 @@ LT_OPTION_DEFINE([LT_INIT], [win32-dll], [enable_win32_dll=yes case $host in -*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-cegcc*) +*-*-cygwin* | *-*-mingw* | *-*-windows* | *-*-pw32* | *-*-cegcc*) AC_CHECK_TOOL(AS, as, false) AC_CHECK_TOOL(DLLTOOL, dlltool, false) AC_CHECK_TOOL(OBJDUMP, objdump, false) @@ -323,29 +323,39 @@ dnl AC_DEFUN([AM_DISABLE_FAST_INSTALL], []) # _LT_WITH_AIX_SONAME([DEFAULT]) # ---------------------------------- -# implement the --with-aix-soname flag, and support the `aix-soname=aix' -# and `aix-soname=both' and `aix-soname=svr4' LT_INIT options. DEFAULT -# is either `aix', `both' or `svr4'. If omitted, it defaults to `aix'. +# implement the --enable-aix-soname configure option, and support the +# `aix-soname=aix' and `aix-soname=both' and `aix-soname=svr4' LT_INIT options. +# DEFAULT is either `aix', `both', or `svr4'. If omitted, it defaults to `aix'. m4_define([_LT_WITH_AIX_SONAME], [m4_define([_LT_WITH_AIX_SONAME_DEFAULT], [m4_if($1, svr4, svr4, m4_if($1, both, both, aix))])dnl shared_archive_member_spec= case $host,$enable_shared in power*-*-aix[[5-9]]*,yes) AC_MSG_CHECKING([which variant of shared library versioning to provide]) - AC_ARG_WITH([aix-soname], - [AS_HELP_STRING([--with-aix-soname=aix|svr4|both], + AC_ARG_ENABLE([aix-soname], + [AS_HELP_STRING([--enable-aix-soname=aix|svr4|both], [shared library versioning (aka "SONAME") variant to provide on AIX, @<:@default=]_LT_WITH_AIX_SONAME_DEFAULT[@:>@.])], - [case $withval in - aix|svr4|both) - ;; - *) - AC_MSG_ERROR([Unknown argument to --with-aix-soname]) - ;; - esac - lt_cv_with_aix_soname=$with_aix_soname], - [AC_CACHE_VAL([lt_cv_with_aix_soname], - [lt_cv_with_aix_soname=]_LT_WITH_AIX_SONAME_DEFAULT) - with_aix_soname=$lt_cv_with_aix_soname]) + [case $enableval in + aix|svr4|both) + ;; + *) + AC_MSG_ERROR([Unknown argument to --enable-aix-soname]) + ;; + esac + lt_cv_with_aix_soname=$enable_aix_soname], + [_AC_ENABLE_IF([with], [aix-soname], + [case $withval in + aix|svr4|both) + ;; + *) + AC_MSG_ERROR([Unknown argument to --with-aix-soname]) + ;; + esac + lt_cv_with_aix_soname=$with_aix_soname], + [AC_CACHE_VAL([lt_cv_with_aix_soname], + [lt_cv_with_aix_soname=]_LT_WITH_AIX_SONAME_DEFAULT)]) + enable_aix_soname=$lt_cv_with_aix_soname]) + with_aix_soname=$enable_aix_soname AC_MSG_RESULT([$with_aix_soname]) if test aix != "$with_aix_soname"; then # For the AIX way of multilib, we name the shared archive member @@ -376,30 +386,50 @@ LT_OPTION_DEFINE([LT_INIT], [aix-soname=svr4], [_LT_WITH_AIX_SONAME([svr4])]) # _LT_WITH_PIC([MODE]) # -------------------- -# implement the --with-pic flag, and support the 'pic-only' and 'no-pic' +# implement the --enable-pic flag, and support the 'pic-only' and 'no-pic' # LT_INIT options. # MODE is either 'yes' or 'no'. If omitted, it defaults to 'both'. m4_define([_LT_WITH_PIC], -[AC_ARG_WITH([pic], - [AS_HELP_STRING([--with-pic@<:@=PKGS@:>@], +[AC_ARG_ENABLE([pic], + [AS_HELP_STRING([--enable-pic@<:@=PKGS@:>@], [try to use only PIC/non-PIC objects @<:@default=use both@:>@])], [lt_p=${PACKAGE-default} - case $withval in - yes|no) pic_mode=$withval ;; - *) - pic_mode=default - # Look at the argument we got. We use all the common list separators. - lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, - for lt_pkg in $withval; do - IFS=$lt_save_ifs - if test "X$lt_pkg" = "X$lt_p"; then - pic_mode=yes - fi - done - IFS=$lt_save_ifs - ;; - esac], - [pic_mode=m4_default([$1], [default])]) + case $enableval in + yes|no) pic_mode=$enableval ;; + *) + pic_mode=default + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for lt_pkg in $enableval; do + IFS=$lt_save_ifs + if test "X$lt_pkg" = "X$lt_p"; then + pic_mode=yes + fi + done + IFS=$lt_save_ifs + ;; + esac], + [dnl Continue to support --with-pic and --without-pic, for backward + dnl compatibility. + _AC_ENABLE_IF([with], [pic], + [lt_p=${PACKAGE-default} + case $withval in + yes|no) pic_mode=$withval ;; + *) + pic_mode=default + # Look at the argument we got. We use all the common list separators. + lt_save_ifs=$IFS; IFS=$IFS$PATH_SEPARATOR, + for lt_pkg in $withval; do + IFS=$lt_save_ifs + if test "X$lt_pkg" = "X$lt_p"; then + pic_mode=yes + fi + done + IFS=$lt_save_ifs + ;; + esac], + [pic_mode=m4_default([$1], [default])])] + ) _LT_DECL([], [pic_mode], [0], [What type of objects to build])dnl ])# _LT_WITH_PIC diff --git a/3rdparty/expat/m4/ltsugar.m4 b/3rdparty/expat/m4/ltsugar.m4 index 48bc9344a4d..902508bd93a 100644 --- a/3rdparty/expat/m4/ltsugar.m4 +++ b/3rdparty/expat/m4/ltsugar.m4 @@ -1,6 +1,6 @@ # ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- # -# Copyright (C) 2004-2005, 2007-2008, 2011-2015 Free Software +# Copyright (C) 2004-2005, 2007-2008, 2011-2019, 2021-2022 Free Software # Foundation, Inc. # Written by Gary V. Vaughan, 2004 # diff --git a/3rdparty/expat/m4/ltversion.m4 b/3rdparty/expat/m4/ltversion.m4 index fa04b52a3bf..149c9719fa5 100644 --- a/3rdparty/expat/m4/ltversion.m4 +++ b/3rdparty/expat/m4/ltversion.m4 @@ -1,6 +1,7 @@ # ltversion.m4 -- version numbers -*- Autoconf -*- # -# Copyright (C) 2004, 2011-2015 Free Software Foundation, Inc. +# Copyright (C) 2004, 2011-2019, 2021-2024 Free Software Foundation, +# Inc. # Written by Scott James Remnant, 2004 # # This file is free software; the Free Software Foundation gives @@ -9,15 +10,15 @@ # @configure_input@ -# serial 4179 ltversion.m4 +# serial 4392 ltversion.m4 # This file is part of GNU Libtool -m4_define([LT_PACKAGE_VERSION], [2.4.6]) -m4_define([LT_PACKAGE_REVISION], [2.4.6]) +m4_define([LT_PACKAGE_VERSION], [2.5.3]) +m4_define([LT_PACKAGE_REVISION], [2.5.3]) AC_DEFUN([LTVERSION_VERSION], -[macro_version='2.4.6' -macro_revision='2.4.6' +[macro_version='2.5.3' +macro_revision='2.5.3' _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) _LT_DECL(, macro_revision, 0) ]) diff --git a/3rdparty/expat/m4/lt~obsolete.m4 b/3rdparty/expat/m4/lt~obsolete.m4 index c6b26f88f6c..0f7a8759da8 100644 --- a/3rdparty/expat/m4/lt~obsolete.m4 +++ b/3rdparty/expat/m4/lt~obsolete.m4 @@ -1,7 +1,7 @@ # lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- # -# Copyright (C) 2004-2005, 2007, 2009, 2011-2015 Free Software -# Foundation, Inc. +# Copyright (C) 2004-2005, 2007, 2009, 2011-2019, 2021-2022 Free +# Software Foundation, Inc. # Written by Scott James Remnant, 2004. # # This file is free software; the Free Software Foundation gives diff --git a/3rdparty/expat/run.sh.in b/3rdparty/expat/run.sh.in index ff3fb36447c..72f86b6dcc4 100644 --- a/3rdparty/expat/run.sh.in +++ b/3rdparty/expat/run.sh.in @@ -1,10 +1,45 @@ #! /usr/bin/env bash -# Copyright (C) 2017 Expat development team -# Licensed under the MIT license +# __ __ _ +# ___\ \/ /_ __ __ _| |_ +# / _ \\ /| '_ \ / _` | __| +# | __// \| |_) | (_| | |_ +# \___/_/\_\ .__/ \__,_|\__| +# |_| XML parser +# +# Copyright (c) 2017-2022 Sebastian Pipping <sebastian@pipping.org> +# Licensed under the MIT license: +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to permit +# persons to whom the Software is furnished to do so, subject to the +# following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +# USE OR OTHER DEALINGS IN THE SOFTWARE. case "@host@" in *-mingw*) - exec wine "$@" + case "$(uname -o)" in + Cygwin|Msys) + # Windows binary on Windows host + exec "$@" + ;; + *) + # Windows binary on non-Windows host + exec wine "$@" + ;; + esac ;; *) exec "$@" diff --git a/3rdparty/expat/test-driver-wrapper.sh b/3rdparty/expat/test-driver-wrapper.sh index 36a185266c6..305c6f5f606 100755 --- a/3rdparty/expat/test-driver-wrapper.sh +++ b/3rdparty/expat/test-driver-wrapper.sh @@ -6,7 +6,8 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2017 Expat development team +# Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2019 Jeffrey Walton <noloader@gmail.com> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/tests/Makefile.am b/3rdparty/expat/tests/Makefile.am index e19fc1ae8ad..3b1b15302a6 100644 --- a/3rdparty/expat/tests/Makefile.am +++ b/3rdparty/expat/tests/Makefile.am @@ -6,7 +6,10 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2017 Expat development team +# Copyright (c) 2017-2024 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> +# Copyright (c) 2020 Jeffrey Walton <noloader@gmail.com> +# Copyright (c) 2024 Dag-Erling Smørgrav <des@des.dev> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -30,37 +33,67 @@ SUBDIRS = . benchmark -AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(srcdir)/../lib +AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(srcdir)/../lib -DXML_TESTING -noinst_LIBRARIES = libruntests.a - -check_PROGRAMS = runtests runtestspp -TESTS = runtests runtestspp +check_PROGRAMS = runtests runtests_cxx +TESTS = runtests runtests_cxx # To support MinGW and Non-MinGW at the same time: LOG_DRIVER = $(srcdir)/../test-driver-wrapper.sh -libruntests_a_SOURCES = \ +runtests_SOURCES = \ + acc_tests.c \ + alloc_tests.c \ + basic_tests.c \ chardata.c \ - structdata.c \ + common.c \ + dummy.c \ + handlers.c \ memcheck.c \ - minicheck.c + minicheck.c \ + misc_tests.c \ + ns_tests.c \ + nsalloc_tests.c \ + runtests.c \ + structdata.c -runtests_SOURCES = \ - runtests.c +runtests_cxx_SOURCES = \ + acc_tests_cxx.cpp \ + alloc_tests_cxx.cpp \ + basic_tests_cxx.cpp \ + chardata_cxx.cpp \ + common_cxx.cpp \ + dummy_cxx.cpp \ + handlers_cxx.cpp \ + memcheck_cxx.cpp \ + minicheck_cxx.cpp \ + misc_tests_cxx.cpp \ + nsalloc_tests_cxx.cpp \ + ns_tests_cxx.cpp \ + runtests_cxx.cpp \ + structdata_cxx.cpp -runtestspp_SOURCES = \ - runtestspp.cpp +runtests_LDADD = ../lib/libtestpat.la +runtests_cxx_LDADD = ../lib/libtestpat.la -runtests_LDADD = libruntests.a ../lib/libexpat.la -runtestspp_LDADD = libruntests.a ../lib/libexpat.la +runtests_LDFLAGS = @AM_LDFLAGS@ @LIBM@ +runtests_cxx_LDFLAGS = @AM_LDFLAGS@ @LIBM@ EXTRA_DIST = \ + acc_tests.h \ + alloc_tests.h \ + basic_tests.h \ chardata.h \ + common.h \ + dummy.h \ + handlers.h \ + misc_tests.h \ + ns_tests.h \ + nsalloc_tests.h \ structdata.h \ minicheck.h \ memcheck.h \ - README.txt \ + README.md \ udiffer.py \ xmltest.log.expected \ xmltest.sh diff --git a/3rdparty/expat/tests/Makefile.in b/3rdparty/expat/tests/Makefile.in index 8b9b38eadcd..c1afa35c334 100644 --- a/3rdparty/expat/tests/Makefile.in +++ b/3rdparty/expat/tests/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2020 Free Software Foundation, Inc. +# Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -22,7 +22,10 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2017 Expat development team +# Copyright (c) 2017-2024 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> +# Copyright (c) 2020 Jeffrey Walton <noloader@gmail.com> +# Copyright (c) 2024 Dag-Erling Smørgrav <des@des.dev> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -43,7 +46,6 @@ # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE # USE OR OTHER DEALINGS IN THE SOFTWARE. - VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ @@ -118,8 +120,8 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -check_PROGRAMS = runtests$(EXEEXT) runtestspp$(EXEEXT) -TESTS = runtests$(EXEEXT) runtestspp$(EXEEXT) +check_PROGRAMS = runtests$(EXEEXT) runtests_cxx$(EXEEXT) +TESTS = runtests$(EXEEXT) runtests_cxx$(EXEEXT) subdir = tests ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ @@ -133,6 +135,8 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/conftools/ax-append-compile-flags.m4 \ $(top_srcdir)/conftools/ax-append-link-flags.m4 \ $(top_srcdir)/conftools/expatcfg-compiler-supports-visibility.m4 \ + $(top_srcdir)/conftools/ax-cxx-compile-stdcxx.m4 \ + $(top_srcdir)/conftools/ax-cxx-compile-stdcxx-11.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) @@ -141,27 +145,34 @@ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/expat_config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = -LIBRARIES = $(noinst_LIBRARIES) -ARFLAGS = cru -AM_V_AR = $(am__v_AR_@AM_V@) -am__v_AR_ = $(am__v_AR_@AM_DEFAULT_V@) -am__v_AR_0 = @echo " AR " $@; -am__v_AR_1 = -libruntests_a_AR = $(AR) $(ARFLAGS) -libruntests_a_LIBADD = -am_libruntests_a_OBJECTS = chardata.$(OBJEXT) structdata.$(OBJEXT) \ - memcheck.$(OBJEXT) minicheck.$(OBJEXT) -libruntests_a_OBJECTS = $(am_libruntests_a_OBJECTS) -am_runtests_OBJECTS = runtests.$(OBJEXT) +am_runtests_OBJECTS = acc_tests.$(OBJEXT) alloc_tests.$(OBJEXT) \ + basic_tests.$(OBJEXT) chardata.$(OBJEXT) common.$(OBJEXT) \ + dummy.$(OBJEXT) handlers.$(OBJEXT) memcheck.$(OBJEXT) \ + minicheck.$(OBJEXT) misc_tests.$(OBJEXT) ns_tests.$(OBJEXT) \ + nsalloc_tests.$(OBJEXT) runtests.$(OBJEXT) \ + structdata.$(OBJEXT) runtests_OBJECTS = $(am_runtests_OBJECTS) -runtests_DEPENDENCIES = libruntests.a ../lib/libexpat.la +runtests_DEPENDENCIES = ../lib/libtestpat.la AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent am__v_lt_1 = -am_runtestspp_OBJECTS = runtestspp.$(OBJEXT) -runtestspp_OBJECTS = $(am_runtestspp_OBJECTS) -runtestspp_DEPENDENCIES = libruntests.a ../lib/libexpat.la +runtests_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(runtests_LDFLAGS) $(LDFLAGS) -o $@ +am_runtests_cxx_OBJECTS = acc_tests_cxx.$(OBJEXT) \ + alloc_tests_cxx.$(OBJEXT) basic_tests_cxx.$(OBJEXT) \ + chardata_cxx.$(OBJEXT) common_cxx.$(OBJEXT) \ + dummy_cxx.$(OBJEXT) handlers_cxx.$(OBJEXT) \ + memcheck_cxx.$(OBJEXT) minicheck_cxx.$(OBJEXT) \ + misc_tests_cxx.$(OBJEXT) nsalloc_tests_cxx.$(OBJEXT) \ + ns_tests_cxx.$(OBJEXT) runtests_cxx.$(OBJEXT) \ + structdata_cxx.$(OBJEXT) +runtests_cxx_OBJECTS = $(am_runtests_cxx_OBJECTS) +runtests_cxx_DEPENDENCIES = ../lib/libtestpat.la +runtests_cxx_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ + $(CXXFLAGS) $(runtests_cxx_LDFLAGS) $(LDFLAGS) -o $@ AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -177,9 +188,21 @@ am__v_at_1 = DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/conftools/depcomp am__maybe_remake_depfiles = depfiles -am__depfiles_remade = ./$(DEPDIR)/chardata.Po ./$(DEPDIR)/memcheck.Po \ - ./$(DEPDIR)/minicheck.Po ./$(DEPDIR)/runtests.Po \ - ./$(DEPDIR)/runtestspp.Po ./$(DEPDIR)/structdata.Po +am__depfiles_remade = ./$(DEPDIR)/acc_tests.Po \ + ./$(DEPDIR)/acc_tests_cxx.Po ./$(DEPDIR)/alloc_tests.Po \ + ./$(DEPDIR)/alloc_tests_cxx.Po ./$(DEPDIR)/basic_tests.Po \ + ./$(DEPDIR)/basic_tests_cxx.Po ./$(DEPDIR)/chardata.Po \ + ./$(DEPDIR)/chardata_cxx.Po ./$(DEPDIR)/common.Po \ + ./$(DEPDIR)/common_cxx.Po ./$(DEPDIR)/dummy.Po \ + ./$(DEPDIR)/dummy_cxx.Po ./$(DEPDIR)/handlers.Po \ + ./$(DEPDIR)/handlers_cxx.Po ./$(DEPDIR)/memcheck.Po \ + ./$(DEPDIR)/memcheck_cxx.Po ./$(DEPDIR)/minicheck.Po \ + ./$(DEPDIR)/minicheck_cxx.Po ./$(DEPDIR)/misc_tests.Po \ + ./$(DEPDIR)/misc_tests_cxx.Po ./$(DEPDIR)/ns_tests.Po \ + ./$(DEPDIR)/ns_tests_cxx.Po ./$(DEPDIR)/nsalloc_tests.Po \ + ./$(DEPDIR)/nsalloc_tests_cxx.Po ./$(DEPDIR)/runtests.Po \ + ./$(DEPDIR)/runtests_cxx.Po ./$(DEPDIR)/structdata.Po \ + ./$(DEPDIR)/structdata_cxx.Po am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -217,10 +240,8 @@ AM_V_CXXLD = $(am__v_CXXLD_@AM_V@) am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@) am__v_CXXLD_0 = @echo " CXXLD " $@; am__v_CXXLD_1 = -SOURCES = $(libruntests_a_SOURCES) $(runtests_SOURCES) \ - $(runtestspp_SOURCES) -DIST_SOURCES = $(libruntests_a_SOURCES) $(runtests_SOURCES) \ - $(runtestspp_SOURCES) +SOURCES = $(runtests_SOURCES) $(runtests_cxx_SOURCES) +DIST_SOURCES = $(runtests_SOURCES) $(runtests_cxx_SOURCES) RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ ctags-recursive dvi-recursive html-recursive info-recursive \ install-data-recursive install-dvi-recursive \ @@ -259,8 +280,6 @@ am__define_uniq_tagged_files = \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` -ETAGS = etags -CTAGS = ctags am__tty_colors_dummy = \ mgn= red= grn= lgn= blu= brg= std=; \ am__color_tests=no @@ -443,6 +462,7 @@ am__set_TESTS_bases = \ bases='$(TEST_LOGS)'; \ bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \ bases=`echo $$bases` +AM_TESTSUITE_SUMMARY_HEADER = ' for $(PACKAGE_STRING)' RECHECK_LOGS = $(TEST_LOGS) TEST_SUITE_LOG = test-suite.log TEST_EXTENSIONS = @EXEEXT@ .test @@ -466,7 +486,7 @@ TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \ DIST_SUBDIRS = $(SUBDIRS) am__DIST_COMMON = $(srcdir)/Makefile.in \ $(top_srcdir)/conftools/depcomp \ - $(top_srcdir)/conftools/test-driver + $(top_srcdir)/conftools/test-driver README.md DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) am__relativize = \ dir0=`pwd`; \ @@ -496,7 +516,7 @@ am__relativize = \ ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ AM_CFLAGS = @AM_CFLAGS@ -AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(srcdir)/../lib +AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(srcdir)/../lib -DXML_TESTING AM_CXXFLAGS = @AM_CXXFLAGS@ AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ AM_LDFLAGS = @AM_LDFLAGS@ @@ -509,8 +529,10 @@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ -CPP = @CPP@ +CMAKE_SHARED_LIBRARY_PREFIX = @CMAKE_SHARED_LIBRARY_PREFIX@ CPPFLAGS = @CPPFLAGS@ +CSCOPE = @CSCOPE@ +CTAGS = @CTAGS@ CXX = @CXX@ CXXCPP = @CXXCPP@ CXXDEPMODE = @CXXDEPMODE@ @@ -526,10 +548,20 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ +ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ +EXPAT_ATTR_INFO = @EXPAT_ATTR_INFO@ +EXPAT_CHAR_TYPE = @EXPAT_CHAR_TYPE@ +EXPAT_CONTEXT_BYTES = @EXPAT_CONTEXT_BYTES@ +EXPAT_DTD = @EXPAT_DTD@ +EXPAT_LARGE_SIZE = @EXPAT_LARGE_SIZE@ +EXPAT_MIN_SIZE = @EXPAT_MIN_SIZE@ +EXPAT_NS = @EXPAT_NS@ FGREP = @FGREP@ +FILECMD = @FILECMD@ FILEMAP = @FILEMAP@ GREP = @GREP@ +HAVE_CXX11 = @HAVE_CXX11@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -539,6 +571,8 @@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBAGE = @LIBAGE@ LIBCURRENT = @LIBCURRENT@ +LIBDIR_BASENAME = @LIBDIR_BASENAME@ +LIBM = @LIBM@ LIBOBJS = @LIBOBJS@ LIBREVISION = @LIBREVISION@ LIBS = @LIBS@ @@ -547,6 +581,7 @@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ @@ -568,9 +603,12 @@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SIZEOF_VOID_P = @SIZEOF_VOID_P@ +SO_MAJOR = @SO_MAJOR@ +SO_MINOR = @SO_MINOR@ +SO_PATCH = @SO_PATCH@ STRIP = @STRIP@ VERSION = @VERSION@ -_EXPAT_OUTPUT_NAME = @_EXPAT_OUTPUT_NAME@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ @@ -626,30 +664,60 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ SUBDIRS = . benchmark -noinst_LIBRARIES = libruntests.a # To support MinGW and Non-MinGW at the same time: LOG_DRIVER = $(srcdir)/../test-driver-wrapper.sh -libruntests_a_SOURCES = \ +runtests_SOURCES = \ + acc_tests.c \ + alloc_tests.c \ + basic_tests.c \ chardata.c \ - structdata.c \ + common.c \ + dummy.c \ + handlers.c \ memcheck.c \ - minicheck.c - -runtests_SOURCES = \ - runtests.c - -runtestspp_SOURCES = \ - runtestspp.cpp - -runtests_LDADD = libruntests.a ../lib/libexpat.la -runtestspp_LDADD = libruntests.a ../lib/libexpat.la + minicheck.c \ + misc_tests.c \ + ns_tests.c \ + nsalloc_tests.c \ + runtests.c \ + structdata.c + +runtests_cxx_SOURCES = \ + acc_tests_cxx.cpp \ + alloc_tests_cxx.cpp \ + basic_tests_cxx.cpp \ + chardata_cxx.cpp \ + common_cxx.cpp \ + dummy_cxx.cpp \ + handlers_cxx.cpp \ + memcheck_cxx.cpp \ + minicheck_cxx.cpp \ + misc_tests_cxx.cpp \ + nsalloc_tests_cxx.cpp \ + ns_tests_cxx.cpp \ + runtests_cxx.cpp \ + structdata_cxx.cpp + +runtests_LDADD = ../lib/libtestpat.la +runtests_cxx_LDADD = ../lib/libtestpat.la +runtests_LDFLAGS = @AM_LDFLAGS@ @LIBM@ +runtests_cxx_LDFLAGS = @AM_LDFLAGS@ @LIBM@ EXTRA_DIST = \ + acc_tests.h \ + alloc_tests.h \ + basic_tests.h \ chardata.h \ + common.h \ + dummy.h \ + handlers.h \ + misc_tests.h \ + ns_tests.h \ + nsalloc_tests.h \ structdata.h \ minicheck.h \ memcheck.h \ - README.txt \ + README.md \ udiffer.py \ xmltest.log.expected \ xmltest.sh @@ -658,7 +726,7 @@ all: all-recursive .SUFFIXES: .SUFFIXES: .c .cpp .lo .log .o .obj .test .test$(EXEEXT) .trs -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ @@ -682,9 +750,9 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(top_srcdir)/configure: $(am__configure_deps) +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): $(am__aclocal_m4_deps) +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): @@ -697,21 +765,13 @@ clean-checkPROGRAMS: echo " rm -f" $$list; \ rm -f $$list -clean-noinstLIBRARIES: - -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) - -libruntests.a: $(libruntests_a_OBJECTS) $(libruntests_a_DEPENDENCIES) $(EXTRA_libruntests_a_DEPENDENCIES) - $(AM_V_at)-rm -f libruntests.a - $(AM_V_AR)$(libruntests_a_AR) libruntests.a $(libruntests_a_OBJECTS) $(libruntests_a_LIBADD) - $(AM_V_at)$(RANLIB) libruntests.a - runtests$(EXEEXT): $(runtests_OBJECTS) $(runtests_DEPENDENCIES) $(EXTRA_runtests_DEPENDENCIES) @rm -f runtests$(EXEEXT) - $(AM_V_CCLD)$(LINK) $(runtests_OBJECTS) $(runtests_LDADD) $(LIBS) + $(AM_V_CCLD)$(runtests_LINK) $(runtests_OBJECTS) $(runtests_LDADD) $(LIBS) -runtestspp$(EXEEXT): $(runtestspp_OBJECTS) $(runtestspp_DEPENDENCIES) $(EXTRA_runtestspp_DEPENDENCIES) - @rm -f runtestspp$(EXEEXT) - $(AM_V_CXXLD)$(CXXLINK) $(runtestspp_OBJECTS) $(runtestspp_LDADD) $(LIBS) +runtests_cxx$(EXEEXT): $(runtests_cxx_OBJECTS) $(runtests_cxx_DEPENDENCIES) $(EXTRA_runtests_cxx_DEPENDENCIES) + @rm -f runtests_cxx$(EXEEXT) + $(AM_V_CXXLD)$(runtests_cxx_LINK) $(runtests_cxx_OBJECTS) $(runtests_cxx_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -719,12 +779,34 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/acc_tests.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/acc_tests_cxx.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alloc_tests.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alloc_tests_cxx.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/basic_tests.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/basic_tests_cxx.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chardata.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/chardata_cxx.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/common.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/common_cxx.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dummy.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dummy_cxx.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/handlers.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/handlers_cxx.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memcheck.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memcheck_cxx.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/minicheck.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/minicheck_cxx.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc_tests.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc_tests_cxx.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ns_tests.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ns_tests_cxx.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nsalloc_tests.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nsalloc_tests_cxx.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/runtests.Po@am__quote@ # am--include-marker -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/runtestspp.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/runtests_cxx.Po@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/structdata.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/structdata_cxx.Po@am__quote@ # am--include-marker $(am__depfiles_remade): @$(MKDIR_P) $(@D) @@ -986,7 +1068,7 @@ $(TEST_SUITE_LOG): $(TEST_LOGS) test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG); \ fi; \ echo "$${col}$$br$${std}"; \ - echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}"; \ + echo "$${col}Testsuite summary"$(AM_TESTSUITE_SUMMARY_HEADER)"$${std}"; \ echo "$${col}$$br$${std}"; \ create_testsuite_report --maybe-color; \ echo "$$col$$br$$std"; \ @@ -1027,9 +1109,9 @@ runtests.log: runtests$(EXEEXT) --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) -runtestspp.log: runtestspp$(EXEEXT) - @p='runtestspp$(EXEEXT)'; \ - b='runtestspp'; \ +runtests_cxx.log: runtests_cxx$(EXEEXT) + @p='runtests_cxx$(EXEEXT)'; \ + b='runtests_cxx'; \ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ @@ -1048,7 +1130,6 @@ runtestspp.log: runtestspp$(EXEEXT) @am__EXEEXT_TRUE@ --log-file $$b.log --trs-file $$b.trs \ @am__EXEEXT_TRUE@ $(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \ @am__EXEEXT_TRUE@ "$$tst" $(AM_TESTS_FD_REDIRECT) - distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am @@ -1111,7 +1192,7 @@ check-am: all-am $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) $(MAKE) $(AM_MAKEFLAGS) check-TESTS check: check-recursive -all-am: Makefile $(LIBRARIES) +all-am: Makefile installdirs: installdirs-recursive installdirs-am: install: install-recursive @@ -1150,15 +1231,37 @@ maintainer-clean-generic: clean: clean-recursive clean-am: clean-checkPROGRAMS clean-generic clean-libtool \ - clean-noinstLIBRARIES mostlyclean-am + mostlyclean-am distclean: distclean-recursive - -rm -f ./$(DEPDIR)/chardata.Po + -rm -f ./$(DEPDIR)/acc_tests.Po + -rm -f ./$(DEPDIR)/acc_tests_cxx.Po + -rm -f ./$(DEPDIR)/alloc_tests.Po + -rm -f ./$(DEPDIR)/alloc_tests_cxx.Po + -rm -f ./$(DEPDIR)/basic_tests.Po + -rm -f ./$(DEPDIR)/basic_tests_cxx.Po + -rm -f ./$(DEPDIR)/chardata.Po + -rm -f ./$(DEPDIR)/chardata_cxx.Po + -rm -f ./$(DEPDIR)/common.Po + -rm -f ./$(DEPDIR)/common_cxx.Po + -rm -f ./$(DEPDIR)/dummy.Po + -rm -f ./$(DEPDIR)/dummy_cxx.Po + -rm -f ./$(DEPDIR)/handlers.Po + -rm -f ./$(DEPDIR)/handlers_cxx.Po -rm -f ./$(DEPDIR)/memcheck.Po + -rm -f ./$(DEPDIR)/memcheck_cxx.Po -rm -f ./$(DEPDIR)/minicheck.Po + -rm -f ./$(DEPDIR)/minicheck_cxx.Po + -rm -f ./$(DEPDIR)/misc_tests.Po + -rm -f ./$(DEPDIR)/misc_tests_cxx.Po + -rm -f ./$(DEPDIR)/ns_tests.Po + -rm -f ./$(DEPDIR)/ns_tests_cxx.Po + -rm -f ./$(DEPDIR)/nsalloc_tests.Po + -rm -f ./$(DEPDIR)/nsalloc_tests_cxx.Po -rm -f ./$(DEPDIR)/runtests.Po - -rm -f ./$(DEPDIR)/runtestspp.Po + -rm -f ./$(DEPDIR)/runtests_cxx.Po -rm -f ./$(DEPDIR)/structdata.Po + -rm -f ./$(DEPDIR)/structdata_cxx.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ distclean-tags @@ -1204,12 +1307,34 @@ install-ps-am: installcheck-am: maintainer-clean: maintainer-clean-recursive - -rm -f ./$(DEPDIR)/chardata.Po + -rm -f ./$(DEPDIR)/acc_tests.Po + -rm -f ./$(DEPDIR)/acc_tests_cxx.Po + -rm -f ./$(DEPDIR)/alloc_tests.Po + -rm -f ./$(DEPDIR)/alloc_tests_cxx.Po + -rm -f ./$(DEPDIR)/basic_tests.Po + -rm -f ./$(DEPDIR)/basic_tests_cxx.Po + -rm -f ./$(DEPDIR)/chardata.Po + -rm -f ./$(DEPDIR)/chardata_cxx.Po + -rm -f ./$(DEPDIR)/common.Po + -rm -f ./$(DEPDIR)/common_cxx.Po + -rm -f ./$(DEPDIR)/dummy.Po + -rm -f ./$(DEPDIR)/dummy_cxx.Po + -rm -f ./$(DEPDIR)/handlers.Po + -rm -f ./$(DEPDIR)/handlers_cxx.Po -rm -f ./$(DEPDIR)/memcheck.Po + -rm -f ./$(DEPDIR)/memcheck_cxx.Po -rm -f ./$(DEPDIR)/minicheck.Po + -rm -f ./$(DEPDIR)/minicheck_cxx.Po + -rm -f ./$(DEPDIR)/misc_tests.Po + -rm -f ./$(DEPDIR)/misc_tests_cxx.Po + -rm -f ./$(DEPDIR)/ns_tests.Po + -rm -f ./$(DEPDIR)/ns_tests_cxx.Po + -rm -f ./$(DEPDIR)/nsalloc_tests.Po + -rm -f ./$(DEPDIR)/nsalloc_tests_cxx.Po -rm -f ./$(DEPDIR)/runtests.Po - -rm -f ./$(DEPDIR)/runtestspp.Po + -rm -f ./$(DEPDIR)/runtests_cxx.Po -rm -f ./$(DEPDIR)/structdata.Po + -rm -f ./$(DEPDIR)/structdata_cxx.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic @@ -1232,19 +1357,18 @@ uninstall-am: .PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ am--depfiles check check-TESTS check-am clean \ - clean-checkPROGRAMS clean-generic clean-libtool \ - clean-noinstLIBRARIES cscopelist-am ctags ctags-am distclean \ - distclean-compile distclean-generic distclean-libtool \ - distclean-tags distdir dvi dvi-am html html-am info info-am \ - install install-am install-data install-data-am install-dvi \ - install-dvi-am install-exec install-exec-am install-html \ - install-html-am install-info install-info-am install-man \ - install-pdf install-pdf-am install-ps install-ps-am \ - install-strip installcheck installcheck-am installdirs \ - installdirs-am maintainer-clean maintainer-clean-generic \ - mostlyclean mostlyclean-compile mostlyclean-generic \ - mostlyclean-libtool pdf pdf-am ps ps-am recheck tags tags-am \ - uninstall uninstall-am + clean-checkPROGRAMS clean-generic clean-libtool cscopelist-am \ + ctags ctags-am distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs installdirs-am maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + recheck tags tags-am uninstall uninstall-am .PRECIOUS: Makefile diff --git a/3rdparty/expat/tests/README.md b/3rdparty/expat/tests/README.md new file mode 100644 index 00000000000..010ca95e9e2 --- /dev/null +++ b/3rdparty/expat/tests/README.md @@ -0,0 +1,11 @@ +This directory contains the test suite for Expat. The tests provide +general unit testing and regression coverage. The tests are not +expected to be useful examples of Expat usage; see the +[examples](../examples) directory for that. + +The Expat tests use a partial internal implementation of the +[Check](https://libcheck.github.io/check/) unit testing framework for +C. + +Expat must be built and, on some platforms, installed, before the +tests can be run. diff --git a/3rdparty/expat/tests/README.txt b/3rdparty/expat/tests/README.txt deleted file mode 100644 index 30e1d4dabe8..00000000000 --- a/3rdparty/expat/tests/README.txt +++ /dev/null @@ -1,13 +0,0 @@ -This directory contains the (fledgling) test suite for Expat. The -tests provide general unit testing and regression coverage. The tests -are not expected to be useful examples of Expat usage; see the -examples/ directory for that. - -The Expat tests use a partial internal implementation of the "Check" -unit testing framework for C. More information on Check can be found at: - - http://check.sourceforge.net/ - -Expat must be built and, depending on platform, must be installed, before "make check" can be executed. - -This test suite can all change in a later version. diff --git a/3rdparty/expat/tests/acc_tests.c b/3rdparty/expat/tests/acc_tests.c new file mode 100644 index 00000000000..f193aa58a49 --- /dev/null +++ b/3rdparty/expat/tests/acc_tests.c @@ -0,0 +1,455 @@ +/* Tests in the "accounting" test case for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include <math.h> /* NAN, INFINITY */ +#include <stdio.h> +#include <string.h> + +#include "expat_config.h" + +#include "expat.h" +#include "internal.h" +#include "common.h" +#include "minicheck.h" +#include "chardata.h" +#include "handlers.h" +#include "acc_tests.h" + +#if XML_GE == 1 +START_TEST(test_accounting_precision) { + struct AccountingTestCase cases[] = { + {"<e/>", NULL, NULL, 0}, + {"<e></e>", NULL, NULL, 0}, + + /* Attributes */ + {"<e k1=\"v2\" k2=\"v2\"/>", NULL, NULL, 0}, + {"<e k1=\"v2\" k2=\"v2\"></e>", NULL, NULL, 0}, + {"<p:e xmlns:p=\"https://domain.invalid/\" />", NULL, NULL, 0}, + {"<e k=\"&'><"\" />", NULL, NULL, + sizeof(XML_Char) * 5 /* number of predefined entities */}, + {"<e1 xmlns='https://example.org/'>\n" + " <e2 xmlns=''/>\n" + "</e1>", + NULL, NULL, 0}, + + /* Text */ + {"<e>text</e>", NULL, NULL, 0}, + {"<e1><e2>text1<e3/>text2</e2></e1>", NULL, NULL, 0}, + {"<e>&'><"</e>", NULL, NULL, + sizeof(XML_Char) * 5 /* number of predefined entities */}, + {"<e>A)</e>", NULL, NULL, 0}, + + /* Prolog */ + {"<?xml version=\"1.0\"?><root/>", NULL, NULL, 0}, + + /* Whitespace */ + {" <e1> <e2> </e2> </e1> ", NULL, NULL, 0}, + {"<e1 ><e2 /></e1 >", NULL, NULL, 0}, + {"<e1><e2 k = \"v\"/><e3 k = 'v'/></e1>", NULL, NULL, 0}, + + /* Comments */ + {"<!-- Comment --><e><!-- Comment --></e>", NULL, NULL, 0}, + + /* Processing instructions */ + {"<?xml-stylesheet type=\"text/xsl\" href=\"https://domain.invalid/\" media=\"all\"?><e/>", + NULL, NULL, 0}, + {"<?pi0?><?pi1 ?><?pi2 ?><r/><?pi4?>", NULL, NULL, 0}, +# ifdef XML_DTD + {"<?pi0?><?pi1 ?><?pi2 ?><!DOCTYPE r SYSTEM 'first.ent'><r/>", + "<?pi3?><!ENTITY % e1 SYSTEM 'second.ent'><?pi4?>%e1;<?pi5?>", "<?pi6?>", + 0}, +# endif /* XML_DTD */ + + /* CDATA */ + {"<e><![CDATA[one two three]]></e>", NULL, NULL, 0}, + /* The following is the essence of this OSS-Fuzz finding: + https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34302 + https://oss-fuzz.com/testcase-detail/4860575394955264 + */ + {"<!DOCTYPE r [\n" + "<!ENTITY e \"111<![CDATA[2 <= 2]]>333\">\n" + "]>\n" + "<r>&e;</r>\n", + NULL, NULL, sizeof(XML_Char) * strlen("111<![CDATA[2 <= 2]]>333")}, + +# ifdef XML_DTD + /* Conditional sections */ + {"<!DOCTYPE r [\n" + "<!ENTITY % draft 'INCLUDE'>\n" + "<!ENTITY % final 'IGNORE'>\n" + "<!ENTITY % import SYSTEM \"first.ent\">\n" + "%import;\n" + "]>\n" + "<r/>\n", + "<![%draft;[<!--1-->]]>\n" + "<![%final;[<!--22-->]]>", + NULL, sizeof(XML_Char) * (strlen("INCLUDE") + strlen("IGNORE"))}, +# endif /* XML_DTD */ + + /* General entities */ + {"<!DOCTYPE root [\n" + "<!ENTITY nine \"123456789\">\n" + "]>\n" + "<root>&nine;</root>", + NULL, NULL, sizeof(XML_Char) * strlen("123456789")}, + {"<!DOCTYPE root [\n" + "<!ENTITY nine \"123456789\">\n" + "]>\n" + "<root k1=\"&nine;\"/>", + NULL, NULL, sizeof(XML_Char) * strlen("123456789")}, + {"<!DOCTYPE root [\n" + "<!ENTITY nine \"123456789\">\n" + "<!ENTITY nine2 \"&nine;&nine;\">\n" + "]>\n" + "<root>&nine2;&nine2;&nine2;</root>", + NULL, NULL, + sizeof(XML_Char) * 3 /* calls to &nine2; */ * 2 /* calls to &nine; */ + * (strlen("&nine;") + strlen("123456789"))}, + {"<!DOCTYPE r [\n" + " <!ENTITY five SYSTEM 'first.ent'>\n" + "]>\n" + "<r>&five;</r>", + "12345", NULL, 0}, + {"<!DOCTYPE r [\n" + " <!ENTITY five SYSTEM 'first.ent'>\n" + "]>\n" + "<r>&five;</r>", + "\xEF\xBB\xBF" /* UTF-8 BOM */, NULL, 0}, + +# ifdef XML_DTD + /* Parameter entities */ + {"<!DOCTYPE r [\n" + "<!ENTITY % comment \"<!---->\">\n" + "%comment;\n" + "]>\n" + "<r/>", + NULL, NULL, sizeof(XML_Char) * strlen("<!---->")}, + {"<!DOCTYPE r [\n" + "<!ENTITY % ninedef \"<!ENTITY nine "123456789">\">\n" + "%ninedef;\n" + "]>\n" + "<r>&nine;</r>", + NULL, NULL, + sizeof(XML_Char) + * (strlen("<!ENTITY nine \"123456789\">") + strlen("123456789"))}, + {"<!DOCTYPE r [\n" + "<!ENTITY % comment \"<!--1-->\">\n" + "<!ENTITY % comment2 \"%comment;<!--22-->%comment;\">\n" + "%comment2;\n" + "]>\n" + "<r/>\n", + NULL, NULL, + sizeof(XML_Char) + * (strlen("%comment;<!--22-->%comment;") + 2 * strlen("<!--1-->"))}, + {"<!DOCTYPE r [\n" + " <!ENTITY % five \"12345\">\n" + " <!ENTITY % five2def \"<!ENTITY five2 "[%five;][%five;]]]]">\">\n" + " %five2def;\n" + "]>\n" + "<r>&five2;</r>", + NULL, NULL, /* from "%five2def;": */ + sizeof(XML_Char) + * (strlen("<!ENTITY five2 \"[%five;][%five;]]]]\">") + + 2 /* calls to "%five;" */ * strlen("12345") + + /* from "&five2;": */ strlen("[12345][12345]]]]"))}, + {"<!DOCTYPE r SYSTEM \"first.ent\">\n" + "<r/>", + "<!ENTITY % comment '<!--1-->'>\n" + "<!ENTITY % comment2 '<!--22-->%comment;<!--22-->%comment;<!--22-->'>\n" + "%comment2;", + NULL, + sizeof(XML_Char) + * (strlen("<!--22-->%comment;<!--22-->%comment;<!--22-->") + + 2 /* calls to "%comment;" */ * strlen("<!---->"))}, + {"<!DOCTYPE r SYSTEM 'first.ent'>\n" + "<r/>", + "<!ENTITY % e1 PUBLIC 'foo' 'second.ent'>\n" + "<!ENTITY % e2 '<!--22-->%e1;<!--22-->'>\n" + "%e2;\n", + "<!--1-->", sizeof(XML_Char) * strlen("<!--22--><!--1--><!--22-->")}, + { + "<!DOCTYPE r SYSTEM 'first.ent'>\n" + "<r/>", + "<!ENTITY % e1 SYSTEM 'second.ent'>\n" + "<!ENTITY % e2 '%e1;'>", + "<?xml version='1.0' encoding='utf-8'?>\n" + "hello\n" + "xml" /* without trailing newline! */, + 0, + }, + { + "<!DOCTYPE r SYSTEM 'first.ent'>\n" + "<r/>", + "<!ENTITY % e1 SYSTEM 'second.ent'>\n" + "<!ENTITY % e2 '%e1;'>", + "<?xml version='1.0' encoding='utf-8'?>\n" + "hello\n" + "xml\n" /* with trailing newline! */, + 0, + }, + {"<!DOCTYPE doc SYSTEM 'first.ent'>\n" + "<doc></doc>\n", + "<!ELEMENT doc EMPTY>\n" + "<!ENTITY % e1 SYSTEM 'second.ent'>\n" + "<!ENTITY % e2 '%e1;'>\n" + "%e1;\n", + "\xEF\xBB\xBF<!ATTLIST doc a1 CDATA 'value'>" /* UTF-8 BOM */, + strlen("\xEF\xBB\xBF<!ATTLIST doc a1 CDATA 'value'>")}, +# endif /* XML_DTD */ + }; + + const size_t countCases = sizeof(cases) / sizeof(cases[0]); + size_t u = 0; + for (; u < countCases; u++) { + const unsigned long long expectedCountBytesDirect + = strlen(cases[u].primaryText); + const unsigned long long expectedCountBytesIndirect + = (cases[u].firstExternalText ? strlen(cases[u].firstExternalText) : 0) + + (cases[u].secondExternalText ? strlen(cases[u].secondExternalText) + : 0) + + cases[u].expectedCountBytesIndirectExtra; + + XML_Parser parser = XML_ParserCreate(NULL); + XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + if (cases[u].firstExternalText) { + XML_SetExternalEntityRefHandler(parser, + accounting_external_entity_ref_handler); + XML_SetUserData(parser, (void *)&cases[u]); + } + + enum XML_Status status + = _XML_Parse_SINGLE_BYTES(parser, cases[u].primaryText, + (int)strlen(cases[u].primaryText), XML_TRUE); + if (status != XML_STATUS_OK) { + _xml_failure(parser, __FILE__, __LINE__); + } + + const unsigned long long actualCountBytesDirect + = testingAccountingGetCountBytesDirect(parser); + const unsigned long long actualCountBytesIndirect + = testingAccountingGetCountBytesIndirect(parser); + + XML_ParserFree(parser); + + if (actualCountBytesDirect != expectedCountBytesDirect) { + fprintf( + stderr, + "Document " EXPAT_FMT_SIZE_T("") " of " EXPAT_FMT_SIZE_T("") ": Expected " EXPAT_FMT_ULL( + "") " count direct bytes, got " EXPAT_FMT_ULL("") " instead.\n", + u + 1, countCases, expectedCountBytesDirect, actualCountBytesDirect); + fail("Count of direct bytes is off"); + } + + if (actualCountBytesIndirect != expectedCountBytesIndirect) { + fprintf( + stderr, + "Document " EXPAT_FMT_SIZE_T("") " of " EXPAT_FMT_SIZE_T("") ": Expected " EXPAT_FMT_ULL( + "") " count indirect bytes, got " EXPAT_FMT_ULL("") " instead.\n", + u + 1, countCases, expectedCountBytesIndirect, + actualCountBytesIndirect); + fail("Count of indirect bytes is off"); + } + } +} +END_TEST + +START_TEST(test_billion_laughs_attack_protection_api) { + XML_Parser parserWithoutParent = XML_ParserCreate(NULL); + XML_Parser parserWithParent = XML_ExternalEntityParserCreate( + parserWithoutParent, XCS("entity123"), NULL); + if (parserWithoutParent == NULL) + fail("parserWithoutParent is NULL"); + if (parserWithParent == NULL) + fail("parserWithParent is NULL"); + + // XML_SetBillionLaughsAttackProtectionMaximumAmplification, error cases + if (XML_SetBillionLaughsAttackProtectionMaximumAmplification(NULL, 123.0f) + == XML_TRUE) + fail("Call with NULL parser is NOT supposed to succeed"); + if (XML_SetBillionLaughsAttackProtectionMaximumAmplification(parserWithParent, + 123.0f) + == XML_TRUE) + fail("Call with non-root parser is NOT supposed to succeed"); + if (XML_SetBillionLaughsAttackProtectionMaximumAmplification( + parserWithoutParent, NAN) + == XML_TRUE) + fail("Call with NaN limit is NOT supposed to succeed"); + if (XML_SetBillionLaughsAttackProtectionMaximumAmplification( + parserWithoutParent, -1.0f) + == XML_TRUE) + fail("Call with negative limit is NOT supposed to succeed"); + if (XML_SetBillionLaughsAttackProtectionMaximumAmplification( + parserWithoutParent, 0.9f) + == XML_TRUE) + fail("Call with positive limit <1.0 is NOT supposed to succeed"); + + // XML_SetBillionLaughsAttackProtectionMaximumAmplification, success cases + if (XML_SetBillionLaughsAttackProtectionMaximumAmplification( + parserWithoutParent, 1.0f) + == XML_FALSE) + fail("Call with positive limit >=1.0 is supposed to succeed"); + if (XML_SetBillionLaughsAttackProtectionMaximumAmplification( + parserWithoutParent, 123456.789f) + == XML_FALSE) + fail("Call with positive limit >=1.0 is supposed to succeed"); + if (XML_SetBillionLaughsAttackProtectionMaximumAmplification( + parserWithoutParent, INFINITY) + == XML_FALSE) + fail("Call with positive limit >=1.0 is supposed to succeed"); + + // XML_SetBillionLaughsAttackProtectionActivationThreshold, error cases + if (XML_SetBillionLaughsAttackProtectionActivationThreshold(NULL, 123) + == XML_TRUE) + fail("Call with NULL parser is NOT supposed to succeed"); + if (XML_SetBillionLaughsAttackProtectionActivationThreshold(parserWithParent, + 123) + == XML_TRUE) + fail("Call with non-root parser is NOT supposed to succeed"); + + // XML_SetBillionLaughsAttackProtectionActivationThreshold, success cases + if (XML_SetBillionLaughsAttackProtectionActivationThreshold( + parserWithoutParent, 123) + == XML_FALSE) + fail("Call with non-NULL parentless parser is supposed to succeed"); + + XML_ParserFree(parserWithParent); + XML_ParserFree(parserWithoutParent); +} +END_TEST + +START_TEST(test_helper_unsigned_char_to_printable) { + // Smoke test + unsigned char uc = 0; + for (; uc < (unsigned char)-1; uc++) { + set_subtest("char %u", (unsigned)uc); + const char *const printable = unsignedCharToPrintable(uc); + if (printable == NULL) + fail("unsignedCharToPrintable returned NULL"); + else if (strlen(printable) < (size_t)1) + fail("unsignedCharToPrintable returned empty string"); + } + + // Two concrete samples + set_subtest("char 'A'"); + if (strcmp(unsignedCharToPrintable('A'), "A") != 0) + fail("unsignedCharToPrintable result mistaken"); + set_subtest("char '\\'"); + if (strcmp(unsignedCharToPrintable('\\'), "\\\\") != 0) + fail("unsignedCharToPrintable result mistaken"); +} +END_TEST + +START_TEST(test_amplification_isolated_external_parser) { + // NOTE: Length 44 is precisely twice the length of "<!ENTITY a SYSTEM 'b'>" + // (22) that is used in function accountingGetCurrentAmplification in + // xmlparse.c. + // 1.........1.........1.........1.........1..4 => 44 + const char doc[] = "<!ENTITY % p1 '123456789_123456789_1234567'>"; + const int docLen = (int)sizeof(doc) - 1; + const float maximumToleratedAmplification = 2.0f; + + struct TestCase { + int offsetOfThreshold; + enum XML_Status expectedStatus; + }; + + struct TestCase cases[] = { + {-2, XML_STATUS_ERROR}, {-1, XML_STATUS_ERROR}, {0, XML_STATUS_ERROR}, + {+1, XML_STATUS_OK}, {+2, XML_STATUS_OK}, + }; + + for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { + const int offsetOfThreshold = cases[i].offsetOfThreshold; + const enum XML_Status expectedStatus = cases[i].expectedStatus; + const unsigned long long activationThresholdBytes + = docLen + offsetOfThreshold; + + set_subtest("offsetOfThreshold=%d, expectedStatus=%d", offsetOfThreshold, + expectedStatus); + + XML_Parser parser = XML_ParserCreate(NULL); + assert_true(parser != NULL); + + assert_true(XML_SetBillionLaughsAttackProtectionMaximumAmplification( + parser, maximumToleratedAmplification) + == XML_TRUE); + assert_true(XML_SetBillionLaughsAttackProtectionActivationThreshold( + parser, activationThresholdBytes) + == XML_TRUE); + + XML_Parser ext_parser = XML_ExternalEntityParserCreate(parser, NULL, NULL); + assert_true(ext_parser != NULL); + + const enum XML_Status actualStatus + = _XML_Parse_SINGLE_BYTES(ext_parser, doc, docLen, XML_TRUE); + + assert_true(actualStatus == expectedStatus); + if (actualStatus != XML_STATUS_OK) { + assert_true(XML_GetErrorCode(ext_parser) + == XML_ERROR_AMPLIFICATION_LIMIT_BREACH); + } + + XML_ParserFree(ext_parser); + XML_ParserFree(parser); + } +} +END_TEST + +#endif // XML_GE == 1 + +void +make_accounting_test_case(Suite *s) { +#if XML_GE == 1 + TCase *tc_accounting = tcase_create("accounting tests"); + + suite_add_tcase(s, tc_accounting); + + tcase_add_test(tc_accounting, test_accounting_precision); + tcase_add_test(tc_accounting, test_billion_laughs_attack_protection_api); + tcase_add_test(tc_accounting, test_helper_unsigned_char_to_printable); + tcase_add_test__ifdef_xml_dtd(tc_accounting, + test_amplification_isolated_external_parser); +#else + UNUSED_P(s); +#endif /* XML_GE == 1 */ +} diff --git a/3rdparty/expat/tests/acc_tests.h b/3rdparty/expat/tests/acc_tests.h new file mode 100644 index 00000000000..bbb93f37ed2 --- /dev/null +++ b/3rdparty/expat/tests/acc_tests.h @@ -0,0 +1,56 @@ +/* Tests in the "accounting" test case for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef XML_ACC_TESTS_H +# define XML_ACC_TESTS_H + +extern void make_accounting_test_case(Suite *s); + +#endif /* XML_ACC_TESTS_H */ + +#ifdef __cplusplus +} +#endif diff --git a/3rdparty/expat/tests/acc_tests_cxx.cpp b/3rdparty/expat/tests/acc_tests_cxx.cpp new file mode 100644 index 00000000000..01644991ae5 --- /dev/null +++ b/3rdparty/expat/tests/acc_tests_cxx.cpp @@ -0,0 +1,32 @@ +/* C++ compilation harness for the test suite. + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "acc_tests.c" diff --git a/3rdparty/expat/tests/alloc_tests.c b/3rdparty/expat/tests/alloc_tests.c new file mode 100644 index 00000000000..e5d46ebea82 --- /dev/null +++ b/3rdparty/expat/tests/alloc_tests.c @@ -0,0 +1,2127 @@ +/* Tests in the "allocation" test case for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#if defined(NDEBUG) +# undef NDEBUG /* because test suite relies on assert(...) at the moment */ +#endif + +#include <string.h> +#include <assert.h> + +#include "expat.h" +#include "common.h" +#include "minicheck.h" +#include "dummy.h" +#include "handlers.h" +#include "alloc_tests.h" + +static void +alloc_setup(void) { + XML_Memory_Handling_Suite memsuite = {duff_allocator, duff_reallocator, free}; + + /* Ensure the parser creation will go through */ + g_allocation_count = ALLOC_ALWAYS_SUCCEED; + g_reallocation_count = REALLOC_ALWAYS_SUCCEED; + g_parser = XML_ParserCreate_MM(NULL, &memsuite, NULL); + if (g_parser == NULL) + fail("Parser not created"); +} + +static void +alloc_teardown(void) { + basic_teardown(); +} + +/* Test the effects of allocation failures on xml declaration processing */ +START_TEST(test_alloc_parse_xdecl) { + const char *text = "<?xml version='1.0' encoding='utf-8'?>\n" + "<doc>Hello, world</doc>"; + int i; + const int max_alloc_count = 15; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetXmlDeclHandler(g_parser, dummy_xdecl_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* Resetting the parser is insufficient, because some memory + * allocations are cached within the parser. Instead we use + * the teardown and setup routines to ensure that we have the + * right sort of parser back in our hands. + */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed with max allocations"); +} +END_TEST + +/* As above, but with an encoding big enough to cause storing the + * version information to expand the string pool being used. + */ +START_TEST(test_alloc_parse_xdecl_2) { + const char *text + = "<?xml version='1.0' encoding='" + /* Each line is 64 characters */ + "ThisIsAStupidlyLongEncodingNameIntendedToTriggerPoolGrowth123456" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMN" + "'?>" + "<doc>Hello, world</doc>"; + int i; + const int max_alloc_count = 20; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetXmlDeclHandler(g_parser, dummy_xdecl_handler); + XML_SetUnknownEncodingHandler(g_parser, long_encoding_handler, NULL); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed with max allocations"); +} +END_TEST + +/* Test the effects of allocation failures on a straightforward parse */ +START_TEST(test_alloc_parse_pi) { + const char *text = "<?xml version='1.0' encoding='utf-8'?>\n" + "<?pi unknown?>\n" + "<doc>" + "Hello, world" + "</doc>"; + int i; + const int max_alloc_count = 15; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetProcessingInstructionHandler(g_parser, dummy_pi_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed with max allocations"); +} +END_TEST + +START_TEST(test_alloc_parse_pi_2) { + const char *text = "<?xml version='1.0' encoding='utf-8'?>\n" + "<doc>" + "Hello, world" + "<?pi unknown?>\n" + "</doc>"; + int i; + const int max_alloc_count = 15; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetProcessingInstructionHandler(g_parser, dummy_pi_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed with max allocations"); +} +END_TEST + +START_TEST(test_alloc_parse_pi_3) { + const char *text + = "<?" + /* 64 characters per line */ + "This processing instruction should be long enough to ensure that" + "it triggers the growth of an internal string pool when the " + "allocator fails at a cruicial moment FGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "Q?><doc/>"; + int i; + const int max_alloc_count = 20; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetProcessingInstructionHandler(g_parser, dummy_pi_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed with max allocations"); +} +END_TEST + +START_TEST(test_alloc_parse_comment) { + const char *text = "<?xml version='1.0' encoding='utf-8'?>\n" + "<!-- Test parsing this comment -->" + "<doc>Hi</doc>"; + int i; + const int max_alloc_count = 15; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetCommentHandler(g_parser, dummy_comment_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed with max allocations"); +} +END_TEST + +START_TEST(test_alloc_parse_comment_2) { + const char *text = "<?xml version='1.0' encoding='utf-8'?>\n" + "<doc>" + "Hello, world" + "<!-- Parse this comment too -->" + "</doc>"; + int i; + const int max_alloc_count = 15; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetCommentHandler(g_parser, dummy_comment_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed with max allocations"); +} +END_TEST + +/* Test that external parser creation running out of memory is + * correctly reported. Based on the external entity test cases. + */ +START_TEST(test_alloc_create_external_parser) { + const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc>&entity;</doc>"; + char foo_text[] = "<!ELEMENT doc (#PCDATA)*>"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetUserData(g_parser, foo_text); + XML_SetExternalEntityRefHandler(g_parser, external_entity_duff_loader); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) { + fail("External parser allocator returned success incorrectly"); + } +} +END_TEST + +/* More external parser memory allocation testing */ +START_TEST(test_alloc_run_external_parser) { + const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc>&entity;</doc>"; + char foo_text[] = "<!ELEMENT doc (#PCDATA)*>"; + unsigned int i; + const unsigned int max_alloc_count = 15; + + for (i = 0; i < max_alloc_count; i++) { + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetUserData(g_parser, foo_text); + XML_SetExternalEntityRefHandler(g_parser, external_entity_null_loader); + g_allocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parsing ignored failing allocator"); + else if (i == max_alloc_count) + fail("Parsing failed with allocation count 10"); +} +END_TEST + +/* Test that running out of memory in dtdCopy is correctly reported. + * Based on test_default_ns_from_ext_subset_and_ext_ge() + */ +START_TEST(test_alloc_dtd_copy_default_atts) { + const char *text = "<?xml version='1.0'?>\n" + "<!DOCTYPE doc SYSTEM 'http://example.org/doc.dtd' [\n" + " <!ENTITY en SYSTEM 'http://example.org/entity.ent'>\n" + "]>\n" + "<doc xmlns='http://example.org/ns1'>\n" + "&en;\n" + "</doc>"; + int callno = 0; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_dbl_handler); + XML_SetUserData(g_parser, &callno); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test more external entity allocation failure paths */ +START_TEST(test_alloc_external_entity) { + const char *text = "<?xml version='1.0'?>\n" + "<!DOCTYPE doc SYSTEM 'http://example.org/doc.dtd' [\n" + " <!ENTITY en SYSTEM 'http://example.org/entity.ent'>\n" + "]>\n" + "<doc xmlns='http://example.org/ns1'>\n" + "&en;\n" + "</doc>"; + int i; + const int alloc_test_max_repeats = 50; + int callno = 0; + + for (i = 0; i < alloc_test_max_repeats; i++) { + g_allocation_count = -1; + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_dbl_handler_2); + callno = 0; + XML_SetUserData(g_parser, &callno); + g_allocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_OK) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + g_allocation_count = -1; + if (i == 0) + fail("External entity parsed despite duff allocator"); + if (i == alloc_test_max_repeats) + fail("External entity not parsed at max allocation count"); +} +END_TEST + +/* Test more allocation failure paths */ +START_TEST(test_alloc_ext_entity_set_encoding) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + int i; + const int max_allocation_count = 30; + + for (i = 0; i < max_allocation_count; i++) { + XML_SetExternalEntityRefHandler(g_parser, + external_entity_alloc_set_encoding); + g_allocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_OK) + break; + g_allocation_count = -1; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Encoding check succeeded despite failing allocator"); + if (i == max_allocation_count) + fail("Encoding failed at max allocation count"); +} +END_TEST + +/* Test the effects of allocation failure in internal entities. + * Based on test_unknown_encoding_internal_entity + */ +START_TEST(test_alloc_internal_entity) { + const char *text = "<?xml version='1.0' encoding='unsupported-encoding'?>\n" + "<!DOCTYPE test [<!ENTITY foo 'bar'>]>\n" + "<test a='&foo;'/>"; + unsigned int i; + const unsigned int max_alloc_count = 20; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetUnknownEncodingHandler(g_parser, unknown_released_encoding_handler, + NULL); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Internal entity worked despite failing allocations"); + else if (i == max_alloc_count) + fail("Internal entity failed at max allocation count"); +} +END_TEST + +/* Test the robustness against allocation failure of element handling + * Based on test_dtd_default_handling(). + */ +START_TEST(test_alloc_dtd_default_handling) { + const char *text = "<!DOCTYPE doc [\n" + "<!ENTITY e SYSTEM 'http://example.org/e'>\n" + "<!NOTATION n SYSTEM 'http://example.org/n'>\n" + "<!ENTITY e1 SYSTEM 'http://example.org/e' NDATA n>\n" + "<!ELEMENT doc (#PCDATA)>\n" + "<!ATTLIST doc a CDATA #IMPLIED>\n" + "<?pi in dtd?>\n" + "<!--comment in dtd-->\n" + "]>\n" + "<doc><![CDATA[text in doc]]></doc>"; + const XML_Char *expected = XCS("\n\n\n\n\n\n\n\n\n<doc>text in doc</doc>"); + CharData storage; + int i; + const int max_alloc_count = 25; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + init_dummy_handlers(); + XML_SetDefaultHandler(g_parser, accumulate_characters); + XML_SetDoctypeDeclHandler(g_parser, dummy_start_doctype_handler, + dummy_end_doctype_handler); + XML_SetEntityDeclHandler(g_parser, dummy_entity_decl_handler); + XML_SetNotationDeclHandler(g_parser, dummy_notation_decl_handler); + XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); + XML_SetAttlistDeclHandler(g_parser, dummy_attlist_decl_handler); + XML_SetProcessingInstructionHandler(g_parser, dummy_pi_handler); + XML_SetCommentHandler(g_parser, dummy_comment_handler); + XML_SetCdataSectionHandler(g_parser, dummy_start_cdata_handler, + dummy_end_cdata_handler); + XML_SetUnparsedEntityDeclHandler(g_parser, + dummy_unparsed_entity_decl_handler); + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetCharacterDataHandler(g_parser, accumulate_characters); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Default DTD parsed despite allocation failures"); + if (i == max_alloc_count) + fail("Default DTD not parsed with maximum alloc count"); + CharData_CheckXMLChars(&storage, expected); + if (get_dummy_handler_flags() + != (DUMMY_START_DOCTYPE_HANDLER_FLAG | DUMMY_END_DOCTYPE_HANDLER_FLAG + | DUMMY_ENTITY_DECL_HANDLER_FLAG | DUMMY_NOTATION_DECL_HANDLER_FLAG + | DUMMY_ELEMENT_DECL_HANDLER_FLAG | DUMMY_ATTLIST_DECL_HANDLER_FLAG + | DUMMY_COMMENT_HANDLER_FLAG | DUMMY_PI_HANDLER_FLAG + | DUMMY_START_CDATA_HANDLER_FLAG | DUMMY_END_CDATA_HANDLER_FLAG + | DUMMY_UNPARSED_ENTITY_DECL_HANDLER_FLAG)) + fail("Not all handlers were called"); +} +END_TEST + +/* Test robustness of XML_SetEncoding() with a failing allocator */ +START_TEST(test_alloc_explicit_encoding) { + int i; + const int max_alloc_count = 5; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + if (XML_SetEncoding(g_parser, XCS("us-ascii")) == XML_STATUS_OK) + break; + } + if (i == 0) + fail("Encoding set despite failing allocator"); + else if (i == max_alloc_count) + fail("Encoding not set at max allocation count"); +} +END_TEST + +/* Test robustness of XML_SetBase against a failing allocator */ +START_TEST(test_alloc_set_base) { + const XML_Char *new_base = XCS("/local/file/name.xml"); + int i; + const int max_alloc_count = 5; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + if (XML_SetBase(g_parser, new_base) == XML_STATUS_OK) + break; + } + if (i == 0) + fail("Base set despite failing allocator"); + else if (i == max_alloc_count) + fail("Base not set with max allocation count"); +} +END_TEST + +/* Test buffer extension in the face of a duff reallocator */ +START_TEST(test_alloc_realloc_buffer) { + const char *text = get_buffer_test_text; + void *buffer; + int i; + const int max_realloc_count = 10; + + /* Get a smallish buffer */ + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + buffer = XML_GetBuffer(g_parser, 1536); + if (buffer == NULL) + fail("1.5K buffer reallocation failed"); + assert(buffer != NULL); + memcpy(buffer, text, strlen(text)); + if (XML_ParseBuffer(g_parser, (int)strlen(text), XML_FALSE) + == XML_STATUS_OK) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + g_reallocation_count = -1; + if (i == 0) + fail("Parse succeeded with no reallocation"); + else if (i == max_realloc_count) + fail("Parse failed with max reallocation count"); +} +END_TEST + +/* Same test for external entity parsers */ +START_TEST(test_alloc_ext_entity_realloc_buffer) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + int i; + const int max_realloc_count = 10; + + for (i = 0; i < max_realloc_count; i++) { + XML_SetExternalEntityRefHandler(g_parser, external_entity_reallocator); + XML_SetUserData(g_parser, &i); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_OK) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Succeeded with no reallocations"); + if (i == max_realloc_count) + fail("Failed with max reallocations"); +} +END_TEST + +/* Test elements with many attributes are handled correctly */ +START_TEST(test_alloc_realloc_many_attributes) { + const char *text = "<!DOCTYPE doc [\n" + "<!ATTLIST doc za CDATA 'default'>\n" + "<!ATTLIST doc zb CDATA 'def2'>\n" + "<!ATTLIST doc zc CDATA 'def3'>\n" + "]>\n" + "<doc a='1'" + " b='2'" + " c='3'" + " d='4'" + " e='5'" + " f='6'" + " g='7'" + " h='8'" + " i='9'" + " j='10'" + " k='11'" + " l='12'" + " m='13'" + " n='14'" + " p='15'" + " q='16'" + " r='17'" + " s='18'>" + "</doc>"; + int i; + const int max_realloc_count = 10; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite no reallocations"); + if (i == max_realloc_count) + fail("Parse failed at max reallocations"); +} +END_TEST + +/* Test handling of a public entity with failing allocator */ +START_TEST(test_alloc_public_entity_value) { + const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/'>\n" + "<doc></doc>\n"; + char dtd_text[] + = "<!ELEMENT doc EMPTY>\n" + "<!ENTITY % e1 PUBLIC 'foo' 'bar.ent'>\n" + "<!ENTITY % " + /* Each line is 64 characters */ + "ThisIsAStupidlyLongParameterNameIntendedToTriggerPoolGrowth12345" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + " '%e1;'>\n" + "%e1;\n"; + int i; + const int max_alloc_count = 50; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + init_dummy_handlers(); + XML_SetUserData(g_parser, dtd_text); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_public); + /* Provoke a particular code path */ + XML_SetEntityDeclHandler(g_parser, dummy_entity_decl_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing allocation"); + if (i == max_alloc_count) + fail("Parsing failed at max allocation count"); + if (get_dummy_handler_flags() != DUMMY_ENTITY_DECL_HANDLER_FLAG) + fail("Entity declaration handler not called"); +} +END_TEST + +START_TEST(test_alloc_realloc_subst_public_entity_value) { + const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/'>\n" + "<doc></doc>\n"; + char dtd_text[] + = "<!ELEMENT doc EMPTY>\n" + "<!ENTITY % " + /* Each line is 64 characters */ + "ThisIsAStupidlyLongParameterNameIntendedToTriggerPoolGrowth12345" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + " PUBLIC 'foo' 'bar.ent'>\n" + "%ThisIsAStupidlyLongParameterNameIntendedToTriggerPoolGrowth12345" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP;"; + int i; + const int max_realloc_count = 10; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + XML_SetUserData(g_parser, dtd_text); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_public); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing reallocation"); + if (i == max_realloc_count) + fail("Parsing failed at max reallocation count"); +} +END_TEST + +START_TEST(test_alloc_parse_public_doctype) { + const char *text + = "<?xml version='1.0' encoding='utf-8'?>\n" + "<!DOCTYPE doc PUBLIC '" + /* 64 characters per line */ + "http://example.com/a/long/enough/name/to/trigger/pool/growth/zz/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "' 'test'>\n" + "<doc></doc>"; + int i; + const int max_alloc_count = 25; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + init_dummy_handlers(); + XML_SetDoctypeDeclHandler(g_parser, dummy_start_doctype_decl_handler, + dummy_end_doctype_decl_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed at maximum allocation count"); + if (get_dummy_handler_flags() + != (DUMMY_START_DOCTYPE_DECL_HANDLER_FLAG + | DUMMY_END_DOCTYPE_DECL_HANDLER_FLAG)) + fail("Doctype handler functions not called"); +} +END_TEST + +START_TEST(test_alloc_parse_public_doctype_long_name) { + const char *text + = "<?xml version='1.0' encoding='utf-8'?>\n" + "<!DOCTYPE doc PUBLIC 'http://example.com/foo' '" + /* 64 characters per line */ + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "'>\n" + "<doc></doc>"; + int i; + const int max_alloc_count = 25; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetDoctypeDeclHandler(g_parser, dummy_start_doctype_decl_handler, + dummy_end_doctype_decl_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed at maximum allocation count"); +} +END_TEST + +/* Test foreign DTD handling */ +START_TEST(test_alloc_set_foreign_dtd) { + const char *text1 = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<doc>&entity;</doc>"; + char text2[] = "<!ELEMENT doc (#PCDATA)*>"; + int i; + const int max_alloc_count = 25; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetUserData(g_parser, &text2); + XML_SetExternalEntityRefHandler(g_parser, external_entity_alloc); + if (XML_UseForeignDTD(g_parser, XML_TRUE) != XML_ERROR_NONE) + fail("Could not set foreign DTD"); + if (_XML_Parse_SINGLE_BYTES(g_parser, text1, (int)strlen(text1), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed at maximum allocation count"); +} +END_TEST + +/* Test based on ibm/valid/P32/ibm32v04.xml */ +START_TEST(test_alloc_attribute_enum_value) { + const char *text = "<?xml version='1.0' standalone='no'?>\n" + "<!DOCTYPE animal SYSTEM 'test.dtd'>\n" + "<animal>This is a \n <a/> \n\nyellow tiger</animal>"; + char dtd_text[] = "<!ELEMENT animal (#PCDATA|a)*>\n" + "<!ELEMENT a EMPTY>\n" + "<!ATTLIST animal xml:space (default|preserve) 'preserve'>"; + int i; + const int max_alloc_count = 30; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetExternalEntityRefHandler(g_parser, external_entity_alloc); + XML_SetUserData(g_parser, dtd_text); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + /* An attribute list handler provokes a different code path */ + XML_SetAttlistDeclHandler(g_parser, dummy_attlist_decl_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed at maximum allocation count"); +} +END_TEST + +/* Test attribute enums sufficient to overflow the string pool */ +START_TEST(test_alloc_realloc_attribute_enum_value) { + const char *text = "<?xml version='1.0' standalone='no'?>\n" + "<!DOCTYPE animal SYSTEM 'test.dtd'>\n" + "<animal>This is a yellow tiger</animal>"; + /* We wish to define a collection of attribute enums that will + * cause the string pool storing them to have to expand. This + * means more than 1024 bytes, including the parentheses and + * separator bars. + */ + char dtd_text[] + = "<!ELEMENT animal (#PCDATA)*>\n" + "<!ATTLIST animal thing " + "(default" + /* Each line is 64 characters */ + "|ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|BBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|CBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|DBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|EBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|FBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|GBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|HBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|IBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|JBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|KBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|LBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|MBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|NBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|OBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|PBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO)" + " 'default'>"; + int i; + const int max_realloc_count = 10; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + XML_SetExternalEntityRefHandler(g_parser, external_entity_alloc); + XML_SetUserData(g_parser, dtd_text); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + /* An attribute list handler provokes a different code path */ + XML_SetAttlistDeclHandler(g_parser, dummy_attlist_decl_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing reallocator"); + if (i == max_realloc_count) + fail("Parse failed at maximum reallocation count"); +} +END_TEST + +/* Test attribute enums in a #IMPLIED attribute forcing pool growth */ +START_TEST(test_alloc_realloc_implied_attribute) { + /* Forcing this particular code path is a balancing act. The + * addition of the closing parenthesis and terminal NUL must be + * what pushes the string of enums over the 1024-byte limit, + * otherwise a different code path will pick up the realloc. + */ + const char *text + = "<!DOCTYPE doc [\n" + "<!ELEMENT doc EMPTY>\n" + "<!ATTLIST doc a " + /* Each line is 64 characters */ + "(ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|BBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|CBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|DBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|EBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|FBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|GBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|HBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|IBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|JBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|KBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|LBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|MBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|NBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|OBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|PBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMN)" + " #IMPLIED>\n" + "]><doc/>"; + int i; + const int max_realloc_count = 10; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + XML_SetAttlistDeclHandler(g_parser, dummy_attlist_decl_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing reallocator"); + if (i == max_realloc_count) + fail("Parse failed at maximum reallocation count"); +} +END_TEST + +/* Test attribute enums in a defaulted attribute forcing pool growth */ +START_TEST(test_alloc_realloc_default_attribute) { + /* Forcing this particular code path is a balancing act. The + * addition of the closing parenthesis and terminal NUL must be + * what pushes the string of enums over the 1024-byte limit, + * otherwise a different code path will pick up the realloc. + */ + const char *text + = "<!DOCTYPE doc [\n" + "<!ELEMENT doc EMPTY>\n" + "<!ATTLIST doc a " + /* Each line is 64 characters */ + "(ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|BBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|CBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|DBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|EBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|FBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|GBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|HBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|IBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|JBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|KBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|LBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|MBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|NBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|OBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + "|PBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMN)" + " 'ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO'" + ">\n]><doc/>"; + int i; + const int max_realloc_count = 10; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + XML_SetAttlistDeclHandler(g_parser, dummy_attlist_decl_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing reallocator"); + if (i == max_realloc_count) + fail("Parse failed at maximum reallocation count"); +} +END_TEST + +/* Test long notation name with dodgy allocator */ +START_TEST(test_alloc_notation) { + const char *text + = "<!DOCTYPE doc [\n" + "<!NOTATION " + /* Each line is 64 characters */ + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + " SYSTEM 'http://example.org/n'>\n" + "<!ENTITY e SYSTEM 'http://example.org/e' NDATA " + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + ">\n" + "<!ELEMENT doc EMPTY>\n" + "]>\n<doc/>"; + int i; + const int max_alloc_count = 20; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + init_dummy_handlers(); + XML_SetNotationDeclHandler(g_parser, dummy_notation_decl_handler); + XML_SetEntityDeclHandler(g_parser, dummy_entity_decl_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite allocation failures"); + if (i == max_alloc_count) + fail("Parse failed at maximum allocation count"); + if (get_dummy_handler_flags() + != (DUMMY_ENTITY_DECL_HANDLER_FLAG | DUMMY_NOTATION_DECL_HANDLER_FLAG)) + fail("Entity declaration handler not called"); +} +END_TEST + +/* Test public notation with dodgy allocator */ +START_TEST(test_alloc_public_notation) { + const char *text + = "<!DOCTYPE doc [\n" + "<!NOTATION note PUBLIC '" + /* 64 characters per line */ + "http://example.com/a/long/enough/name/to/trigger/pool/growth/zz/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "' 'foo'>\n" + "<!ENTITY e SYSTEM 'http://example.com/e' NDATA note>\n" + "<!ELEMENT doc EMPTY>\n" + "]>\n<doc/>"; + int i; + const int max_alloc_count = 20; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + init_dummy_handlers(); + XML_SetNotationDeclHandler(g_parser, dummy_notation_decl_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite allocation failures"); + if (i == max_alloc_count) + fail("Parse failed at maximum allocation count"); + if (get_dummy_handler_flags() != DUMMY_NOTATION_DECL_HANDLER_FLAG) + fail("Notation handler not called"); +} +END_TEST + +/* Test public notation with dodgy allocator */ +START_TEST(test_alloc_system_notation) { + const char *text + = "<!DOCTYPE doc [\n" + "<!NOTATION note SYSTEM '" + /* 64 characters per line */ + "http://example.com/a/long/enough/name/to/trigger/pool/growth/zz/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "'>\n" + "<!ENTITY e SYSTEM 'http://example.com/e' NDATA note>\n" + "<!ELEMENT doc EMPTY>\n" + "]>\n<doc/>"; + int i; + const int max_alloc_count = 20; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + init_dummy_handlers(); + XML_SetNotationDeclHandler(g_parser, dummy_notation_decl_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite allocation failures"); + if (i == max_alloc_count) + fail("Parse failed at maximum allocation count"); + if (get_dummy_handler_flags() != DUMMY_NOTATION_DECL_HANDLER_FLAG) + fail("Notation handler not called"); +} +END_TEST + +START_TEST(test_alloc_nested_groups) { + const char *text + = "<!DOCTYPE doc [\n" + "<!ELEMENT doc " + /* Sixteen elements per line */ + "(e,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?," + "(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?" + "))))))))))))))))))))))))))))))))>\n" + "<!ELEMENT e EMPTY>" + "]>\n" + "<doc><e/></doc>"; + CharData storage; + int i; + const int max_alloc_count = 20; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + CharData_Init(&storage); + XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); + XML_SetStartElementHandler(g_parser, record_element_start_handler); + XML_SetUserData(g_parser, &storage); + init_dummy_handlers(); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + + if (i == 0) + fail("Parse succeeded despite failing reallocator"); + if (i == max_alloc_count) + fail("Parse failed at maximum reallocation count"); + CharData_CheckXMLChars(&storage, XCS("doce")); + if (get_dummy_handler_flags() != DUMMY_ELEMENT_DECL_HANDLER_FLAG) + fail("Element handler not fired"); +} +END_TEST + +START_TEST(test_alloc_realloc_nested_groups) { + const char *text + = "<!DOCTYPE doc [\n" + "<!ELEMENT doc " + /* Sixteen elements per line */ + "(e,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?," + "(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?" + "))))))))))))))))))))))))))))))))>\n" + "<!ELEMENT e EMPTY>" + "]>\n" + "<doc><e/></doc>"; + CharData storage; + int i; + const int max_realloc_count = 10; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + CharData_Init(&storage); + XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); + XML_SetStartElementHandler(g_parser, record_element_start_handler); + XML_SetUserData(g_parser, &storage); + init_dummy_handlers(); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + + if (i == 0) + fail("Parse succeeded despite failing reallocator"); + if (i == max_realloc_count) + fail("Parse failed at maximum reallocation count"); + CharData_CheckXMLChars(&storage, XCS("doce")); + if (get_dummy_handler_flags() != DUMMY_ELEMENT_DECL_HANDLER_FLAG) + fail("Element handler not fired"); +} +END_TEST + +START_TEST(test_alloc_large_group) { + const char *text = "<!DOCTYPE doc [\n" + "<!ELEMENT doc (" + "a1|a2|a3|a4|a5|a6|a7|a8|" + "b1|b2|b3|b4|b5|b6|b7|b8|" + "c1|c2|c3|c4|c5|c6|c7|c8|" + "d1|d2|d3|d4|d5|d6|d7|d8|" + "e1" + ")+>\n" + "]>\n" + "<doc>\n" + "<a1/>\n" + "</doc>\n"; + int i; + const int max_alloc_count = 50; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); + init_dummy_handlers(); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed at maximum allocation count"); + if (get_dummy_handler_flags() != DUMMY_ELEMENT_DECL_HANDLER_FLAG) + fail("Element handler flag not raised"); +} +END_TEST + +START_TEST(test_alloc_realloc_group_choice) { + const char *text = "<!DOCTYPE doc [\n" + "<!ELEMENT doc (" + "a1|a2|a3|a4|a5|a6|a7|a8|" + "b1|b2|b3|b4|b5|b6|b7|b8|" + "c1|c2|c3|c4|c5|c6|c7|c8|" + "d1|d2|d3|d4|d5|d6|d7|d8|" + "e1" + ")+>\n" + "]>\n" + "<doc>\n" + "<a1/>\n" + "<b2 attr='foo'>This is a foo</b2>\n" + "<c3></c3>\n" + "</doc>\n"; + int i; + const int max_realloc_count = 10; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); + init_dummy_handlers(); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing reallocator"); + if (i == max_realloc_count) + fail("Parse failed at maximum reallocation count"); + if (get_dummy_handler_flags() != DUMMY_ELEMENT_DECL_HANDLER_FLAG) + fail("Element handler flag not raised"); +} +END_TEST + +START_TEST(test_alloc_pi_in_epilog) { + const char *text = "<doc></doc>\n" + "<?pi in epilog?>"; + int i; + const int max_alloc_count = 15; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetProcessingInstructionHandler(g_parser, dummy_pi_handler); + init_dummy_handlers(); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse completed despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed at maximum allocation count"); + if (get_dummy_handler_flags() != DUMMY_PI_HANDLER_FLAG) + fail("Processing instruction handler not invoked"); +} +END_TEST + +START_TEST(test_alloc_comment_in_epilog) { + const char *text = "<doc></doc>\n" + "<!-- comment in epilog -->"; + int i; + const int max_alloc_count = 15; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetCommentHandler(g_parser, dummy_comment_handler); + init_dummy_handlers(); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse completed despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed at maximum allocation count"); + if (get_dummy_handler_flags() != DUMMY_COMMENT_HANDLER_FLAG) + fail("Processing instruction handler not invoked"); +} +END_TEST + +START_TEST(test_alloc_realloc_long_attribute_value) { + const char *text + = "<!DOCTYPE doc [<!ENTITY foo '" + /* Each line is 64 characters */ + "This entity will be substituted as an attribute value, and is " + "calculated to be exactly long enough that the terminating NUL " + "that the library adds internally will trigger the string pool to" + "grow. GHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "'>]>\n" + "<doc a='&foo;'></doc>"; + int i; + const int max_realloc_count = 10; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing reallocator"); + if (i == max_realloc_count) + fail("Parse failed at maximum reallocation count"); +} +END_TEST + +START_TEST(test_alloc_attribute_whitespace) { + const char *text = "<doc a=' '></doc>"; + int i; + const int max_alloc_count = 15; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed at maximum allocation count"); +} +END_TEST + +START_TEST(test_alloc_attribute_predefined_entity) { + const char *text = "<doc a='&'></doc>"; + int i; + const int max_alloc_count = 15; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed at maximum allocation count"); +} +END_TEST + +/* Test that a character reference at the end of a suitably long + * default value for an attribute can trigger pool growth, and recovers + * if the allocator fails on it. + */ +START_TEST(test_alloc_long_attr_default_with_char_ref) { + const char *text + = "<!DOCTYPE doc [<!ATTLIST doc a CDATA '" + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHI" + "1'>]>\n" + "<doc/>"; + int i; + const int max_alloc_count = 20; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed at maximum allocation count"); +} +END_TEST + +/* Test that a long character reference substitution triggers a pool + * expansion correctly for an attribute value. + */ +START_TEST(test_alloc_long_attr_value) { + const char *text + = "<!DOCTYPE test [<!ENTITY foo '\n" + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "'>]>\n" + "<test a='&foo;'/>"; + int i; + const int max_alloc_count = 25; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing allocator"); + if (i == max_alloc_count) + fail("Parse failed at maximum allocation count"); +} +END_TEST + +/* Test that an error in a nested parameter entity substitution is + * handled correctly. It seems unlikely that the code path being + * exercised can be reached purely by carefully crafted XML, but an + * allocation error in the right place will definitely do it. + */ +START_TEST(test_alloc_nested_entities) { + const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/one.ent'>\n" + "<doc />"; + ExtFaults test_data + = {"<!ENTITY % pe1 '" + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "'>\n" + "<!ENTITY % pe2 '%pe1;'>\n" + "<!ENTITY % pe3 '%pe2;'>", + "Memory Fail not faulted", NULL, XML_ERROR_NO_MEMORY}; + + /* Causes an allocation error in a nested storeEntityValue() */ + g_allocation_count = 12; + XML_SetUserData(g_parser, &test_data); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter); + expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, + "Entity allocation failure not noted"); +} +END_TEST + +START_TEST(test_alloc_realloc_param_entity_newline) { + const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/'>\n" + "<doc/>"; + char dtd_text[] + = "<!ENTITY % pe '<!ATTLIST doc att CDATA \"" + /* 64 characters per line */ + "This default value is carefully crafted so that the carriage " + "return right at the end of the entity string causes an internal " + "string pool to have to grow. This allows us to test the alloc " + "failure path from that point. OPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDE" + "\">\n'>" + "%pe;\n"; + int i; + const int max_realloc_count = 5; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + XML_SetUserData(g_parser, dtd_text); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_alloc); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing reallocator"); + if (i == max_realloc_count) + fail("Parse failed at maximum reallocation count"); +} +END_TEST + +START_TEST(test_alloc_realloc_ce_extends_pe) { + const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/'>\n" + "<doc/>"; + char dtd_text[] + = "<!ENTITY % pe '<!ATTLIST doc att CDATA \"" + /* 64 characters per line */ + "This default value is carefully crafted so that the character " + "entity at the end causes an internal string pool to have to " + "grow. This allows us to test the allocation failure path from " + "that point onwards. EFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGQ" + "\">\n'>" + "%pe;\n"; + int i; + const int max_realloc_count = 5; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + XML_SetUserData(g_parser, dtd_text); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_alloc); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parse succeeded despite failing reallocator"); + if (i == max_realloc_count) + fail("Parse failed at maximum reallocation count"); +} +END_TEST + +START_TEST(test_alloc_realloc_attributes) { + const char *text = "<!DOCTYPE doc [\n" + " <!ATTLIST doc\n" + " a1 (a|b|c) 'a'\n" + " a2 (foo|bar) #IMPLIED\n" + " a3 NMTOKEN #IMPLIED\n" + " a4 NMTOKENS #IMPLIED\n" + " a5 ID #IMPLIED\n" + " a6 IDREF #IMPLIED\n" + " a7 IDREFS #IMPLIED\n" + " a8 ENTITY #IMPLIED\n" + " a9 ENTITIES #IMPLIED\n" + " a10 CDATA #IMPLIED\n" + " >]>\n" + "<doc>wombat</doc>\n"; + int i; + const int max_realloc_count = 5; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + + if (i == 0) + fail("Parse succeeded despite failing reallocator"); + if (i == max_realloc_count) + fail("Parse failed at maximum reallocation count"); +} +END_TEST + +START_TEST(test_alloc_long_doc_name) { + const char *text = + /* 64 characters per line */ + "<LongRootElementNameThatWillCauseTheNextAllocationToExpandTheStr" + "ingPoolForTheDTDQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + " a='1'/>"; + int i; + const int max_alloc_count = 20; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing reallocations"); + else if (i == max_alloc_count) + fail("Parsing failed even at max reallocation count"); +} +END_TEST + +START_TEST(test_alloc_long_base) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY e SYSTEM 'foo'>\n" + "]>\n" + "<doc>&e;</doc>"; + char entity_text[] = "Hello world"; + const XML_Char *base = + /* 64 characters per line */ + /* clang-format off */ + XCS("LongBaseURI/that/will/overflow/an/internal/buffer/and/cause/it/t") + XCS("o/have/to/grow/PQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/"); + /* clang-format on */ + int i; + const int max_alloc_count = 25; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetUserData(g_parser, entity_text); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_alloc); + if (XML_SetBase(g_parser, base) == XML_STATUS_ERROR) { + XML_ParserReset(g_parser, NULL); + continue; + } + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing allocations"); + else if (i == max_alloc_count) + fail("Parsing failed even at max allocation count"); +} +END_TEST + +START_TEST(test_alloc_long_public_id) { + const char *text + = "<!DOCTYPE doc [\n" + " <!ENTITY e PUBLIC '" + /* 64 characters per line */ + "LongPublicIDThatShouldResultInAnInternalStringPoolGrowingAtASpec" + "ificMomentKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "' 'bar'>\n" + "]>\n" + "<doc>&e;</doc>"; + char entity_text[] = "Hello world"; + int i; + const int max_alloc_count = 40; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetUserData(g_parser, entity_text); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_alloc); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing allocations"); + else if (i == max_alloc_count) + fail("Parsing failed even at max allocation count"); +} +END_TEST + +START_TEST(test_alloc_long_entity_value) { + const char *text + = "<!DOCTYPE doc [\n" + " <!ENTITY e1 '" + /* 64 characters per line */ + "Long entity value that should provoke a string pool to grow whil" + "e setting up to parse the external entity below. xyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "'>\n" + " <!ENTITY e2 SYSTEM 'bar'>\n" + "]>\n" + "<doc>&e2;</doc>"; + char entity_text[] = "Hello world"; + int i; + const int max_alloc_count = 40; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetUserData(g_parser, entity_text); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_alloc); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing allocations"); + else if (i == max_alloc_count) + fail("Parsing failed even at max allocation count"); +} +END_TEST + +START_TEST(test_alloc_long_notation) { + const char *text + = "<!DOCTYPE doc [\n" + " <!NOTATION note SYSTEM '" + /* 64 characters per line */ + "ALongNotationNameThatShouldProvokeStringPoolGrowthWhileCallingAn" + "ExternalEntityParserUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "'>\n" + " <!ENTITY e1 SYSTEM 'foo' NDATA " + /* 64 characters per line */ + "ALongNotationNameThatShouldProvokeStringPoolGrowthWhileCallingAn" + "ExternalEntityParserUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" + ">\n" + " <!ENTITY e2 SYSTEM 'bar'>\n" + "]>\n" + "<doc>&e2;</doc>"; + ExtOption options[] + = {{XCS("foo"), "Entity Foo"}, {XCS("bar"), "Entity Bar"}, {NULL, NULL}}; + int i; + const int max_alloc_count = 40; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetUserData(g_parser, options); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_optioner); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + + /* See comment in test_alloc_parse_xdecl() */ + alloc_teardown(); + alloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing allocations"); + else if (i == max_alloc_count) + fail("Parsing failed even at max allocation count"); +} +END_TEST + +START_TEST(test_alloc_reset_after_external_entity_parser_create_fail) { + const char *const text = "<!DOCTYPE doc SYSTEM 'foo'><doc/>"; + + XML_SetExternalEntityRefHandler( + g_parser, external_entity_parser_create_alloc_fail_handler); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Call to parse was expected to fail"); + + if (XML_GetErrorCode(g_parser) != XML_ERROR_EXTERNAL_ENTITY_HANDLING) + fail("Call to parse was expected to fail from the external entity handler"); + + XML_ParserReset(g_parser, NULL); +} +END_TEST + +void +make_alloc_test_case(Suite *s) { + TCase *tc_alloc = tcase_create("allocation tests"); + + suite_add_tcase(s, tc_alloc); + tcase_add_checked_fixture(tc_alloc, alloc_setup, alloc_teardown); + + tcase_add_test(tc_alloc, test_alloc_parse_xdecl); + tcase_add_test(tc_alloc, test_alloc_parse_xdecl_2); + tcase_add_test(tc_alloc, test_alloc_parse_pi); + tcase_add_test(tc_alloc, test_alloc_parse_pi_2); + tcase_add_test(tc_alloc, test_alloc_parse_pi_3); + tcase_add_test(tc_alloc, test_alloc_parse_comment); + tcase_add_test(tc_alloc, test_alloc_parse_comment_2); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_create_external_parser); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_run_external_parser); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_dtd_copy_default_atts); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_external_entity); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_ext_entity_set_encoding); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_internal_entity); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_dtd_default_handling); + tcase_add_test(tc_alloc, test_alloc_explicit_encoding); + tcase_add_test(tc_alloc, test_alloc_set_base); + tcase_add_test(tc_alloc, test_alloc_realloc_buffer); + tcase_add_test__if_xml_ge(tc_alloc, test_alloc_ext_entity_realloc_buffer); + tcase_add_test(tc_alloc, test_alloc_realloc_many_attributes); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_public_entity_value); + tcase_add_test__ifdef_xml_dtd(tc_alloc, + test_alloc_realloc_subst_public_entity_value); + tcase_add_test(tc_alloc, test_alloc_parse_public_doctype); + tcase_add_test(tc_alloc, test_alloc_parse_public_doctype_long_name); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_set_foreign_dtd); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_attribute_enum_value); + tcase_add_test__ifdef_xml_dtd(tc_alloc, + test_alloc_realloc_attribute_enum_value); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_realloc_implied_attribute); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_realloc_default_attribute); + tcase_add_test__if_xml_ge(tc_alloc, test_alloc_notation); + tcase_add_test(tc_alloc, test_alloc_public_notation); + tcase_add_test(tc_alloc, test_alloc_system_notation); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_nested_groups); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_realloc_nested_groups); + tcase_add_test(tc_alloc, test_alloc_large_group); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_realloc_group_choice); + tcase_add_test(tc_alloc, test_alloc_pi_in_epilog); + tcase_add_test(tc_alloc, test_alloc_comment_in_epilog); + tcase_add_test__ifdef_xml_dtd(tc_alloc, + test_alloc_realloc_long_attribute_value); + tcase_add_test(tc_alloc, test_alloc_attribute_whitespace); + tcase_add_test(tc_alloc, test_alloc_attribute_predefined_entity); + tcase_add_test(tc_alloc, test_alloc_long_attr_default_with_char_ref); + tcase_add_test__if_xml_ge(tc_alloc, test_alloc_long_attr_value); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_nested_entities); + tcase_add_test__ifdef_xml_dtd(tc_alloc, + test_alloc_realloc_param_entity_newline); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_realloc_ce_extends_pe); + tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_realloc_attributes); + tcase_add_test(tc_alloc, test_alloc_long_doc_name); + tcase_add_test__if_xml_ge(tc_alloc, test_alloc_long_base); + tcase_add_test__if_xml_ge(tc_alloc, test_alloc_long_public_id); + tcase_add_test__if_xml_ge(tc_alloc, test_alloc_long_entity_value); + tcase_add_test__if_xml_ge(tc_alloc, test_alloc_long_notation); + + tcase_add_test__ifdef_xml_dtd( + tc_alloc, test_alloc_reset_after_external_entity_parser_create_fail); +} diff --git a/3rdparty/expat/tests/alloc_tests.h b/3rdparty/expat/tests/alloc_tests.h new file mode 100644 index 00000000000..1eae130be78 --- /dev/null +++ b/3rdparty/expat/tests/alloc_tests.h @@ -0,0 +1,56 @@ +/* Tests in the "allocation" test case for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef XML_ALLOC_TESTS_H +# define XML_ALLOC_TESTS_H + +extern void make_alloc_test_case(Suite *s); + +#endif /* XML_ALLOC_TESTS_H */ + +#ifdef __cplusplus +} +#endif diff --git a/3rdparty/expat/tests/alloc_tests_cxx.cpp b/3rdparty/expat/tests/alloc_tests_cxx.cpp new file mode 100644 index 00000000000..3270b1a6c98 --- /dev/null +++ b/3rdparty/expat/tests/alloc_tests_cxx.cpp @@ -0,0 +1,32 @@ +/* C++ compilation harness for the test suite. + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "alloc_tests.c" diff --git a/3rdparty/expat/tests/basic_tests.c b/3rdparty/expat/tests/basic_tests.c new file mode 100644 index 00000000000..d38b8fd1841 --- /dev/null +++ b/3rdparty/expat/tests/basic_tests.c @@ -0,0 +1,6159 @@ +/* Tests in the "basic" test case for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild@sony.com> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#if defined(NDEBUG) +# undef NDEBUG /* because test suite relies on assert(...) at the moment */ +#endif + +#include <assert.h> + +#include <stdio.h> +#include <string.h> +#include <time.h> + +#if ! defined(__cplusplus) +# include <stdbool.h> +#endif + +#include "expat_config.h" + +#include "expat.h" +#include "internal.h" +#include "minicheck.h" +#include "structdata.h" +#include "common.h" +#include "dummy.h" +#include "handlers.h" +#include "siphash.h" +#include "basic_tests.h" + +static void +basic_setup(void) { + g_parser = XML_ParserCreate(NULL); + if (g_parser == NULL) + fail("Parser not created."); +} + +/* + * Character & encoding tests. + */ + +START_TEST(test_nul_byte) { + char text[] = "<doc>\0</doc>"; + + /* test that a NUL byte (in US-ASCII data) is an error */ + if (_XML_Parse_SINGLE_BYTES(g_parser, text, sizeof(text) - 1, XML_TRUE) + == XML_STATUS_OK) + fail("Parser did not report error on NUL-byte."); + if (XML_GetErrorCode(g_parser) != XML_ERROR_INVALID_TOKEN) + xml_failure(g_parser); +} +END_TEST + +START_TEST(test_u0000_char) { + /* test that a NUL byte (in US-ASCII data) is an error */ + expect_failure("<doc>�</doc>", XML_ERROR_BAD_CHAR_REF, + "Parser did not report error on NUL-byte."); +} +END_TEST + +START_TEST(test_siphash_self) { + if (! sip24_valid()) + fail("SipHash self-test failed"); +} +END_TEST + +START_TEST(test_siphash_spec) { + /* https://131002.net/siphash/siphash.pdf (page 19, "Test values") */ + const char message[] = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09" + "\x0a\x0b\x0c\x0d\x0e"; + const size_t len = sizeof(message) - 1; + const uint64_t expected = SIP_ULL(0xa129ca61U, 0x49be45e5U); + struct siphash state; + struct sipkey key; + + sip_tokey(&key, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09" + "\x0a\x0b\x0c\x0d\x0e\x0f"); + sip24_init(&state, &key); + + /* Cover spread across calls */ + sip24_update(&state, message, 4); + sip24_update(&state, message + 4, len - 4); + + /* Cover null length */ + sip24_update(&state, message, 0); + + if (sip24_final(&state) != expected) + fail("sip24_final failed spec test\n"); + + /* Cover wrapper */ + if (siphash24(message, len, &key) != expected) + fail("siphash24 failed spec test\n"); +} +END_TEST + +START_TEST(test_bom_utf8) { + /* This test is really just making sure we don't core on a UTF-8 BOM. */ + const char *text = "\357\273\277<e/>"; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +START_TEST(test_bom_utf16_be) { + char text[] = "\376\377\0<\0e\0/\0>"; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +START_TEST(test_bom_utf16_le) { + char text[] = "\377\376<\0e\0/\0>\0"; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +START_TEST(test_nobom_utf16_le) { + char text[] = " \0<\0e\0/\0>\0"; + + if (g_chunkSize == 1) { + // TODO: with just the first byte, we can't tell the difference between + // UTF-16-LE and UTF-8. Avoid the failure for now. + return; + } + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +START_TEST(test_hash_collision) { + /* For full coverage of the lookup routine, we need to ensure a + * hash collision even though we can only tell that we have one + * through breakpoint debugging or coverage statistics. The + * following will cause a hash collision on machines with a 64-bit + * long type; others will have to experiment. The full coverage + * tests invoked from qa.sh usually provide a hash collision, but + * not always. This is an attempt to provide insurance. + */ +#define COLLIDING_HASH_SALT (unsigned long)SIP_ULL(0xffffffffU, 0xff99fc90U) + const char *text + = "<doc>\n" + "<a1/><a2/><a3/><a4/><a5/><a6/><a7/><a8/>\n" + "<b1></b1><b2 attr='foo'>This is a foo</b2><b3></b3><b4></b4>\n" + "<b5></b5><b6></b6><b7></b7><b8></b8>\n" + "<c1/><c2/><c3/><c4/><c5/><c6/><c7/><c8/>\n" + "<d1/><d2/><d3/><d4/><d5/><d6/><d7/>\n" + "<d8>This triggers the table growth and collides with b2</d8>\n" + "</doc>\n"; + + XML_SetHashSalt(g_parser, COLLIDING_HASH_SALT); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST +#undef COLLIDING_HASH_SALT + +/* Regression test for SF bug #491986. */ +START_TEST(test_danish_latin1) { + const char *text = "<?xml version='1.0' encoding='iso-8859-1'?>\n" + "<e>J\xF8rgen \xE6\xF8\xE5\xC6\xD8\xC5</e>"; +#ifdef XML_UNICODE + const XML_Char *expected + = XCS("J\x00f8rgen \x00e6\x00f8\x00e5\x00c6\x00d8\x00c5"); +#else + const XML_Char *expected + = XCS("J\xC3\xB8rgen \xC3\xA6\xC3\xB8\xC3\xA5\xC3\x86\xC3\x98\xC3\x85"); +#endif + run_character_check(text, expected); +} +END_TEST + +/* Regression test for SF bug #514281. */ +START_TEST(test_french_charref_hexidecimal) { + const char *text = "<?xml version='1.0' encoding='iso-8859-1'?>\n" + "<doc>éèàçêÈ</doc>"; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x00e9\x00e8\x00e0\x00e7\x00ea\x00c8"); +#else + const XML_Char *expected + = XCS("\xC3\xA9\xC3\xA8\xC3\xA0\xC3\xA7\xC3\xAA\xC3\x88"); +#endif + run_character_check(text, expected); +} +END_TEST + +START_TEST(test_french_charref_decimal) { + const char *text = "<?xml version='1.0' encoding='iso-8859-1'?>\n" + "<doc>éèàçêÈ</doc>"; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x00e9\x00e8\x00e0\x00e7\x00ea\x00c8"); +#else + const XML_Char *expected + = XCS("\xC3\xA9\xC3\xA8\xC3\xA0\xC3\xA7\xC3\xAA\xC3\x88"); +#endif + run_character_check(text, expected); +} +END_TEST + +START_TEST(test_french_latin1) { + const char *text = "<?xml version='1.0' encoding='iso-8859-1'?>\n" + "<doc>\xE9\xE8\xE0\xE7\xEa\xC8</doc>"; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x00e9\x00e8\x00e0\x00e7\x00ea\x00c8"); +#else + const XML_Char *expected + = XCS("\xC3\xA9\xC3\xA8\xC3\xA0\xC3\xA7\xC3\xAA\xC3\x88"); +#endif + run_character_check(text, expected); +} +END_TEST + +START_TEST(test_french_utf8) { + const char *text = "<?xml version='1.0' encoding='utf-8'?>\n" + "<doc>\xC3\xA9</doc>"; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x00e9"); +#else + const XML_Char *expected = XCS("\xC3\xA9"); +#endif + run_character_check(text, expected); +} +END_TEST + +/* Regression test for SF bug #600479. + XXX There should be a test that exercises all legal XML Unicode + characters as PCDATA and attribute value content, and XML Name + characters as part of element and attribute names. +*/ +START_TEST(test_utf8_false_rejection) { + const char *text = "<doc>\xEF\xBA\xBF</doc>"; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\xfebf"); +#else + const XML_Char *expected = XCS("\xEF\xBA\xBF"); +#endif + run_character_check(text, expected); +} +END_TEST + +/* Regression test for SF bug #477667. + This test assures that any 8-bit character followed by a 7-bit + character will not be mistakenly interpreted as a valid UTF-8 + sequence. +*/ +START_TEST(test_illegal_utf8) { + char text[100]; + int i; + + for (i = 128; i <= 255; ++i) { + snprintf(text, sizeof(text), "<e>%ccd</e>", i); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_OK) { + snprintf(text, sizeof(text), + "expected token error for '%c' (ordinal %d) in UTF-8 text", i, + i); + fail(text); + } else if (XML_GetErrorCode(g_parser) != XML_ERROR_INVALID_TOKEN) + xml_failure(g_parser); + /* Reset the parser since we use the same parser repeatedly. */ + XML_ParserReset(g_parser, NULL); + } +} +END_TEST + +/* Examples, not masks: */ +#define UTF8_LEAD_1 "\x7f" /* 0b01111111 */ +#define UTF8_LEAD_2 "\xdf" /* 0b11011111 */ +#define UTF8_LEAD_3 "\xef" /* 0b11101111 */ +#define UTF8_LEAD_4 "\xf7" /* 0b11110111 */ +#define UTF8_FOLLOW "\xbf" /* 0b10111111 */ + +START_TEST(test_utf8_auto_align) { + struct TestCase { + ptrdiff_t expectedMovementInChars; + const char *input; + }; + + struct TestCase cases[] = { + {00, ""}, + + {00, UTF8_LEAD_1}, + + {-1, UTF8_LEAD_2}, + {00, UTF8_LEAD_2 UTF8_FOLLOW}, + + {-1, UTF8_LEAD_3}, + {-2, UTF8_LEAD_3 UTF8_FOLLOW}, + {00, UTF8_LEAD_3 UTF8_FOLLOW UTF8_FOLLOW}, + + {-1, UTF8_LEAD_4}, + {-2, UTF8_LEAD_4 UTF8_FOLLOW}, + {-3, UTF8_LEAD_4 UTF8_FOLLOW UTF8_FOLLOW}, + {00, UTF8_LEAD_4 UTF8_FOLLOW UTF8_FOLLOW UTF8_FOLLOW}, + }; + + size_t i = 0; + bool success = true; + for (; i < sizeof(cases) / sizeof(*cases); i++) { + const char *fromLim = cases[i].input + strlen(cases[i].input); + const char *const fromLimInitially = fromLim; + ptrdiff_t actualMovementInChars; + + _INTERNAL_trim_to_complete_utf8_characters(cases[i].input, &fromLim); + + actualMovementInChars = (fromLim - fromLimInitially); + if (actualMovementInChars != cases[i].expectedMovementInChars) { + size_t j = 0; + success = false; + printf("[-] UTF-8 case %2u: Expected movement by %2d chars" + ", actually moved by %2d chars: \"", + (unsigned)(i + 1), (int)cases[i].expectedMovementInChars, + (int)actualMovementInChars); + for (; j < strlen(cases[i].input); j++) { + printf("\\x%02x", (unsigned char)cases[i].input[j]); + } + printf("\"\n"); + } + } + + if (! success) { + fail("UTF-8 auto-alignment is not bullet-proof\n"); + } +} +END_TEST + +START_TEST(test_utf16) { + /* <?xml version="1.0" encoding="UTF-16"?> + * <doc a='123'>some {A} text</doc> + * + * where {A} is U+FF21, FULLWIDTH LATIN CAPITAL LETTER A + */ + char text[] + = "\000<\000?\000x\000m\000\154\000 \000v\000e\000r\000s\000i\000o" + "\000n\000=\000'\0001\000.\000\060\000'\000 \000e\000n\000c\000o" + "\000d\000i\000n\000g\000=\000'\000U\000T\000F\000-\0001\000\066" + "\000'\000?\000>\000\n" + "\000<\000d\000o\000c\000 \000a\000=\000'\0001\0002\0003\000'\000>" + "\000s\000o\000m\000e\000 \xff\x21\000 \000t\000e\000x\000t\000" + "<\000/\000d\000o\000c\000>"; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("some \xff21 text"); +#else + const XML_Char *expected = XCS("some \357\274\241 text"); +#endif + CharData storage; + + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetCharacterDataHandler(g_parser, accumulate_characters); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_utf16_le_epilog_newline) { + unsigned int first_chunk_bytes = 17; + char text[] = "\xFF\xFE" /* BOM */ + "<\000e\000/\000>\000" /* document element */ + "\r\000\n\000\r\000\n\000"; /* epilog */ + + if (first_chunk_bytes >= sizeof(text) - 1) + fail("bad value of first_chunk_bytes"); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, first_chunk_bytes, XML_FALSE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + else { + enum XML_Status rc; + rc = _XML_Parse_SINGLE_BYTES(g_parser, text + first_chunk_bytes, + sizeof(text) - first_chunk_bytes - 1, + XML_TRUE); + if (rc == XML_STATUS_ERROR) + xml_failure(g_parser); + } +} +END_TEST + +/* Test that an outright lie in the encoding is faulted */ +START_TEST(test_not_utf16) { + const char *text = "<?xml version='1.0' encoding='utf-16'?>" + "<doc>Hi</doc>"; + + /* Use a handler to provoke the appropriate code paths */ + XML_SetXmlDeclHandler(g_parser, dummy_xdecl_handler); + expect_failure(text, XML_ERROR_INCORRECT_ENCODING, + "UTF-16 declared in UTF-8 not faulted"); +} +END_TEST + +/* Test that an unknown encoding is rejected */ +START_TEST(test_bad_encoding) { + const char *text = "<doc>Hi</doc>"; + + if (! XML_SetEncoding(g_parser, XCS("unknown-encoding"))) + fail("XML_SetEncoding failed"); + expect_failure(text, XML_ERROR_UNKNOWN_ENCODING, + "Unknown encoding not faulted"); +} +END_TEST + +/* Regression test for SF bug #481609, #774028. */ +START_TEST(test_latin1_umlauts) { + const char *text + = "<?xml version='1.0' encoding='iso-8859-1'?>\n" + "<e a='\xE4 \xF6 \xFC ä ö ü ä ö ü >'\n" + " >\xE4 \xF6 \xFC ä ö ü ä ö ü ></e>"; +#ifdef XML_UNICODE + /* Expected results in UTF-16 */ + const XML_Char *expected = XCS("\x00e4 \x00f6 \x00fc ") + XCS("\x00e4 \x00f6 \x00fc ") XCS("\x00e4 \x00f6 \x00fc >"); +#else + /* Expected results in UTF-8 */ + const XML_Char *expected = XCS("\xC3\xA4 \xC3\xB6 \xC3\xBC ") + XCS("\xC3\xA4 \xC3\xB6 \xC3\xBC ") XCS("\xC3\xA4 \xC3\xB6 \xC3\xBC >"); +#endif + + run_character_check(text, expected); + XML_ParserReset(g_parser, NULL); + run_attribute_check(text, expected); + /* Repeat with a default handler */ + XML_ParserReset(g_parser, NULL); + XML_SetDefaultHandler(g_parser, dummy_default_handler); + run_character_check(text, expected); + XML_ParserReset(g_parser, NULL); + XML_SetDefaultHandler(g_parser, dummy_default_handler); + run_attribute_check(text, expected); +} +END_TEST + +/* Test that an element name with a 4-byte UTF-8 character is rejected */ +START_TEST(test_long_utf8_character) { + const char *text + = "<?xml version='1.0' encoding='utf-8'?>\n" + /* 0xf0 0x90 0x80 0x80 = U+10000, the first Linear B character */ + "<do\xf0\x90\x80\x80/>"; + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "4-byte UTF-8 character in element name not faulted"); +} +END_TEST + +/* Test that a long latin-1 attribute (too long to convert in one go) + * is correctly converted + */ +START_TEST(test_long_latin1_attribute) { + const char *text + = "<?xml version='1.0' encoding='iso-8859-1'?>\n" + "<doc att='" + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" + /* Last character splits across a buffer boundary */ + "\xe4'>\n</doc>"; + + const XML_Char *expected = + /* 64 characters per line */ + /* clang-format off */ + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO") + /* clang-format on */ +#ifdef XML_UNICODE + XCS("\x00e4"); +#else + XCS("\xc3\xa4"); +#endif + + run_attribute_check(text, expected); +} +END_TEST + +/* Test that a long ASCII attribute (too long to convert in one go) + * is correctly converted + */ +START_TEST(test_long_ascii_attribute) { + const char *text + = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<doc att='" + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "01234'>\n</doc>"; + const XML_Char *expected = + /* 64 characters per line */ + /* clang-format off */ + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("01234"); + /* clang-format on */ + + run_attribute_check(text, expected); +} +END_TEST + +/* Regression test #1 for SF bug #653180. */ +START_TEST(test_line_number_after_parse) { + const char *text = "<tag>\n" + "\n" + "\n</tag>"; + XML_Size lineno; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + lineno = XML_GetCurrentLineNumber(g_parser); + if (lineno != 4) { + char buffer[100]; + snprintf(buffer, sizeof(buffer), + "expected 4 lines, saw %" XML_FMT_INT_MOD "u", lineno); + fail(buffer); + } +} +END_TEST + +/* Regression test #2 for SF bug #653180. */ +START_TEST(test_column_number_after_parse) { + const char *text = "<tag></tag>"; + XML_Size colno; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + colno = XML_GetCurrentColumnNumber(g_parser); + if (colno != 11) { + char buffer[100]; + snprintf(buffer, sizeof(buffer), + "expected 11 columns, saw %" XML_FMT_INT_MOD "u", colno); + fail(buffer); + } +} +END_TEST + +/* Regression test #3 for SF bug #653180. */ +START_TEST(test_line_and_column_numbers_inside_handlers) { + const char *text = "<a>\n" /* Unix end-of-line */ + " <b>\r\n" /* Windows end-of-line */ + " <c/>\r" /* Mac OS end-of-line */ + " </b>\n" + " <d>\n" + " <f/>\n" + " </d>\n" + "</a>"; + const StructDataEntry expected[] + = {{XCS("a"), 0, 1, STRUCT_START_TAG}, {XCS("b"), 2, 2, STRUCT_START_TAG}, + {XCS("c"), 4, 3, STRUCT_START_TAG}, {XCS("c"), 8, 3, STRUCT_END_TAG}, + {XCS("b"), 2, 4, STRUCT_END_TAG}, {XCS("d"), 2, 5, STRUCT_START_TAG}, + {XCS("f"), 4, 6, STRUCT_START_TAG}, {XCS("f"), 8, 6, STRUCT_END_TAG}, + {XCS("d"), 2, 7, STRUCT_END_TAG}, {XCS("a"), 0, 8, STRUCT_END_TAG}}; + const int expected_count = sizeof(expected) / sizeof(StructDataEntry); + StructData storage; + + StructData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetStartElementHandler(g_parser, start_element_event_handler2); + XML_SetEndElementHandler(g_parser, end_element_event_handler2); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + + StructData_CheckItems(&storage, expected, expected_count); + StructData_Dispose(&storage); +} +END_TEST + +/* Regression test #4 for SF bug #653180. */ +START_TEST(test_line_number_after_error) { + const char *text = "<a>\n" + " <b>\n" + " </a>"; /* missing </b> */ + XML_Size lineno; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Expected a parse error"); + + lineno = XML_GetCurrentLineNumber(g_parser); + if (lineno != 3) { + char buffer[100]; + snprintf(buffer, sizeof(buffer), + "expected 3 lines, saw %" XML_FMT_INT_MOD "u", lineno); + fail(buffer); + } +} +END_TEST + +/* Regression test #5 for SF bug #653180. */ +START_TEST(test_column_number_after_error) { + const char *text = "<a>\n" + " <b>\n" + " </a>"; /* missing </b> */ + XML_Size colno; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Expected a parse error"); + + colno = XML_GetCurrentColumnNumber(g_parser); + if (colno != 4) { + char buffer[100]; + snprintf(buffer, sizeof(buffer), + "expected 4 columns, saw %" XML_FMT_INT_MOD "u", colno); + fail(buffer); + } +} +END_TEST + +/* Regression test for SF bug #478332. */ +START_TEST(test_really_long_lines) { + /* This parses an input line longer than INIT_DATA_BUF_SIZE + characters long (defined to be 1024 in xmlparse.c). We take a + really cheesy approach to building the input buffer, because + this avoids writing bugs in buffer-filling code. + */ + const char *text + = "<e>" + /* 64 chars */ + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + /* until we have at least 1024 characters on the line: */ + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "</e>"; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test cdata processing across a buffer boundary */ +START_TEST(test_really_long_encoded_lines) { + /* As above, except that we want to provoke an output buffer + * overflow with a non-trivial encoding. For this we need to pass + * the whole cdata in one go, not byte-by-byte. + */ + void *buffer; + const char *text + = "<?xml version='1.0' encoding='iso-8859-1'?>" + "<e>" + /* 64 chars */ + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + /* until we have at least 1024 characters on the line: */ + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" + "</e>"; + int parse_len = (int)strlen(text); + + /* Need a cdata handler to provoke the code path we want to test */ + XML_SetCharacterDataHandler(g_parser, dummy_cdata_handler); + buffer = XML_GetBuffer(g_parser, parse_len); + if (buffer == NULL) + fail("Could not allocate parse buffer"); + assert(buffer != NULL); + memcpy(buffer, text, parse_len); + if (XML_ParseBuffer(g_parser, parse_len, XML_TRUE) == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* + * Element event tests. + */ + +START_TEST(test_end_element_events) { + const char *text = "<a><b><c/></b><d><f/></d></a>"; + const XML_Char *expected = XCS("/c/b/f/d/a"); + CharData storage; + + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetEndElementHandler(g_parser, end_element_event_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* + * Attribute tests. + */ + +/* Helper used by the following tests; this checks any "attr" and "refs" + attributes to make sure whitespace has been normalized. + + Return true if whitespace has been normalized in a string, using + the rules for attribute value normalization. The 'is_cdata' flag + is needed since CDATA attributes don't need to have multiple + whitespace characters collapsed to a single space, while other + attribute data types do. (Section 3.3.3 of the recommendation.) +*/ +static int +is_whitespace_normalized(const XML_Char *s, int is_cdata) { + int blanks = 0; + int at_start = 1; + while (*s) { + if (*s == XCS(' ')) + ++blanks; + else if (*s == XCS('\t') || *s == XCS('\n') || *s == XCS('\r')) + return 0; + else { + if (at_start) { + at_start = 0; + if (blanks && ! is_cdata) + /* illegal leading blanks */ + return 0; + } else if (blanks > 1 && ! is_cdata) + return 0; + blanks = 0; + } + ++s; + } + if (blanks && ! is_cdata) + return 0; + return 1; +} + +/* Check the attribute whitespace checker: */ +START_TEST(test_helper_is_whitespace_normalized) { + assert(is_whitespace_normalized(XCS("abc"), 0)); + assert(is_whitespace_normalized(XCS("abc"), 1)); + assert(is_whitespace_normalized(XCS("abc def ghi"), 0)); + assert(is_whitespace_normalized(XCS("abc def ghi"), 1)); + assert(! is_whitespace_normalized(XCS(" abc def ghi"), 0)); + assert(is_whitespace_normalized(XCS(" abc def ghi"), 1)); + assert(! is_whitespace_normalized(XCS("abc def ghi"), 0)); + assert(is_whitespace_normalized(XCS("abc def ghi"), 1)); + assert(! is_whitespace_normalized(XCS("abc def ghi "), 0)); + assert(is_whitespace_normalized(XCS("abc def ghi "), 1)); + assert(! is_whitespace_normalized(XCS(" "), 0)); + assert(is_whitespace_normalized(XCS(" "), 1)); + assert(! is_whitespace_normalized(XCS("\t"), 0)); + assert(! is_whitespace_normalized(XCS("\t"), 1)); + assert(! is_whitespace_normalized(XCS("\n"), 0)); + assert(! is_whitespace_normalized(XCS("\n"), 1)); + assert(! is_whitespace_normalized(XCS("\r"), 0)); + assert(! is_whitespace_normalized(XCS("\r"), 1)); + assert(! is_whitespace_normalized(XCS("abc\t def"), 1)); +} +END_TEST + +static void XMLCALL +check_attr_contains_normalized_whitespace(void *userData, const XML_Char *name, + const XML_Char **atts) { + int i; + UNUSED_P(userData); + UNUSED_P(name); + for (i = 0; atts[i] != NULL; i += 2) { + const XML_Char *attrname = atts[i]; + const XML_Char *value = atts[i + 1]; + if (xcstrcmp(XCS("attr"), attrname) == 0 + || xcstrcmp(XCS("ents"), attrname) == 0 + || xcstrcmp(XCS("refs"), attrname) == 0) { + if (! is_whitespace_normalized(value, 0)) { + char buffer[256]; + snprintf(buffer, sizeof(buffer), + "attribute value not normalized: %" XML_FMT_STR + "='%" XML_FMT_STR "'", + attrname, value); + fail(buffer); + } + } + } +} + +START_TEST(test_attr_whitespace_normalization) { + const char *text + = "<!DOCTYPE doc [\n" + " <!ATTLIST doc\n" + " attr NMTOKENS #REQUIRED\n" + " ents ENTITIES #REQUIRED\n" + " refs IDREFS #REQUIRED>\n" + "]>\n" + "<doc attr=' a b c\t\td\te\t' refs=' id-1 \t id-2\t\t' \n" + " ents=' ent-1 \t\r\n" + " ent-2 ' >\n" + " <e id='id-1'/>\n" + " <e id='id-2'/>\n" + "</doc>"; + + XML_SetStartElementHandler(g_parser, + check_attr_contains_normalized_whitespace); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* + * XML declaration tests. + */ + +START_TEST(test_xmldecl_misplaced) { + expect_failure("\n" + "<?xml version='1.0'?>\n" + "<a/>", + XML_ERROR_MISPLACED_XML_PI, + "failed to report misplaced XML declaration"); +} +END_TEST + +START_TEST(test_xmldecl_invalid) { + expect_failure("<?xml version='1.0' \xc3\xa7?>\n<doc/>", XML_ERROR_XML_DECL, + "Failed to report invalid XML declaration"); +} +END_TEST + +START_TEST(test_xmldecl_missing_attr) { + expect_failure("<?xml ='1.0'?>\n<doc/>\n", XML_ERROR_XML_DECL, + "Failed to report missing XML declaration attribute"); +} +END_TEST + +START_TEST(test_xmldecl_missing_value) { + expect_failure("<?xml version='1.0' encoding='us-ascii' standalone?>\n" + "<doc/>", + XML_ERROR_XML_DECL, + "Failed to report missing attribute value"); +} +END_TEST + +/* Regression test for SF bug #584832. */ +START_TEST(test_unknown_encoding_internal_entity) { + const char *text = "<?xml version='1.0' encoding='unsupported-encoding'?>\n" + "<!DOCTYPE test [<!ENTITY foo 'bar'>]>\n" + "<test a='&foo;'/>"; + + XML_SetUnknownEncodingHandler(g_parser, UnknownEncodingHandler, NULL); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test unrecognised encoding handler */ +START_TEST(test_unrecognised_encoding_internal_entity) { + const char *text = "<?xml version='1.0' encoding='unsupported-encoding'?>\n" + "<!DOCTYPE test [<!ENTITY foo 'bar'>]>\n" + "<test a='&foo;'/>"; + + XML_SetUnknownEncodingHandler(g_parser, UnrecognisedEncodingHandler, NULL); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Unrecognised encoding not rejected"); +} +END_TEST + +/* Regression test for SF bug #620106. */ +START_TEST(test_ext_entity_set_encoding) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + ExtTest test_data + = {/* This text says it's an unsupported encoding, but it's really + UTF-8, which we tell Expat using XML_SetEncoding(). + */ + "<?xml encoding='iso-8859-3'?>\xC3\xA9", XCS("utf-8"), NULL}; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x00e9"); +#else + const XML_Char *expected = XCS("\xc3\xa9"); +#endif + + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); + run_ext_character_check(text, &test_data, expected); +} +END_TEST + +/* Test external entities with no handler */ +START_TEST(test_ext_entity_no_handler) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + + XML_SetDefaultHandler(g_parser, dummy_default_handler); + run_character_check(text, XCS("")); +} +END_TEST + +/* Test UTF-8 BOM is accepted */ +START_TEST(test_ext_entity_set_bom) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + ExtTest test_data = {"\xEF\xBB\xBF" /* BOM */ + "<?xml encoding='iso-8859-3'?>" + "\xC3\xA9", + XCS("utf-8"), NULL}; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x00e9"); +#else + const XML_Char *expected = XCS("\xc3\xa9"); +#endif + + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); + run_ext_character_check(text, &test_data, expected); +} +END_TEST + +/* Test that bad encodings are faulted */ +START_TEST(test_ext_entity_bad_encoding) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + ExtFaults fault + = {"<?xml encoding='iso-8859-3'?>u", "Unsupported encoding not faulted", + XCS("unknown"), XML_ERROR_UNKNOWN_ENCODING}; + + XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter); + XML_SetUserData(g_parser, &fault); + expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, + "Bad encoding should not have been accepted"); +} +END_TEST + +/* Try handing an invalid encoding to an external entity parser */ +START_TEST(test_ext_entity_bad_encoding_2) { + const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc>&entity;</doc>"; + ExtFaults fault + = {"<!ELEMENT doc (#PCDATA)*>", "Unknown encoding not faulted", + XCS("unknown-encoding"), XML_ERROR_UNKNOWN_ENCODING}; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter); + XML_SetUserData(g_parser, &fault); + expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, + "Bad encoding not faulted in external entity handler"); +} +END_TEST + +/* Test that no error is reported for unknown entities if we don't + read an external subset. This was fixed in Expat 1.95.5. +*/ +START_TEST(test_wfc_undeclared_entity_unread_external_subset) { + const char *text = "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc>&entity;</doc>"; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test that an error is reported for unknown entities if we don't + have an external subset. +*/ +START_TEST(test_wfc_undeclared_entity_no_external_subset) { + expect_failure("<doc>&entity;</doc>", XML_ERROR_UNDEFINED_ENTITY, + "Parser did not report undefined entity w/out a DTD."); +} +END_TEST + +/* Test that an error is reported for unknown entities if we don't + read an external subset, but have been declared standalone. +*/ +START_TEST(test_wfc_undeclared_entity_standalone) { + const char *text + = "<?xml version='1.0' encoding='us-ascii' standalone='yes'?>\n" + "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc>&entity;</doc>"; + + expect_failure(text, XML_ERROR_UNDEFINED_ENTITY, + "Parser did not report undefined entity (standalone)."); +} +END_TEST + +/* Test that an error is reported for unknown entities if we have read + an external subset, and standalone is true. +*/ +START_TEST(test_wfc_undeclared_entity_with_external_subset_standalone) { + const char *text + = "<?xml version='1.0' encoding='us-ascii' standalone='yes'?>\n" + "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc>&entity;</doc>"; + ExtTest test_data = {"<!ELEMENT doc (#PCDATA)*>", NULL, NULL}; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetUserData(g_parser, &test_data); + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); + expect_failure(text, XML_ERROR_UNDEFINED_ENTITY, + "Parser did not report undefined entity (external DTD)."); +} +END_TEST + +/* Test that external entity handling is not done if the parsing flag + * is set to UNLESS_STANDALONE + */ +START_TEST(test_entity_with_external_subset_unless_standalone) { + const char *text + = "<?xml version='1.0' encoding='us-ascii' standalone='yes'?>\n" + "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc>&entity;</doc>"; + ExtTest test_data = {"<!ENTITY entity 'bar'>", NULL, NULL}; + + XML_SetParamEntityParsing(g_parser, + XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE); + XML_SetUserData(g_parser, &test_data); + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); + expect_failure(text, XML_ERROR_UNDEFINED_ENTITY, + "Parser did not report undefined entity"); +} +END_TEST + +/* Test that no error is reported for unknown entities if we have read + an external subset, and standalone is false. +*/ +START_TEST(test_wfc_undeclared_entity_with_external_subset) { + const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc>&entity;</doc>"; + ExtTest test_data = {"<!ELEMENT doc (#PCDATA)*>", NULL, NULL}; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); + run_ext_character_check(text, &test_data, XCS("")); +} +END_TEST + +/* Test that an error is reported if our NotStandalone handler fails */ +START_TEST(test_not_standalone_handler_reject) { + const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc>&entity;</doc>"; + ExtTest test_data = {"<!ELEMENT doc (#PCDATA)*>", NULL, NULL}; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetUserData(g_parser, &test_data); + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); + XML_SetNotStandaloneHandler(g_parser, reject_not_standalone_handler); + expect_failure(text, XML_ERROR_NOT_STANDALONE, + "NotStandalone handler failed to reject"); + + /* Try again but without external entity handling */ + XML_ParserReset(g_parser, NULL); + XML_SetNotStandaloneHandler(g_parser, reject_not_standalone_handler); + expect_failure(text, XML_ERROR_NOT_STANDALONE, + "NotStandalone handler failed to reject"); +} +END_TEST + +/* Test that no error is reported if our NotStandalone handler succeeds */ +START_TEST(test_not_standalone_handler_accept) { + const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc>&entity;</doc>"; + ExtTest test_data = {"<!ELEMENT doc (#PCDATA)*>", NULL, NULL}; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); + XML_SetNotStandaloneHandler(g_parser, accept_not_standalone_handler); + run_ext_character_check(text, &test_data, XCS("")); + + /* Repeat without the external entity handler */ + XML_ParserReset(g_parser, NULL); + XML_SetNotStandaloneHandler(g_parser, accept_not_standalone_handler); + run_character_check(text, XCS("")); +} +END_TEST + +START_TEST(test_wfc_no_recursive_entity_refs) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY entity '&entity;'>\n" + "]>\n" + "<doc>&entity;</doc>"; + + expect_failure(text, XML_ERROR_RECURSIVE_ENTITY_REF, + "Parser did not report recursive entity reference."); +} +END_TEST + +START_TEST(test_recursive_external_parameter_entity_2) { + struct TestCase { + const char *doc; + enum XML_Status expectedStatus; + }; + + struct TestCase cases[] = { + {"<!ENTITY % p1 '%p1;'>", XML_STATUS_ERROR}, + {"<!ENTITY % p1 '%p1;'>" + "<!ENTITY % p1 'first declaration wins'>", + XML_STATUS_ERROR}, + {"<!ENTITY % p1 'first declaration wins'>" + "<!ENTITY % p1 '%p1;'>", + XML_STATUS_OK}, + {"<!ENTITY % p1 '%p1;'>", XML_STATUS_OK}, + }; + + for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { + const char *const doc = cases[i].doc; + const enum XML_Status expectedStatus = cases[i].expectedStatus; + set_subtest("%s", doc); + + XML_Parser parser = XML_ParserCreate(NULL); + assert_true(parser != NULL); + + XML_Parser ext_parser = XML_ExternalEntityParserCreate(parser, NULL, NULL); + assert_true(ext_parser != NULL); + + const enum XML_Status actualStatus + = _XML_Parse_SINGLE_BYTES(ext_parser, doc, (int)strlen(doc), XML_TRUE); + + assert_true(actualStatus == expectedStatus); + if (actualStatus != XML_STATUS_OK) { + assert_true(XML_GetErrorCode(ext_parser) + == XML_ERROR_RECURSIVE_ENTITY_REF); + } + + XML_ParserFree(ext_parser); + XML_ParserFree(parser); + } +} +END_TEST + +/* Test incomplete external entities are faulted */ +START_TEST(test_ext_entity_invalid_parse) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + const ExtFaults faults[] + = {{"<", "Incomplete element declaration not faulted", NULL, + XML_ERROR_UNCLOSED_TOKEN}, + {"<\xe2\x82", /* First two bytes of a three-byte char */ + "Incomplete character not faulted", NULL, XML_ERROR_PARTIAL_CHAR}, + {"<tag>\xe2\x82", "Incomplete character in CDATA not faulted", NULL, + XML_ERROR_PARTIAL_CHAR}, + {NULL, NULL, NULL, XML_ERROR_NONE}}; + const ExtFaults *fault = faults; + + for (; fault->parse_text != NULL; fault++) { + set_subtest("\"%s\"", fault->parse_text); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter); + XML_SetUserData(g_parser, (void *)fault); + expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, + "Parser did not report external entity error"); + XML_ParserReset(g_parser, NULL); + } +} +END_TEST + +/* Regression test for SF bug #483514. */ +START_TEST(test_dtd_default_handling) { + const char *text = "<!DOCTYPE doc [\n" + "<!ENTITY e SYSTEM 'http://example.org/e'>\n" + "<!NOTATION n SYSTEM 'http://example.org/n'>\n" + "<!ELEMENT doc EMPTY>\n" + "<!ATTLIST doc a CDATA #IMPLIED>\n" + "<?pi in dtd?>\n" + "<!--comment in dtd-->\n" + "]><doc/>"; + + XML_SetDefaultHandler(g_parser, accumulate_characters); + XML_SetStartDoctypeDeclHandler(g_parser, dummy_start_doctype_handler); + XML_SetEndDoctypeDeclHandler(g_parser, dummy_end_doctype_handler); + XML_SetEntityDeclHandler(g_parser, dummy_entity_decl_handler); + XML_SetNotationDeclHandler(g_parser, dummy_notation_decl_handler); + XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); + XML_SetAttlistDeclHandler(g_parser, dummy_attlist_decl_handler); + XML_SetProcessingInstructionHandler(g_parser, dummy_pi_handler); + XML_SetCommentHandler(g_parser, dummy_comment_handler); + XML_SetStartCdataSectionHandler(g_parser, dummy_start_cdata_handler); + XML_SetEndCdataSectionHandler(g_parser, dummy_end_cdata_handler); + run_character_check(text, XCS("\n\n\n\n\n\n\n<doc/>")); +} +END_TEST + +/* Test handling of attribute declarations */ +START_TEST(test_dtd_attr_handling) { + const char *prolog = "<!DOCTYPE doc [\n" + "<!ELEMENT doc EMPTY>\n"; + AttTest attr_data[] + = {{"<!ATTLIST doc a ( one | two | three ) #REQUIRED>\n" + "]>" + "<doc a='two'/>", + XCS("doc"), XCS("a"), + XCS("(one|two|three)"), /* Extraneous spaces will be removed */ + NULL, XML_TRUE}, + {"<!NOTATION foo SYSTEM 'http://example.org/foo'>\n" + "<!ATTLIST doc a NOTATION (foo) #IMPLIED>\n" + "]>" + "<doc/>", + XCS("doc"), XCS("a"), XCS("NOTATION(foo)"), NULL, XML_FALSE}, + {"<!ATTLIST doc a NOTATION (foo) 'bar'>\n" + "]>" + "<doc/>", + XCS("doc"), XCS("a"), XCS("NOTATION(foo)"), XCS("bar"), XML_FALSE}, + {"<!ATTLIST doc a CDATA '\xdb\xb2'>\n" + "]>" + "<doc/>", + XCS("doc"), XCS("a"), XCS("CDATA"), +#ifdef XML_UNICODE + XCS("\x06f2"), +#else + XCS("\xdb\xb2"), +#endif + XML_FALSE}, + {NULL, NULL, NULL, NULL, NULL, XML_FALSE}}; + AttTest *test; + + for (test = attr_data; test->definition != NULL; test++) { + set_subtest("%s", test->definition); + XML_SetAttlistDeclHandler(g_parser, verify_attlist_decl_handler); + XML_SetUserData(g_parser, test); + if (_XML_Parse_SINGLE_BYTES(g_parser, prolog, (int)strlen(prolog), + XML_FALSE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + if (_XML_Parse_SINGLE_BYTES(g_parser, test->definition, + (int)strlen(test->definition), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + XML_ParserReset(g_parser, NULL); + } +} +END_TEST + +/* See related SF bug #673791. + When namespace processing is enabled, setting the namespace URI for + a prefix is not allowed; this test ensures that it *is* allowed + when namespace processing is not enabled. + (See Namespaces in XML, section 2.) +*/ +START_TEST(test_empty_ns_without_namespaces) { + const char *text = "<doc xmlns:prefix='http://example.org/'>\n" + " <e xmlns:prefix=''/>\n" + "</doc>"; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Regression test for SF bug #824420. + Checks that an xmlns:prefix attribute set in an attribute's default + value isn't misinterpreted. +*/ +START_TEST(test_ns_in_attribute_default_without_namespaces) { + const char *text = "<!DOCTYPE e:element [\n" + " <!ATTLIST e:element\n" + " xmlns:e CDATA 'http://example.org/'>\n" + " ]>\n" + "<e:element/>"; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Regression test for SF bug #1515266: missing check of stopped + parser in doContext() 'for' loop. */ +START_TEST(test_stop_parser_between_char_data_calls) { + /* The sample data must be big enough that there are two calls to + the character data handler from within the inner "for" loop of + the XML_TOK_DATA_CHARS case in doContent(), and the character + handler must stop the parser and clear the character data + handler. + */ + const char *text = long_character_data_text; + + XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); + g_resumable = XML_FALSE; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + xml_failure(g_parser); + if (XML_GetErrorCode(g_parser) != XML_ERROR_ABORTED) + xml_failure(g_parser); +} +END_TEST + +/* Regression test for SF bug #1515266: missing check of stopped + parser in doContext() 'for' loop. */ +START_TEST(test_suspend_parser_between_char_data_calls) { + /* The sample data must be big enough that there are two calls to + the character data handler from within the inner "for" loop of + the XML_TOK_DATA_CHARS case in doContent(), and the character + handler must stop the parser and clear the character data + handler. + */ + const char *text = long_character_data_text; + + XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); + g_resumable = XML_TRUE; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_SUSPENDED) + xml_failure(g_parser); + if (XML_GetErrorCode(g_parser) != XML_ERROR_NONE) + xml_failure(g_parser); + /* Try parsing directly */ + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Attempt to continue parse while suspended not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_SUSPENDED) + fail("Suspended parse not faulted with correct error"); +} +END_TEST + +/* Test repeated calls to XML_StopParser are handled correctly */ +START_TEST(test_repeated_stop_parser_between_char_data_calls) { + const char *text = long_character_data_text; + + XML_SetCharacterDataHandler(g_parser, parser_stop_character_handler); + g_resumable = XML_FALSE; + g_abortable = XML_FALSE; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Failed to double-stop parser"); + + XML_ParserReset(g_parser, NULL); + XML_SetCharacterDataHandler(g_parser, parser_stop_character_handler); + g_resumable = XML_TRUE; + g_abortable = XML_FALSE; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_SUSPENDED) + fail("Failed to double-suspend parser"); + + XML_ParserReset(g_parser, NULL); + XML_SetCharacterDataHandler(g_parser, parser_stop_character_handler); + g_resumable = XML_TRUE; + g_abortable = XML_TRUE; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Failed to suspend-abort parser"); +} +END_TEST + +START_TEST(test_good_cdata_ascii) { + const char *text = "<a><![CDATA[<greeting>Hello, world!</greeting>]]></a>"; + const XML_Char *expected = XCS("<greeting>Hello, world!</greeting>"); + + CharData storage; + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetCharacterDataHandler(g_parser, accumulate_characters); + /* Add start and end handlers for coverage */ + XML_SetStartCdataSectionHandler(g_parser, dummy_start_cdata_handler); + XML_SetEndCdataSectionHandler(g_parser, dummy_end_cdata_handler); + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); + + /* Try again, this time with a default handler */ + XML_ParserReset(g_parser, NULL); + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetCharacterDataHandler(g_parser, accumulate_characters); + XML_SetDefaultHandler(g_parser, dummy_default_handler); + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_good_cdata_utf16) { + /* Test data is: + * <?xml version='1.0' encoding='utf-16'?> + * <a><![CDATA[hello]]></a> + */ + const char text[] + = "\0<\0?\0x\0m\0l\0" + " \0v\0e\0r\0s\0i\0o\0n\0=\0'\0\x31\0.\0\x30\0'\0" + " \0e\0n\0c\0o\0d\0i\0n\0g\0=\0'\0u\0t\0f\0-\0" + "1\0" + "6\0'" + "\0?\0>\0\n" + "\0<\0a\0>\0<\0!\0[\0C\0D\0A\0T\0A\0[\0h\0e\0l\0l\0o\0]\0]\0>\0<\0/\0a\0>"; + const XML_Char *expected = XCS("hello"); + + CharData storage; + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetCharacterDataHandler(g_parser, accumulate_characters); + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_good_cdata_utf16_le) { + /* Test data is: + * <?xml version='1.0' encoding='utf-16'?> + * <a><![CDATA[hello]]></a> + */ + const char text[] + = "<\0?\0x\0m\0l\0" + " \0v\0e\0r\0s\0i\0o\0n\0=\0'\0\x31\0.\0\x30\0'\0" + " \0e\0n\0c\0o\0d\0i\0n\0g\0=\0'\0u\0t\0f\0-\0" + "1\0" + "6\0'" + "\0?\0>\0\n" + "\0<\0a\0>\0<\0!\0[\0C\0D\0A\0T\0A\0[\0h\0e\0l\0l\0o\0]\0]\0>\0<\0/\0a\0>\0"; + const XML_Char *expected = XCS("hello"); + + CharData storage; + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetCharacterDataHandler(g_parser, accumulate_characters); + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test UTF16 conversion of a long cdata string */ + +/* 16 characters: handy macro to reduce visual clutter */ +#define A_TO_P_IN_UTF16 "\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P" + +START_TEST(test_long_cdata_utf16) { + /* Test data is: + * <?xlm version='1.0' encoding='utf-16'?> + * <a><![CDATA[ + * ABCDEFGHIJKLMNOP + * ]]></a> + */ + const char text[] + = "\0<\0?\0x\0m\0l\0 " + "\0v\0e\0r\0s\0i\0o\0n\0=\0'\0\x31\0.\0\x30\0'\0 " + "\0e\0n\0c\0o\0d\0i\0n\0g\0=\0'\0u\0t\0f\0-\0\x31\0\x36\0'\0?\0>" + "\0<\0a\0>\0<\0!\0[\0C\0D\0A\0T\0A\0[" + /* 64 characters per line */ + /* clang-format off */ + A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 + A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 + A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 + A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 + A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 + A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 + A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 + A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 + A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 + A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 + A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 + A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 + A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 + A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 + A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 + A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 + A_TO_P_IN_UTF16 + /* clang-format on */ + "\0]\0]\0>\0<\0/\0a\0>"; + const XML_Char *expected = + /* clang-format off */ + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") + XCS("ABCDEFGHIJKLMNOP"); + /* clang-format on */ + CharData storage; + void *buffer; + + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetCharacterDataHandler(g_parser, accumulate_characters); + buffer = XML_GetBuffer(g_parser, sizeof(text) - 1); + if (buffer == NULL) + fail("Could not allocate parse buffer"); + assert(buffer != NULL); + memcpy(buffer, text, sizeof(text) - 1); + if (XML_ParseBuffer(g_parser, sizeof(text) - 1, XML_TRUE) == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test handling of multiple unit UTF-16 characters */ +START_TEST(test_multichar_cdata_utf16) { + /* Test data is: + * <?xml version='1.0' encoding='utf-16'?> + * <a><![CDATA[{MINIM}{CROTCHET}]]></a> + * + * where {MINIM} is U+1d15e (a minim or half-note) + * UTF-16: 0xd834 0xdd5e + * UTF-8: 0xf0 0x9d 0x85 0x9e + * and {CROTCHET} is U+1d15f (a crotchet or quarter-note) + * UTF-16: 0xd834 0xdd5f + * UTF-8: 0xf0 0x9d 0x85 0x9f + */ + const char text[] = "\0<\0?\0x\0m\0l\0" + " \0v\0e\0r\0s\0i\0o\0n\0=\0'\0\x31\0.\0\x30\0'\0" + " \0e\0n\0c\0o\0d\0i\0n\0g\0=\0'\0u\0t\0f\0-\0" + "1\0" + "6\0'" + "\0?\0>\0\n" + "\0<\0a\0>\0<\0!\0[\0C\0D\0A\0T\0A\0[" + "\xd8\x34\xdd\x5e\xd8\x34\xdd\x5f" + "\0]\0]\0>\0<\0/\0a\0>"; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\xd834\xdd5e\xd834\xdd5f"); +#else + const XML_Char *expected = XCS("\xf0\x9d\x85\x9e\xf0\x9d\x85\x9f"); +#endif + CharData storage; + + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetCharacterDataHandler(g_parser, accumulate_characters); + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test that an element name with a UTF-16 surrogate pair is rejected */ +START_TEST(test_utf16_bad_surrogate_pair) { + /* Test data is: + * <?xml version='1.0' encoding='utf-16'?> + * <a><![CDATA[{BADLINB}]]></a> + * + * where {BADLINB} is U+10000 (the first Linear B character) + * with the UTF-16 surrogate pair in the wrong order, i.e. + * 0xdc00 0xd800 + */ + const char text[] = "\0<\0?\0x\0m\0l\0" + " \0v\0e\0r\0s\0i\0o\0n\0=\0'\0\x31\0.\0\x30\0'\0" + " \0e\0n\0c\0o\0d\0i\0n\0g\0=\0'\0u\0t\0f\0-\0" + "1\0" + "6\0'" + "\0?\0>\0\n" + "\0<\0a\0>\0<\0!\0[\0C\0D\0A\0T\0A\0[" + "\xdc\x00\xd8\x00" + "\0]\0]\0>\0<\0/\0a\0>"; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + != XML_STATUS_ERROR) + fail("Reversed UTF-16 surrogate pair not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_INVALID_TOKEN) + xml_failure(g_parser); +} +END_TEST + +START_TEST(test_bad_cdata) { + struct CaseData { + const char *text; + enum XML_Error expectedError; + }; + + struct CaseData cases[] + = {{"<a><", XML_ERROR_UNCLOSED_TOKEN}, + {"<a><!", XML_ERROR_UNCLOSED_TOKEN}, + {"<a><![", XML_ERROR_UNCLOSED_TOKEN}, + {"<a><![C", XML_ERROR_UNCLOSED_TOKEN}, + {"<a><![CD", XML_ERROR_UNCLOSED_TOKEN}, + {"<a><![CDA", XML_ERROR_UNCLOSED_TOKEN}, + {"<a><![CDAT", XML_ERROR_UNCLOSED_TOKEN}, + {"<a><![CDATA", XML_ERROR_UNCLOSED_TOKEN}, + + {"<a><![CDATA[", XML_ERROR_UNCLOSED_CDATA_SECTION}, + {"<a><![CDATA[]", XML_ERROR_UNCLOSED_CDATA_SECTION}, + {"<a><![CDATA[]]", XML_ERROR_UNCLOSED_CDATA_SECTION}, + + {"<a><!<a/>", XML_ERROR_INVALID_TOKEN}, + {"<a><![<a/>", XML_ERROR_UNCLOSED_TOKEN}, /* ?! */ + {"<a><![C<a/>", XML_ERROR_UNCLOSED_TOKEN}, /* ?! */ + {"<a><![CD<a/>", XML_ERROR_INVALID_TOKEN}, + {"<a><![CDA<a/>", XML_ERROR_INVALID_TOKEN}, + {"<a><![CDAT<a/>", XML_ERROR_INVALID_TOKEN}, + {"<a><![CDATA<a/>", XML_ERROR_INVALID_TOKEN}, + + {"<a><![CDATA[<a/>", XML_ERROR_UNCLOSED_CDATA_SECTION}, + {"<a><![CDATA[]<a/>", XML_ERROR_UNCLOSED_CDATA_SECTION}, + {"<a><![CDATA[]]<a/>", XML_ERROR_UNCLOSED_CDATA_SECTION}}; + + size_t i = 0; + for (; i < sizeof(cases) / sizeof(struct CaseData); i++) { + set_subtest("%s", cases[i].text); + const enum XML_Status actualStatus = _XML_Parse_SINGLE_BYTES( + g_parser, cases[i].text, (int)strlen(cases[i].text), XML_TRUE); + const enum XML_Error actualError = XML_GetErrorCode(g_parser); + + assert(actualStatus == XML_STATUS_ERROR); + + if (actualError != cases[i].expectedError) { + char message[100]; + snprintf(message, sizeof(message), + "Expected error %d but got error %d for case %u: \"%s\"\n", + cases[i].expectedError, actualError, (unsigned int)i + 1, + cases[i].text); + fail(message); + } + + XML_ParserReset(g_parser, NULL); + } +} +END_TEST + +/* Test failures in UTF-16 CDATA */ +START_TEST(test_bad_cdata_utf16) { + struct CaseData { + size_t text_bytes; + const char *text; + enum XML_Error expected_error; + }; + + const char prolog[] = "\0<\0?\0x\0m\0l\0" + " \0v\0e\0r\0s\0i\0o\0n\0=\0'\0\x31\0.\0\x30\0'\0" + " \0e\0n\0c\0o\0d\0i\0n\0g\0=\0'\0u\0t\0f\0-\0" + "1\0" + "6\0'" + "\0?\0>\0\n" + "\0<\0a\0>"; + struct CaseData cases[] = { + {1, "\0", XML_ERROR_UNCLOSED_TOKEN}, + {2, "\0<", XML_ERROR_UNCLOSED_TOKEN}, + {3, "\0<\0", XML_ERROR_UNCLOSED_TOKEN}, + {4, "\0<\0!", XML_ERROR_UNCLOSED_TOKEN}, + {5, "\0<\0!\0", XML_ERROR_UNCLOSED_TOKEN}, + {6, "\0<\0!\0[", XML_ERROR_UNCLOSED_TOKEN}, + {7, "\0<\0!\0[\0", XML_ERROR_UNCLOSED_TOKEN}, + {8, "\0<\0!\0[\0C", XML_ERROR_UNCLOSED_TOKEN}, + {9, "\0<\0!\0[\0C\0", XML_ERROR_UNCLOSED_TOKEN}, + {10, "\0<\0!\0[\0C\0D", XML_ERROR_UNCLOSED_TOKEN}, + {11, "\0<\0!\0[\0C\0D\0", XML_ERROR_UNCLOSED_TOKEN}, + {12, "\0<\0!\0[\0C\0D\0A", XML_ERROR_UNCLOSED_TOKEN}, + {13, "\0<\0!\0[\0C\0D\0A\0", XML_ERROR_UNCLOSED_TOKEN}, + {14, "\0<\0!\0[\0C\0D\0A\0T", XML_ERROR_UNCLOSED_TOKEN}, + {15, "\0<\0!\0[\0C\0D\0A\0T\0", XML_ERROR_UNCLOSED_TOKEN}, + {16, "\0<\0!\0[\0C\0D\0A\0T\0A", XML_ERROR_UNCLOSED_TOKEN}, + {17, "\0<\0!\0[\0C\0D\0A\0T\0A\0", XML_ERROR_UNCLOSED_TOKEN}, + {18, "\0<\0!\0[\0C\0D\0A\0T\0A\0[", XML_ERROR_UNCLOSED_CDATA_SECTION}, + {19, "\0<\0!\0[\0C\0D\0A\0T\0A\0[\0", XML_ERROR_UNCLOSED_CDATA_SECTION}, + {20, "\0<\0!\0[\0C\0D\0A\0T\0A\0[\0Z", XML_ERROR_UNCLOSED_CDATA_SECTION}, + /* Now add a four-byte UTF-16 character */ + {21, "\0<\0!\0[\0C\0D\0A\0T\0A\0[\0Z\xd8", + XML_ERROR_UNCLOSED_CDATA_SECTION}, + {22, "\0<\0!\0[\0C\0D\0A\0T\0A\0[\0Z\xd8\x34", XML_ERROR_PARTIAL_CHAR}, + {23, "\0<\0!\0[\0C\0D\0A\0T\0A\0[\0Z\xd8\x34\xdd", + XML_ERROR_PARTIAL_CHAR}, + {24, "\0<\0!\0[\0C\0D\0A\0T\0A\0[\0Z\xd8\x34\xdd\x5e", + XML_ERROR_UNCLOSED_CDATA_SECTION}}; + size_t i; + + for (i = 0; i < sizeof(cases) / sizeof(struct CaseData); i++) { + set_subtest("case %lu", (long unsigned)(i + 1)); + enum XML_Status actual_status; + enum XML_Error actual_error; + + if (_XML_Parse_SINGLE_BYTES(g_parser, prolog, (int)sizeof(prolog) - 1, + XML_FALSE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + actual_status = _XML_Parse_SINGLE_BYTES(g_parser, cases[i].text, + (int)cases[i].text_bytes, XML_TRUE); + assert(actual_status == XML_STATUS_ERROR); + actual_error = XML_GetErrorCode(g_parser); + if (actual_error != cases[i].expected_error) { + char message[1024]; + + snprintf(message, sizeof(message), + "Expected error %d (%" XML_FMT_STR "), got %d (%" XML_FMT_STR + ") for case %lu\n", + cases[i].expected_error, + XML_ErrorString(cases[i].expected_error), actual_error, + XML_ErrorString(actual_error), (long unsigned)(i + 1)); + fail(message); + } + XML_ParserReset(g_parser, NULL); + } +} +END_TEST + +/* Test stopping the parser in cdata handler */ +START_TEST(test_stop_parser_between_cdata_calls) { + const char *text = long_cdata_text; + + XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); + g_resumable = XML_FALSE; + expect_failure(text, XML_ERROR_ABORTED, "Parse not aborted in CDATA handler"); +} +END_TEST + +/* Test suspending the parser in cdata handler */ +START_TEST(test_suspend_parser_between_cdata_calls) { + const char *text = long_cdata_text; + enum XML_Status result; + + XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); + g_resumable = XML_TRUE; + result = _XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE); + if (result != XML_STATUS_SUSPENDED) { + if (result == XML_STATUS_ERROR) + xml_failure(g_parser); + fail("Parse not suspended in CDATA handler"); + } + if (XML_GetErrorCode(g_parser) != XML_ERROR_NONE) + xml_failure(g_parser); +} +END_TEST + +/* Test memory allocation functions */ +START_TEST(test_memory_allocation) { + char *buffer = (char *)XML_MemMalloc(g_parser, 256); + char *p; + + if (buffer == NULL) { + fail("Allocation failed"); + } else { + /* Try writing to memory; some OSes try to cheat! */ + buffer[0] = 'T'; + buffer[1] = 'E'; + buffer[2] = 'S'; + buffer[3] = 'T'; + buffer[4] = '\0'; + if (strcmp(buffer, "TEST") != 0) { + fail("Memory not writable"); + } else { + p = (char *)XML_MemRealloc(g_parser, buffer, 512); + if (p == NULL) { + fail("Reallocation failed"); + } else { + /* Write again, just to be sure */ + buffer = p; + buffer[0] = 'V'; + if (strcmp(buffer, "VEST") != 0) { + fail("Reallocated memory not writable"); + } + } + } + XML_MemFree(g_parser, buffer); + } +} +END_TEST + +/* Test XML_DefaultCurrent() passes handling on correctly */ +START_TEST(test_default_current) { + const char *text = "<doc>hell]</doc>"; + const char *entity_text = "<!DOCTYPE doc [\n" + "<!ENTITY entity '%'>\n" + "]>\n" + "<doc>&entity;</doc>"; + + set_subtest("with defaulting"); + { + struct handler_record_list storage; + storage.count = 0; + XML_SetDefaultHandler(g_parser, record_default_handler); + XML_SetCharacterDataHandler(g_parser, record_cdata_handler); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + int i = 0; + assert_record_handler_called(&storage, i++, "record_default_handler", 5); + // we should have gotten one or more cdata callbacks, totaling 5 chars + int cdata_len_remaining = 5; + while (cdata_len_remaining > 0) { + const struct handler_record_entry *c_entry + = handler_record_get(&storage, i++); + assert_true(strcmp(c_entry->name, "record_cdata_handler") == 0); + assert_true(c_entry->arg > 0); + assert_true(c_entry->arg <= cdata_len_remaining); + cdata_len_remaining -= c_entry->arg; + // default handler must follow, with the exact same len argument. + assert_record_handler_called(&storage, i++, "record_default_handler", + c_entry->arg); + } + assert_record_handler_called(&storage, i++, "record_default_handler", 6); + assert_true(storage.count == i); + } + + /* Again, without the defaulting */ + set_subtest("no defaulting"); + { + struct handler_record_list storage; + storage.count = 0; + XML_ParserReset(g_parser, NULL); + XML_SetDefaultHandler(g_parser, record_default_handler); + XML_SetCharacterDataHandler(g_parser, record_cdata_nodefault_handler); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + int i = 0; + assert_record_handler_called(&storage, i++, "record_default_handler", 5); + // we should have gotten one or more cdata callbacks, totaling 5 chars + int cdata_len_remaining = 5; + while (cdata_len_remaining > 0) { + const struct handler_record_entry *c_entry + = handler_record_get(&storage, i++); + assert_true(strcmp(c_entry->name, "record_cdata_nodefault_handler") == 0); + assert_true(c_entry->arg > 0); + assert_true(c_entry->arg <= cdata_len_remaining); + cdata_len_remaining -= c_entry->arg; + } + assert_record_handler_called(&storage, i++, "record_default_handler", 6); + assert_true(storage.count == i); + } + + /* Now with an internal entity to complicate matters */ + set_subtest("with internal entity"); + { + struct handler_record_list storage; + storage.count = 0; + XML_ParserReset(g_parser, NULL); + XML_SetDefaultHandler(g_parser, record_default_handler); + XML_SetCharacterDataHandler(g_parser, record_cdata_handler); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, entity_text, (int)strlen(entity_text), + XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + /* The default handler suppresses the entity */ + assert_record_handler_called(&storage, 0, "record_default_handler", 9); + assert_record_handler_called(&storage, 1, "record_default_handler", 1); + assert_record_handler_called(&storage, 2, "record_default_handler", 3); + assert_record_handler_called(&storage, 3, "record_default_handler", 1); + assert_record_handler_called(&storage, 4, "record_default_handler", 1); + assert_record_handler_called(&storage, 5, "record_default_handler", 1); + assert_record_handler_called(&storage, 6, "record_default_handler", 8); + assert_record_handler_called(&storage, 7, "record_default_handler", 1); + assert_record_handler_called(&storage, 8, "record_default_handler", 6); + assert_record_handler_called(&storage, 9, "record_default_handler", 1); + assert_record_handler_called(&storage, 10, "record_default_handler", 7); + assert_record_handler_called(&storage, 11, "record_default_handler", 1); + assert_record_handler_called(&storage, 12, "record_default_handler", 1); + assert_record_handler_called(&storage, 13, "record_default_handler", 1); + assert_record_handler_called(&storage, 14, "record_default_handler", 1); + assert_record_handler_called(&storage, 15, "record_default_handler", 1); + assert_record_handler_called(&storage, 16, "record_default_handler", 5); + assert_record_handler_called(&storage, 17, "record_default_handler", 8); + assert_record_handler_called(&storage, 18, "record_default_handler", 6); + assert_true(storage.count == 19); + } + + /* Again, with a skip handler */ + set_subtest("with skip handler"); + { + struct handler_record_list storage; + storage.count = 0; + XML_ParserReset(g_parser, NULL); + XML_SetDefaultHandler(g_parser, record_default_handler); + XML_SetCharacterDataHandler(g_parser, record_cdata_handler); + XML_SetSkippedEntityHandler(g_parser, record_skip_handler); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, entity_text, (int)strlen(entity_text), + XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + /* The default handler suppresses the entity */ + assert_record_handler_called(&storage, 0, "record_default_handler", 9); + assert_record_handler_called(&storage, 1, "record_default_handler", 1); + assert_record_handler_called(&storage, 2, "record_default_handler", 3); + assert_record_handler_called(&storage, 3, "record_default_handler", 1); + assert_record_handler_called(&storage, 4, "record_default_handler", 1); + assert_record_handler_called(&storage, 5, "record_default_handler", 1); + assert_record_handler_called(&storage, 6, "record_default_handler", 8); + assert_record_handler_called(&storage, 7, "record_default_handler", 1); + assert_record_handler_called(&storage, 8, "record_default_handler", 6); + assert_record_handler_called(&storage, 9, "record_default_handler", 1); + assert_record_handler_called(&storage, 10, "record_default_handler", 7); + assert_record_handler_called(&storage, 11, "record_default_handler", 1); + assert_record_handler_called(&storage, 12, "record_default_handler", 1); + assert_record_handler_called(&storage, 13, "record_default_handler", 1); + assert_record_handler_called(&storage, 14, "record_default_handler", 1); + assert_record_handler_called(&storage, 15, "record_default_handler", 1); + assert_record_handler_called(&storage, 16, "record_default_handler", 5); + assert_record_handler_called(&storage, 17, "record_skip_handler", 0); + assert_record_handler_called(&storage, 18, "record_default_handler", 6); + assert_true(storage.count == 19); + } + + /* This time, allow the entity through */ + set_subtest("allow entity"); + { + struct handler_record_list storage; + storage.count = 0; + XML_ParserReset(g_parser, NULL); + XML_SetDefaultHandlerExpand(g_parser, record_default_handler); + XML_SetCharacterDataHandler(g_parser, record_cdata_handler); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, entity_text, (int)strlen(entity_text), + XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + assert_record_handler_called(&storage, 0, "record_default_handler", 9); + assert_record_handler_called(&storage, 1, "record_default_handler", 1); + assert_record_handler_called(&storage, 2, "record_default_handler", 3); + assert_record_handler_called(&storage, 3, "record_default_handler", 1); + assert_record_handler_called(&storage, 4, "record_default_handler", 1); + assert_record_handler_called(&storage, 5, "record_default_handler", 1); + assert_record_handler_called(&storage, 6, "record_default_handler", 8); + assert_record_handler_called(&storage, 7, "record_default_handler", 1); + assert_record_handler_called(&storage, 8, "record_default_handler", 6); + assert_record_handler_called(&storage, 9, "record_default_handler", 1); + assert_record_handler_called(&storage, 10, "record_default_handler", 7); + assert_record_handler_called(&storage, 11, "record_default_handler", 1); + assert_record_handler_called(&storage, 12, "record_default_handler", 1); + assert_record_handler_called(&storage, 13, "record_default_handler", 1); + assert_record_handler_called(&storage, 14, "record_default_handler", 1); + assert_record_handler_called(&storage, 15, "record_default_handler", 1); + assert_record_handler_called(&storage, 16, "record_default_handler", 5); + assert_record_handler_called(&storage, 17, "record_cdata_handler", 1); + assert_record_handler_called(&storage, 18, "record_default_handler", 1); + assert_record_handler_called(&storage, 19, "record_default_handler", 6); + assert_true(storage.count == 20); + } + + /* Finally, without passing the cdata to the default handler */ + set_subtest("not passing cdata"); + { + struct handler_record_list storage; + storage.count = 0; + XML_ParserReset(g_parser, NULL); + XML_SetDefaultHandlerExpand(g_parser, record_default_handler); + XML_SetCharacterDataHandler(g_parser, record_cdata_nodefault_handler); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, entity_text, (int)strlen(entity_text), + XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + assert_record_handler_called(&storage, 0, "record_default_handler", 9); + assert_record_handler_called(&storage, 1, "record_default_handler", 1); + assert_record_handler_called(&storage, 2, "record_default_handler", 3); + assert_record_handler_called(&storage, 3, "record_default_handler", 1); + assert_record_handler_called(&storage, 4, "record_default_handler", 1); + assert_record_handler_called(&storage, 5, "record_default_handler", 1); + assert_record_handler_called(&storage, 6, "record_default_handler", 8); + assert_record_handler_called(&storage, 7, "record_default_handler", 1); + assert_record_handler_called(&storage, 8, "record_default_handler", 6); + assert_record_handler_called(&storage, 9, "record_default_handler", 1); + assert_record_handler_called(&storage, 10, "record_default_handler", 7); + assert_record_handler_called(&storage, 11, "record_default_handler", 1); + assert_record_handler_called(&storage, 12, "record_default_handler", 1); + assert_record_handler_called(&storage, 13, "record_default_handler", 1); + assert_record_handler_called(&storage, 14, "record_default_handler", 1); + assert_record_handler_called(&storage, 15, "record_default_handler", 1); + assert_record_handler_called(&storage, 16, "record_default_handler", 5); + assert_record_handler_called(&storage, 17, "record_cdata_nodefault_handler", + 1); + assert_record_handler_called(&storage, 18, "record_default_handler", 6); + assert_true(storage.count == 19); + } +} +END_TEST + +/* Test DTD element parsing code paths */ +START_TEST(test_dtd_elements) { + const char *text = "<!DOCTYPE doc [\n" + "<!ELEMENT doc (chapter)>\n" + "<!ELEMENT chapter (#PCDATA)>\n" + "]>\n" + "<doc><chapter>Wombats are go</chapter></doc>"; + + XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +static void XMLCALL +element_decl_check_model(void *userData, const XML_Char *name, + XML_Content *model) { + UNUSED_P(userData); + uint32_t errorFlags = 0; + + /* Expected model array structure is this: + * [0] (type 6, quant 0) + * [1] (type 5, quant 0) + * [3] (type 4, quant 0, name "bar") + * [4] (type 4, quant 0, name "foo") + * [5] (type 4, quant 3, name "xyz") + * [2] (type 4, quant 2, name "zebra") + */ + errorFlags |= ((xcstrcmp(name, XCS("junk")) == 0) ? 0 : (1u << 0)); + errorFlags |= ((model != NULL) ? 0 : (1u << 1)); + + if (model != NULL) { + errorFlags |= ((model[0].type == XML_CTYPE_SEQ) ? 0 : (1u << 2)); + errorFlags |= ((model[0].quant == XML_CQUANT_NONE) ? 0 : (1u << 3)); + errorFlags |= ((model[0].numchildren == 2) ? 0 : (1u << 4)); + errorFlags |= ((model[0].children == &model[1]) ? 0 : (1u << 5)); + errorFlags |= ((model[0].name == NULL) ? 0 : (1u << 6)); + + errorFlags |= ((model[1].type == XML_CTYPE_CHOICE) ? 0 : (1u << 7)); + errorFlags |= ((model[1].quant == XML_CQUANT_NONE) ? 0 : (1u << 8)); + errorFlags |= ((model[1].numchildren == 3) ? 0 : (1u << 9)); + errorFlags |= ((model[1].children == &model[3]) ? 0 : (1u << 10)); + errorFlags |= ((model[1].name == NULL) ? 0 : (1u << 11)); + + errorFlags |= ((model[2].type == XML_CTYPE_NAME) ? 0 : (1u << 12)); + errorFlags |= ((model[2].quant == XML_CQUANT_REP) ? 0 : (1u << 13)); + errorFlags |= ((model[2].numchildren == 0) ? 0 : (1u << 14)); + errorFlags |= ((model[2].children == NULL) ? 0 : (1u << 15)); + errorFlags + |= ((xcstrcmp(model[2].name, XCS("zebra")) == 0) ? 0 : (1u << 16)); + + errorFlags |= ((model[3].type == XML_CTYPE_NAME) ? 0 : (1u << 17)); + errorFlags |= ((model[3].quant == XML_CQUANT_NONE) ? 0 : (1u << 18)); + errorFlags |= ((model[3].numchildren == 0) ? 0 : (1u << 19)); + errorFlags |= ((model[3].children == NULL) ? 0 : (1u << 20)); + errorFlags |= ((xcstrcmp(model[3].name, XCS("bar")) == 0) ? 0 : (1u << 21)); + + errorFlags |= ((model[4].type == XML_CTYPE_NAME) ? 0 : (1u << 22)); + errorFlags |= ((model[4].quant == XML_CQUANT_NONE) ? 0 : (1u << 23)); + errorFlags |= ((model[4].numchildren == 0) ? 0 : (1u << 24)); + errorFlags |= ((model[4].children == NULL) ? 0 : (1u << 25)); + errorFlags |= ((xcstrcmp(model[4].name, XCS("foo")) == 0) ? 0 : (1u << 26)); + + errorFlags |= ((model[5].type == XML_CTYPE_NAME) ? 0 : (1u << 27)); + errorFlags |= ((model[5].quant == XML_CQUANT_PLUS) ? 0 : (1u << 28)); + errorFlags |= ((model[5].numchildren == 0) ? 0 : (1u << 29)); + errorFlags |= ((model[5].children == NULL) ? 0 : (1u << 30)); + errorFlags |= ((xcstrcmp(model[5].name, XCS("xyz")) == 0) ? 0 : (1u << 31)); + } + + XML_SetUserData(g_parser, (void *)(uintptr_t)errorFlags); + XML_FreeContentModel(g_parser, model); +} + +START_TEST(test_dtd_elements_nesting) { + // Payload inspired by a test in Perl's XML::Parser + const char *text = "<!DOCTYPE foo [\n" + "<!ELEMENT junk ((bar|foo|xyz+), zebra*)>\n" + "]>\n" + "<foo/>"; + + XML_SetUserData(g_parser, (void *)(uintptr_t)-1); + + XML_SetElementDeclHandler(g_parser, element_decl_check_model); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + + if ((uint32_t)(uintptr_t)XML_GetUserData(g_parser) != 0) + fail("Element declaration model regression detected"); +} +END_TEST + +/* Test foreign DTD handling */ +START_TEST(test_set_foreign_dtd) { + const char *text1 = "<?xml version='1.0' encoding='us-ascii'?>\n"; + const char *text2 = "<doc>&entity;</doc>"; + ExtTest test_data = {"<!ELEMENT doc (#PCDATA)*>", NULL, NULL}; + + /* Check hash salt is passed through too */ + XML_SetHashSalt(g_parser, 0x12345678); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetUserData(g_parser, &test_data); + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); + /* Add a default handler to exercise more code paths */ + XML_SetDefaultHandler(g_parser, dummy_default_handler); + if (XML_UseForeignDTD(g_parser, XML_TRUE) != XML_ERROR_NONE) + fail("Could not set foreign DTD"); + if (_XML_Parse_SINGLE_BYTES(g_parser, text1, (int)strlen(text1), XML_FALSE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + + /* Ensure that trying to set the DTD after parsing has started + * is faulted, even if it's the same setting. + */ + if (XML_UseForeignDTD(g_parser, XML_TRUE) + != XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING) + fail("Failed to reject late foreign DTD setting"); + /* Ditto for the hash salt */ + if (XML_SetHashSalt(g_parser, 0x23456789)) + fail("Failed to reject late hash salt change"); + + /* Now finish the parse */ + if (_XML_Parse_SINGLE_BYTES(g_parser, text2, (int)strlen(text2), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test foreign DTD handling with a failing NotStandalone handler */ +START_TEST(test_foreign_dtd_not_standalone) { + const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<doc>&entity;</doc>"; + ExtTest test_data = {"<!ELEMENT doc (#PCDATA)*>", NULL, NULL}; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetUserData(g_parser, &test_data); + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); + XML_SetNotStandaloneHandler(g_parser, reject_not_standalone_handler); + if (XML_UseForeignDTD(g_parser, XML_TRUE) != XML_ERROR_NONE) + fail("Could not set foreign DTD"); + expect_failure(text, XML_ERROR_NOT_STANDALONE, + "NotStandalonehandler failed to reject"); +} +END_TEST + +/* Test invalid character in a foreign DTD is faulted */ +START_TEST(test_invalid_foreign_dtd) { + const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<doc>&entity;</doc>"; + ExtFaults test_data + = {"$", "Dollar not faulted", NULL, XML_ERROR_INVALID_TOKEN}; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetUserData(g_parser, &test_data); + XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter); + XML_UseForeignDTD(g_parser, XML_TRUE); + expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, + "Bad DTD should not have been accepted"); +} +END_TEST + +/* Test foreign DTD use with a doctype */ +START_TEST(test_foreign_dtd_with_doctype) { + const char *text1 = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<!DOCTYPE doc [<!ENTITY entity 'hello world'>]>\n"; + const char *text2 = "<doc>&entity;</doc>"; + ExtTest test_data = {"<!ELEMENT doc (#PCDATA)*>", NULL, NULL}; + + /* Check hash salt is passed through too */ + XML_SetHashSalt(g_parser, 0x12345678); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetUserData(g_parser, &test_data); + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); + /* Add a default handler to exercise more code paths */ + XML_SetDefaultHandler(g_parser, dummy_default_handler); + if (XML_UseForeignDTD(g_parser, XML_TRUE) != XML_ERROR_NONE) + fail("Could not set foreign DTD"); + if (_XML_Parse_SINGLE_BYTES(g_parser, text1, (int)strlen(text1), XML_FALSE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + + /* Ensure that trying to set the DTD after parsing has started + * is faulted, even if it's the same setting. + */ + if (XML_UseForeignDTD(g_parser, XML_TRUE) + != XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING) + fail("Failed to reject late foreign DTD setting"); + /* Ditto for the hash salt */ + if (XML_SetHashSalt(g_parser, 0x23456789)) + fail("Failed to reject late hash salt change"); + + /* Now finish the parse */ + if (_XML_Parse_SINGLE_BYTES(g_parser, text2, (int)strlen(text2), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test XML_UseForeignDTD with no external subset present */ +START_TEST(test_foreign_dtd_without_external_subset) { + const char *text = "<!DOCTYPE doc [<!ENTITY foo 'bar'>]>\n" + "<doc>&foo;</doc>"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetUserData(g_parser, NULL); + XML_SetExternalEntityRefHandler(g_parser, external_entity_null_loader); + XML_UseForeignDTD(g_parser, XML_TRUE); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +START_TEST(test_empty_foreign_dtd) { + const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<doc>&entity;</doc>"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_null_loader); + XML_UseForeignDTD(g_parser, XML_TRUE); + expect_failure(text, XML_ERROR_UNDEFINED_ENTITY, + "Undefined entity not faulted"); +} +END_TEST + +/* Test XML Base is set and unset appropriately */ +START_TEST(test_set_base) { + const XML_Char *old_base; + const XML_Char *new_base = XCS("/local/file/name.xml"); + + old_base = XML_GetBase(g_parser); + if (XML_SetBase(g_parser, new_base) != XML_STATUS_OK) + fail("Unable to set base"); + if (xcstrcmp(XML_GetBase(g_parser), new_base) != 0) + fail("Base setting not correct"); + if (XML_SetBase(g_parser, NULL) != XML_STATUS_OK) + fail("Unable to NULL base"); + if (XML_GetBase(g_parser) != NULL) + fail("Base setting not nulled"); + XML_SetBase(g_parser, old_base); +} +END_TEST + +/* Test attribute counts, indexing, etc */ +START_TEST(test_attributes) { + const char *text = "<!DOCTYPE doc [\n" + "<!ELEMENT doc (tag)>\n" + "<!ATTLIST doc id ID #REQUIRED>\n" + "]>" + "<doc a='1' id='one' b='2'>" + "<tag c='3'/>" + "</doc>"; + AttrInfo doc_info[] = {{XCS("a"), XCS("1")}, + {XCS("b"), XCS("2")}, + {XCS("id"), XCS("one")}, + {NULL, NULL}}; + AttrInfo tag_info[] = {{XCS("c"), XCS("3")}, {NULL, NULL}}; + ElementInfo info[] = {{XCS("doc"), 3, XCS("id"), NULL}, + {XCS("tag"), 1, NULL, NULL}, + {NULL, 0, NULL, NULL}}; + info[0].attributes = doc_info; + info[1].attributes = tag_info; + + XML_Parser parser = XML_ParserCreate(NULL); + assert_true(parser != NULL); + ParserAndElementInfo parserAndElementInfos = { + parser, + info, + }; + + XML_SetStartElementHandler(parser, counting_start_element_handler); + XML_SetUserData(parser, &parserAndElementInfos); + if (_XML_Parse_SINGLE_BYTES(parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(parser); + + XML_ParserFree(parser); +} +END_TEST + +/* Test reset works correctly in the middle of processing an internal + * entity. Exercises some obscure code in XML_ParserReset(). + */ +START_TEST(test_reset_in_entity) { + const char *text = "<!DOCTYPE doc [\n" + "<!ENTITY wombat 'wom'>\n" + "<!ENTITY entity 'hi &wom; there'>\n" + "]>\n" + "<doc>&entity;</doc>"; + XML_ParsingStatus status; + + g_resumable = XML_TRUE; + XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + XML_GetParsingStatus(g_parser, &status); + if (status.parsing != XML_SUSPENDED) + fail("Parsing status not SUSPENDED"); + XML_ParserReset(g_parser, NULL); + XML_GetParsingStatus(g_parser, &status); + if (status.parsing != XML_INITIALIZED) + fail("Parsing status doesn't reset to INITIALIZED"); +} +END_TEST + +/* Test that resume correctly passes through parse errors */ +START_TEST(test_resume_invalid_parse) { + const char *text = "<doc>Hello</doc"; /* Missing closing wedge */ + + g_resumable = XML_TRUE; + XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); + if (XML_Parse(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + if (XML_ResumeParser(g_parser) == XML_STATUS_OK) + fail("Resumed invalid parse not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_UNCLOSED_TOKEN) + fail("Invalid parse not correctly faulted"); +} +END_TEST + +/* Test that re-suspended parses are correctly passed through */ +START_TEST(test_resume_resuspended) { + const char *text = "<doc>Hello<meep/>world</doc>"; + + g_resumable = XML_TRUE; + XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); + if (XML_Parse(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + g_resumable = XML_TRUE; + XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); + if (XML_ResumeParser(g_parser) != XML_STATUS_SUSPENDED) + fail("Resumption not suspended"); + /* This one should succeed and finish up */ + if (XML_ResumeParser(g_parser) != XML_STATUS_OK) + xml_failure(g_parser); +} +END_TEST + +/* Test that CDATA shows up correctly through a default handler */ +START_TEST(test_cdata_default) { + const char *text = "<doc><![CDATA[Hello\nworld]]></doc>"; + const XML_Char *expected = XCS("<doc><![CDATA[Hello\nworld]]></doc>"); + CharData storage; + + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetDefaultHandler(g_parser, accumulate_characters); + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test resetting a subordinate parser does exactly nothing */ +START_TEST(test_subordinate_reset) { + const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc>&entity;</doc>"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_resetter); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test suspending a subordinate parser */ +START_TEST(test_subordinate_suspend) { + const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc>&entity;</doc>"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_suspender); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test suspending a subordinate parser from an XML declaration */ +/* Increases code coverage of the tests */ + +START_TEST(test_subordinate_xdecl_suspend) { + const char *text + = "<!DOCTYPE doc [\n" + " <!ENTITY entity SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&entity;</doc>"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_suspend_xmldecl); + g_resumable = XML_TRUE; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +START_TEST(test_subordinate_xdecl_abort) { + const char *text + = "<!DOCTYPE doc [\n" + " <!ENTITY entity SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&entity;</doc>"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_suspend_xmldecl); + g_resumable = XML_FALSE; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test external entity fault handling with suspension */ +START_TEST(test_ext_entity_invalid_suspended_parse) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + ExtFaults faults[] + = {{"<?xml version='1.0' encoding='us-ascii'?><", + "Incomplete element declaration not faulted", NULL, + XML_ERROR_UNCLOSED_TOKEN}, + {/* First two bytes of a three-byte char */ + "<?xml version='1.0' encoding='utf-8'?>\xe2\x82", + "Incomplete character not faulted", NULL, XML_ERROR_PARTIAL_CHAR}, + {NULL, NULL, NULL, XML_ERROR_NONE}}; + ExtFaults *fault; + + for (fault = &faults[0]; fault->parse_text != NULL; fault++) { + set_subtest("%s", fault->parse_text); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, + external_entity_suspending_faulter); + XML_SetUserData(g_parser, fault); + expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, + "Parser did not report external entity error"); + XML_ParserReset(g_parser, NULL); + } +} +END_TEST + +/* Test setting an explicit encoding */ +START_TEST(test_explicit_encoding) { + const char *text1 = "<doc>Hello "; + const char *text2 = " World</doc>"; + + /* Just check that we can set the encoding to NULL before starting */ + if (XML_SetEncoding(g_parser, NULL) != XML_STATUS_OK) + fail("Failed to initialise encoding to NULL"); + /* Say we are UTF-8 */ + if (XML_SetEncoding(g_parser, XCS("utf-8")) != XML_STATUS_OK) + fail("Failed to set explicit encoding"); + if (_XML_Parse_SINGLE_BYTES(g_parser, text1, (int)strlen(text1), XML_FALSE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + /* Try to switch encodings mid-parse */ + if (XML_SetEncoding(g_parser, XCS("us-ascii")) != XML_STATUS_ERROR) + fail("Allowed encoding change"); + if (_XML_Parse_SINGLE_BYTES(g_parser, text2, (int)strlen(text2), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + /* Try now the parse is over */ + if (XML_SetEncoding(g_parser, NULL) != XML_STATUS_OK) + fail("Failed to unset encoding"); +} +END_TEST + +/* Test handling of trailing CR (rather than newline) */ +START_TEST(test_trailing_cr) { + const char *text = "<doc>\r"; + int found_cr; + + /* Try with a character handler, for code coverage */ + XML_SetCharacterDataHandler(g_parser, cr_cdata_handler); + XML_SetUserData(g_parser, &found_cr); + found_cr = 0; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_OK) + fail("Failed to fault unclosed doc"); + if (found_cr == 0) + fail("Did not catch the carriage return"); + XML_ParserReset(g_parser, NULL); + + /* Now with a default handler instead */ + XML_SetDefaultHandler(g_parser, cr_cdata_handler); + XML_SetUserData(g_parser, &found_cr); + found_cr = 0; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_OK) + fail("Failed to fault unclosed doc"); + if (found_cr == 0) + fail("Did not catch default carriage return"); +} +END_TEST + +/* Test trailing CR in an external entity parse */ +START_TEST(test_ext_entity_trailing_cr) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + int found_cr; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_cr_catcher); + XML_SetUserData(g_parser, &found_cr); + found_cr = 0; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_OK) + xml_failure(g_parser); + if (found_cr == 0) + fail("No carriage return found"); + XML_ParserReset(g_parser, NULL); + + /* Try again with a different trailing CR */ + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_bad_cr_catcher); + XML_SetUserData(g_parser, &found_cr); + found_cr = 0; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_OK) + xml_failure(g_parser); + if (found_cr == 0) + fail("No carriage return found"); +} +END_TEST + +/* Test handling of trailing square bracket */ +START_TEST(test_trailing_rsqb) { + const char *text8 = "<doc>]"; + const char text16[] = "\xFF\xFE<\000d\000o\000c\000>\000]\000"; + int found_rsqb; + int text8_len = (int)strlen(text8); + + XML_SetCharacterDataHandler(g_parser, rsqb_handler); + XML_SetUserData(g_parser, &found_rsqb); + found_rsqb = 0; + if (_XML_Parse_SINGLE_BYTES(g_parser, text8, text8_len, XML_TRUE) + == XML_STATUS_OK) + fail("Failed to fault unclosed doc"); + if (found_rsqb == 0) + fail("Did not catch the right square bracket"); + + /* Try again with a different encoding */ + XML_ParserReset(g_parser, NULL); + XML_SetCharacterDataHandler(g_parser, rsqb_handler); + XML_SetUserData(g_parser, &found_rsqb); + found_rsqb = 0; + if (_XML_Parse_SINGLE_BYTES(g_parser, text16, (int)sizeof(text16) - 1, + XML_TRUE) + == XML_STATUS_OK) + fail("Failed to fault unclosed doc"); + if (found_rsqb == 0) + fail("Did not catch the right square bracket"); + + /* And finally with a default handler */ + XML_ParserReset(g_parser, NULL); + XML_SetDefaultHandler(g_parser, rsqb_handler); + XML_SetUserData(g_parser, &found_rsqb); + found_rsqb = 0; + if (_XML_Parse_SINGLE_BYTES(g_parser, text16, (int)sizeof(text16) - 1, + XML_TRUE) + == XML_STATUS_OK) + fail("Failed to fault unclosed doc"); + if (found_rsqb == 0) + fail("Did not catch the right square bracket"); +} +END_TEST + +/* Test trailing right square bracket in an external entity parse */ +START_TEST(test_ext_entity_trailing_rsqb) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + int found_rsqb; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_rsqb_catcher); + XML_SetUserData(g_parser, &found_rsqb); + found_rsqb = 0; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_OK) + xml_failure(g_parser); + if (found_rsqb == 0) + fail("No right square bracket found"); +} +END_TEST + +/* Test CDATA handling in an external entity */ +START_TEST(test_ext_entity_good_cdata) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_good_cdata_ascii); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_OK) + xml_failure(g_parser); +} +END_TEST + +/* Test user parameter settings */ +START_TEST(test_user_parameters) { + const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<!-- Primary parse -->\n" + "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc>&entity;"; + const char *epilog = "<!-- Back to primary parser -->\n" + "</doc>"; + + g_comment_count = 0; + g_skip_count = 0; + g_xdecl_count = 0; + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetXmlDeclHandler(g_parser, xml_decl_handler); + XML_SetExternalEntityRefHandler(g_parser, external_entity_param_checker); + XML_SetCommentHandler(g_parser, data_check_comment_handler); + XML_SetSkippedEntityHandler(g_parser, param_check_skip_handler); + XML_UseParserAsHandlerArg(g_parser); + XML_SetUserData(g_parser, (void *)1); + g_handler_data = g_parser; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + /* Ensure we can't change policy mid-parse */ + if (XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_NEVER)) + fail("Changed param entity parsing policy while parsing"); + if (_XML_Parse_SINGLE_BYTES(g_parser, epilog, (int)strlen(epilog), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + if (g_comment_count != 3) + fail("Comment handler not invoked enough times"); + if (g_skip_count != 1) + fail("Skip handler not invoked enough times"); + if (g_xdecl_count != 1) + fail("XML declaration handler not invoked"); +} +END_TEST + +/* Test that an explicit external entity handler argument replaces + * the parser as the first argument. + * + * We do not call the first parameter to the external entity handler + * 'parser' for once, since the first time the handler is called it + * will actually be a text string. We need to be able to access the + * global 'parser' variable to create our external entity parser from, + * since there are code paths we need to ensure get executed. + */ +START_TEST(test_ext_entity_ref_parameter) { + const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" + "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc>&entity;</doc>"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_ref_param_checker); + /* Set a handler arg that is not NULL and not parser (which is + * what NULL would cause to be passed. + */ + XML_SetExternalEntityRefHandlerArg(g_parser, (void *)text); + g_handler_data = text; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + + /* Now try again with unset args */ + XML_ParserReset(g_parser, NULL); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_ref_param_checker); + XML_SetExternalEntityRefHandlerArg(g_parser, NULL); + g_handler_data = g_parser; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test the parsing of an empty string */ +START_TEST(test_empty_parse) { + const char *text = "<doc></doc>"; + const char *partial = "<doc>"; + + if (XML_Parse(g_parser, NULL, 0, XML_FALSE) == XML_STATUS_ERROR) + fail("Parsing empty string faulted"); + if (XML_Parse(g_parser, NULL, 0, XML_TRUE) != XML_STATUS_ERROR) + fail("Parsing final empty string not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_NO_ELEMENTS) + fail("Parsing final empty string faulted for wrong reason"); + + /* Now try with valid text before the empty end */ + XML_ParserReset(g_parser, NULL); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + if (XML_Parse(g_parser, NULL, 0, XML_TRUE) == XML_STATUS_ERROR) + fail("Parsing final empty string faulted"); + + /* Now try with invalid text before the empty end */ + XML_ParserReset(g_parser, NULL); + if (_XML_Parse_SINGLE_BYTES(g_parser, partial, (int)strlen(partial), + XML_FALSE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + if (XML_Parse(g_parser, NULL, 0, XML_TRUE) != XML_STATUS_ERROR) + fail("Parsing final incomplete empty string not faulted"); +} +END_TEST + +/* Test XML_Parse for len < 0 */ +START_TEST(test_negative_len_parse) { + const char *const doc = "<root/>"; + for (int isFinal = 0; isFinal < 2; isFinal++) { + set_subtest("isFinal=%d", isFinal); + + XML_Parser parser = XML_ParserCreate(NULL); + + if (XML_GetErrorCode(parser) != XML_ERROR_NONE) + fail("There was not supposed to be any initial parse error."); + + const enum XML_Status status = XML_Parse(parser, doc, -1, isFinal); + + if (status != XML_STATUS_ERROR) + fail("Negative len was expected to fail the parse but did not."); + + if (XML_GetErrorCode(parser) != XML_ERROR_INVALID_ARGUMENT) + fail("Parse error does not match XML_ERROR_INVALID_ARGUMENT."); + + XML_ParserFree(parser); + } +} +END_TEST + +/* Test XML_ParseBuffer for len < 0 */ +START_TEST(test_negative_len_parse_buffer) { + const char *const doc = "<root/>"; + for (int isFinal = 0; isFinal < 2; isFinal++) { + set_subtest("isFinal=%d", isFinal); + + XML_Parser parser = XML_ParserCreate(NULL); + + if (XML_GetErrorCode(parser) != XML_ERROR_NONE) + fail("There was not supposed to be any initial parse error."); + + void *const buffer = XML_GetBuffer(parser, (int)strlen(doc)); + + if (buffer == NULL) + fail("XML_GetBuffer failed."); + + memcpy(buffer, doc, strlen(doc)); + + const enum XML_Status status = XML_ParseBuffer(parser, -1, isFinal); + + if (status != XML_STATUS_ERROR) + fail("Negative len was expected to fail the parse but did not."); + + if (XML_GetErrorCode(parser) != XML_ERROR_INVALID_ARGUMENT) + fail("Parse error does not match XML_ERROR_INVALID_ARGUMENT."); + + XML_ParserFree(parser); + } +} +END_TEST + +/* Test odd corners of the XML_GetBuffer interface */ +static enum XML_Status +get_feature(enum XML_FeatureEnum feature_id, long *presult) { + const XML_Feature *feature = XML_GetFeatureList(); + + if (feature == NULL) + return XML_STATUS_ERROR; + for (; feature->feature != XML_FEATURE_END; feature++) { + if (feature->feature == feature_id) { + *presult = feature->value; + return XML_STATUS_OK; + } + } + return XML_STATUS_ERROR; +} + +/* Test odd corners of the XML_GetBuffer interface */ +START_TEST(test_get_buffer_1) { + const char *text = get_buffer_test_text; + void *buffer; + long context_bytes; + + /* Attempt to allocate a negative length buffer */ + if (XML_GetBuffer(g_parser, -12) != NULL) + fail("Negative length buffer not failed"); + + /* Now get a small buffer and extend it past valid length */ + buffer = XML_GetBuffer(g_parser, 1536); + if (buffer == NULL) + fail("1.5K buffer failed"); + assert(buffer != NULL); + memcpy(buffer, text, strlen(text)); + if (XML_ParseBuffer(g_parser, (int)strlen(text), XML_FALSE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + if (XML_GetBuffer(g_parser, INT_MAX) != NULL) + fail("INT_MAX buffer not failed"); + + /* Now try extending it a more reasonable but still too large + * amount. The allocator in XML_GetBuffer() doubles the buffer + * size until it exceeds the requested amount or INT_MAX. If it + * exceeds INT_MAX, it rejects the request, so we want a request + * between INT_MAX and INT_MAX/2. A gap of 1K seems comfortable, + * with an extra byte just to ensure that the request is off any + * boundary. The request will be inflated internally by + * XML_CONTEXT_BYTES (if >=1), so we subtract that from our + * request. + */ + if (get_feature(XML_FEATURE_CONTEXT_BYTES, &context_bytes) != XML_STATUS_OK) + context_bytes = 0; + if (XML_GetBuffer(g_parser, INT_MAX - (context_bytes + 1025)) != NULL) + fail("INT_MAX- buffer not failed"); + + /* Now try extending it a carefully crafted amount */ + if (XML_GetBuffer(g_parser, 1000) == NULL) + fail("1000 buffer failed"); +} +END_TEST + +/* Test more corners of the XML_GetBuffer interface */ +START_TEST(test_get_buffer_2) { + const char *text = get_buffer_test_text; + void *buffer; + + /* Now get a decent buffer */ + buffer = XML_GetBuffer(g_parser, 1536); + if (buffer == NULL) + fail("1.5K buffer failed"); + assert(buffer != NULL); + memcpy(buffer, text, strlen(text)); + if (XML_ParseBuffer(g_parser, (int)strlen(text), XML_FALSE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + + /* Extend it, to catch a different code path */ + if (XML_GetBuffer(g_parser, 1024) == NULL) + fail("1024 buffer failed"); +} +END_TEST + +/* Test for signed integer overflow CVE-2022-23852 */ +#if XML_CONTEXT_BYTES > 0 +START_TEST(test_get_buffer_3_overflow) { + XML_Parser parser = XML_ParserCreate(NULL); + assert(parser != NULL); + + const char *const text = "\n"; + const int expectedKeepValue = (int)strlen(text); + + // After this call, variable "keep" in XML_GetBuffer will + // have value expectedKeepValue + if (_XML_Parse_SINGLE_BYTES(parser, text, (int)strlen(text), + XML_FALSE /* isFinal */) + == XML_STATUS_ERROR) + xml_failure(parser); + + assert(expectedKeepValue > 0); + if (XML_GetBuffer(parser, INT_MAX - expectedKeepValue + 1) != NULL) + fail("enlarging buffer not failed"); + + XML_ParserFree(parser); +} +END_TEST +#endif // XML_CONTEXT_BYTES > 0 + +START_TEST(test_buffer_can_grow_to_max) { + const char *const prefixes[] = { + "", + "<", + "<x a='", + "<doc><x a='", + "<document><x a='", + "<averylongelementnamesuchthatitwillhopefullystretchacrossmultiplelinesand" + "lookprettyridiculousitsalsoveryhardtoreadandifyouredoingitihavetowonderif" + "youreallydonthaveanythingbettertodoofcourseiguessicouldveputsomethingbadin" + "herebutipromisethatididntheybtwhowgreatarespacesandpunctuationforhelping" + "withreadabilityprettygreatithinkanywaysthisisprobablylongenoughbye><x a='"}; + const int num_prefixes = sizeof(prefixes) / sizeof(prefixes[0]); + int maxbuf = INT_MAX / 2 + (INT_MAX & 1); // round up without overflow +#if defined(__MINGW32__) && ! defined(__MINGW64__) + // workaround for mingw/wine32 on GitHub CI not being able to reach 1GiB + // Can we make a big allocation? + void *big = malloc(maxbuf); + if (! big) { + // The big allocation failed. Let's be a little lenient. + maxbuf = maxbuf / 2; + } + free(big); +#endif + + for (int i = 0; i < num_prefixes; ++i) { + set_subtest("\"%s\"", prefixes[i]); + XML_Parser parser = XML_ParserCreate(NULL); + const int prefix_len = (int)strlen(prefixes[i]); + const enum XML_Status s + = _XML_Parse_SINGLE_BYTES(parser, prefixes[i], prefix_len, XML_FALSE); + if (s != XML_STATUS_OK) + xml_failure(parser); + + // XML_CONTEXT_BYTES of the prefix may remain in the buffer; + // subtracting the whole prefix is easiest, and close enough. + assert_true(XML_GetBuffer(parser, maxbuf - prefix_len) != NULL); + // The limit should be consistent; no prefix should allow us to + // reach above the max buffer size. + assert_true(XML_GetBuffer(parser, maxbuf + 1) == NULL); + XML_ParserFree(parser); + } +} +END_TEST + +START_TEST(test_getbuffer_allocates_on_zero_len) { + for (int first_len = 1; first_len >= 0; first_len--) { + set_subtest("with len=%d first", first_len); + XML_Parser parser = XML_ParserCreate(NULL); + assert_true(parser != NULL); + assert_true(XML_GetBuffer(parser, first_len) != NULL); + assert_true(XML_GetBuffer(parser, 0) != NULL); + if (XML_ParseBuffer(parser, 0, XML_FALSE) != XML_STATUS_OK) + xml_failure(parser); + XML_ParserFree(parser); + } +} +END_TEST + +/* Test position information macros */ +START_TEST(test_byte_info_at_end) { + const char *text = "<doc></doc>"; + + if (XML_GetCurrentByteIndex(g_parser) != -1 + || XML_GetCurrentByteCount(g_parser) != 0) + fail("Byte index/count incorrect at start of parse"); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + /* At end, the count will be zero and the index the end of string */ + if (XML_GetCurrentByteCount(g_parser) != 0) + fail("Terminal byte count incorrect"); + if (XML_GetCurrentByteIndex(g_parser) != (XML_Index)strlen(text)) + fail("Terminal byte index incorrect"); +} +END_TEST + +/* Test position information from errors */ +#define PRE_ERROR_STR "<doc></" +#define POST_ERROR_STR "wombat></doc>" +START_TEST(test_byte_info_at_error) { + const char *text = PRE_ERROR_STR POST_ERROR_STR; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_OK) + fail("Syntax error not faulted"); + if (XML_GetCurrentByteCount(g_parser) != 0) + fail("Error byte count incorrect"); + if (XML_GetCurrentByteIndex(g_parser) != strlen(PRE_ERROR_STR)) + fail("Error byte index incorrect"); +} +END_TEST +#undef PRE_ERROR_STR +#undef POST_ERROR_STR + +/* Test position information in handler */ +#define START_ELEMENT "<e>" +#define CDATA_TEXT "Hello" +#define END_ELEMENT "</e>" +START_TEST(test_byte_info_at_cdata) { + const char *text = START_ELEMENT CDATA_TEXT END_ELEMENT; + int offset, size; + ByteTestData data; + + /* Check initial context is empty */ + if (XML_GetInputContext(g_parser, &offset, &size) != NULL) + fail("Unexpected context at start of parse"); + + data.start_element_len = (int)strlen(START_ELEMENT); + data.cdata_len = (int)strlen(CDATA_TEXT); + data.total_string_len = (int)strlen(text); + XML_SetCharacterDataHandler(g_parser, byte_character_handler); + XML_SetUserData(g_parser, &data); + if (XML_Parse(g_parser, text, (int)strlen(text), XML_TRUE) != XML_STATUS_OK) + xml_failure(g_parser); +} +END_TEST +#undef START_ELEMENT +#undef CDATA_TEXT +#undef END_ELEMENT + +/* Test predefined entities are correctly recognised */ +START_TEST(test_predefined_entities) { + const char *text = "<doc><>&"'</doc>"; + const XML_Char *expected = XCS("<doc><>&"'</doc>"); + const XML_Char *result = XCS("<>&\"'"); + CharData storage; + + XML_SetDefaultHandler(g_parser, accumulate_characters); + /* run_character_check uses XML_SetCharacterDataHandler(), which + * unfortunately heads off a code path that we need to exercise. + */ + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + /* The default handler doesn't translate the entities */ + CharData_CheckXMLChars(&storage, expected); + + /* Now try again and check the translation */ + XML_ParserReset(g_parser, NULL); + run_character_check(text, result); +} +END_TEST + +/* Regression test that an invalid tag in an external parameter + * reference in an external DTD is correctly faulted. + * + * Only a few specific tags are legal in DTDs ignoring comments and + * processing instructions, all of which begin with an exclamation + * mark. "<el/>" is not one of them, so the parser should raise an + * error on encountering it. + */ +START_TEST(test_invalid_tag_in_dtd) { + const char *text = "<!DOCTYPE doc SYSTEM '004-1.ent'>\n" + "<doc></doc>\n"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_param); + expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, + "Invalid tag IN DTD external param not rejected"); +} +END_TEST + +/* Test entities not quite the predefined ones are not mis-recognised */ +START_TEST(test_not_predefined_entities) { + const char *text[] = {"<doc>&pt;</doc>", "<doc>&amo;</doc>", + "<doc>&quid;</doc>", "<doc>&apod;</doc>", NULL}; + int i = 0; + + while (text[i] != NULL) { + expect_failure(text[i], XML_ERROR_UNDEFINED_ENTITY, + "Undefined entity not rejected"); + XML_ParserReset(g_parser, NULL); + i++; + } +} +END_TEST + +/* Test conditional inclusion (IGNORE) */ +START_TEST(test_ignore_section) { + const char *text = "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc><e>&entity;</e></doc>"; + const XML_Char *expected + = XCS("<![IGNORE[<!ELEMENT e (#PCDATA)*>]]>\n&entity;"); + CharData storage; + + CharData_Init(&storage); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetUserData(g_parser, &storage); + XML_SetExternalEntityRefHandler(g_parser, external_entity_load_ignore); + XML_SetDefaultHandler(g_parser, accumulate_characters); + XML_SetStartDoctypeDeclHandler(g_parser, dummy_start_doctype_handler); + XML_SetEndDoctypeDeclHandler(g_parser, dummy_end_doctype_handler); + XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); + XML_SetStartElementHandler(g_parser, dummy_start_element); + XML_SetEndElementHandler(g_parser, dummy_end_element); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_ignore_section_utf16) { + const char text[] = + /* <!DOCTYPE d SYSTEM 's'> */ + "<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0d\0 " + "\0S\0Y\0S\0T\0E\0M\0 \0'\0s\0'\0>\0\n\0" + /* <d><e>&en;</e></d> */ + "<\0d\0>\0<\0e\0>\0&\0e\0n\0;\0<\0/\0e\0>\0<\0/\0d\0>\0"; + const XML_Char *expected = XCS("<![IGNORE[<!ELEMENT e (#PCDATA)*>]]>\n&en;"); + CharData storage; + + CharData_Init(&storage); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetUserData(g_parser, &storage); + XML_SetExternalEntityRefHandler(g_parser, external_entity_load_ignore_utf16); + XML_SetDefaultHandler(g_parser, accumulate_characters); + XML_SetStartDoctypeDeclHandler(g_parser, dummy_start_doctype_handler); + XML_SetEndDoctypeDeclHandler(g_parser, dummy_end_doctype_handler); + XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); + XML_SetStartElementHandler(g_parser, dummy_start_element); + XML_SetEndElementHandler(g_parser, dummy_end_element); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_ignore_section_utf16_be) { + const char text[] = + /* <!DOCTYPE d SYSTEM 's'> */ + "\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0d\0 " + "\0S\0Y\0S\0T\0E\0M\0 \0'\0s\0'\0>\0\n" + /* <d><e>&en;</e></d> */ + "\0<\0d\0>\0<\0e\0>\0&\0e\0n\0;\0<\0/\0e\0>\0<\0/\0d\0>"; + const XML_Char *expected = XCS("<![IGNORE[<!ELEMENT e (#PCDATA)*>]]>\n&en;"); + CharData storage; + + CharData_Init(&storage); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetUserData(g_parser, &storage); + XML_SetExternalEntityRefHandler(g_parser, + external_entity_load_ignore_utf16_be); + XML_SetDefaultHandler(g_parser, accumulate_characters); + XML_SetStartDoctypeDeclHandler(g_parser, dummy_start_doctype_handler); + XML_SetEndDoctypeDeclHandler(g_parser, dummy_end_doctype_handler); + XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); + XML_SetStartElementHandler(g_parser, dummy_start_element); + XML_SetEndElementHandler(g_parser, dummy_end_element); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test mis-formatted conditional exclusion */ +START_TEST(test_bad_ignore_section) { + const char *text = "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc><e>&entity;</e></doc>"; + ExtFaults faults[] + = {{"<![IGNORE[<!ELEM", "Broken-off declaration not faulted", NULL, + XML_ERROR_SYNTAX}, + {"<![IGNORE[\x01]]>", "Invalid XML character not faulted", NULL, + XML_ERROR_INVALID_TOKEN}, + {/* FIrst two bytes of a three-byte char */ + "<![IGNORE[\xe2\x82", "Partial XML character not faulted", NULL, + XML_ERROR_PARTIAL_CHAR}, + {NULL, NULL, NULL, XML_ERROR_NONE}}; + ExtFaults *fault; + + for (fault = &faults[0]; fault->parse_text != NULL; fault++) { + set_subtest("%s", fault->parse_text); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter); + XML_SetUserData(g_parser, fault); + expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, + "Incomplete IGNORE section not failed"); + XML_ParserReset(g_parser, NULL); + } +} +END_TEST + +struct bom_testdata { + const char *external; + int split; + XML_Bool nested_callback_happened; +}; + +static int XMLCALL +external_bom_checker(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text; + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + + XML_Parser ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + + if (! xcstrcmp(systemId, XCS("004-2.ent"))) { + struct bom_testdata *const testdata + = (struct bom_testdata *)XML_GetUserData(parser); + const char *const external = testdata->external; + const int split = testdata->split; + testdata->nested_callback_happened = XML_TRUE; + + if (_XML_Parse_SINGLE_BYTES(ext_parser, external, split, XML_FALSE) + != XML_STATUS_OK) { + xml_failure(ext_parser); + } + text = external + split; // the parse below will continue where we left off. + } else if (! xcstrcmp(systemId, XCS("004-1.ent"))) { + text = "<!ELEMENT doc EMPTY>\n" + "<!ENTITY % e1 SYSTEM '004-2.ent'>\n" + "<!ENTITY % e2 '%e1;'>\n"; + } else { + fail("unknown systemId"); + } + + if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_OK) + xml_failure(ext_parser); + + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +/* regression test: BOM should be consumed when followed by a partial token. */ +START_TEST(test_external_bom_consumed) { + const char *const text = "<!DOCTYPE doc SYSTEM '004-1.ent'>\n" + "<doc></doc>\n"; + const char *const external = "\xEF\xBB\xBF<!ATTLIST doc a1 CDATA 'value'>"; + const int len = (int)strlen(external); + for (int split = 0; split <= len; ++split) { + set_subtest("split at byte %d", split); + + struct bom_testdata testdata; + testdata.external = external; + testdata.split = split; + testdata.nested_callback_happened = XML_FALSE; + + XML_Parser parser = XML_ParserCreate(NULL); + if (parser == NULL) { + fail("Couldn't create parser"); + } + XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(parser, external_bom_checker); + XML_SetUserData(parser, &testdata); + if (_XML_Parse_SINGLE_BYTES(parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(parser); + if (! testdata.nested_callback_happened) { + fail("ref handler not called"); + } + XML_ParserFree(parser); + } +} +END_TEST + +/* Test recursive parsing */ +START_TEST(test_external_entity_values) { + const char *text = "<!DOCTYPE doc SYSTEM '004-1.ent'>\n" + "<doc></doc>\n"; + ExtFaults data_004_2[] = { + {"<!ATTLIST doc a1 CDATA 'value'>", NULL, NULL, XML_ERROR_NONE}, + {"<!ATTLIST $doc a1 CDATA 'value'>", "Invalid token not faulted", NULL, + XML_ERROR_INVALID_TOKEN}, + {"'wombat", "Unterminated string not faulted", NULL, + XML_ERROR_UNCLOSED_TOKEN}, + {"\xe2\x82", "Partial UTF-8 character not faulted", NULL, + XML_ERROR_PARTIAL_CHAR}, + {"<?xml version='1.0' encoding='utf-8'?>\n", NULL, NULL, XML_ERROR_NONE}, + {"<?xml?>", "Malformed XML declaration not faulted", NULL, + XML_ERROR_XML_DECL}, + {/* UTF-8 BOM */ + "\xEF\xBB\xBF<!ATTLIST doc a1 CDATA 'value'>", NULL, NULL, + XML_ERROR_NONE}, + {"<?xml version='1.0' encoding='utf-8'?>\n$", + "Invalid token after text declaration not faulted", NULL, + XML_ERROR_INVALID_TOKEN}, + {"<?xml version='1.0' encoding='utf-8'?>\n'wombat", + "Unterminated string after text decl not faulted", NULL, + XML_ERROR_UNCLOSED_TOKEN}, + {"<?xml version='1.0' encoding='utf-8'?>\n\xe2\x82", + "Partial UTF-8 character after text decl not faulted", NULL, + XML_ERROR_PARTIAL_CHAR}, + {"%e1;", "Recursive parameter entity not faulted", NULL, + XML_ERROR_RECURSIVE_ENTITY_REF}, + {NULL, NULL, NULL, XML_ERROR_NONE}}; + int i; + + for (i = 0; data_004_2[i].parse_text != NULL; i++) { + set_subtest("%s", data_004_2[i].parse_text); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_valuer); + XML_SetUserData(g_parser, &data_004_2[i]); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + XML_ParserReset(g_parser, NULL); + } +} +END_TEST + +/* Test the recursive parse interacts with a not standalone handler */ +START_TEST(test_ext_entity_not_standalone) { + const char *text = "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc></doc>"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_not_standalone); + expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, + "Standalone rejection not caught"); +} +END_TEST + +START_TEST(test_ext_entity_value_abort) { + const char *text = "<!DOCTYPE doc SYSTEM '004-1.ent'>\n" + "<doc></doc>\n"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_value_aborter); + g_resumable = XML_FALSE; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +START_TEST(test_bad_public_doctype) { + const char *text = "<?xml version='1.0' encoding='utf-8'?>\n" + "<!DOCTYPE doc PUBLIC '{BadName}' 'test'>\n" + "<doc></doc>"; + + /* Setting a handler provokes a particular code path */ + XML_SetDoctypeDeclHandler(g_parser, dummy_start_doctype_handler, + dummy_end_doctype_handler); + expect_failure(text, XML_ERROR_PUBLICID, "Bad Public ID not failed"); +} +END_TEST + +/* Test based on ibm/valid/P32/ibm32v04.xml */ +START_TEST(test_attribute_enum_value) { + const char *text = "<?xml version='1.0' standalone='no'?>\n" + "<!DOCTYPE animal SYSTEM 'test.dtd'>\n" + "<animal>This is a \n <a/> \n\nyellow tiger</animal>"; + ExtTest dtd_data + = {"<!ELEMENT animal (#PCDATA|a)*>\n" + "<!ELEMENT a EMPTY>\n" + "<!ATTLIST animal xml:space (default|preserve) 'preserve'>", + NULL, NULL}; + const XML_Char *expected = XCS("This is a \n \n\nyellow tiger"); + + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); + XML_SetUserData(g_parser, &dtd_data); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + /* An attribute list handler provokes a different code path */ + XML_SetAttlistDeclHandler(g_parser, dummy_attlist_decl_handler); + run_ext_character_check(text, &dtd_data, expected); +} +END_TEST + +/* Slightly bizarrely, the library seems to silently ignore entity + * definitions for predefined entities, even when they are wrong. The + * language of the XML 1.0 spec is somewhat unhelpful as to what ought + * to happen, so this is currently treated as acceptable. + */ +START_TEST(test_predefined_entity_redefinition) { + const char *text = "<!DOCTYPE doc [\n" + "<!ENTITY apos 'foo'>\n" + "]>\n" + "<doc>'</doc>"; + run_character_check(text, XCS("'")); +} +END_TEST + +/* Test that the parser stops processing the DTD after an unresolved + * parameter entity is encountered. + */ +START_TEST(test_dtd_stop_processing) { + const char *text = "<!DOCTYPE doc [\n" + "%foo;\n" + "<!ENTITY bar 'bas'>\n" + "]><doc/>"; + + XML_SetEntityDeclHandler(g_parser, dummy_entity_decl_handler); + init_dummy_handlers(); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + if (get_dummy_handler_flags() != 0) + fail("DTD processing still going after undefined PE"); +} +END_TEST + +/* Test public notations with no system ID */ +START_TEST(test_public_notation_no_sysid) { + const char *text = "<!DOCTYPE doc [\n" + "<!NOTATION note PUBLIC 'foo'>\n" + "<!ELEMENT doc EMPTY>\n" + "]>\n<doc/>"; + + init_dummy_handlers(); + XML_SetNotationDeclHandler(g_parser, dummy_notation_decl_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + if (get_dummy_handler_flags() != DUMMY_NOTATION_DECL_HANDLER_FLAG) + fail("Notation declaration handler not called"); +} +END_TEST + +START_TEST(test_nested_groups) { + const char *text + = "<!DOCTYPE doc [\n" + "<!ELEMENT doc " + /* Sixteen elements per line */ + "(e,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?," + "(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?" + "))))))))))))))))))))))))))))))))>\n" + "<!ELEMENT e EMPTY>" + "]>\n" + "<doc><e/></doc>"; + CharData storage; + + CharData_Init(&storage); + XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); + XML_SetStartElementHandler(g_parser, record_element_start_handler); + XML_SetUserData(g_parser, &storage); + init_dummy_handlers(); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, XCS("doce")); + if (get_dummy_handler_flags() != DUMMY_ELEMENT_DECL_HANDLER_FLAG) + fail("Element handler not fired"); +} +END_TEST + +START_TEST(test_group_choice) { + const char *text = "<!DOCTYPE doc [\n" + "<!ELEMENT doc (a|b|c)+>\n" + "<!ELEMENT a EMPTY>\n" + "<!ELEMENT b (#PCDATA)>\n" + "<!ELEMENT c ANY>\n" + "]>\n" + "<doc>\n" + "<a/>\n" + "<b attr='foo'>This is a foo</b>\n" + "<c></c>\n" + "</doc>\n"; + + XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); + init_dummy_handlers(); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + if (get_dummy_handler_flags() != DUMMY_ELEMENT_DECL_HANDLER_FLAG) + fail("Element handler flag not raised"); +} +END_TEST + +START_TEST(test_standalone_parameter_entity) { + const char *text = "<?xml version='1.0' standalone='yes'?>\n" + "<!DOCTYPE doc SYSTEM 'http://example.org/' [\n" + "<!ENTITY % entity '<!ELEMENT doc (#PCDATA)>'>\n" + "%entity;\n" + "]>\n" + "<doc></doc>"; + char dtd_data[] = "<!ENTITY % e1 'foo'>\n"; + + XML_SetUserData(g_parser, dtd_data); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_public); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test skipping of parameter entity in an external DTD */ +/* Derived from ibm/invalid/P69/ibm69i01.xml */ +START_TEST(test_skipped_parameter_entity) { + const char *text = "<?xml version='1.0'?>\n" + "<!DOCTYPE root SYSTEM 'http://example.org/dtd.ent' [\n" + "<!ELEMENT root (#PCDATA|a)* >\n" + "]>\n" + "<root></root>"; + ExtTest dtd_data = {"%pe2;", NULL, NULL}; + + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); + XML_SetUserData(g_parser, &dtd_data); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetSkippedEntityHandler(g_parser, dummy_skip_handler); + init_dummy_handlers(); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + if (get_dummy_handler_flags() != DUMMY_SKIP_HANDLER_FLAG) + fail("Skip handler not executed"); +} +END_TEST + +/* Test recursive parameter entity definition rejected in external DTD */ +START_TEST(test_recursive_external_parameter_entity) { + const char *text = "<?xml version='1.0'?>\n" + "<!DOCTYPE root SYSTEM 'http://example.org/dtd.ent' [\n" + "<!ELEMENT root (#PCDATA|a)* >\n" + "]>\n" + "<root></root>"; + ExtFaults dtd_data = {"<!ENTITY % pe2 '%pe2;'>\n%pe2;", + "Recursive external parameter entity not faulted", NULL, + XML_ERROR_RECURSIVE_ENTITY_REF}; + + XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter); + XML_SetUserData(g_parser, &dtd_data); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, + "Recursive external parameter not spotted"); +} +END_TEST + +/* Test undefined parameter entity in external entity handler */ +START_TEST(test_undefined_ext_entity_in_external_dtd) { + const char *text = "<!DOCTYPE doc SYSTEM 'foo'>\n" + "<doc></doc>\n"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_devaluer); + XML_SetUserData(g_parser, NULL); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + + /* Now repeat without the external entity ref handler invoking + * another copy of itself. + */ + XML_ParserReset(g_parser, NULL); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_devaluer); + XML_SetUserData(g_parser, g_parser); /* Any non-NULL value will do */ + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test suspending the parse on receiving an XML declaration works */ +START_TEST(test_suspend_xdecl) { + const char *text = long_character_data_text; + + XML_SetXmlDeclHandler(g_parser, entity_suspending_xdecl_handler); + XML_SetUserData(g_parser, g_parser); + g_resumable = XML_TRUE; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_SUSPENDED) + xml_failure(g_parser); + if (XML_GetErrorCode(g_parser) != XML_ERROR_NONE) + xml_failure(g_parser); + /* Attempt to start a new parse while suspended */ + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Attempt to parse while suspended not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_SUSPENDED) + fail("Suspended parse not faulted with correct error"); +} +END_TEST + +/* Test aborting the parse in an epilog works */ +START_TEST(test_abort_epilog) { + const char *text = "<doc></doc>\n\r\n"; + XML_Char trigger_char = XCS('\r'); + + XML_SetDefaultHandler(g_parser, selective_aborting_default_handler); + XML_SetUserData(g_parser, &trigger_char); + g_resumable = XML_FALSE; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Abort not triggered"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_ABORTED) + xml_failure(g_parser); +} +END_TEST + +/* Test a different code path for abort in the epilog */ +START_TEST(test_abort_epilog_2) { + const char *text = "<doc></doc>\n"; + XML_Char trigger_char = XCS('\n'); + + XML_SetDefaultHandler(g_parser, selective_aborting_default_handler); + XML_SetUserData(g_parser, &trigger_char); + g_resumable = XML_FALSE; + expect_failure(text, XML_ERROR_ABORTED, "Abort not triggered"); +} +END_TEST + +/* Test suspension from the epilog */ +START_TEST(test_suspend_epilog) { + const char *text = "<doc></doc>\n"; + XML_Char trigger_char = XCS('\n'); + + XML_SetDefaultHandler(g_parser, selective_aborting_default_handler); + XML_SetUserData(g_parser, &trigger_char); + g_resumable = XML_TRUE; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_SUSPENDED) + xml_failure(g_parser); +} +END_TEST + +START_TEST(test_suspend_in_sole_empty_tag) { + const char *text = "<doc/>"; + enum XML_Status rc; + + XML_SetEndElementHandler(g_parser, suspending_end_handler); + XML_SetUserData(g_parser, g_parser); + rc = _XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE); + if (rc == XML_STATUS_ERROR) + xml_failure(g_parser); + else if (rc != XML_STATUS_SUSPENDED) + fail("Suspend not triggered"); + rc = XML_ResumeParser(g_parser); + if (rc == XML_STATUS_ERROR) + xml_failure(g_parser); + else if (rc != XML_STATUS_OK) + fail("Resume failed"); +} +END_TEST + +START_TEST(test_unfinished_epilog) { + const char *text = "<doc></doc><"; + + expect_failure(text, XML_ERROR_UNCLOSED_TOKEN, + "Incomplete epilog entry not faulted"); +} +END_TEST + +START_TEST(test_partial_char_in_epilog) { + const char *text = "<doc></doc>\xe2\x82"; + + /* First check that no fault is raised if the parse is not finished */ + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + /* Now check that it is faulted once we finish */ + if (XML_ParseBuffer(g_parser, 0, XML_TRUE) != XML_STATUS_ERROR) + fail("Partial character in epilog not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_PARTIAL_CHAR) + xml_failure(g_parser); +} +END_TEST + +/* Test resuming a parse suspended in entity substitution */ +START_TEST(test_suspend_resume_internal_entity) { + const char *text + = "<!DOCTYPE doc [\n" + "<!ENTITY foo '<suspend>Hi<suspend>Ho</suspend></suspend>'>\n" + "]>\n" + "<doc>&foo;</doc>\n"; + const XML_Char *expected1 = XCS("Hi"); + const XML_Char *expected2 = XCS("HiHo"); + CharData storage; + + CharData_Init(&storage); + XML_SetStartElementHandler(g_parser, start_element_suspender); + XML_SetCharacterDataHandler(g_parser, accumulate_characters); + XML_SetUserData(g_parser, &storage); + // can't use SINGLE_BYTES here, because it'll return early on suspension, and + // we won't know exactly how much input we actually managed to give Expat. + if (XML_Parse(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_SUSPENDED) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, XCS("")); + if (XML_ResumeParser(g_parser) != XML_STATUS_SUSPENDED) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected1); + if (XML_ResumeParser(g_parser) != XML_STATUS_OK) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected2); +} +END_TEST + +START_TEST(test_suspend_resume_internal_entity_issue_629) { + const char *const text + = "<!DOCTYPE a [<!ENTITY e '<!--COMMENT-->a'>]><a>&e;<b>\n" + "<" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "/>" + "</b></a>"; + const size_t firstChunkSizeBytes = 54; + + XML_Parser parser = XML_ParserCreate(NULL); + XML_SetUserData(parser, parser); + XML_SetCommentHandler(parser, suspending_comment_handler); + + if (XML_Parse(parser, text, (int)firstChunkSizeBytes, XML_FALSE) + != XML_STATUS_SUSPENDED) + xml_failure(parser); + if (XML_ResumeParser(parser) != XML_STATUS_OK) + xml_failure(parser); + if (_XML_Parse_SINGLE_BYTES(parser, text + firstChunkSizeBytes, + (int)(strlen(text) - firstChunkSizeBytes), + XML_TRUE) + != XML_STATUS_OK) + xml_failure(parser); + XML_ParserFree(parser); +} +END_TEST + +/* Test syntax error is caught at parse resumption */ +START_TEST(test_resume_entity_with_syntax_error) { + const char *text = "<!DOCTYPE doc [\n" + "<!ENTITY foo '<suspend>Hi</wombat>'>\n" + "]>\n" + "<doc>&foo;</doc>\n"; + + XML_SetStartElementHandler(g_parser, start_element_suspender); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_SUSPENDED) + xml_failure(g_parser); + if (XML_ResumeParser(g_parser) != XML_STATUS_ERROR) + fail("Syntax error in entity not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_TAG_MISMATCH) + xml_failure(g_parser); +} +END_TEST + +/* Test suspending and resuming in a parameter entity substitution */ +START_TEST(test_suspend_resume_parameter_entity) { + const char *text = "<!DOCTYPE doc [\n" + "<!ENTITY % foo '<!ELEMENT doc (#PCDATA)*>'>\n" + "%foo;\n" + "]>\n" + "<doc>Hello, world</doc>"; + const XML_Char *expected = XCS("Hello, world"); + CharData storage; + + CharData_Init(&storage); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetElementDeclHandler(g_parser, element_decl_suspender); + XML_SetCharacterDataHandler(g_parser, accumulate_characters); + XML_SetUserData(g_parser, &storage); + if (XML_Parse(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_SUSPENDED) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, XCS("")); + if (XML_ResumeParser(g_parser) != XML_STATUS_OK) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test attempting to use parser after an error is faulted */ +START_TEST(test_restart_on_error) { + const char *text = "<$doc><doc></doc>"; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Invalid tag name not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_INVALID_TOKEN) + xml_failure(g_parser); + if (XML_Parse(g_parser, NULL, 0, XML_TRUE) != XML_STATUS_ERROR) + fail("Restarting invalid parse not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_INVALID_TOKEN) + xml_failure(g_parser); +} +END_TEST + +/* Test that angle brackets in an attribute default value are faulted */ +START_TEST(test_reject_lt_in_attribute_value) { + const char *text = "<!DOCTYPE doc [<!ATTLIST doc a CDATA '<bar>'>]>\n" + "<doc></doc>"; + + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "Bad attribute default not faulted"); +} +END_TEST + +START_TEST(test_reject_unfinished_param_in_att_value) { + const char *text = "<!DOCTYPE doc [<!ATTLIST doc a CDATA '&foo'>]>\n" + "<doc></doc>"; + + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "Bad attribute default not faulted"); +} +END_TEST + +START_TEST(test_trailing_cr_in_att_value) { + const char *text = "<doc a='value\r'/>"; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Try parsing a general entity within a parameter entity in a + * standalone internal DTD. Covers a corner case in the parser. + */ +START_TEST(test_standalone_internal_entity) { + const char *text = "<?xml version='1.0' standalone='yes' ?>\n" + "<!DOCTYPE doc [\n" + " <!ELEMENT doc (#PCDATA)>\n" + " <!ENTITY % pe '<!ATTLIST doc att2 CDATA \"≥\">'>\n" + " <!ENTITY ge 'AttDefaultValue'>\n" + " %pe;\n" + "]>\n" + "<doc att2='any'/>"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test that a reference to an unknown external entity is skipped */ +START_TEST(test_skipped_external_entity) { + const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/'>\n" + "<doc></doc>\n"; + ExtTest test_data = {"<!ELEMENT doc EMPTY>\n" + "<!ENTITY % e2 '%e1;'>\n", + NULL, NULL}; + + XML_SetUserData(g_parser, &test_data); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test a different form of unknown external entity */ +START_TEST(test_skipped_null_loaded_ext_entity) { + const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/one.ent'>\n" + "<doc />"; + ExtHdlrData test_data + = {"<!ENTITY % pe1 SYSTEM 'http://example.org/two.ent'>\n" + "<!ENTITY % pe2 '%pe1;'>\n" + "%pe2;\n", + external_entity_null_loader}; + + XML_SetUserData(g_parser, &test_data); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_oneshot_loader); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +START_TEST(test_skipped_unloaded_ext_entity) { + const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/one.ent'>\n" + "<doc />"; + ExtHdlrData test_data + = {"<!ENTITY % pe1 SYSTEM 'http://example.org/two.ent'>\n" + "<!ENTITY % pe2 '%pe1;'>\n" + "%pe2;\n", + NULL}; + + XML_SetUserData(g_parser, &test_data); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_oneshot_loader); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test that a parameter entity value ending with a carriage return + * has it translated internally into a newline. + */ +START_TEST(test_param_entity_with_trailing_cr) { +#define PARAM_ENTITY_NAME "pe" +#define PARAM_ENTITY_CORE_VALUE "<!ATTLIST doc att CDATA \"default\">" + const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/'>\n" + "<doc/>"; + ExtTest test_data + = {"<!ENTITY % " PARAM_ENTITY_NAME " '" PARAM_ENTITY_CORE_VALUE "\r'>\n" + "%" PARAM_ENTITY_NAME ";\n", + NULL, NULL}; + + XML_SetUserData(g_parser, &test_data); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); + XML_SetEntityDeclHandler(g_parser, param_entity_match_handler); + param_entity_match_init(XCS(PARAM_ENTITY_NAME), + XCS(PARAM_ENTITY_CORE_VALUE) XCS("\n")); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + int entity_match_flag = get_param_entity_match_flag(); + if (entity_match_flag == ENTITY_MATCH_FAIL) + fail("Parameter entity CR->NEWLINE conversion failed"); + else if (entity_match_flag == ENTITY_MATCH_NOT_FOUND) + fail("Parameter entity not parsed"); +} +#undef PARAM_ENTITY_NAME +#undef PARAM_ENTITY_CORE_VALUE +END_TEST + +START_TEST(test_invalid_character_entity) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY entity '�'>\n" + "]>\n" + "<doc>&entity;</doc>"; + + expect_failure(text, XML_ERROR_BAD_CHAR_REF, + "Out of range character reference not faulted"); +} +END_TEST + +START_TEST(test_invalid_character_entity_2) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY entity '&#xg0;'>\n" + "]>\n" + "<doc>&entity;</doc>"; + + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "Out of range character reference not faulted"); +} +END_TEST + +START_TEST(test_invalid_character_entity_3) { + const char text[] = + /* <!DOCTYPE doc [\n */ + "\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0d\0o\0c\0 \0[\0\n" + /* U+0E04 = KHO KHWAI + * U+0E08 = CHO CHAN */ + /* <!ENTITY entity '&\u0e04\u0e08;'>\n */ + "\0<\0!\0E\0N\0T\0I\0T\0Y\0 \0e\0n\0t\0i\0t\0y\0 " + "\0'\0&\x0e\x04\x0e\x08\0;\0'\0>\0\n" + /* ]>\n */ + "\0]\0>\0\n" + /* <doc>&entity;</doc> */ + "\0<\0d\0o\0c\0>\0&\0e\0n\0t\0i\0t\0y\0;\0<\0/\0d\0o\0c\0>"; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + != XML_STATUS_ERROR) + fail("Invalid start of entity name not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_UNDEFINED_ENTITY) + xml_failure(g_parser); +} +END_TEST + +START_TEST(test_invalid_character_entity_4) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY entity '�'>\n" /* = � */ + "]>\n" + "<doc>&entity;</doc>"; + + expect_failure(text, XML_ERROR_BAD_CHAR_REF, + "Out of range character reference not faulted"); +} +END_TEST + +/* Test that processing instructions are picked up by a default handler */ +START_TEST(test_pi_handled_in_default) { + const char *text = "<?test processing instruction?>\n<doc/>"; + const XML_Char *expected = XCS("<?test processing instruction?>\n<doc/>"); + CharData storage; + + CharData_Init(&storage); + XML_SetDefaultHandler(g_parser, accumulate_characters); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test that comments are picked up by a default handler */ +START_TEST(test_comment_handled_in_default) { + const char *text = "<!-- This is a comment -->\n<doc/>"; + const XML_Char *expected = XCS("<!-- This is a comment -->\n<doc/>"); + CharData storage; + + CharData_Init(&storage); + XML_SetDefaultHandler(g_parser, accumulate_characters); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test PIs that look almost but not quite like XML declarations */ +START_TEST(test_pi_yml) { + const char *text = "<?yml something like data?><doc/>"; + const XML_Char *expected = XCS("yml: something like data\n"); + CharData storage; + + CharData_Init(&storage); + XML_SetProcessingInstructionHandler(g_parser, accumulate_pi_characters); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_pi_xnl) { + const char *text = "<?xnl nothing like data?><doc/>"; + const XML_Char *expected = XCS("xnl: nothing like data\n"); + CharData storage; + + CharData_Init(&storage); + XML_SetProcessingInstructionHandler(g_parser, accumulate_pi_characters); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_pi_xmm) { + const char *text = "<?xmm everything like data?><doc/>"; + const XML_Char *expected = XCS("xmm: everything like data\n"); + CharData storage; + + CharData_Init(&storage); + XML_SetProcessingInstructionHandler(g_parser, accumulate_pi_characters); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_utf16_pi) { + const char text[] = + /* <?{KHO KHWAI}{CHO CHAN}?> + * where {KHO KHWAI} = U+0E04 + * and {CHO CHAN} = U+0E08 + */ + "<\0?\0\x04\x0e\x08\x0e?\0>\0" + /* <q/> */ + "<\0q\0/\0>\0"; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x0e04\x0e08: \n"); +#else + const XML_Char *expected = XCS("\xe0\xb8\x84\xe0\xb8\x88: \n"); +#endif + CharData storage; + + CharData_Init(&storage); + XML_SetProcessingInstructionHandler(g_parser, accumulate_pi_characters); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_utf16_be_pi) { + const char text[] = + /* <?{KHO KHWAI}{CHO CHAN}?> + * where {KHO KHWAI} = U+0E04 + * and {CHO CHAN} = U+0E08 + */ + "\0<\0?\x0e\x04\x0e\x08\0?\0>" + /* <q/> */ + "\0<\0q\0/\0>"; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x0e04\x0e08: \n"); +#else + const XML_Char *expected = XCS("\xe0\xb8\x84\xe0\xb8\x88: \n"); +#endif + CharData storage; + + CharData_Init(&storage); + XML_SetProcessingInstructionHandler(g_parser, accumulate_pi_characters); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test that comments can be picked up and translated */ +START_TEST(test_utf16_be_comment) { + const char text[] = + /* <!-- Comment A --> */ + "\0<\0!\0-\0-\0 \0C\0o\0m\0m\0e\0n\0t\0 \0A\0 \0-\0-\0>\0\n" + /* <doc/> */ + "\0<\0d\0o\0c\0/\0>"; + const XML_Char *expected = XCS(" Comment A "); + CharData storage; + + CharData_Init(&storage); + XML_SetCommentHandler(g_parser, accumulate_comment); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_utf16_le_comment) { + const char text[] = + /* <!-- Comment B --> */ + "<\0!\0-\0-\0 \0C\0o\0m\0m\0e\0n\0t\0 \0B\0 \0-\0-\0>\0\n\0" + /* <doc/> */ + "<\0d\0o\0c\0/\0>\0"; + const XML_Char *expected = XCS(" Comment B "); + CharData storage; + + CharData_Init(&storage); + XML_SetCommentHandler(g_parser, accumulate_comment); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test that the unknown encoding handler with map entries that expect + * conversion but no conversion function is faulted + */ +START_TEST(test_missing_encoding_conversion_fn) { + const char *text = "<?xml version='1.0' encoding='no-conv'?>\n" + "<doc>\x81</doc>"; + + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + /* MiscEncodingHandler sets up an encoding with every top-bit-set + * character introducing a two-byte sequence. For this, it + * requires a convert function. The above function call doesn't + * pass one through, so when BadEncodingHandler actually gets + * called it should supply an invalid encoding. + */ + expect_failure(text, XML_ERROR_UNKNOWN_ENCODING, + "Encoding with missing convert() not faulted"); +} +END_TEST + +START_TEST(test_failing_encoding_conversion_fn) { + const char *text = "<?xml version='1.0' encoding='failing-conv'?>\n" + "<doc>\x81</doc>"; + + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + /* BadEncodingHandler sets up an encoding with every top-bit-set + * character introducing a two-byte sequence. For this, it + * requires a convert function. The above function call passes + * one that insists all possible sequences are invalid anyway. + */ + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "Encoding with failing convert() not faulted"); +} +END_TEST + +/* Test unknown encoding conversions */ +START_TEST(test_unknown_encoding_success) { + const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n" + /* Equivalent to <eoc>Hello, world</eoc> */ + "<\x81\x64\x80oc>Hello, world</\x81\x64\x80oc>"; + + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + run_character_check(text, XCS("Hello, world")); +} +END_TEST + +/* Test bad name character in unknown encoding */ +START_TEST(test_unknown_encoding_bad_name) { + const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n" + "<\xff\x64oc>Hello, world</\xff\x64oc>"; + + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "Bad name start in unknown encoding not faulted"); +} +END_TEST + +/* Test bad mid-name character in unknown encoding */ +START_TEST(test_unknown_encoding_bad_name_2) { + const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n" + "<d\xffoc>Hello, world</d\xffoc>"; + + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "Bad name in unknown encoding not faulted"); +} +END_TEST + +/* Test element name that is long enough to fill the conversion buffer + * in an unknown encoding, finishing with an encoded character. + */ +START_TEST(test_unknown_encoding_long_name_1) { + const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n" + "<abcdefghabcdefghabcdefghijkl\x80m\x80n\x80o\x80p>" + "Hi" + "</abcdefghabcdefghabcdefghijkl\x80m\x80n\x80o\x80p>"; + const XML_Char *expected = XCS("abcdefghabcdefghabcdefghijklmnop"); + CharData storage; + + CharData_Init(&storage); + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + XML_SetStartElementHandler(g_parser, record_element_start_handler); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test element name that is long enough to fill the conversion buffer + * in an unknown encoding, finishing with an simple character. + */ +START_TEST(test_unknown_encoding_long_name_2) { + const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n" + "<abcdefghabcdefghabcdefghijklmnop>" + "Hi" + "</abcdefghabcdefghabcdefghijklmnop>"; + const XML_Char *expected = XCS("abcdefghabcdefghabcdefghijklmnop"); + CharData storage; + + CharData_Init(&storage); + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + XML_SetStartElementHandler(g_parser, record_element_start_handler); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_invalid_unknown_encoding) { + const char *text = "<?xml version='1.0' encoding='invalid-9'?>\n" + "<doc>Hello world</doc>"; + + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + expect_failure(text, XML_ERROR_UNKNOWN_ENCODING, + "Invalid unknown encoding not faulted"); +} +END_TEST + +START_TEST(test_unknown_ascii_encoding_ok) { + const char *text = "<?xml version='1.0' encoding='ascii-like'?>\n" + "<doc>Hello, world</doc>"; + + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + run_character_check(text, XCS("Hello, world")); +} +END_TEST + +START_TEST(test_unknown_ascii_encoding_fail) { + const char *text = "<?xml version='1.0' encoding='ascii-like'?>\n" + "<doc>Hello, \x80 world</doc>"; + + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "Invalid character not faulted"); +} +END_TEST + +START_TEST(test_unknown_encoding_invalid_length) { + const char *text = "<?xml version='1.0' encoding='invalid-len'?>\n" + "<doc>Hello, world</doc>"; + + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + expect_failure(text, XML_ERROR_UNKNOWN_ENCODING, + "Invalid unknown encoding not faulted"); +} +END_TEST + +START_TEST(test_unknown_encoding_invalid_topbit) { + const char *text = "<?xml version='1.0' encoding='invalid-a'?>\n" + "<doc>Hello, world</doc>"; + + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + expect_failure(text, XML_ERROR_UNKNOWN_ENCODING, + "Invalid unknown encoding not faulted"); +} +END_TEST + +START_TEST(test_unknown_encoding_invalid_surrogate) { + const char *text = "<?xml version='1.0' encoding='invalid-surrogate'?>\n" + "<doc>Hello, \x82 world</doc>"; + + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "Invalid unknown encoding not faulted"); +} +END_TEST + +START_TEST(test_unknown_encoding_invalid_high) { + const char *text = "<?xml version='1.0' encoding='invalid-high'?>\n" + "<doc>Hello, world</doc>"; + + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + expect_failure(text, XML_ERROR_UNKNOWN_ENCODING, + "Invalid unknown encoding not faulted"); +} +END_TEST + +START_TEST(test_unknown_encoding_invalid_attr_value) { + const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n" + "<doc attr='\xff\x30'/>"; + + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "Invalid attribute valid not faulted"); +} +END_TEST + +/* Test an external entity parser set to use latin-1 detects UTF-16 + * BOMs correctly. + */ +/* Test that UTF-16 BOM does not select UTF-16 given explicit encoding */ +START_TEST(test_ext_entity_latin1_utf16le_bom) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + ExtTest2 test_data + = {/* If UTF-16, 0xfeff is the BOM and 0x204c is black left bullet */ + /* If Latin-1, 0xff = Y-diaeresis, 0xfe = lowercase thorn, + * 0x4c = L and 0x20 is a space + */ + "\xff\xfe\x4c\x20", 4, XCS("iso-8859-1"), NULL}; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x00ff\x00feL "); +#else + /* In UTF-8, y-diaeresis is 0xc3 0xbf, lowercase thorn is 0xc3 0xbe */ + const XML_Char *expected = XCS("\xc3\xbf\xc3\xbeL "); +#endif + CharData storage; + + CharData_Init(&storage); + test_data.storage = &storage; + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); + XML_SetUserData(g_parser, &test_data); + XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_ext_entity_latin1_utf16be_bom) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + ExtTest2 test_data + = {/* If UTF-16, 0xfeff is the BOM and 0x204c is black left bullet */ + /* If Latin-1, 0xff = Y-diaeresis, 0xfe = lowercase thorn, + * 0x4c = L and 0x20 is a space + */ + "\xfe\xff\x20\x4c", 4, XCS("iso-8859-1"), NULL}; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x00fe\x00ff L"); +#else + /* In UTF-8, y-diaeresis is 0xc3 0xbf, lowercase thorn is 0xc3 0xbe */ + const XML_Char *expected = XCS("\xc3\xbe\xc3\xbf L"); +#endif + CharData storage; + + CharData_Init(&storage); + test_data.storage = &storage; + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); + XML_SetUserData(g_parser, &test_data); + XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Parsing the full buffer rather than a byte at a time makes a + * difference to the encoding scanning code, so repeat the above tests + * without breaking them down by byte. + */ +START_TEST(test_ext_entity_latin1_utf16le_bom2) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + ExtTest2 test_data + = {/* If UTF-16, 0xfeff is the BOM and 0x204c is black left bullet */ + /* If Latin-1, 0xff = Y-diaeresis, 0xfe = lowercase thorn, + * 0x4c = L and 0x20 is a space + */ + "\xff\xfe\x4c\x20", 4, XCS("iso-8859-1"), NULL}; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x00ff\x00feL "); +#else + /* In UTF-8, y-diaeresis is 0xc3 0xbf, lowercase thorn is 0xc3 0xbe */ + const XML_Char *expected = XCS("\xc3\xbf\xc3\xbeL "); +#endif + CharData storage; + + CharData_Init(&storage); + test_data.storage = &storage; + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); + XML_SetUserData(g_parser, &test_data); + XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_ext_entity_latin1_utf16be_bom2) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + ExtTest2 test_data + = {/* If UTF-16, 0xfeff is the BOM and 0x204c is black left bullet */ + /* If Latin-1, 0xff = Y-diaeresis, 0xfe = lowercase thorn, + * 0x4c = L and 0x20 is a space + */ + "\xfe\xff\x20\x4c", 4, XCS("iso-8859-1"), NULL}; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x00fe\x00ff L"); +#else + /* In UTF-8, y-diaeresis is 0xc3 0xbf, lowercase thorn is 0xc3 0xbe */ + const XML_Char *expected = "\xc3\xbe\xc3\xbf L"; +#endif + CharData storage; + + CharData_Init(&storage); + test_data.storage = &storage; + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); + XML_SetUserData(g_parser, &test_data); + XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test little-endian UTF-16 given an explicit big-endian encoding */ +START_TEST(test_ext_entity_utf16_be) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + ExtTest2 test_data = {"<\0e\0/\0>\0", 8, XCS("utf-16be"), NULL}; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x3c00\x6500\x2f00\x3e00"); +#else + const XML_Char *expected = XCS("\xe3\xb0\x80" /* U+3C00 */ + "\xe6\x94\x80" /* U+6500 */ + "\xe2\xbc\x80" /* U+2F00 */ + "\xe3\xb8\x80"); /* U+3E00 */ +#endif + CharData storage; + + CharData_Init(&storage); + test_data.storage = &storage; + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); + XML_SetUserData(g_parser, &test_data); + XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test big-endian UTF-16 given an explicit little-endian encoding */ +START_TEST(test_ext_entity_utf16_le) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + ExtTest2 test_data = {"\0<\0e\0/\0>", 8, XCS("utf-16le"), NULL}; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x3c00\x6500\x2f00\x3e00"); +#else + const XML_Char *expected = XCS("\xe3\xb0\x80" /* U+3C00 */ + "\xe6\x94\x80" /* U+6500 */ + "\xe2\xbc\x80" /* U+2F00 */ + "\xe3\xb8\x80"); /* U+3E00 */ +#endif + CharData storage; + + CharData_Init(&storage); + test_data.storage = &storage; + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); + XML_SetUserData(g_parser, &test_data); + XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test little-endian UTF-16 given no explicit encoding. + * The existing default encoding (UTF-8) is assumed to hold without a + * BOM to contradict it, so the entity value will in fact provoke an + * error because 0x00 is not a valid XML character. We parse the + * whole buffer in one go rather than feeding it in byte by byte to + * exercise different code paths in the initial scanning routines. + */ +START_TEST(test_ext_entity_utf16_unknown) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + ExtFaults2 test_data + = {"a\0b\0c\0", 6, "Invalid character in entity not faulted", NULL, + XML_ERROR_INVALID_TOKEN}; + + XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter2); + XML_SetUserData(g_parser, &test_data); + expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, + "Invalid character should not have been accepted"); +} +END_TEST + +/* Test not-quite-UTF-8 BOM (0xEF 0xBB 0xBF) */ +START_TEST(test_ext_entity_utf8_non_bom) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" + "]>\n" + "<doc>&en;</doc>"; + ExtTest2 test_data + = {"\xef\xbb\x80", /* Arabic letter DAD medial form, U+FEC0 */ + 3, NULL, NULL}; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\xfec0"); +#else + const XML_Char *expected = XCS("\xef\xbb\x80"); +#endif + CharData storage; + + CharData_Init(&storage); + test_data.storage = &storage; + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); + XML_SetUserData(g_parser, &test_data); + XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test that UTF-8 in a CDATA section is correctly passed through */ +START_TEST(test_utf8_in_cdata_section) { + const char *text = "<doc><![CDATA[one \xc3\xa9 two]]></doc>"; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("one \x00e9 two"); +#else + const XML_Char *expected = XCS("one \xc3\xa9 two"); +#endif + + run_character_check(text, expected); +} +END_TEST + +/* Test that little-endian UTF-16 in a CDATA section is handled */ +START_TEST(test_utf8_in_cdata_section_2) { + const char *text = "<doc><![CDATA[\xc3\xa9]\xc3\xa9two]]></doc>"; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x00e9]\x00e9two"); +#else + const XML_Char *expected = XCS("\xc3\xa9]\xc3\xa9two"); +#endif + + run_character_check(text, expected); +} +END_TEST + +START_TEST(test_utf8_in_start_tags) { + struct test_case { + bool goodName; + bool goodNameStart; + const char *tagName; + }; + + // The idea with the tests below is this: + // We want to cover 1-, 2- and 3-byte sequences, 4-byte sequences + // go to isNever and are hence not a concern. + // + // We start with a character that is a valid name character + // (or even name-start character, see XML 1.0r4 spec) and then we flip + // single bits at places where (1) the result leaves the UTF-8 encoding space + // and (2) we stay in the same n-byte sequence family. + // + // The flipped bits are highlighted in angle brackets in comments, + // e.g. "[<1>011 1001]" means we had [0011 1001] but we now flipped + // the most significant bit to 1 to leave UTF-8 encoding space. + struct test_case cases[] = { + // 1-byte UTF-8: [0xxx xxxx] + {true, true, "\x3A"}, // [0011 1010] = ASCII colon ':' + {false, false, "\xBA"}, // [<1>011 1010] + {true, false, "\x39"}, // [0011 1001] = ASCII nine '9' + {false, false, "\xB9"}, // [<1>011 1001] + + // 2-byte UTF-8: [110x xxxx] [10xx xxxx] + {true, true, "\xDB\xA5"}, // [1101 1011] [1010 0101] = + // Arabic small waw U+06E5 + {false, false, "\x9B\xA5"}, // [1<0>01 1011] [1010 0101] + {false, false, "\xDB\x25"}, // [1101 1011] [<0>010 0101] + {false, false, "\xDB\xE5"}, // [1101 1011] [1<1>10 0101] + {true, false, "\xCC\x81"}, // [1100 1100] [1000 0001] = + // combining char U+0301 + {false, false, "\x8C\x81"}, // [1<0>00 1100] [1000 0001] + {false, false, "\xCC\x01"}, // [1100 1100] [<0>000 0001] + {false, false, "\xCC\xC1"}, // [1100 1100] [1<1>00 0001] + + // 3-byte UTF-8: [1110 xxxx] [10xx xxxx] [10xxxxxx] + {true, true, "\xE0\xA4\x85"}, // [1110 0000] [1010 0100] [1000 0101] = + // Devanagari Letter A U+0905 + {false, false, "\xA0\xA4\x85"}, // [1<0>10 0000] [1010 0100] [1000 0101] + {false, false, "\xE0\x24\x85"}, // [1110 0000] [<0>010 0100] [1000 0101] + {false, false, "\xE0\xE4\x85"}, // [1110 0000] [1<1>10 0100] [1000 0101] + {false, false, "\xE0\xA4\x05"}, // [1110 0000] [1010 0100] [<0>000 0101] + {false, false, "\xE0\xA4\xC5"}, // [1110 0000] [1010 0100] [1<1>00 0101] + {true, false, "\xE0\xA4\x81"}, // [1110 0000] [1010 0100] [1000 0001] = + // combining char U+0901 + {false, false, "\xA0\xA4\x81"}, // [1<0>10 0000] [1010 0100] [1000 0001] + {false, false, "\xE0\x24\x81"}, // [1110 0000] [<0>010 0100] [1000 0001] + {false, false, "\xE0\xE4\x81"}, // [1110 0000] [1<1>10 0100] [1000 0001] + {false, false, "\xE0\xA4\x01"}, // [1110 0000] [1010 0100] [<0>000 0001] + {false, false, "\xE0\xA4\xC1"}, // [1110 0000] [1010 0100] [1<1>00 0001] + }; + const bool atNameStart[] = {true, false}; + + size_t i = 0; + char doc[1024]; + size_t failCount = 0; + + // we need all the bytes to be parsed, but we don't want the errors that can + // trigger on isFinal=XML_TRUE, so we skip the test if the heuristic is on. + if (g_reparseDeferralEnabledDefault) { + return; + } + + for (; i < sizeof(cases) / sizeof(cases[0]); i++) { + size_t j = 0; + for (; j < sizeof(atNameStart) / sizeof(atNameStart[0]); j++) { + const bool expectedSuccess + = atNameStart[j] ? cases[i].goodNameStart : cases[i].goodName; + snprintf(doc, sizeof(doc), "<%s%s><!--", atNameStart[j] ? "" : "a", + cases[i].tagName); + XML_Parser parser = XML_ParserCreate(NULL); + + const enum XML_Status status = _XML_Parse_SINGLE_BYTES( + parser, doc, (int)strlen(doc), /*isFinal=*/XML_FALSE); + + bool success = true; + if ((status == XML_STATUS_OK) != expectedSuccess) { + success = false; + } + if ((status == XML_STATUS_ERROR) + && (XML_GetErrorCode(parser) != XML_ERROR_INVALID_TOKEN)) { + success = false; + } + + if (! success) { + fprintf( + stderr, + "FAIL case %2u (%sat name start, %u-byte sequence, error code %d)\n", + (unsigned)i + 1u, atNameStart[j] ? " " : "not ", + (unsigned)strlen(cases[i].tagName), XML_GetErrorCode(parser)); + failCount++; + } + + XML_ParserFree(parser); + } + } + + if (failCount > 0) { + fail("UTF-8 regression detected"); + } +} +END_TEST + +/* Test trailing spaces in elements are accepted */ +START_TEST(test_trailing_spaces_in_elements) { + const char *text = "<doc >Hi</doc >"; + const XML_Char *expected = XCS("doc/doc"); + CharData storage; + + CharData_Init(&storage); + XML_SetElementHandler(g_parser, record_element_start_handler, + record_element_end_handler); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_utf16_attribute) { + const char text[] = + /* <d {KHO KHWAI}{CHO CHAN}='a'/> + * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8 + * and {CHO CHAN} = U+0E08 = 0xe0 0xb8 0x88 in UTF-8 + */ + "<\0d\0 \0\x04\x0e\x08\x0e=\0'\0a\0'\0/\0>\0"; + const XML_Char *expected = XCS("a"); + CharData storage; + + CharData_Init(&storage); + XML_SetStartElementHandler(g_parser, accumulate_attribute); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_utf16_second_attr) { + /* <d a='1' {KHO KHWAI}{CHO CHAN}='2'/> + * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8 + * and {CHO CHAN} = U+0E08 = 0xe0 0xb8 0x88 in UTF-8 + */ + const char text[] = "<\0d\0 \0a\0=\0'\0\x31\0'\0 \0" + "\x04\x0e\x08\x0e=\0'\0\x32\0'\0/\0>\0"; + const XML_Char *expected = XCS("1"); + CharData storage; + + CharData_Init(&storage); + XML_SetStartElementHandler(g_parser, accumulate_attribute); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_attr_after_solidus) { + const char *text = "<doc attr1='a' / attr2='b'>"; + + expect_failure(text, XML_ERROR_INVALID_TOKEN, "Misplaced / not faulted"); +} +END_TEST + +START_TEST(test_utf16_pe) { + /* <!DOCTYPE doc [ + * <!ENTITY % {KHO KHWAI}{CHO CHAN} '<!ELEMENT doc (#PCDATA)>'> + * %{KHO KHWAI}{CHO CHAN}; + * ]> + * <doc></doc> + * + * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8 + * and {CHO CHAN} = U+0E08 = 0xe0 0xb8 0x88 in UTF-8 + */ + const char text[] = "\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0d\0o\0c\0 \0[\0\n" + "\0<\0!\0E\0N\0T\0I\0T\0Y\0 \0%\0 \x0e\x04\x0e\x08\0 " + "\0'\0<\0!\0E\0L\0E\0M\0E\0N\0T\0 " + "\0d\0o\0c\0 \0(\0#\0P\0C\0D\0A\0T\0A\0)\0>\0'\0>\0\n" + "\0%\x0e\x04\x0e\x08\0;\0\n" + "\0]\0>\0\n" + "\0<\0d\0o\0c\0>\0<\0/\0d\0o\0c\0>"; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x0e04\x0e08=<!ELEMENT doc (#PCDATA)>\n"); +#else + const XML_Char *expected + = XCS("\xe0\xb8\x84\xe0\xb8\x88=<!ELEMENT doc (#PCDATA)>\n"); +#endif + CharData storage; + + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetEntityDeclHandler(g_parser, accumulate_entity_decl); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test that duff attribute description keywords are rejected */ +START_TEST(test_bad_attr_desc_keyword) { + const char *text = "<!DOCTYPE doc [\n" + " <!ATTLIST doc attr CDATA #!IMPLIED>\n" + "]>\n" + "<doc />"; + + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "Bad keyword !IMPLIED not faulted"); +} +END_TEST + +/* Test that an invalid attribute description keyword consisting of + * UTF-16 characters with their top bytes non-zero are correctly + * faulted + */ +START_TEST(test_bad_attr_desc_keyword_utf16) { + /* <!DOCTYPE d [ + * <!ATTLIST d a CDATA #{KHO KHWAI}{CHO CHAN}> + * ]><d/> + * + * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8 + * and {CHO CHAN} = U+0E08 = 0xe0 0xb8 0x88 in UTF-8 + */ + const char text[] + = "\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0d\0 \0[\0\n" + "\0<\0!\0A\0T\0T\0L\0I\0S\0T\0 \0d\0 \0a\0 \0C\0D\0A\0T\0A\0 " + "\0#\x0e\x04\x0e\x08\0>\0\n" + "\0]\0>\0<\0d\0/\0>"; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + != XML_STATUS_ERROR) + fail("Invalid UTF16 attribute keyword not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_SYNTAX) + xml_failure(g_parser); +} +END_TEST + +/* Test that invalid syntax in a <!DOCTYPE> is rejected. Do this + * using prefix-encoding (see above) to trigger specific code paths + */ +START_TEST(test_bad_doctype) { + const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n" + "<!DOCTYPE doc [ \x80\x44 ]><doc/>"; + + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + expect_failure(text, XML_ERROR_SYNTAX, + "Invalid bytes in DOCTYPE not faulted"); +} +END_TEST + +START_TEST(test_bad_doctype_utf8) { + const char *text = "<!DOCTYPE \xDB\x25" + "doc><doc/>"; // [1101 1011] [<0>010 0101] + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "Invalid UTF-8 in DOCTYPE not faulted"); +} +END_TEST + +START_TEST(test_bad_doctype_utf16) { + const char text[] = + /* <!DOCTYPE doc [ \x06f2 ]><doc/> + * + * U+06F2 = EXTENDED ARABIC-INDIC DIGIT TWO, a valid number + * (name character) but not a valid letter (name start character) + */ + "\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0d\0o\0c\0 \0[\0 " + "\x06\xf2" + "\0 \0]\0>\0<\0d\0o\0c\0/\0>"; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + != XML_STATUS_ERROR) + fail("Invalid bytes in DOCTYPE not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_SYNTAX) + xml_failure(g_parser); +} +END_TEST + +START_TEST(test_bad_doctype_plus) { + const char *text = "<!DOCTYPE 1+ [ <!ENTITY foo 'bar'> ]>\n" + "<1+>&foo;</1+>"; + + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "'+' in document name not faulted"); +} +END_TEST + +START_TEST(test_bad_doctype_star) { + const char *text = "<!DOCTYPE 1* [ <!ENTITY foo 'bar'> ]>\n" + "<1*>&foo;</1*>"; + + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "'*' in document name not faulted"); +} +END_TEST + +START_TEST(test_bad_doctype_query) { + const char *text = "<!DOCTYPE 1? [ <!ENTITY foo 'bar'> ]>\n" + "<1?>&foo;</1?>"; + + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "'?' in document name not faulted"); +} +END_TEST + +START_TEST(test_unknown_encoding_bad_ignore) { + const char *text = "<?xml version='1.0' encoding='prefix-conv'?>" + "<!DOCTYPE doc SYSTEM 'foo'>" + "<doc><e>&entity;</e></doc>"; + ExtFaults fault = {"<![IGNORE[<!ELEMENT \xffG (#PCDATA)*>]]>", + "Invalid character not faulted", XCS("prefix-conv"), + XML_ERROR_INVALID_TOKEN}; + + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter); + XML_SetUserData(g_parser, &fault); + expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, + "Bad IGNORE section with unknown encoding not failed"); +} +END_TEST + +START_TEST(test_entity_in_utf16_be_attr) { + const char text[] = + /* <e a='ä ä'></e> */ + "\0<\0e\0 \0a\0=\0'\0&\0#\0\x32\0\x32\0\x38\0;\0 " + "\0&\0#\0x\0\x30\0\x30\0E\0\x34\0;\0'\0>\0<\0/\0e\0>"; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x00e4 \x00e4"); +#else + const XML_Char *expected = XCS("\xc3\xa4 \xc3\xa4"); +#endif + CharData storage; + + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetStartElementHandler(g_parser, accumulate_attribute); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_entity_in_utf16_le_attr) { + const char text[] = + /* <e a='ä ä'></e> */ + "<\0e\0 \0a\0=\0'\0&\0#\0\x32\0\x32\0\x38\0;\0 \0" + "&\0#\0x\0\x30\0\x30\0E\0\x34\0;\0'\0>\0<\0/\0e\0>\0"; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("\x00e4 \x00e4"); +#else + const XML_Char *expected = XCS("\xc3\xa4 \xc3\xa4"); +#endif + CharData storage; + + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetStartElementHandler(g_parser, accumulate_attribute); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_entity_public_utf16_be) { + const char text[] = + /* <!DOCTYPE d [ */ + "\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0d\0 \0[\0\n" + /* <!ENTITY % e PUBLIC 'foo' 'bar.ent'> */ + "\0<\0!\0E\0N\0T\0I\0T\0Y\0 \0%\0 \0e\0 \0P\0U\0B\0L\0I\0C\0 " + "\0'\0f\0o\0o\0'\0 \0'\0b\0a\0r\0.\0e\0n\0t\0'\0>\0\n" + /* %e; */ + "\0%\0e\0;\0\n" + /* ]> */ + "\0]\0>\0\n" + /* <d>&j;</d> */ + "\0<\0d\0>\0&\0j\0;\0<\0/\0d\0>"; + ExtTest2 test_data + = {/* <!ENTITY j 'baz'> */ + "\0<\0!\0E\0N\0T\0I\0T\0Y\0 \0j\0 \0'\0b\0a\0z\0'\0>", 34, NULL, NULL}; + const XML_Char *expected = XCS("baz"); + CharData storage; + + CharData_Init(&storage); + test_data.storage = &storage; + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); + XML_SetUserData(g_parser, &test_data); + XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_entity_public_utf16_le) { + const char text[] = + /* <!DOCTYPE d [ */ + "<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0d\0 \0[\0\n\0" + /* <!ENTITY % e PUBLIC 'foo' 'bar.ent'> */ + "<\0!\0E\0N\0T\0I\0T\0Y\0 \0%\0 \0e\0 \0P\0U\0B\0L\0I\0C\0 \0" + "'\0f\0o\0o\0'\0 \0'\0b\0a\0r\0.\0e\0n\0t\0'\0>\0\n\0" + /* %e; */ + "%\0e\0;\0\n\0" + /* ]> */ + "]\0>\0\n\0" + /* <d>&j;</d> */ + "<\0d\0>\0&\0j\0;\0<\0/\0d\0>\0"; + ExtTest2 test_data + = {/* <!ENTITY j 'baz'> */ + "<\0!\0E\0N\0T\0I\0T\0Y\0 \0j\0 \0'\0b\0a\0z\0'\0>\0", 34, NULL, NULL}; + const XML_Char *expected = XCS("baz"); + CharData storage; + + CharData_Init(&storage); + test_data.storage = &storage; + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); + XML_SetUserData(g_parser, &test_data); + XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +/* Test that a doctype with neither an internal nor external subset is + * faulted + */ +START_TEST(test_short_doctype) { + const char *text = "<!DOCTYPE doc></doc>"; + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "DOCTYPE without subset not rejected"); +} +END_TEST + +START_TEST(test_short_doctype_2) { + const char *text = "<!DOCTYPE doc PUBLIC></doc>"; + expect_failure(text, XML_ERROR_SYNTAX, + "DOCTYPE without Public ID not rejected"); +} +END_TEST + +START_TEST(test_short_doctype_3) { + const char *text = "<!DOCTYPE doc SYSTEM></doc>"; + expect_failure(text, XML_ERROR_SYNTAX, + "DOCTYPE without System ID not rejected"); +} +END_TEST + +START_TEST(test_long_doctype) { + const char *text = "<!DOCTYPE doc PUBLIC 'foo' 'bar' 'baz'></doc>"; + expect_failure(text, XML_ERROR_SYNTAX, "DOCTYPE with extra ID not rejected"); +} +END_TEST + +START_TEST(test_bad_entity) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY foo PUBLIC>\n" + "]>\n" + "<doc/>"; + expect_failure(text, XML_ERROR_SYNTAX, + "ENTITY without Public ID is not rejected"); +} +END_TEST + +/* Test unquoted value is faulted */ +START_TEST(test_bad_entity_2) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY % foo bar>\n" + "]>\n" + "<doc/>"; + expect_failure(text, XML_ERROR_SYNTAX, + "ENTITY without Public ID is not rejected"); +} +END_TEST + +START_TEST(test_bad_entity_3) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY % foo PUBLIC>\n" + "]>\n" + "<doc/>"; + expect_failure(text, XML_ERROR_SYNTAX, + "Parameter ENTITY without Public ID is not rejected"); +} +END_TEST + +START_TEST(test_bad_entity_4) { + const char *text = "<!DOCTYPE doc [\n" + " <!ENTITY % foo SYSTEM>\n" + "]>\n" + "<doc/>"; + expect_failure(text, XML_ERROR_SYNTAX, + "Parameter ENTITY without Public ID is not rejected"); +} +END_TEST + +START_TEST(test_bad_notation) { + const char *text = "<!DOCTYPE doc [\n" + " <!NOTATION n SYSTEM>\n" + "]>\n" + "<doc/>"; + expect_failure(text, XML_ERROR_SYNTAX, + "Notation without System ID is not rejected"); +} +END_TEST + +/* Test for issue #11, wrongly suppressed default handler */ +START_TEST(test_default_doctype_handler) { + const char *text = "<!DOCTYPE doc PUBLIC 'pubname' 'test.dtd' [\n" + " <!ENTITY foo 'bar'>\n" + "]>\n" + "<doc>&foo;</doc>"; + DefaultCheck test_data[] = {{XCS("'pubname'"), 9, XML_FALSE}, + {XCS("'test.dtd'"), 10, XML_FALSE}, + {NULL, 0, XML_FALSE}}; + int i; + + XML_SetUserData(g_parser, &test_data); + XML_SetDefaultHandler(g_parser, checking_default_handler); + XML_SetEntityDeclHandler(g_parser, dummy_entity_decl_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + for (i = 0; test_data[i].expected != NULL; i++) + if (! test_data[i].seen) + fail("Default handler not run for public !DOCTYPE"); +} +END_TEST + +START_TEST(test_empty_element_abort) { + const char *text = "<abort/>"; + + XML_SetStartElementHandler(g_parser, start_element_suspender); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Expected to error on abort"); +} +END_TEST + +/* Regression test for GH issue #612: unfinished m_declAttributeType + * allocation in ->m_tempPool can corrupt following allocation. + */ +START_TEST(test_pool_integrity_with_unfinished_attr) { + const char *text = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<!DOCTYPE foo [\n" + "<!ELEMENT foo ANY>\n" + "<!ENTITY % entp SYSTEM \"external.dtd\">\n" + "%entp;\n" + "]>\n" + "<a></a>\n"; + const XML_Char *expected = XCS("COMMENT"); + CharData storage; + + CharData_Init(&storage); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_unfinished_attlist); + XML_SetAttlistDeclHandler(g_parser, dummy_attlist_decl_handler); + XML_SetCommentHandler(g_parser, accumulate_comment); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_nested_entity_suspend) { + const char *const text = "<!DOCTYPE a [\n" + " <!ENTITY e1 '<!--e1-->'>\n" + " <!ENTITY e2 '<!--e2 head-->&e1;<!--e2 tail-->'>\n" + " <!ENTITY e3 '<!--e3 head-->&e2;<!--e3 tail-->'>\n" + "]>\n" + "<a><!--start-->&e3;<!--end--></a>"; + const XML_Char *const expected = XCS("start") XCS("e3 head") XCS("e2 head") + XCS("e1") XCS("e2 tail") XCS("e3 tail") XCS("end"); + CharData storage; + CharData_Init(&storage); + XML_Parser parser = XML_ParserCreate(NULL); + ParserPlusStorage parserPlusStorage = {parser, &storage}; + + XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetCommentHandler(parser, accumulate_and_suspend_comment_handler); + XML_SetUserData(parser, &parserPlusStorage); + + enum XML_Status status = XML_Parse(parser, text, (int)strlen(text), XML_TRUE); + while (status == XML_STATUS_SUSPENDED) { + status = XML_ResumeParser(parser); + } + if (status != XML_STATUS_OK) + xml_failure(parser); + + CharData_CheckXMLChars(&storage, expected); + XML_ParserFree(parser); +} +END_TEST + +/* Regression test for quadratic parsing on large tokens */ +START_TEST(test_big_tokens_scale_linearly) { + const struct { + const char *pre; + const char *post; + } text[] = { + {"<a>", "</a>"}, // assumed good, used as baseline + {"<b><![CDATA[ value: ", " ]]></b>"}, // CDATA, performed OK before patch + {"<c attr='", "'></c>"}, // big attribute, used to be O(N²) + {"<d><!-- ", " --></d>"}, // long comment, used to be O(N²) + {"<e><", "/></e>"}, // big elem name, used to be O(N²) + }; + const int num_cases = sizeof(text) / sizeof(text[0]); + char aaaaaa[4096]; + const int fillsize = (int)sizeof(aaaaaa); + const int fillcount = 100; + const unsigned approx_bytes = fillsize * fillcount; // ignore pre/post. + const unsigned max_factor = 4; + const unsigned max_scanned = max_factor * approx_bytes; + + memset(aaaaaa, 'a', fillsize); + + if (! g_reparseDeferralEnabledDefault) { + return; // heuristic is disabled; we would get O(n^2) and fail. + } + + for (int i = 0; i < num_cases; ++i) { + XML_Parser parser = XML_ParserCreate(NULL); + assert_true(parser != NULL); + enum XML_Status status; + set_subtest("text=\"%saaaaaa%s\"", text[i].pre, text[i].post); + + // parse the start text + g_bytesScanned = 0; + status = _XML_Parse_SINGLE_BYTES(parser, text[i].pre, + (int)strlen(text[i].pre), XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + + // parse lots of 'a', failing the test early if it takes too long + unsigned past_max_count = 0; + for (int f = 0; f < fillcount; ++f) { + status = _XML_Parse_SINGLE_BYTES(parser, aaaaaa, fillsize, XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + if (g_bytesScanned > max_scanned) { + // We're not done, and have already passed the limit -- the test will + // definitely fail. This block allows us to save time by failing early. + const unsigned pushed + = (unsigned)strlen(text[i].pre) + (f + 1) * fillsize; + fprintf( + stderr, + "after %d/%d loops: pushed=%u scanned=%u (factor ~%.2f) max_scanned: %u (factor ~%u)\n", + f + 1, fillcount, pushed, g_bytesScanned, + g_bytesScanned / (double)pushed, max_scanned, max_factor); + past_max_count++; + // We are failing, but allow a few log prints first. If we don't reach + // a count of five, the test will fail after the loop instead. + assert_true(past_max_count < 5); + } + } + + // parse the end text + status = _XML_Parse_SINGLE_BYTES(parser, text[i].post, + (int)strlen(text[i].post), XML_TRUE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + + assert_true(g_bytesScanned > approx_bytes); // or the counter isn't working + if (g_bytesScanned > max_scanned) { + fprintf( + stderr, + "after all input: scanned=%u (factor ~%.2f) max_scanned: %u (factor ~%u)\n", + g_bytesScanned, g_bytesScanned / (double)approx_bytes, max_scanned, + max_factor); + fail("scanned too many bytes"); + } + + XML_ParserFree(parser); + } +} +END_TEST + +START_TEST(test_set_reparse_deferral) { + const char *const pre = "<d>"; + const char *const start = "<x attr='"; + const char *const end = "'></x>"; + char eeeeee[100]; + const int fillsize = (int)sizeof(eeeeee); + memset(eeeeee, 'e', fillsize); + + for (int enabled = 0; enabled <= 1; enabled += 1) { + set_subtest("deferral=%d", enabled); + + XML_Parser parser = XML_ParserCreate(NULL); + assert_true(parser != NULL); + assert_true(XML_SetReparseDeferralEnabled(parser, enabled)); + // pre-grow the buffer to avoid reparsing due to almost-fullness + assert_true(XML_GetBuffer(parser, fillsize * 10103) != NULL); + + CharData storage; + CharData_Init(&storage); + XML_SetUserData(parser, &storage); + XML_SetStartElementHandler(parser, start_element_event_handler); + + enum XML_Status status; + // parse the start text + status = XML_Parse(parser, pre, (int)strlen(pre), XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + CharData_CheckXMLChars(&storage, XCS("d")); // first element should be done + + // ..and the start of the token + status = XML_Parse(parser, start, (int)strlen(start), XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + CharData_CheckXMLChars(&storage, XCS("d")); // still just the first one + + // try to parse lots of 'e', but the token isn't finished + for (int c = 0; c < 100; ++c) { + status = XML_Parse(parser, eeeeee, fillsize, XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + } + CharData_CheckXMLChars(&storage, XCS("d")); // *still* just the first one + + // end the <x> token. + status = XML_Parse(parser, end, (int)strlen(end), XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + + if (enabled) { + // In general, we may need to push more data to trigger a reparse attempt, + // but in this test, the data is constructed to always require it. + CharData_CheckXMLChars(&storage, XCS("d")); // or the test is incorrect + // 2x the token length should suffice; the +1 covers the start and end. + for (int c = 0; c < 101; ++c) { + status = XML_Parse(parser, eeeeee, fillsize, XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + } + } + CharData_CheckXMLChars(&storage, XCS("dx")); // the <x> should be done + + XML_ParserFree(parser); + } +} +END_TEST + +struct element_decl_data { + XML_Parser parser; + int count; +}; + +static void +element_decl_counter(void *userData, const XML_Char *name, XML_Content *model) { + UNUSED_P(name); + struct element_decl_data *testdata = (struct element_decl_data *)userData; + testdata->count += 1; + XML_FreeContentModel(testdata->parser, model); +} + +static int +external_inherited_parser(XML_Parser p, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + const char *const pre = "<!ELEMENT document ANY>\n"; + const char *const start = "<!ELEMENT "; + const char *const end = " ANY>\n"; + const char *const post = "<!ELEMENT xyz ANY>\n"; + const int enabled = *(int *)XML_GetUserData(p); + char eeeeee[100]; + char spaces[100]; + const int fillsize = (int)sizeof(eeeeee); + assert_true(fillsize == (int)sizeof(spaces)); + memset(eeeeee, 'e', fillsize); + memset(spaces, ' ', fillsize); + + XML_Parser parser = XML_ExternalEntityParserCreate(p, context, NULL); + assert_true(parser != NULL); + // pre-grow the buffer to avoid reparsing due to almost-fullness + assert_true(XML_GetBuffer(parser, fillsize * 10103) != NULL); + + struct element_decl_data testdata; + testdata.parser = parser; + testdata.count = 0; + XML_SetUserData(parser, &testdata); + XML_SetElementDeclHandler(parser, element_decl_counter); + + enum XML_Status status; + // parse the initial text + status = XML_Parse(parser, pre, (int)strlen(pre), XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + assert_true(testdata.count == 1); // first element should be done + + // ..and the start of the big token + status = XML_Parse(parser, start, (int)strlen(start), XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + assert_true(testdata.count == 1); // still just the first one + + // try to parse lots of 'e', but the token isn't finished + for (int c = 0; c < 100; ++c) { + status = XML_Parse(parser, eeeeee, fillsize, XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + } + assert_true(testdata.count == 1); // *still* just the first one + + // end the big token. + status = XML_Parse(parser, end, (int)strlen(end), XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + + if (enabled) { + // In general, we may need to push more data to trigger a reparse attempt, + // but in this test, the data is constructed to always require it. + assert_true(testdata.count == 1); // or the test is incorrect + // 2x the token length should suffice; the +1 covers the start and end. + for (int c = 0; c < 101; ++c) { + status = XML_Parse(parser, spaces, fillsize, XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + } + } + assert_true(testdata.count == 2); // the big token should be done + + // parse the final text + status = XML_Parse(parser, post, (int)strlen(post), XML_TRUE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + assert_true(testdata.count == 3); // after isFinal=XML_TRUE, all must be done + + XML_ParserFree(parser); + return XML_STATUS_OK; +} + +START_TEST(test_reparse_deferral_is_inherited) { + const char *const text + = "<!DOCTYPE document SYSTEM 'something.ext'><document/>"; + for (int enabled = 0; enabled <= 1; ++enabled) { + set_subtest("deferral=%d", enabled); + + XML_Parser parser = XML_ParserCreate(NULL); + assert_true(parser != NULL); + XML_SetUserData(parser, (void *)&enabled); + XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + // this handler creates a sub-parser and checks that its deferral behavior + // is what we expected, based on the value of `enabled` (in userdata). + XML_SetExternalEntityRefHandler(parser, external_inherited_parser); + assert_true(XML_SetReparseDeferralEnabled(parser, enabled)); + if (XML_Parse(parser, text, (int)strlen(text), XML_TRUE) != XML_STATUS_OK) + xml_failure(parser); + + XML_ParserFree(parser); + } +} +END_TEST + +START_TEST(test_set_reparse_deferral_on_null_parser) { + assert_true(XML_SetReparseDeferralEnabled(NULL, 0) == XML_FALSE); + assert_true(XML_SetReparseDeferralEnabled(NULL, 1) == XML_FALSE); + assert_true(XML_SetReparseDeferralEnabled(NULL, 10) == XML_FALSE); + assert_true(XML_SetReparseDeferralEnabled(NULL, 100) == XML_FALSE); + assert_true(XML_SetReparseDeferralEnabled(NULL, (XML_Bool)INT_MIN) + == XML_FALSE); + assert_true(XML_SetReparseDeferralEnabled(NULL, (XML_Bool)INT_MAX) + == XML_FALSE); +} +END_TEST + +START_TEST(test_set_reparse_deferral_on_the_fly) { + const char *const pre = "<d><x attr='"; + const char *const end = "'></x>"; + char iiiiii[100]; + const int fillsize = (int)sizeof(iiiiii); + memset(iiiiii, 'i', fillsize); + + XML_Parser parser = XML_ParserCreate(NULL); + assert_true(parser != NULL); + assert_true(XML_SetReparseDeferralEnabled(parser, XML_TRUE)); + + CharData storage; + CharData_Init(&storage); + XML_SetUserData(parser, &storage); + XML_SetStartElementHandler(parser, start_element_event_handler); + + enum XML_Status status; + // parse the start text + status = XML_Parse(parser, pre, (int)strlen(pre), XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + CharData_CheckXMLChars(&storage, XCS("d")); // first element should be done + + // try to parse some 'i', but the token isn't finished + status = XML_Parse(parser, iiiiii, fillsize, XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + CharData_CheckXMLChars(&storage, XCS("d")); // *still* just the first one + + // end the <x> token. + status = XML_Parse(parser, end, (int)strlen(end), XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + CharData_CheckXMLChars(&storage, XCS("d")); // not yet. + + // now change the heuristic setting and add *no* data + assert_true(XML_SetReparseDeferralEnabled(parser, XML_FALSE)); + // we avoid isFinal=XML_TRUE, because that would force-bypass the heuristic. + status = XML_Parse(parser, "", 0, XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + CharData_CheckXMLChars(&storage, XCS("dx")); + + XML_ParserFree(parser); +} +END_TEST + +START_TEST(test_set_bad_reparse_option) { + XML_Parser parser = XML_ParserCreate(NULL); + assert_true(XML_FALSE == XML_SetReparseDeferralEnabled(parser, 2)); + assert_true(XML_FALSE == XML_SetReparseDeferralEnabled(parser, 3)); + assert_true(XML_FALSE == XML_SetReparseDeferralEnabled(parser, 99)); + assert_true(XML_FALSE == XML_SetReparseDeferralEnabled(parser, 127)); + assert_true(XML_FALSE == XML_SetReparseDeferralEnabled(parser, 128)); + assert_true(XML_FALSE == XML_SetReparseDeferralEnabled(parser, 129)); + assert_true(XML_FALSE == XML_SetReparseDeferralEnabled(parser, 255)); + assert_true(XML_TRUE == XML_SetReparseDeferralEnabled(parser, 0)); + assert_true(XML_TRUE == XML_SetReparseDeferralEnabled(parser, 1)); + XML_ParserFree(parser); +} +END_TEST + +static size_t g_totalAlloc = 0; +static size_t g_biggestAlloc = 0; + +static void * +counting_realloc(void *ptr, size_t size) { + g_totalAlloc += size; + if (size > g_biggestAlloc) { + g_biggestAlloc = size; + } + return realloc(ptr, size); +} + +static void * +counting_malloc(size_t size) { + return counting_realloc(NULL, size); +} + +START_TEST(test_bypass_heuristic_when_close_to_bufsize) { + if (g_chunkSize != 0) { + // this test does not use SINGLE_BYTES, because it depends on very precise + // buffer fills. + return; + } + if (! g_reparseDeferralEnabledDefault) { + return; // this test is irrelevant when the deferral heuristic is disabled. + } + + const int document_length = 65536; + char *const document = (char *)malloc(document_length); + + const XML_Memory_Handling_Suite memfuncs = { + counting_malloc, + counting_realloc, + free, + }; + + const int leading_list[] = {0, 3, 61, 96, 400, 401, 4000, 4010, 4099, -1}; + const int bigtoken_list[] = {3000, 4000, 4001, 4096, 4099, 5000, 20000, -1}; + const int fillsize_list[] = {131, 256, 399, 400, 401, 1025, 4099, 4321, -1}; + + for (const int *leading = leading_list; *leading >= 0; leading++) { + for (const int *bigtoken = bigtoken_list; *bigtoken >= 0; bigtoken++) { + for (const int *fillsize = fillsize_list; *fillsize >= 0; fillsize++) { + set_subtest("leading=%d bigtoken=%d fillsize=%d", *leading, *bigtoken, + *fillsize); + // start by checking that the test looks reasonably valid + assert_true(*leading + *bigtoken <= document_length); + + // put 'x' everywhere; some will be overwritten by elements. + memset(document, 'x', document_length); + // maybe add an initial tag + if (*leading) { + assert_true(*leading >= 3); // or the test case is invalid + memcpy(document, "<a>", 3); + } + // add the large token + document[*leading + 0] = '<'; + document[*leading + 1] = 'b'; + memset(&document[*leading + 2], ' ', *bigtoken - 2); // a spacy token + document[*leading + *bigtoken - 1] = '>'; + + // 1 for 'b', plus 1 or 0 depending on the presence of 'a' + const int expected_elem_total = 1 + (*leading ? 1 : 0); + + XML_Parser parser = XML_ParserCreate_MM(NULL, &memfuncs, NULL); + assert_true(parser != NULL); + + CharData storage; + CharData_Init(&storage); + XML_SetUserData(parser, &storage); + XML_SetStartElementHandler(parser, start_element_event_handler); + + g_biggestAlloc = 0; + g_totalAlloc = 0; + int offset = 0; + // fill data until the big token is covered (but not necessarily parsed) + while (offset < *leading + *bigtoken) { + assert_true(offset + *fillsize <= document_length); + const enum XML_Status status + = XML_Parse(parser, &document[offset], *fillsize, XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + offset += *fillsize; + } + // Now, check that we've had a buffer allocation that could fit the + // context bytes and our big token. In order to detect a special case, + // we need to know how many bytes of our big token were included in the + // first push that contained _any_ bytes of the big token: + const int bigtok_first_chunk_bytes = *fillsize - (*leading % *fillsize); + if (bigtok_first_chunk_bytes >= *bigtoken && XML_CONTEXT_BYTES == 0) { + // Special case: we aren't saving any context, and the whole big token + // was covered by a single fill, so Expat may have parsed directly + // from our input pointer, without allocating an internal buffer. + } else if (*leading < XML_CONTEXT_BYTES) { + assert_true(g_biggestAlloc >= *leading + (size_t)*bigtoken); + } else { + assert_true(g_biggestAlloc >= XML_CONTEXT_BYTES + (size_t)*bigtoken); + } + // fill data until the big token is actually parsed + while (storage.count < expected_elem_total) { + const size_t alloc_before = g_totalAlloc; + assert_true(offset + *fillsize <= document_length); + const enum XML_Status status + = XML_Parse(parser, &document[offset], *fillsize, XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + offset += *fillsize; + // since all the bytes of the big token are already in the buffer, + // the bufsize ceiling should make us finish its parsing without any + // further buffer allocations. We assume that there will be no other + // large allocations in this test. + assert_true(g_totalAlloc - alloc_before < 4096); + } + // test-the-test: was our alloc even called? + assert_true(g_totalAlloc > 0); + // test-the-test: there shouldn't be any extra start elements + assert_true(storage.count == expected_elem_total); + + XML_ParserFree(parser); + } + } + } + free(document); +} +END_TEST + +START_TEST(test_varying_buffer_fills) { + const int KiB = 1024; + const int MiB = 1024 * KiB; + const int document_length = 16 * MiB; + const int big = 7654321; // arbitrarily chosen between 4 and 8 MiB + + if (g_chunkSize != 0) { + return; // this test is slow, and doesn't use _XML_Parse_SINGLE_BYTES(). + } + + char *const document = (char *)malloc(document_length); + assert_true(document != NULL); + memset(document, 'x', document_length); + document[0] = '<'; + document[1] = 't'; + memset(&document[2], ' ', big - 2); // a very spacy token + document[big - 1] = '>'; + + // Each testcase is a list of buffer fill sizes, terminated by a value < 0. + // When reparse deferral is enabled, the final (negated) value is the expected + // maximum number of bytes scanned in parse attempts. + const int testcases[][30] = { + {8 * MiB, -8 * MiB}, + {4 * MiB, 4 * MiB, -12 * MiB}, // try at 4MB, then 8MB = 12 MB total + // zero-size fills shouldn't trigger the bypass + {4 * MiB, 0, 4 * MiB, -12 * MiB}, + {4 * MiB, 0, 0, 4 * MiB, -12 * MiB}, + {4 * MiB, 0, 1 * MiB, 0, 3 * MiB, -12 * MiB}, + // try to hit the buffer ceiling only once (at the end) + {4 * MiB, 2 * MiB, 1 * MiB, 512 * KiB, 256 * KiB, 256 * KiB, -12 * MiB}, + // try to hit the same buffer ceiling multiple times + {4 * MiB + 1, 2 * MiB, 1 * MiB, 512 * KiB, -25 * MiB}, + + // try to hit every ceiling, by always landing 1K shy of the buffer size + {1 * KiB, 2 * KiB, 4 * KiB, 8 * KiB, 16 * KiB, 32 * KiB, 64 * KiB, + 128 * KiB, 256 * KiB, 512 * KiB, 1 * MiB, 2 * MiB, 4 * MiB, -16 * MiB}, + + // try to avoid every ceiling, by always landing 1B past the buffer size + // the normal 2x heuristic threshold still forces parse attempts. + {2 * KiB + 1, // will attempt 2KiB + 1 ==> total 2KiB + 1 + 2 * KiB, 4 * KiB, // will attempt 8KiB + 1 ==> total 10KiB + 2 + 8 * KiB, 16 * KiB, // will attempt 32KiB + 1 ==> total 42KiB + 3 + 32 * KiB, 64 * KiB, // will attempt 128KiB + 1 ==> total 170KiB + 4 + 128 * KiB, 256 * KiB, // will attempt 512KiB + 1 ==> total 682KiB + 5 + 512 * KiB, 1 * MiB, // will attempt 2MiB + 1 ==> total 2M + 682K + 6 + 2 * MiB, 4 * MiB, // will attempt 8MiB + 1 ==> total 10M + 682K + 7 + -(10 * MiB + 682 * KiB + 7)}, + // try to avoid every ceiling again, except on our last fill. + {2 * KiB + 1, // will attempt 2KiB + 1 ==> total 2KiB + 1 + 2 * KiB, 4 * KiB, // will attempt 8KiB + 1 ==> total 10KiB + 2 + 8 * KiB, 16 * KiB, // will attempt 32KiB + 1 ==> total 42KiB + 3 + 32 * KiB, 64 * KiB, // will attempt 128KiB + 1 ==> total 170KiB + 4 + 128 * KiB, 256 * KiB, // will attempt 512KiB + 1 ==> total 682KiB + 5 + 512 * KiB, 1 * MiB, // will attempt 2MiB + 1 ==> total 2M + 682K + 6 + 2 * MiB, 4 * MiB - 1, // will attempt 8MiB ==> total 10M + 682K + 6 + -(10 * MiB + 682 * KiB + 6)}, + + // try to hit ceilings on the way multiple times + {512 * KiB + 1, 256 * KiB, 128 * KiB, 128 * KiB - 1, // 1 MiB buffer + 512 * KiB + 1, 256 * KiB, 128 * KiB, 128 * KiB - 1, // 2 MiB buffer + 1 * MiB + 1, 512 * KiB, 256 * KiB, 256 * KiB - 1, // 4 MiB buffer + 2 * MiB + 1, 1 * MiB, 512 * KiB, // 8 MiB buffer + // we'll make a parse attempt at every parse call + -(45 * MiB + 12)}, + }; + const int testcount = sizeof(testcases) / sizeof(testcases[0]); + for (int test_i = 0; test_i < testcount; test_i++) { + const int *fillsize = testcases[test_i]; + set_subtest("#%d {%d %d %d %d ...}", test_i, fillsize[0], fillsize[1], + fillsize[2], fillsize[3]); + XML_Parser parser = XML_ParserCreate(NULL); + assert_true(parser != NULL); + + CharData storage; + CharData_Init(&storage); + XML_SetUserData(parser, &storage); + XML_SetStartElementHandler(parser, start_element_event_handler); + + g_bytesScanned = 0; + int worstcase_bytes = 0; // sum of (buffered bytes at each XML_Parse call) + int offset = 0; + while (*fillsize >= 0) { + assert_true(offset + *fillsize <= document_length); // or test is invalid + const enum XML_Status status + = XML_Parse(parser, &document[offset], *fillsize, XML_FALSE); + if (status != XML_STATUS_OK) { + xml_failure(parser); + } + offset += *fillsize; + fillsize++; + assert_true(offset <= INT_MAX - worstcase_bytes); // avoid overflow + worstcase_bytes += offset; // we might've tried to parse all pending bytes + } + assert_true(storage.count == 1); // the big token should've been parsed + assert_true(g_bytesScanned > 0); // test-the-test: does our counter work? + if (g_reparseDeferralEnabledDefault) { + // heuristic is enabled; some XML_Parse calls may have deferred reparsing + const unsigned max_bytes_scanned = -*fillsize; + if (g_bytesScanned > max_bytes_scanned) { + fprintf(stderr, + "bytes scanned in parse attempts: actual=%u limit=%u \n", + g_bytesScanned, max_bytes_scanned); + fail("too many bytes scanned in parse attempts"); + } + } + assert_true(g_bytesScanned <= (unsigned)worstcase_bytes); + + XML_ParserFree(parser); + } + free(document); +} +END_TEST + +void +make_basic_test_case(Suite *s) { + TCase *tc_basic = tcase_create("basic tests"); + + suite_add_tcase(s, tc_basic); + tcase_add_checked_fixture(tc_basic, basic_setup, basic_teardown); + + tcase_add_test(tc_basic, test_nul_byte); + tcase_add_test(tc_basic, test_u0000_char); + tcase_add_test(tc_basic, test_siphash_self); + tcase_add_test(tc_basic, test_siphash_spec); + tcase_add_test(tc_basic, test_bom_utf8); + tcase_add_test(tc_basic, test_bom_utf16_be); + tcase_add_test(tc_basic, test_bom_utf16_le); + tcase_add_test(tc_basic, test_nobom_utf16_le); + tcase_add_test(tc_basic, test_hash_collision); + tcase_add_test(tc_basic, test_illegal_utf8); + tcase_add_test(tc_basic, test_utf8_auto_align); + tcase_add_test(tc_basic, test_utf16); + tcase_add_test(tc_basic, test_utf16_le_epilog_newline); + tcase_add_test(tc_basic, test_not_utf16); + tcase_add_test(tc_basic, test_bad_encoding); + tcase_add_test(tc_basic, test_latin1_umlauts); + tcase_add_test(tc_basic, test_long_utf8_character); + tcase_add_test(tc_basic, test_long_latin1_attribute); + tcase_add_test(tc_basic, test_long_ascii_attribute); + /* Regression test for SF bug #491986. */ + tcase_add_test(tc_basic, test_danish_latin1); + /* Regression test for SF bug #514281. */ + tcase_add_test(tc_basic, test_french_charref_hexidecimal); + tcase_add_test(tc_basic, test_french_charref_decimal); + tcase_add_test(tc_basic, test_french_latin1); + tcase_add_test(tc_basic, test_french_utf8); + tcase_add_test(tc_basic, test_utf8_false_rejection); + tcase_add_test(tc_basic, test_line_number_after_parse); + tcase_add_test(tc_basic, test_column_number_after_parse); + tcase_add_test(tc_basic, test_line_and_column_numbers_inside_handlers); + tcase_add_test(tc_basic, test_line_number_after_error); + tcase_add_test(tc_basic, test_column_number_after_error); + tcase_add_test(tc_basic, test_really_long_lines); + tcase_add_test(tc_basic, test_really_long_encoded_lines); + tcase_add_test(tc_basic, test_end_element_events); + tcase_add_test(tc_basic, test_helper_is_whitespace_normalized); + tcase_add_test(tc_basic, test_attr_whitespace_normalization); + tcase_add_test(tc_basic, test_xmldecl_misplaced); + tcase_add_test(tc_basic, test_xmldecl_invalid); + tcase_add_test(tc_basic, test_xmldecl_missing_attr); + tcase_add_test(tc_basic, test_xmldecl_missing_value); + tcase_add_test__if_xml_ge(tc_basic, test_unknown_encoding_internal_entity); + tcase_add_test(tc_basic, test_unrecognised_encoding_internal_entity); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_set_encoding); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_no_handler); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_set_bom); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_bad_encoding); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_bad_encoding_2); + tcase_add_test(tc_basic, test_wfc_undeclared_entity_unread_external_subset); + tcase_add_test(tc_basic, test_wfc_undeclared_entity_no_external_subset); + tcase_add_test(tc_basic, test_wfc_undeclared_entity_standalone); + tcase_add_test(tc_basic, + test_wfc_undeclared_entity_with_external_subset_standalone); + tcase_add_test(tc_basic, test_entity_with_external_subset_unless_standalone); + tcase_add_test(tc_basic, test_wfc_undeclared_entity_with_external_subset); + tcase_add_test(tc_basic, test_not_standalone_handler_reject); + tcase_add_test(tc_basic, test_not_standalone_handler_accept); + tcase_add_test__if_xml_ge(tc_basic, test_wfc_no_recursive_entity_refs); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_invalid_parse); + tcase_add_test__if_xml_ge(tc_basic, test_dtd_default_handling); + tcase_add_test(tc_basic, test_dtd_attr_handling); + tcase_add_test(tc_basic, test_empty_ns_without_namespaces); + tcase_add_test(tc_basic, test_ns_in_attribute_default_without_namespaces); + tcase_add_test(tc_basic, test_stop_parser_between_char_data_calls); + tcase_add_test(tc_basic, test_suspend_parser_between_char_data_calls); + tcase_add_test(tc_basic, test_repeated_stop_parser_between_char_data_calls); + tcase_add_test(tc_basic, test_good_cdata_ascii); + tcase_add_test(tc_basic, test_good_cdata_utf16); + tcase_add_test(tc_basic, test_good_cdata_utf16_le); + tcase_add_test(tc_basic, test_long_cdata_utf16); + tcase_add_test(tc_basic, test_multichar_cdata_utf16); + tcase_add_test(tc_basic, test_utf16_bad_surrogate_pair); + tcase_add_test(tc_basic, test_bad_cdata); + tcase_add_test(tc_basic, test_bad_cdata_utf16); + tcase_add_test(tc_basic, test_stop_parser_between_cdata_calls); + tcase_add_test(tc_basic, test_suspend_parser_between_cdata_calls); + tcase_add_test(tc_basic, test_memory_allocation); + tcase_add_test__if_xml_ge(tc_basic, test_default_current); + tcase_add_test(tc_basic, test_dtd_elements); + tcase_add_test(tc_basic, test_dtd_elements_nesting); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_set_foreign_dtd); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_foreign_dtd_not_standalone); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_invalid_foreign_dtd); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_foreign_dtd_with_doctype); + tcase_add_test__ifdef_xml_dtd(tc_basic, + test_foreign_dtd_without_external_subset); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_empty_foreign_dtd); + tcase_add_test(tc_basic, test_set_base); + tcase_add_test(tc_basic, test_attributes); + tcase_add_test__if_xml_ge(tc_basic, test_reset_in_entity); + tcase_add_test(tc_basic, test_resume_invalid_parse); + tcase_add_test(tc_basic, test_resume_resuspended); + tcase_add_test(tc_basic, test_cdata_default); + tcase_add_test(tc_basic, test_subordinate_reset); + tcase_add_test(tc_basic, test_subordinate_suspend); + tcase_add_test__if_xml_ge(tc_basic, test_subordinate_xdecl_suspend); + tcase_add_test__if_xml_ge(tc_basic, test_subordinate_xdecl_abort); + tcase_add_test__ifdef_xml_dtd(tc_basic, + test_ext_entity_invalid_suspended_parse); + tcase_add_test(tc_basic, test_explicit_encoding); + tcase_add_test(tc_basic, test_trailing_cr); + tcase_add_test__if_xml_ge(tc_basic, test_ext_entity_trailing_cr); + tcase_add_test(tc_basic, test_trailing_rsqb); + tcase_add_test__if_xml_ge(tc_basic, test_ext_entity_trailing_rsqb); + tcase_add_test__if_xml_ge(tc_basic, test_ext_entity_good_cdata); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_user_parameters); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_ref_parameter); + tcase_add_test(tc_basic, test_empty_parse); + tcase_add_test(tc_basic, test_negative_len_parse); + tcase_add_test(tc_basic, test_negative_len_parse_buffer); + tcase_add_test(tc_basic, test_get_buffer_1); + tcase_add_test(tc_basic, test_get_buffer_2); +#if XML_CONTEXT_BYTES > 0 + tcase_add_test(tc_basic, test_get_buffer_3_overflow); +#endif + tcase_add_test(tc_basic, test_buffer_can_grow_to_max); + tcase_add_test(tc_basic, test_getbuffer_allocates_on_zero_len); + tcase_add_test(tc_basic, test_byte_info_at_end); + tcase_add_test(tc_basic, test_byte_info_at_error); + tcase_add_test(tc_basic, test_byte_info_at_cdata); + tcase_add_test(tc_basic, test_predefined_entities); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_invalid_tag_in_dtd); + tcase_add_test(tc_basic, test_not_predefined_entities); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_ignore_section); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_ignore_section_utf16); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_ignore_section_utf16_be); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_bad_ignore_section); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_external_bom_consumed); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_external_entity_values); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_not_standalone); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_value_abort); + tcase_add_test(tc_basic, test_bad_public_doctype); + tcase_add_test(tc_basic, test_attribute_enum_value); + tcase_add_test(tc_basic, test_predefined_entity_redefinition); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_dtd_stop_processing); + tcase_add_test(tc_basic, test_public_notation_no_sysid); + tcase_add_test(tc_basic, test_nested_groups); + tcase_add_test(tc_basic, test_group_choice); + tcase_add_test(tc_basic, test_standalone_parameter_entity); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_skipped_parameter_entity); + tcase_add_test__ifdef_xml_dtd(tc_basic, + test_recursive_external_parameter_entity); + tcase_add_test__ifdef_xml_dtd(tc_basic, + test_recursive_external_parameter_entity_2); + tcase_add_test(tc_basic, test_undefined_ext_entity_in_external_dtd); + tcase_add_test(tc_basic, test_suspend_xdecl); + tcase_add_test(tc_basic, test_abort_epilog); + tcase_add_test(tc_basic, test_abort_epilog_2); + tcase_add_test(tc_basic, test_suspend_epilog); + tcase_add_test(tc_basic, test_suspend_in_sole_empty_tag); + tcase_add_test(tc_basic, test_unfinished_epilog); + tcase_add_test(tc_basic, test_partial_char_in_epilog); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_suspend_resume_internal_entity); + tcase_add_test__ifdef_xml_dtd(tc_basic, + test_suspend_resume_internal_entity_issue_629); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_resume_entity_with_syntax_error); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_suspend_resume_parameter_entity); + tcase_add_test(tc_basic, test_restart_on_error); + tcase_add_test(tc_basic, test_reject_lt_in_attribute_value); + tcase_add_test(tc_basic, test_reject_unfinished_param_in_att_value); + tcase_add_test(tc_basic, test_trailing_cr_in_att_value); + tcase_add_test(tc_basic, test_standalone_internal_entity); + tcase_add_test(tc_basic, test_skipped_external_entity); + tcase_add_test(tc_basic, test_skipped_null_loaded_ext_entity); + tcase_add_test(tc_basic, test_skipped_unloaded_ext_entity); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_param_entity_with_trailing_cr); + tcase_add_test__if_xml_ge(tc_basic, test_invalid_character_entity); + tcase_add_test__if_xml_ge(tc_basic, test_invalid_character_entity_2); + tcase_add_test__if_xml_ge(tc_basic, test_invalid_character_entity_3); + tcase_add_test__if_xml_ge(tc_basic, test_invalid_character_entity_4); + tcase_add_test(tc_basic, test_pi_handled_in_default); + tcase_add_test(tc_basic, test_comment_handled_in_default); + tcase_add_test(tc_basic, test_pi_yml); + tcase_add_test(tc_basic, test_pi_xnl); + tcase_add_test(tc_basic, test_pi_xmm); + tcase_add_test(tc_basic, test_utf16_pi); + tcase_add_test(tc_basic, test_utf16_be_pi); + tcase_add_test(tc_basic, test_utf16_be_comment); + tcase_add_test(tc_basic, test_utf16_le_comment); + tcase_add_test(tc_basic, test_missing_encoding_conversion_fn); + tcase_add_test(tc_basic, test_failing_encoding_conversion_fn); + tcase_add_test(tc_basic, test_unknown_encoding_success); + tcase_add_test(tc_basic, test_unknown_encoding_bad_name); + tcase_add_test(tc_basic, test_unknown_encoding_bad_name_2); + tcase_add_test(tc_basic, test_unknown_encoding_long_name_1); + tcase_add_test(tc_basic, test_unknown_encoding_long_name_2); + tcase_add_test(tc_basic, test_invalid_unknown_encoding); + tcase_add_test(tc_basic, test_unknown_ascii_encoding_ok); + tcase_add_test(tc_basic, test_unknown_ascii_encoding_fail); + tcase_add_test(tc_basic, test_unknown_encoding_invalid_length); + tcase_add_test(tc_basic, test_unknown_encoding_invalid_topbit); + tcase_add_test(tc_basic, test_unknown_encoding_invalid_surrogate); + tcase_add_test(tc_basic, test_unknown_encoding_invalid_high); + tcase_add_test(tc_basic, test_unknown_encoding_invalid_attr_value); + tcase_add_test__if_xml_ge(tc_basic, test_ext_entity_latin1_utf16le_bom); + tcase_add_test__if_xml_ge(tc_basic, test_ext_entity_latin1_utf16be_bom); + tcase_add_test__if_xml_ge(tc_basic, test_ext_entity_latin1_utf16le_bom2); + tcase_add_test__if_xml_ge(tc_basic, test_ext_entity_latin1_utf16be_bom2); + tcase_add_test__if_xml_ge(tc_basic, test_ext_entity_utf16_be); + tcase_add_test__if_xml_ge(tc_basic, test_ext_entity_utf16_le); + tcase_add_test__if_xml_ge(tc_basic, test_ext_entity_utf16_unknown); + tcase_add_test__if_xml_ge(tc_basic, test_ext_entity_utf8_non_bom); + tcase_add_test(tc_basic, test_utf8_in_cdata_section); + tcase_add_test(tc_basic, test_utf8_in_cdata_section_2); + tcase_add_test(tc_basic, test_utf8_in_start_tags); + tcase_add_test(tc_basic, test_trailing_spaces_in_elements); + tcase_add_test(tc_basic, test_utf16_attribute); + tcase_add_test(tc_basic, test_utf16_second_attr); + tcase_add_test(tc_basic, test_attr_after_solidus); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_utf16_pe); + tcase_add_test(tc_basic, test_bad_attr_desc_keyword); + tcase_add_test(tc_basic, test_bad_attr_desc_keyword_utf16); + tcase_add_test(tc_basic, test_bad_doctype); + tcase_add_test(tc_basic, test_bad_doctype_utf8); + tcase_add_test(tc_basic, test_bad_doctype_utf16); + tcase_add_test(tc_basic, test_bad_doctype_plus); + tcase_add_test(tc_basic, test_bad_doctype_star); + tcase_add_test(tc_basic, test_bad_doctype_query); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_unknown_encoding_bad_ignore); + tcase_add_test(tc_basic, test_entity_in_utf16_be_attr); + tcase_add_test(tc_basic, test_entity_in_utf16_le_attr); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_entity_public_utf16_be); + tcase_add_test__ifdef_xml_dtd(tc_basic, test_entity_public_utf16_le); + tcase_add_test(tc_basic, test_short_doctype); + tcase_add_test(tc_basic, test_short_doctype_2); + tcase_add_test(tc_basic, test_short_doctype_3); + tcase_add_test(tc_basic, test_long_doctype); + tcase_add_test(tc_basic, test_bad_entity); + tcase_add_test(tc_basic, test_bad_entity_2); + tcase_add_test(tc_basic, test_bad_entity_3); + tcase_add_test(tc_basic, test_bad_entity_4); + tcase_add_test(tc_basic, test_bad_notation); + tcase_add_test(tc_basic, test_default_doctype_handler); + tcase_add_test(tc_basic, test_empty_element_abort); + tcase_add_test__ifdef_xml_dtd(tc_basic, + test_pool_integrity_with_unfinished_attr); + tcase_add_test__if_xml_ge(tc_basic, test_nested_entity_suspend); + tcase_add_test(tc_basic, test_big_tokens_scale_linearly); + tcase_add_test(tc_basic, test_set_reparse_deferral); + tcase_add_test(tc_basic, test_reparse_deferral_is_inherited); + tcase_add_test(tc_basic, test_set_reparse_deferral_on_null_parser); + tcase_add_test(tc_basic, test_set_reparse_deferral_on_the_fly); + tcase_add_test(tc_basic, test_set_bad_reparse_option); + tcase_add_test(tc_basic, test_bypass_heuristic_when_close_to_bufsize); + tcase_add_test(tc_basic, test_varying_buffer_fills); +} diff --git a/3rdparty/expat/tests/basic_tests.h b/3rdparty/expat/tests/basic_tests.h new file mode 100644 index 00000000000..4c16562ca0f --- /dev/null +++ b/3rdparty/expat/tests/basic_tests.h @@ -0,0 +1,56 @@ +/* Tests in the "basic" test case for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef XML_BASIC_TESTS_H +# define XML_BASIC_TESTS_H + +extern void make_basic_test_case(Suite *s); + +#endif /* XML_BASIC_TESTS_H */ + +#ifdef __cplusplus +} +#endif diff --git a/3rdparty/expat/tests/basic_tests_cxx.cpp b/3rdparty/expat/tests/basic_tests_cxx.cpp new file mode 100644 index 00000000000..d7e75a9061c --- /dev/null +++ b/3rdparty/expat/tests/basic_tests_cxx.cpp @@ -0,0 +1,32 @@ +/* C++ compilation harness for the test suite. + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "basic_tests.c" diff --git a/3rdparty/expat/tests/benchmark/Makefile.am b/3rdparty/expat/tests/benchmark/Makefile.am index 5ea8dc10c5b..f1bf3365f63 100644 --- a/3rdparty/expat/tests/benchmark/Makefile.am +++ b/3rdparty/expat/tests/benchmark/Makefile.am @@ -6,7 +6,8 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2017 Expat development team +# Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2020 Jeffrey Walton <noloader@gmail.com> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/tests/benchmark/Makefile.in b/3rdparty/expat/tests/benchmark/Makefile.in index 665bca31e35..d0e6d0769db 100644 --- a/3rdparty/expat/tests/benchmark/Makefile.in +++ b/3rdparty/expat/tests/benchmark/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2020 Free Software Foundation, Inc. +# Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -22,7 +22,8 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2017 Expat development team +# Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2020 Jeffrey Walton <noloader@gmail.com> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -132,6 +133,8 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/conftools/ax-append-compile-flags.m4 \ $(top_srcdir)/conftools/ax-append-link-flags.m4 \ $(top_srcdir)/conftools/expatcfg-compiler-supports-visibility.m4 \ + $(top_srcdir)/conftools/ax-cxx-compile-stdcxx.m4 \ + $(top_srcdir)/conftools/ax-cxx-compile-stdcxx-11.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) @@ -207,8 +210,6 @@ am__define_uniq_tagged_files = \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` -ETAGS = etags -CTAGS = ctags am__DIST_COMMON = $(srcdir)/Makefile.in \ $(top_srcdir)/conftools/depcomp DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -228,8 +229,10 @@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ -CPP = @CPP@ +CMAKE_SHARED_LIBRARY_PREFIX = @CMAKE_SHARED_LIBRARY_PREFIX@ CPPFLAGS = @CPPFLAGS@ +CSCOPE = @CSCOPE@ +CTAGS = @CTAGS@ CXX = @CXX@ CXXCPP = @CXXCPP@ CXXDEPMODE = @CXXDEPMODE@ @@ -245,10 +248,20 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ +ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ +EXPAT_ATTR_INFO = @EXPAT_ATTR_INFO@ +EXPAT_CHAR_TYPE = @EXPAT_CHAR_TYPE@ +EXPAT_CONTEXT_BYTES = @EXPAT_CONTEXT_BYTES@ +EXPAT_DTD = @EXPAT_DTD@ +EXPAT_LARGE_SIZE = @EXPAT_LARGE_SIZE@ +EXPAT_MIN_SIZE = @EXPAT_MIN_SIZE@ +EXPAT_NS = @EXPAT_NS@ FGREP = @FGREP@ +FILECMD = @FILECMD@ FILEMAP = @FILEMAP@ GREP = @GREP@ +HAVE_CXX11 = @HAVE_CXX11@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -258,6 +271,8 @@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBAGE = @LIBAGE@ LIBCURRENT = @LIBCURRENT@ +LIBDIR_BASENAME = @LIBDIR_BASENAME@ +LIBM = @LIBM@ LIBOBJS = @LIBOBJS@ LIBREVISION = @LIBREVISION@ LIBS = @LIBS@ @@ -266,6 +281,7 @@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ @@ -287,9 +303,12 @@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SIZEOF_VOID_P = @SIZEOF_VOID_P@ +SO_MAJOR = @SO_MAJOR@ +SO_MINOR = @SO_MINOR@ +SO_PATCH = @SO_PATCH@ STRIP = @STRIP@ VERSION = @VERSION@ -_EXPAT_OUTPUT_NAME = @_EXPAT_OUTPUT_NAME@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ @@ -353,7 +372,7 @@ all: all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ @@ -377,9 +396,9 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(top_srcdir)/configure: $(am__configure_deps) +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): $(am__aclocal_m4_deps) +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): @@ -488,7 +507,6 @@ cscopelist-am: $(am__tagged_files) distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am diff --git a/3rdparty/expat/tests/benchmark/benchmark.c b/3rdparty/expat/tests/benchmark/benchmark.c index fda8268f189..355d83f896d 100644 --- a/3rdparty/expat/tests/benchmark/benchmark.c +++ b/3rdparty/expat/tests/benchmark/benchmark.c @@ -6,8 +6,10 @@ \___/_/\_\ .__/ \__,_|\__| |_| XML parser - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2003-2006 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -31,6 +33,8 @@ */ #include <sys/stat.h> +#include <assert.h> +#include <stddef.h> // ptrdiff_t #include <stdlib.h> #include <stdio.h> #include <time.h> @@ -60,7 +64,8 @@ main(int argc, char *argv[]) { char *XMLBuf, *XMLBufEnd, *XMLBufPtr; FILE *fd; struct stat fileAttr; - int nrOfLoops, bufferSize, fileSize, i, isFinal; + int nrOfLoops, bufferSize, i, isFinal; + size_t fileSize; int j = 0, ns = 0; clock_t tstart, tend; double cpuTime = 0.0; @@ -112,12 +117,13 @@ main(int argc, char *argv[]) { isFinal = 0; tstart = clock(); do { - int parseBufferSize = XMLBufEnd - XMLBufPtr; - if (parseBufferSize <= bufferSize) + ptrdiff_t parseBufferSize = XMLBufEnd - XMLBufPtr; + if (parseBufferSize <= (ptrdiff_t)bufferSize) isFinal = 1; else parseBufferSize = bufferSize; - if (! XML_Parse(parser, XMLBufPtr, parseBufferSize, isFinal)) { + assert(parseBufferSize <= (ptrdiff_t)bufferSize); + if (! XML_Parse(parser, XMLBufPtr, (int)parseBufferSize, isFinal)) { fprintf(stderr, "error '%" XML_FMT_STR "' at line %" XML_FMT_INT_MOD "u character %" XML_FMT_INT_MOD "u\n", diff --git a/3rdparty/expat/tests/chardata.c b/3rdparty/expat/tests/chardata.c index 75a50166ec5..2adb2c5462b 100644 --- a/3rdparty/expat/tests/chardata.c +++ b/3rdparty/expat/tests/chardata.c @@ -6,8 +6,13 @@ \___/_/\_\ .__/ \__,_|\__| |_| XML parser - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2002-2004 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2016 Gilles Espinasse <g.esp@free.fr> + Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2022 Sean McBride <sean@rogue-research.com> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -30,9 +35,11 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifdef HAVE_EXPAT_CONFIG_H -# include <expat_config.h> +#if defined(NDEBUG) +# undef NDEBUG /* because test suite relies on assert(...) at the moment */ #endif + +#include "expat_config.h" #include "minicheck.h" #include <assert.h> @@ -78,15 +85,16 @@ CharData_AppendXMLChars(CharData *storage, const XML_Char *s, int len) { int CharData_CheckXMLChars(CharData *storage, const XML_Char *expected) { - char buffer[1024]; int len = xmlstrlen(expected); int count; assert(storage != NULL); count = (storage->count < 0) ? 0 : storage->count; if (len != count) { - sprintf(buffer, "wrong number of data characters: got %d, expected %d", - count, len); + char buffer[1024]; + snprintf(buffer, sizeof(buffer), + "wrong number of data characters: got %d, expected %d", count, + len); fail(buffer); return 0; } diff --git a/3rdparty/expat/tests/chardata.h b/3rdparty/expat/tests/chardata.h index 4001b9b9d15..ccb631f64b2 100644 --- a/3rdparty/expat/tests/chardata.h +++ b/3rdparty/expat/tests/chardata.h @@ -7,8 +7,9 @@ \___/_/\_\ .__/ \__,_|\__| |_| XML parser - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2002-2004 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/tests/chardata_cxx.cpp b/3rdparty/expat/tests/chardata_cxx.cpp new file mode 100644 index 00000000000..81820c72dca --- /dev/null +++ b/3rdparty/expat/tests/chardata_cxx.cpp @@ -0,0 +1,32 @@ +/* C++ compilation harness for the test suite. + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "chardata.c" diff --git a/3rdparty/expat/tests/common.c b/3rdparty/expat/tests/common.c new file mode 100644 index 00000000000..3aea8d74d1e --- /dev/null +++ b/3rdparty/expat/tests/common.c @@ -0,0 +1,296 @@ +/* Commonly used functions for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild@sony.com> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include <assert.h> +#include <stdio.h> +#include <string.h> + +#include "expat_config.h" +#include "expat.h" +#include "internal.h" +#include "chardata.h" +#include "minicheck.h" +#include "common.h" +#include "handlers.h" + +/* Common test data */ + +const char *long_character_data_text + = "<?xml version='1.0' encoding='iso-8859-1'?><s>" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "</s>"; + +const char *long_cdata_text + = "<s><![CDATA[" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "012345678901234567890123456789012345678901234567890123456789" + "]]></s>"; + +/* Having an element name longer than 1024 characters exercises some + * of the pool allocation code in the parser that otherwise does not + * get executed. The count at the end of the line is the number of + * characters (bytes) in the element name by that point.x + */ +const char *get_buffer_test_text + = "<documentwitharidiculouslylongelementnametotease" /* 0x030 */ + "aparticularcorneroftheallocationinXML_GetBuffers" /* 0x060 */ + "othatwecanimprovethecoverageyetagain012345678901" /* 0x090 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x0c0 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x0f0 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x120 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x150 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x180 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x1b0 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x1e0 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x210 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x240 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x270 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x2a0 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x2d0 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x300 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x330 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x360 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x390 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x3c0 */ + "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x3f0 */ + "123456789abcdef0123456789abcdef0123456789>\n<ef0"; /* 0x420 */ + +/* Test control globals */ + +/* Used as the "resumable" parameter to XML_StopParser by some tests */ +XML_Bool g_resumable = XML_FALSE; + +/* Used to control abort checks in some tests */ +XML_Bool g_abortable = XML_FALSE; + +/* Used to control _XML_Parse_SINGLE_BYTES() chunk size */ +int g_chunkSize = 1; + +/* Common test functions */ + +void +tcase_add_test__ifdef_xml_dtd(TCase *tc, tcase_test_function test) { +#ifdef XML_DTD + tcase_add_test(tc, test); +#else + UNUSED_P(tc); + UNUSED_P(test); +#endif +} + +void +tcase_add_test__if_xml_ge(TCase *tc, tcase_test_function test) { +#if XML_GE == 1 + tcase_add_test(tc, test); +#else + UNUSED_P(tc); + UNUSED_P(test); +#endif +} + +void +basic_teardown(void) { + if (g_parser != NULL) { + XML_ParserFree(g_parser); + g_parser = NULL; + } +} + +/* Generate a failure using the parser state to create an error message; + this should be used when the parser reports an error we weren't + expecting. +*/ +void +_xml_failure(XML_Parser parser, const char *file, int line) { + char buffer[1024]; + enum XML_Error err = XML_GetErrorCode(parser); + snprintf(buffer, sizeof(buffer), + " %d: %" XML_FMT_STR " (line %" XML_FMT_INT_MOD + "u, offset %" XML_FMT_INT_MOD "u)\n reported from %s, line %d\n", + err, XML_ErrorString(err), XML_GetCurrentLineNumber(parser), + XML_GetCurrentColumnNumber(parser), file, line); + _fail(file, line, buffer); +} + +enum XML_Status +_XML_Parse_SINGLE_BYTES(XML_Parser parser, const char *s, int len, + int isFinal) { + // This ensures that tests have to run pathological parse cases + // (e.g. when `s` is NULL) against plain XML_Parse rather than + // chunking _XML_Parse_SINGLE_BYTES. + assert((parser != NULL) && (s != NULL) && (len >= 0)); + const int chunksize = g_chunkSize; + if (chunksize > 0) { + // parse in chunks of `chunksize` bytes as long as not exhausting + for (; len > chunksize; len -= chunksize, s += chunksize) { + enum XML_Status res = XML_Parse(parser, s, chunksize, XML_FALSE); + if (res != XML_STATUS_OK) { + return res; + } + } + } + // parse the final chunk, the size of which will be <= chunksize + return XML_Parse(parser, s, len, isFinal); +} + +void +_expect_failure(const char *text, enum XML_Error errorCode, + const char *errorMessage, const char *file, int lineno) { + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_OK) + /* Hackish use of _fail() macro, but lets us report + the right filename and line number. */ + _fail(file, lineno, errorMessage); + if (XML_GetErrorCode(g_parser) != errorCode) + _xml_failure(g_parser, file, lineno); +} + +void +_run_character_check(const char *text, const XML_Char *expected, + const char *file, int line) { + CharData storage; + + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetCharacterDataHandler(g_parser, accumulate_characters); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + _xml_failure(g_parser, file, line); + CharData_CheckXMLChars(&storage, expected); +} + +void +_run_attribute_check(const char *text, const XML_Char *expected, + const char *file, int line) { + CharData storage; + + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetStartElementHandler(g_parser, accumulate_attribute); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + _xml_failure(g_parser, file, line); + CharData_CheckXMLChars(&storage, expected); +} + +void +_run_ext_character_check(const char *text, ExtTest *test_data, + const XML_Char *expected, const char *file, int line) { + CharData *const storage = (CharData *)malloc(sizeof(CharData)); + + CharData_Init(storage); + test_data->storage = storage; + XML_SetUserData(g_parser, test_data); + XML_SetCharacterDataHandler(g_parser, ext_accumulate_characters); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + _xml_failure(g_parser, file, line); + CharData_CheckXMLChars(storage, expected); + + free(storage); +} + +/* Control variable; the number of times duff_allocator() will successfully + * allocate */ +#define ALLOC_ALWAYS_SUCCEED (-1) +#define REALLOC_ALWAYS_SUCCEED (-1) + +int g_allocation_count = ALLOC_ALWAYS_SUCCEED; +int g_reallocation_count = REALLOC_ALWAYS_SUCCEED; + +/* Crocked allocator for allocation failure tests */ +void * +duff_allocator(size_t size) { + if (g_allocation_count == 0) + return NULL; + if (g_allocation_count != ALLOC_ALWAYS_SUCCEED) + g_allocation_count--; + return malloc(size); +} + +/* Crocked reallocator for allocation failure tests */ +void * +duff_reallocator(void *ptr, size_t size) { + if (g_reallocation_count == 0) + return NULL; + if (g_reallocation_count != REALLOC_ALWAYS_SUCCEED) + g_reallocation_count--; + return realloc(ptr, size); +} diff --git a/3rdparty/expat/tests/common.h b/3rdparty/expat/tests/common.h new file mode 100644 index 00000000000..bc4c7da6807 --- /dev/null +++ b/3rdparty/expat/tests/common.h @@ -0,0 +1,153 @@ +/* Commonly used functions for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef XML_COMMON_H +# define XML_COMMON_H + +# include "expat_config.h" +# include "minicheck.h" +# include "chardata.h" + +# ifdef XML_LARGE_SIZE +# define XML_FMT_INT_MOD "ll" +# else +# define XML_FMT_INT_MOD "l" +# endif + +# ifdef XML_UNICODE_WCHAR_T +# define XML_FMT_STR "ls" +# include <wchar.h> +# define xcstrlen(s) wcslen(s) +# define xcstrcmp(s, t) wcscmp((s), (t)) +# define xcstrncmp(s, t, n) wcsncmp((s), (t), (n)) +# define XCS(s) _XCS(s) +# define _XCS(s) L##s +# else +# ifdef XML_UNICODE +# error "No support for UTF-16 character without wchar_t in tests" +# else +# define XML_FMT_STR "s" +# define xcstrlen(s) strlen(s) +# define xcstrcmp(s, t) strcmp((s), (t)) +# define xcstrncmp(s, t, n) strncmp((s), (t), (n)) +# define XCS(s) s +# endif /* XML_UNICODE */ +# endif /* XML_UNICODE_WCHAR_T */ + +extern XML_Parser g_parser; + +extern XML_Bool g_resumable; +extern XML_Bool g_abortable; + +extern int g_chunkSize; + +extern const char *long_character_data_text; +extern const char *long_cdata_text; +extern const char *get_buffer_test_text; + +extern void tcase_add_test__ifdef_xml_dtd(TCase *tc, tcase_test_function test); +extern void tcase_add_test__if_xml_ge(TCase *tc, tcase_test_function test); + +extern void basic_teardown(void); + +extern void _xml_failure(XML_Parser parser, const char *file, int line); + +# define xml_failure(parser) _xml_failure((parser), __FILE__, __LINE__) + +extern enum XML_Status _XML_Parse_SINGLE_BYTES(XML_Parser parser, const char *s, + int len, int isFinal); + +extern void _expect_failure(const char *text, enum XML_Error errorCode, + const char *errorMessage, const char *file, + int lineno); + +# define expect_failure(text, errorCode, errorMessage) \ + _expect_failure((text), (errorCode), (errorMessage), __FILE__, __LINE__) + +/* Support functions for handlers to collect up character and attribute data. + */ + +extern void _run_character_check(const char *text, const XML_Char *expected, + const char *file, int line); + +# define run_character_check(text, expected) \ + _run_character_check(text, expected, __FILE__, __LINE__) + +extern void _run_attribute_check(const char *text, const XML_Char *expected, + const char *file, int line); + +# define run_attribute_check(text, expected) \ + _run_attribute_check(text, expected, __FILE__, __LINE__) + +typedef struct ExtTest { + const char *parse_text; + const XML_Char *encoding; + CharData *storage; +} ExtTest; + +extern void _run_ext_character_check(const char *text, ExtTest *test_data, + const XML_Char *expected, const char *file, + int line); + +# define run_ext_character_check(text, test_data, expected) \ + _run_ext_character_check(text, test_data, expected, __FILE__, __LINE__) + +# define ALLOC_ALWAYS_SUCCEED (-1) +# define REALLOC_ALWAYS_SUCCEED (-1) + +extern int g_allocation_count; +extern int g_reallocation_count; + +extern void *duff_allocator(size_t size); + +extern void *duff_reallocator(void *ptr, size_t size); + +#endif /* XML_COMMON_H */ + +#ifdef __cplusplus +} +#endif diff --git a/3rdparty/expat/tests/common_cxx.cpp b/3rdparty/expat/tests/common_cxx.cpp new file mode 100644 index 00000000000..698a0ccfa9d --- /dev/null +++ b/3rdparty/expat/tests/common_cxx.cpp @@ -0,0 +1,32 @@ +/* C++ compilation harness for the test suite. + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "common.c" diff --git a/3rdparty/expat/tests/dummy.c b/3rdparty/expat/tests/dummy.c new file mode 100644 index 00000000000..4ab57edd2cf --- /dev/null +++ b/3rdparty/expat/tests/dummy.c @@ -0,0 +1,261 @@ +/* Dummy handler functions for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "expat.h" +#include "internal.h" +#include "common.h" +#include "dummy.h" + +/* Dummy handlers for when we need to set a handler to tickle a bug, + but it doesn't need to do anything. +*/ +static unsigned long dummy_handler_flags = 0; + +void +init_dummy_handlers(void) { + dummy_handler_flags = 0; +} + +unsigned long +get_dummy_handler_flags(void) { + return dummy_handler_flags; +} + +void XMLCALL +dummy_xdecl_handler(void *userData, const XML_Char *version, + const XML_Char *encoding, int standalone) { + UNUSED_P(userData); + UNUSED_P(version); + UNUSED_P(encoding); + UNUSED_P(standalone); +} + +void XMLCALL +dummy_start_doctype_handler(void *userData, const XML_Char *doctypeName, + const XML_Char *sysid, const XML_Char *pubid, + int has_internal_subset) { + UNUSED_P(userData); + UNUSED_P(doctypeName); + UNUSED_P(sysid); + UNUSED_P(pubid); + UNUSED_P(has_internal_subset); + dummy_handler_flags |= DUMMY_START_DOCTYPE_HANDLER_FLAG; +} + +void XMLCALL +dummy_end_doctype_handler(void *userData) { + UNUSED_P(userData); + dummy_handler_flags |= DUMMY_END_DOCTYPE_HANDLER_FLAG; +} + +void XMLCALL +dummy_entity_decl_handler(void *userData, const XML_Char *entityName, + int is_parameter_entity, const XML_Char *value, + int value_length, const XML_Char *base, + const XML_Char *systemId, const XML_Char *publicId, + const XML_Char *notationName) { + UNUSED_P(userData); + UNUSED_P(entityName); + UNUSED_P(is_parameter_entity); + UNUSED_P(value); + UNUSED_P(value_length); + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + UNUSED_P(notationName); + dummy_handler_flags |= DUMMY_ENTITY_DECL_HANDLER_FLAG; +} + +void XMLCALL +dummy_notation_decl_handler(void *userData, const XML_Char *notationName, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + UNUSED_P(userData); + UNUSED_P(notationName); + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + dummy_handler_flags |= DUMMY_NOTATION_DECL_HANDLER_FLAG; +} + +void XMLCALL +dummy_element_decl_handler(void *userData, const XML_Char *name, + XML_Content *model) { + UNUSED_P(userData); + UNUSED_P(name); + /* The content model must be freed by the handler. Unfortunately + * we cannot pass the parser as the userData because this is used + * with other handlers that require other userData. + */ + XML_FreeContentModel(g_parser, model); + dummy_handler_flags |= DUMMY_ELEMENT_DECL_HANDLER_FLAG; +} + +void XMLCALL +dummy_attlist_decl_handler(void *userData, const XML_Char *elname, + const XML_Char *attname, const XML_Char *att_type, + const XML_Char *dflt, int isrequired) { + UNUSED_P(userData); + UNUSED_P(elname); + UNUSED_P(attname); + UNUSED_P(att_type); + UNUSED_P(dflt); + UNUSED_P(isrequired); + dummy_handler_flags |= DUMMY_ATTLIST_DECL_HANDLER_FLAG; +} + +void XMLCALL +dummy_comment_handler(void *userData, const XML_Char *data) { + UNUSED_P(userData); + UNUSED_P(data); + dummy_handler_flags |= DUMMY_COMMENT_HANDLER_FLAG; +} + +void XMLCALL +dummy_pi_handler(void *userData, const XML_Char *target, const XML_Char *data) { + UNUSED_P(userData); + UNUSED_P(target); + UNUSED_P(data); + dummy_handler_flags |= DUMMY_PI_HANDLER_FLAG; +} + +void XMLCALL +dummy_start_element(void *userData, const XML_Char *name, + const XML_Char **atts) { + UNUSED_P(userData); + UNUSED_P(name); + UNUSED_P(atts); + dummy_handler_flags |= DUMMY_START_ELEMENT_HANDLER_FLAG; +} + +void XMLCALL +dummy_end_element(void *userData, const XML_Char *name) { + UNUSED_P(userData); + UNUSED_P(name); +} + +void XMLCALL +dummy_start_cdata_handler(void *userData) { + UNUSED_P(userData); + dummy_handler_flags |= DUMMY_START_CDATA_HANDLER_FLAG; +} + +void XMLCALL +dummy_end_cdata_handler(void *userData) { + UNUSED_P(userData); + dummy_handler_flags |= DUMMY_END_CDATA_HANDLER_FLAG; +} + +void XMLCALL +dummy_cdata_handler(void *userData, const XML_Char *s, int len) { + UNUSED_P(userData); + UNUSED_P(s); + UNUSED_P(len); +} + +void XMLCALL +dummy_start_namespace_decl_handler(void *userData, const XML_Char *prefix, + const XML_Char *uri) { + UNUSED_P(userData); + UNUSED_P(prefix); + UNUSED_P(uri); + dummy_handler_flags |= DUMMY_START_NS_DECL_HANDLER_FLAG; +} + +void XMLCALL +dummy_end_namespace_decl_handler(void *userData, const XML_Char *prefix) { + UNUSED_P(userData); + UNUSED_P(prefix); + dummy_handler_flags |= DUMMY_END_NS_DECL_HANDLER_FLAG; +} + +/* This handler is obsolete, but while the code exists we should + * ensure that dealing with the handler is covered by tests. + */ +void XMLCALL +dummy_unparsed_entity_decl_handler(void *userData, const XML_Char *entityName, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId, + const XML_Char *notationName) { + UNUSED_P(userData); + UNUSED_P(entityName); + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + UNUSED_P(notationName); + dummy_handler_flags |= DUMMY_UNPARSED_ENTITY_DECL_HANDLER_FLAG; +} + +void XMLCALL +dummy_default_handler(void *userData, const XML_Char *s, int len) { + UNUSED_P(userData); + UNUSED_P(s); + UNUSED_P(len); +} + +void XMLCALL +dummy_start_doctype_decl_handler(void *userData, const XML_Char *doctypeName, + const XML_Char *sysid, const XML_Char *pubid, + int has_internal_subset) { + UNUSED_P(userData); + UNUSED_P(doctypeName); + UNUSED_P(sysid); + UNUSED_P(pubid); + UNUSED_P(has_internal_subset); + dummy_handler_flags |= DUMMY_START_DOCTYPE_DECL_HANDLER_FLAG; +} + +void XMLCALL +dummy_end_doctype_decl_handler(void *userData) { + UNUSED_P(userData); + dummy_handler_flags |= DUMMY_END_DOCTYPE_DECL_HANDLER_FLAG; +} + +void XMLCALL +dummy_skip_handler(void *userData, const XML_Char *entityName, + int is_parameter_entity) { + UNUSED_P(userData); + UNUSED_P(entityName); + UNUSED_P(is_parameter_entity); + dummy_handler_flags |= DUMMY_SKIP_HANDLER_FLAG; +} diff --git a/3rdparty/expat/tests/dummy.h b/3rdparty/expat/tests/dummy.h new file mode 100644 index 00000000000..3d7ec63ed33 --- /dev/null +++ b/3rdparty/expat/tests/dummy.h @@ -0,0 +1,150 @@ +/* Dummy handler functions for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef XML_DUMMY_H +# define XML_DUMMY_H + +# define DUMMY_START_DOCTYPE_HANDLER_FLAG (1UL << 0) +# define DUMMY_END_DOCTYPE_HANDLER_FLAG (1UL << 1) +# define DUMMY_ENTITY_DECL_HANDLER_FLAG (1UL << 2) +# define DUMMY_NOTATION_DECL_HANDLER_FLAG (1UL << 3) +# define DUMMY_ELEMENT_DECL_HANDLER_FLAG (1UL << 4) +# define DUMMY_ATTLIST_DECL_HANDLER_FLAG (1UL << 5) +# define DUMMY_COMMENT_HANDLER_FLAG (1UL << 6) +# define DUMMY_PI_HANDLER_FLAG (1UL << 7) +# define DUMMY_START_ELEMENT_HANDLER_FLAG (1UL << 8) +# define DUMMY_START_CDATA_HANDLER_FLAG (1UL << 9) +# define DUMMY_END_CDATA_HANDLER_FLAG (1UL << 10) +# define DUMMY_UNPARSED_ENTITY_DECL_HANDLER_FLAG (1UL << 11) +# define DUMMY_START_NS_DECL_HANDLER_FLAG (1UL << 12) +# define DUMMY_END_NS_DECL_HANDLER_FLAG (1UL << 13) +# define DUMMY_START_DOCTYPE_DECL_HANDLER_FLAG (1UL << 14) +# define DUMMY_END_DOCTYPE_DECL_HANDLER_FLAG (1UL << 15) +# define DUMMY_SKIP_HANDLER_FLAG (1UL << 16) +# define DUMMY_DEFAULT_HANDLER_FLAG (1UL << 17) + +extern void init_dummy_handlers(void); +extern unsigned long get_dummy_handler_flags(void); + +extern void XMLCALL dummy_xdecl_handler(void *userData, const XML_Char *version, + const XML_Char *encoding, + int standalone); + +extern void XMLCALL dummy_start_doctype_handler(void *userData, + const XML_Char *doctypeName, + const XML_Char *sysid, + const XML_Char *pubid, + int has_internal_subset); + +extern void XMLCALL dummy_end_doctype_handler(void *userData); + +extern void XMLCALL dummy_entity_decl_handler( + void *userData, const XML_Char *entityName, int is_parameter_entity, + const XML_Char *value, int value_length, const XML_Char *base, + const XML_Char *systemId, const XML_Char *publicId, + const XML_Char *notationName); + +extern void XMLCALL dummy_notation_decl_handler(void *userData, + const XML_Char *notationName, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern void XMLCALL dummy_element_decl_handler(void *userData, + const XML_Char *name, + XML_Content *model); + +extern void XMLCALL dummy_attlist_decl_handler( + void *userData, const XML_Char *elname, const XML_Char *attname, + const XML_Char *att_type, const XML_Char *dflt, int isrequired); + +extern void XMLCALL dummy_comment_handler(void *userData, const XML_Char *data); + +extern void XMLCALL dummy_pi_handler(void *userData, const XML_Char *target, + const XML_Char *data); + +extern void XMLCALL dummy_start_element(void *userData, const XML_Char *name, + const XML_Char **atts); + +extern void XMLCALL dummy_end_element(void *userData, const XML_Char *name); + +extern void XMLCALL dummy_start_cdata_handler(void *userData); + +extern void XMLCALL dummy_end_cdata_handler(void *userData); + +extern void XMLCALL dummy_cdata_handler(void *userData, const XML_Char *s, + int len); + +extern void XMLCALL dummy_start_namespace_decl_handler(void *userData, + const XML_Char *prefix, + const XML_Char *uri); + +extern void XMLCALL dummy_end_namespace_decl_handler(void *userData, + const XML_Char *prefix); + +extern void XMLCALL dummy_unparsed_entity_decl_handler( + void *userData, const XML_Char *entityName, const XML_Char *base, + const XML_Char *systemId, const XML_Char *publicId, + const XML_Char *notationName); + +extern void XMLCALL dummy_default_handler(void *userData, const XML_Char *s, + int len); + +extern void XMLCALL dummy_start_doctype_decl_handler( + void *userData, const XML_Char *doctypeName, const XML_Char *sysid, + const XML_Char *pubid, int has_internal_subset); + +extern void XMLCALL dummy_end_doctype_decl_handler(void *userData); + +extern void XMLCALL dummy_skip_handler(void *userData, + const XML_Char *entityName, + int is_parameter_entity); + +#endif /* XML_DUMMY_H */ + +#ifdef __cplusplus +} +#endif diff --git a/3rdparty/expat/tests/dummy_cxx.cpp b/3rdparty/expat/tests/dummy_cxx.cpp new file mode 100644 index 00000000000..27c9f431ecd --- /dev/null +++ b/3rdparty/expat/tests/dummy_cxx.cpp @@ -0,0 +1,32 @@ +/* C++ compilation harness for the test suite. + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "dummy.c" diff --git a/3rdparty/expat/tests/handlers.c b/3rdparty/expat/tests/handlers.c new file mode 100644 index 00000000000..0211985fe95 --- /dev/null +++ b/3rdparty/expat/tests/handlers.c @@ -0,0 +1,1956 @@ +/* XML handler functions for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild@sony.com> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#if defined(NDEBUG) +# undef NDEBUG /* because test suite relies on assert(...) at the moment */ +#endif + +#include <stdio.h> +#include <string.h> +#include <assert.h> + +#include "expat_config.h" + +#include "expat.h" +#include "internal.h" +#include "chardata.h" +#include "structdata.h" +#include "common.h" +#include "handlers.h" + +/* Global variables for user parameter settings tests */ +/* Variable holding the expected handler userData */ +const void *g_handler_data = NULL; +/* Count of the number of times the comment handler has been invoked */ +int g_comment_count = 0; +/* Count of the number of skipped entities */ +int g_skip_count = 0; +/* Count of the number of times the XML declaration handler is invoked */ +int g_xdecl_count = 0; + +/* Start/End Element Handlers */ + +void XMLCALL +start_element_event_handler(void *userData, const XML_Char *name, + const XML_Char **atts) { + UNUSED_P(atts); + CharData_AppendXMLChars((CharData *)userData, name, -1); +} + +void XMLCALL +end_element_event_handler(void *userData, const XML_Char *name) { + CharData *storage = (CharData *)userData; + CharData_AppendXMLChars(storage, XCS("/"), 1); + CharData_AppendXMLChars(storage, name, -1); +} + +void XMLCALL +start_element_event_handler2(void *userData, const XML_Char *name, + const XML_Char **attr) { + StructData *storage = (StructData *)userData; + UNUSED_P(attr); + StructData_AddItem(storage, name, XML_GetCurrentColumnNumber(g_parser), + XML_GetCurrentLineNumber(g_parser), STRUCT_START_TAG); +} + +void XMLCALL +end_element_event_handler2(void *userData, const XML_Char *name) { + StructData *storage = (StructData *)userData; + StructData_AddItem(storage, name, XML_GetCurrentColumnNumber(g_parser), + XML_GetCurrentLineNumber(g_parser), STRUCT_END_TAG); +} + +void XMLCALL +counting_start_element_handler(void *userData, const XML_Char *name, + const XML_Char **atts) { + ParserAndElementInfo *const parserAndElementInfos + = (ParserAndElementInfo *)userData; + ElementInfo *info = parserAndElementInfos->info; + AttrInfo *attr; + int count, id, i; + + while (info->name != NULL) { + if (! xcstrcmp(name, info->name)) + break; + info++; + } + if (info->name == NULL) + fail("Element not recognised"); + /* The attribute count is twice what you might expect. It is a + * count of items in atts, an array which contains alternating + * attribute names and attribute values. For the naive user this + * is possibly a little unexpected, but it is what the + * documentation in expat.h tells us to expect. + */ + count = XML_GetSpecifiedAttributeCount(parserAndElementInfos->parser); + if (info->attr_count * 2 != count) { + fail("Not got expected attribute count"); + return; + } + id = XML_GetIdAttributeIndex(parserAndElementInfos->parser); + if (id == -1 && info->id_name != NULL) { + fail("ID not present"); + return; + } + if (id != -1 && xcstrcmp(atts[id], info->id_name)) { + fail("ID does not have the correct name"); + return; + } + for (i = 0; i < info->attr_count; i++) { + attr = info->attributes; + while (attr->name != NULL) { + if (! xcstrcmp(atts[0], attr->name)) + break; + attr++; + } + if (attr->name == NULL) { + fail("Attribute not recognised"); + return; + } + if (xcstrcmp(atts[1], attr->value)) { + fail("Attribute has wrong value"); + return; + } + /* Remember, two entries in atts per attribute (see above) */ + atts += 2; + } +} + +void XMLCALL +suspending_end_handler(void *userData, const XML_Char *s) { + UNUSED_P(s); + XML_StopParser((XML_Parser)userData, 1); +} + +void XMLCALL +start_element_suspender(void *userData, const XML_Char *name, + const XML_Char **atts) { + UNUSED_P(userData); + UNUSED_P(atts); + if (! xcstrcmp(name, XCS("suspend"))) + XML_StopParser(g_parser, XML_TRUE); + if (! xcstrcmp(name, XCS("abort"))) + XML_StopParser(g_parser, XML_FALSE); +} + +/* Check that an element name and attribute name match the expected values. + The expected values are passed as an array reference of string pointers + provided as the userData argument; the first is the expected + element name, and the second is the expected attribute name. +*/ +int g_triplet_start_flag = XML_FALSE; +int g_triplet_end_flag = XML_FALSE; + +void XMLCALL +triplet_start_checker(void *userData, const XML_Char *name, + const XML_Char **atts) { + XML_Char **elemstr = (XML_Char **)userData; + char buffer[1024]; + if (xcstrcmp(elemstr[0], name) != 0) { + snprintf(buffer, sizeof(buffer), + "unexpected start string: '%" XML_FMT_STR "'", name); + fail(buffer); + } + if (xcstrcmp(elemstr[1], atts[0]) != 0) { + snprintf(buffer, sizeof(buffer), + "unexpected attribute string: '%" XML_FMT_STR "'", atts[0]); + fail(buffer); + } + g_triplet_start_flag = XML_TRUE; +} + +/* Check that the element name passed to the end-element handler matches + the expected value. The expected value is passed as the first element + in an array of strings passed as the userData argument. +*/ +void XMLCALL +triplet_end_checker(void *userData, const XML_Char *name) { + XML_Char **elemstr = (XML_Char **)userData; + if (xcstrcmp(elemstr[0], name) != 0) { + char buffer[1024]; + snprintf(buffer, sizeof(buffer), + "unexpected end string: '%" XML_FMT_STR "'", name); + fail(buffer); + } + g_triplet_end_flag = XML_TRUE; +} + +void XMLCALL +overwrite_start_checker(void *userData, const XML_Char *name, + const XML_Char **atts) { + CharData *storage = (CharData *)userData; + CharData_AppendXMLChars(storage, XCS("start "), 6); + CharData_AppendXMLChars(storage, name, -1); + while (*atts != NULL) { + CharData_AppendXMLChars(storage, XCS("\nattribute "), 11); + CharData_AppendXMLChars(storage, *atts, -1); + atts += 2; + } + CharData_AppendXMLChars(storage, XCS("\n"), 1); +} + +void XMLCALL +overwrite_end_checker(void *userData, const XML_Char *name) { + CharData *storage = (CharData *)userData; + CharData_AppendXMLChars(storage, XCS("end "), 4); + CharData_AppendXMLChars(storage, name, -1); + CharData_AppendXMLChars(storage, XCS("\n"), 1); +} + +void XMLCALL +start_element_fail(void *userData, const XML_Char *name, + const XML_Char **atts) { + UNUSED_P(userData); + UNUSED_P(name); + UNUSED_P(atts); + + /* We should never get here. */ + fail("should never reach start_element_fail()"); +} + +void XMLCALL +start_ns_clearing_start_element(void *userData, const XML_Char *prefix, + const XML_Char *uri) { + UNUSED_P(prefix); + UNUSED_P(uri); + XML_SetStartElementHandler((XML_Parser)userData, NULL); +} + +void XMLCALL +start_element_issue_240(void *userData, const XML_Char *name, + const XML_Char **atts) { + DataIssue240 *mydata = (DataIssue240 *)userData; + UNUSED_P(name); + UNUSED_P(atts); + mydata->deep++; +} + +void XMLCALL +end_element_issue_240(void *userData, const XML_Char *name) { + DataIssue240 *mydata = (DataIssue240 *)userData; + + UNUSED_P(name); + mydata->deep--; + if (mydata->deep == 0) { + XML_StopParser(mydata->parser, 0); + } +} + +/* Text encoding handlers */ + +int XMLCALL +UnknownEncodingHandler(void *data, const XML_Char *encoding, + XML_Encoding *info) { + UNUSED_P(data); + if (xcstrcmp(encoding, XCS("unsupported-encoding")) == 0) { + int i; + for (i = 0; i < 256; ++i) + info->map[i] = i; + info->data = NULL; + info->convert = NULL; + info->release = NULL; + return XML_STATUS_OK; + } + return XML_STATUS_ERROR; +} + +static void +dummy_release(void *data) { + UNUSED_P(data); +} + +int XMLCALL +UnrecognisedEncodingHandler(void *data, const XML_Char *encoding, + XML_Encoding *info) { + UNUSED_P(data); + UNUSED_P(encoding); + info->data = NULL; + info->convert = NULL; + info->release = dummy_release; + return XML_STATUS_ERROR; +} + +int XMLCALL +unknown_released_encoding_handler(void *data, const XML_Char *encoding, + XML_Encoding *info) { + UNUSED_P(data); + if (! xcstrcmp(encoding, XCS("unsupported-encoding"))) { + int i; + + for (i = 0; i < 256; i++) + info->map[i] = i; + info->data = NULL; + info->convert = NULL; + info->release = dummy_release; + return XML_STATUS_OK; + } + return XML_STATUS_ERROR; +} + +static int XMLCALL +failing_converter(void *data, const char *s) { + UNUSED_P(data); + UNUSED_P(s); + /* Always claim to have failed */ + return -1; +} + +static int XMLCALL +prefix_converter(void *data, const char *s) { + UNUSED_P(data); + /* If the first byte is 0xff, raise an error */ + if (s[0] == (char)-1) + return -1; + /* Just add the low bits of the first byte to the second */ + return (s[1] + (s[0] & 0x7f)) & 0x01ff; +} + +int XMLCALL +MiscEncodingHandler(void *data, const XML_Char *encoding, XML_Encoding *info) { + int i; + int high_map = -2; /* Assume a 2-byte sequence */ + + if (! xcstrcmp(encoding, XCS("invalid-9")) + || ! xcstrcmp(encoding, XCS("ascii-like")) + || ! xcstrcmp(encoding, XCS("invalid-len")) + || ! xcstrcmp(encoding, XCS("invalid-a")) + || ! xcstrcmp(encoding, XCS("invalid-surrogate")) + || ! xcstrcmp(encoding, XCS("invalid-high"))) + high_map = -1; + + for (i = 0; i < 128; ++i) + info->map[i] = i; + for (; i < 256; ++i) + info->map[i] = high_map; + + /* If required, put an invalid value in the ASCII entries */ + if (! xcstrcmp(encoding, XCS("invalid-9"))) + info->map[9] = 5; + /* If required, have a top-bit set character starts a 5-byte sequence */ + if (! xcstrcmp(encoding, XCS("invalid-len"))) + info->map[0x81] = -5; + /* If required, make a top-bit set character a valid ASCII character */ + if (! xcstrcmp(encoding, XCS("invalid-a"))) + info->map[0x82] = 'a'; + /* If required, give a top-bit set character a forbidden value, + * what would otherwise be the first of a surrogate pair. + */ + if (! xcstrcmp(encoding, XCS("invalid-surrogate"))) + info->map[0x83] = 0xd801; + /* If required, give a top-bit set character too high a value */ + if (! xcstrcmp(encoding, XCS("invalid-high"))) + info->map[0x84] = 0x010101; + + info->data = data; + info->release = NULL; + if (! xcstrcmp(encoding, XCS("failing-conv"))) + info->convert = failing_converter; + else if (! xcstrcmp(encoding, XCS("prefix-conv"))) + info->convert = prefix_converter; + else + info->convert = NULL; + return XML_STATUS_OK; +} + +int XMLCALL +long_encoding_handler(void *userData, const XML_Char *encoding, + XML_Encoding *info) { + int i; + + UNUSED_P(userData); + UNUSED_P(encoding); + for (i = 0; i < 256; i++) + info->map[i] = i; + info->data = NULL; + info->convert = NULL; + info->release = NULL; + return XML_STATUS_OK; +} + +/* External Entity Handlers */ + +int XMLCALL +external_entity_optioner(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + ExtOption *options = (ExtOption *)XML_GetUserData(parser); + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(publicId); + while (options->parse_text != NULL) { + if (! xcstrcmp(systemId, options->system_id)) { + enum XML_Status rc; + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + return XML_STATUS_ERROR; + rc = _XML_Parse_SINGLE_BYTES(ext_parser, options->parse_text, + (int)strlen(options->parse_text), XML_TRUE); + XML_ParserFree(ext_parser); + return rc; + } + options++; + } + fail("No suitable option found"); + return XML_STATUS_ERROR; +} + +int XMLCALL +external_entity_loader(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + ExtTest *test_data = (ExtTest *)XML_GetUserData(parser); + XML_Parser extparser; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + extparser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (extparser == NULL) + fail("Could not create external entity parser."); + if (test_data->encoding != NULL) { + if (! XML_SetEncoding(extparser, test_data->encoding)) + fail("XML_SetEncoding() ignored for external entity"); + } + if (_XML_Parse_SINGLE_BYTES(extparser, test_data->parse_text, + (int)strlen(test_data->parse_text), XML_TRUE) + == XML_STATUS_ERROR) { + xml_failure(extparser); + return XML_STATUS_ERROR; + } + XML_ParserFree(extparser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_faulter(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + XML_Parser ext_parser; + ExtFaults *fault = (ExtFaults *)XML_GetUserData(parser); + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + if (fault->encoding != NULL) { + if (! XML_SetEncoding(ext_parser, fault->encoding)) + fail("XML_SetEncoding failed"); + } + if (_XML_Parse_SINGLE_BYTES(ext_parser, fault->parse_text, + (int)strlen(fault->parse_text), XML_TRUE) + != XML_STATUS_ERROR) + fail(fault->fail_text); + if (XML_GetErrorCode(ext_parser) != fault->error) + xml_failure(ext_parser); + + XML_ParserFree(ext_parser); + return XML_STATUS_ERROR; +} + +int XMLCALL +external_entity_null_loader(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + UNUSED_P(parser); + UNUSED_P(context); + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_resetter(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text = "<!ELEMENT doc (#PCDATA)*>"; + XML_Parser ext_parser; + XML_ParsingStatus status; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + XML_GetParsingStatus(ext_parser, &status); + if (status.parsing != XML_INITIALIZED) { + fail("Parsing status is not INITIALIZED"); + return XML_STATUS_ERROR; + } + if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) { + xml_failure(parser); + return XML_STATUS_ERROR; + } + XML_GetParsingStatus(ext_parser, &status); + if (status.parsing != XML_FINISHED) { + fail("Parsing status is not FINISHED"); + return XML_STATUS_ERROR; + } + /* Check we can't parse here */ + if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Parsing when finished not faulted"); + if (XML_GetErrorCode(ext_parser) != XML_ERROR_FINISHED) + fail("Parsing when finished faulted with wrong code"); + XML_ParserReset(ext_parser, NULL); + XML_GetParsingStatus(ext_parser, &status); + if (status.parsing != XML_FINISHED) { + fail("Parsing status not still FINISHED"); + return XML_STATUS_ERROR; + } + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +void XMLCALL +entity_suspending_decl_handler(void *userData, const XML_Char *name, + XML_Content *model) { + XML_Parser ext_parser = (XML_Parser)userData; + + UNUSED_P(name); + if (XML_StopParser(ext_parser, XML_TRUE) != XML_STATUS_ERROR) + fail("Attempting to suspend a subordinate parser not faulted"); + if (XML_GetErrorCode(ext_parser) != XML_ERROR_SUSPEND_PE) + fail("Suspending subordinate parser get wrong code"); + XML_SetElementDeclHandler(ext_parser, NULL); + XML_FreeContentModel(g_parser, model); +} + +int XMLCALL +external_entity_suspender(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text = "<!ELEMENT doc (#PCDATA)*>"; + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + XML_SetElementDeclHandler(ext_parser, entity_suspending_decl_handler); + XML_SetUserData(ext_parser, ext_parser); + if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) { + xml_failure(ext_parser); + return XML_STATUS_ERROR; + } + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +void XMLCALL +entity_suspending_xdecl_handler(void *userData, const XML_Char *version, + const XML_Char *encoding, int standalone) { + XML_Parser ext_parser = (XML_Parser)userData; + + UNUSED_P(version); + UNUSED_P(encoding); + UNUSED_P(standalone); + XML_StopParser(ext_parser, g_resumable); + XML_SetXmlDeclHandler(ext_parser, NULL); +} + +int XMLCALL +external_entity_suspend_xmldecl(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text = "<?xml version='1.0' encoding='us-ascii'?>"; + XML_Parser ext_parser; + XML_ParsingStatus status; + enum XML_Status rc; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + XML_SetXmlDeclHandler(ext_parser, entity_suspending_xdecl_handler); + XML_SetUserData(ext_parser, ext_parser); + rc = _XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE); + XML_GetParsingStatus(ext_parser, &status); + if (g_resumable) { + if (rc == XML_STATUS_ERROR) + xml_failure(ext_parser); + if (status.parsing != XML_SUSPENDED) + fail("Ext Parsing status not SUSPENDED"); + } else { + if (rc != XML_STATUS_ERROR) + fail("Ext parsing not aborted"); + if (XML_GetErrorCode(ext_parser) != XML_ERROR_ABORTED) + xml_failure(ext_parser); + if (status.parsing != XML_FINISHED) + fail("Ext Parsing status not FINISHED"); + } + + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_suspending_faulter(XML_Parser parser, const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId) { + XML_Parser ext_parser; + ExtFaults *fault = (ExtFaults *)XML_GetUserData(parser); + void *buffer; + int parse_len = (int)strlen(fault->parse_text); + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + XML_SetXmlDeclHandler(ext_parser, entity_suspending_xdecl_handler); + XML_SetUserData(ext_parser, ext_parser); + g_resumable = XML_TRUE; + buffer = XML_GetBuffer(ext_parser, parse_len); + if (buffer == NULL) + fail("Could not allocate parse buffer"); + assert(buffer != NULL); + memcpy(buffer, fault->parse_text, parse_len); + if (XML_ParseBuffer(ext_parser, parse_len, XML_FALSE) != XML_STATUS_SUSPENDED) + fail("XML declaration did not suspend"); + if (XML_ResumeParser(ext_parser) != XML_STATUS_OK) + xml_failure(ext_parser); + if (XML_ParseBuffer(ext_parser, 0, XML_TRUE) != XML_STATUS_ERROR) + fail(fault->fail_text); + if (XML_GetErrorCode(ext_parser) != fault->error) + xml_failure(ext_parser); + + XML_ParserFree(ext_parser); + return XML_STATUS_ERROR; +} + +int XMLCALL +external_entity_failer__if_not_xml_ge(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId) { + UNUSED_P(parser); + UNUSED_P(context); + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); +#if XML_GE == 0 + fail( + "Function external_entity_suspending_failer was called despite XML_GE==0."); +#endif + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_cr_catcher(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text = "\r"; + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + XML_SetCharacterDataHandler(ext_parser, cr_cdata_handler); + if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(ext_parser); + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_bad_cr_catcher(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text = "<tag>\r"; + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + XML_SetCharacterDataHandler(ext_parser, cr_cdata_handler); + if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_OK) + fail("Async entity error not caught"); + if (XML_GetErrorCode(ext_parser) != XML_ERROR_ASYNC_ENTITY) + xml_failure(ext_parser); + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_rsqb_catcher(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text = "<tag>]"; + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + XML_SetCharacterDataHandler(ext_parser, rsqb_handler); + if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Async entity error not caught"); + if (XML_GetErrorCode(ext_parser) != XML_ERROR_ASYNC_ENTITY) + xml_failure(ext_parser); + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_good_cdata_ascii(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text = "<a><![CDATA[<greeting>Hello, world!</greeting>]]></a>"; + const XML_Char *expected = XCS("<greeting>Hello, world!</greeting>"); + CharData storage; + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + CharData_Init(&storage); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + XML_SetUserData(ext_parser, &storage); + XML_SetCharacterDataHandler(ext_parser, accumulate_characters); + + if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(ext_parser); + CharData_CheckXMLChars(&storage, expected); + + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_param_checker(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text = "<!-- Subordinate parser -->\n" + "<!ELEMENT doc (#PCDATA)*>"; + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + g_handler_data = ext_parser; + if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) { + xml_failure(parser); + return XML_STATUS_ERROR; + } + g_handler_data = parser; + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_ref_param_checker(XML_Parser parameter, const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId) { + const char *text = "<!ELEMENT doc (#PCDATA)*>"; + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + if ((void *)parameter != g_handler_data) + fail("External entity ref handler parameter not correct"); + + /* Here we use the global 'parser' variable */ + ext_parser = XML_ExternalEntityParserCreate(g_parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(ext_parser); + + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_param(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text1 = "<!ELEMENT doc EMPTY>\n" + "<!ENTITY % e1 SYSTEM '004-2.ent'>\n" + "<!ENTITY % e2 '%e1;'>\n" + "%e1;\n"; + const char *text2 = "<!ELEMENT el EMPTY>\n" + "<el/>\n"; + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(publicId); + if (systemId == NULL) + return XML_STATUS_OK; + + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + + if (! xcstrcmp(systemId, XCS("004-1.ent"))) { + if (_XML_Parse_SINGLE_BYTES(ext_parser, text1, (int)strlen(text1), XML_TRUE) + != XML_STATUS_ERROR) + fail("Inner DTD with invalid tag not rejected"); + if (XML_GetErrorCode(ext_parser) != XML_ERROR_EXTERNAL_ENTITY_HANDLING) + xml_failure(ext_parser); + } else if (! xcstrcmp(systemId, XCS("004-2.ent"))) { + if (_XML_Parse_SINGLE_BYTES(ext_parser, text2, (int)strlen(text2), XML_TRUE) + != XML_STATUS_ERROR) + fail("Invalid tag in external param not rejected"); + if (XML_GetErrorCode(ext_parser) != XML_ERROR_SYNTAX) + xml_failure(ext_parser); + } else { + fail("Unknown system ID"); + } + + XML_ParserFree(ext_parser); + return XML_STATUS_ERROR; +} + +int XMLCALL +external_entity_load_ignore(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text = "<![IGNORE[<!ELEMENT e (#PCDATA)*>]]>"; + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(parser); + + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_load_ignore_utf16(XML_Parser parser, const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId) { + const char text[] = + /* <![IGNORE[<!ELEMENT e (#PCDATA)*>]]> */ + "<\0!\0[\0I\0G\0N\0O\0R\0E\0[\0" + "<\0!\0E\0L\0E\0M\0E\0N\0T\0 \0e\0 \0" + "(\0#\0P\0C\0D\0A\0T\0A\0)\0*\0>\0]\0]\0>\0"; + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(parser); + + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_load_ignore_utf16_be(XML_Parser parser, const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId) { + const char text[] = + /* <![IGNORE[<!ELEMENT e (#PCDATA)*>]]> */ + "\0<\0!\0[\0I\0G\0N\0O\0R\0E\0[" + "\0<\0!\0E\0L\0E\0M\0E\0N\0T\0 \0e\0 " + "\0(\0#\0P\0C\0D\0A\0T\0A\0)\0*\0>\0]\0]\0>"; + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(parser); + + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_valuer(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text1 = "<!ELEMENT doc EMPTY>\n" + "<!ENTITY % e1 SYSTEM '004-2.ent'>\n" + "<!ENTITY % e2 '%e1;'>\n" + "%e1;\n"; + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(publicId); + if (systemId == NULL) + return XML_STATUS_OK; + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + if (! xcstrcmp(systemId, XCS("004-1.ent"))) { + if (_XML_Parse_SINGLE_BYTES(ext_parser, text1, (int)strlen(text1), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(ext_parser); + } else if (! xcstrcmp(systemId, XCS("004-2.ent"))) { + ExtFaults *fault = (ExtFaults *)XML_GetUserData(parser); + enum XML_Status status; + enum XML_Error error; + + status = _XML_Parse_SINGLE_BYTES(ext_parser, fault->parse_text, + (int)strlen(fault->parse_text), XML_TRUE); + if (fault->error == XML_ERROR_NONE) { + if (status == XML_STATUS_ERROR) + xml_failure(ext_parser); + } else { + if (status != XML_STATUS_ERROR) + fail(fault->fail_text); + error = XML_GetErrorCode(ext_parser); + if (error != fault->error + && (fault->error != XML_ERROR_XML_DECL + || error != XML_ERROR_TEXT_DECL)) + xml_failure(ext_parser); + } + } + + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_not_standalone(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text1 = "<!ELEMENT doc EMPTY>\n" + "<!ENTITY % e1 SYSTEM 'bar'>\n" + "%e1;\n"; + const char *text2 = "<!ATTLIST doc a1 CDATA 'value'>"; + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(publicId); + if (systemId == NULL) + return XML_STATUS_OK; + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + if (! xcstrcmp(systemId, XCS("foo"))) { + XML_SetNotStandaloneHandler(ext_parser, reject_not_standalone_handler); + if (_XML_Parse_SINGLE_BYTES(ext_parser, text1, (int)strlen(text1), XML_TRUE) + != XML_STATUS_ERROR) + fail("Expected not standalone rejection"); + if (XML_GetErrorCode(ext_parser) != XML_ERROR_NOT_STANDALONE) + xml_failure(ext_parser); + XML_SetNotStandaloneHandler(ext_parser, NULL); + XML_ParserFree(ext_parser); + return XML_STATUS_ERROR; + } else if (! xcstrcmp(systemId, XCS("bar"))) { + if (_XML_Parse_SINGLE_BYTES(ext_parser, text2, (int)strlen(text2), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(ext_parser); + } + + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_value_aborter(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text1 = "<!ELEMENT doc EMPTY>\n" + "<!ENTITY % e1 SYSTEM '004-2.ent'>\n" + "<!ENTITY % e2 '%e1;'>\n" + "%e1;\n"; + const char *text2 = "<?xml version='1.0' encoding='utf-8'?>"; + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(publicId); + if (systemId == NULL) + return XML_STATUS_OK; + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + if (! xcstrcmp(systemId, XCS("004-1.ent"))) { + if (_XML_Parse_SINGLE_BYTES(ext_parser, text1, (int)strlen(text1), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(ext_parser); + } + if (! xcstrcmp(systemId, XCS("004-2.ent"))) { + XML_SetXmlDeclHandler(ext_parser, entity_suspending_xdecl_handler); + XML_SetUserData(ext_parser, ext_parser); + if (_XML_Parse_SINGLE_BYTES(ext_parser, text2, (int)strlen(text2), XML_TRUE) + != XML_STATUS_ERROR) + fail("Aborted parse not faulted"); + if (XML_GetErrorCode(ext_parser) != XML_ERROR_ABORTED) + xml_failure(ext_parser); + } + + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_public(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text1 = (const char *)XML_GetUserData(parser); + const char *text2 = "<!ATTLIST doc a CDATA 'value'>"; + const char *text = NULL; + XML_Parser ext_parser; + int parse_res; + + UNUSED_P(base); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + return XML_STATUS_ERROR; + if (systemId != NULL && ! xcstrcmp(systemId, XCS("http://example.org/"))) { + text = text1; + } else if (publicId != NULL && ! xcstrcmp(publicId, XCS("foo"))) { + text = text2; + } else + fail("Unexpected parameters to external entity parser"); + assert(text != NULL); + parse_res + = _XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE); + XML_ParserFree(ext_parser); + return parse_res; +} + +int XMLCALL +external_entity_devaluer(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text = "<!ELEMENT doc EMPTY>\n" + "<!ENTITY % e1 SYSTEM 'bar'>\n" + "%e1;\n"; + XML_Parser ext_parser; + int clear_handler_flag = (XML_GetUserData(parser) != NULL); + + UNUSED_P(base); + UNUSED_P(publicId); + if (systemId == NULL || ! xcstrcmp(systemId, XCS("bar"))) + return XML_STATUS_OK; + if (xcstrcmp(systemId, XCS("foo"))) + fail("Unexpected system ID"); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could note create external entity parser"); + if (clear_handler_flag) + XML_SetExternalEntityRefHandler(ext_parser, NULL); + if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(ext_parser); + + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_oneshot_loader(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + ExtHdlrData *test_data = (ExtHdlrData *)XML_GetUserData(parser); + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser."); + /* Use the requested entity parser for further externals */ + XML_SetExternalEntityRefHandler(ext_parser, test_data->handler); + if (_XML_Parse_SINGLE_BYTES(ext_parser, test_data->parse_text, + (int)strlen(test_data->parse_text), XML_TRUE) + == XML_STATUS_ERROR) { + xml_failure(ext_parser); + } + + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_loader2(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + ExtTest2 *test_data = (ExtTest2 *)XML_GetUserData(parser); + XML_Parser extparser; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + extparser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (extparser == NULL) + fail("Coulr not create external entity parser"); + if (test_data->encoding != NULL) { + if (! XML_SetEncoding(extparser, test_data->encoding)) + fail("XML_SetEncoding() ignored for external entity"); + } + if (_XML_Parse_SINGLE_BYTES(extparser, test_data->parse_text, + test_data->parse_len, XML_TRUE) + == XML_STATUS_ERROR) { + xml_failure(extparser); + } + + XML_ParserFree(extparser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_faulter2(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + ExtFaults2 *test_data = (ExtFaults2 *)XML_GetUserData(parser); + XML_Parser extparser; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + extparser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (extparser == NULL) + fail("Could not create external entity parser"); + if (test_data->encoding != NULL) { + if (! XML_SetEncoding(extparser, test_data->encoding)) + fail("XML_SetEncoding() ignored for external entity"); + } + if (_XML_Parse_SINGLE_BYTES(extparser, test_data->parse_text, + test_data->parse_len, XML_TRUE) + != XML_STATUS_ERROR) + fail(test_data->fail_text); + if (XML_GetErrorCode(extparser) != test_data->error) + xml_failure(extparser); + + XML_ParserFree(extparser); + return XML_STATUS_ERROR; +} + +int XMLCALL +external_entity_unfinished_attlist(XML_Parser parser, const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId) { + const char *text = "<!ELEMENT barf ANY>\n" + "<!ATTLIST barf my_attr (blah|%blah;a|foo) #REQUIRED>\n" + "<!--COMMENT-->\n"; + XML_Parser ext_parser; + + UNUSED_P(base); + UNUSED_P(publicId); + if (systemId == NULL) + return XML_STATUS_OK; + + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + + if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(ext_parser); + + XML_ParserFree(ext_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_handler(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + void *user_data = XML_GetUserData(parser); + const char *text; + XML_Parser p2; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + if (user_data == NULL) + text = ("<!ELEMENT doc (e+)>\n" + "<!ATTLIST doc xmlns CDATA #IMPLIED>\n" + "<!ELEMENT e EMPTY>\n"); + else + text = ("<?xml version='1.0' encoding='us-ascii'?>" + "<e/>"); + + /* Set user data to any non-NULL value */ + XML_SetUserData(parser, parser); + p2 = XML_ExternalEntityParserCreate(parser, context, NULL); + if (_XML_Parse_SINGLE_BYTES(p2, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) { + xml_failure(p2); + return XML_STATUS_ERROR; + } + XML_ParserFree(p2); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_duff_loader(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + XML_Parser new_parser; + unsigned int i; + const unsigned int max_alloc_count = 10; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + /* Try a few different allocation levels */ + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + new_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (new_parser != NULL) { + XML_ParserFree(new_parser); + break; + } + } + if (i == 0) + fail("External parser creation ignored failing allocator"); + else if (i == max_alloc_count) + fail("Extern parser not created with max allocation count"); + + /* Make sure other random allocation doesn't now fail */ + g_allocation_count = ALLOC_ALWAYS_SUCCEED; + + /* Make sure the failure code path is executed too */ + return XML_STATUS_ERROR; +} + +int XMLCALL +external_entity_dbl_handler(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + int *pcallno = (int *)XML_GetUserData(parser); + int callno = *pcallno; + const char *text; + XML_Parser new_parser = NULL; + int i; + const int max_alloc_count = 20; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + if (callno == 0) { + /* First time through, check how many calls to malloc occur */ + text = ("<!ELEMENT doc (e+)>\n" + "<!ATTLIST doc xmlns CDATA #IMPLIED>\n" + "<!ELEMENT e EMPTY>\n"); + g_allocation_count = 10000; + new_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (new_parser == NULL) { + fail("Unable to allocate first external parser"); + return XML_STATUS_ERROR; + } + /* Stash the number of calls in the user data */ + *pcallno = 10000 - g_allocation_count; + } else { + text = ("<?xml version='1.0' encoding='us-ascii'?>" + "<e/>"); + /* Try at varying levels to exercise more code paths */ + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = callno + i; + new_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (new_parser != NULL) + break; + } + if (i == 0) { + fail("Second external parser unexpectedly created"); + XML_ParserFree(new_parser); + return XML_STATUS_ERROR; + } else if (i == max_alloc_count) { + fail("Second external parser not created"); + return XML_STATUS_ERROR; + } + } + + g_allocation_count = ALLOC_ALWAYS_SUCCEED; + if (_XML_Parse_SINGLE_BYTES(new_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) { + xml_failure(new_parser); + return XML_STATUS_ERROR; + } + XML_ParserFree(new_parser); + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_dbl_handler_2(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + int *pcallno = (int *)XML_GetUserData(parser); + int callno = *pcallno; + const char *text; + XML_Parser new_parser; + enum XML_Status rv; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + if (callno == 0) { + /* Try different allocation levels for whole exercise */ + text = ("<!ELEMENT doc (e+)>\n" + "<!ATTLIST doc xmlns CDATA #IMPLIED>\n" + "<!ELEMENT e EMPTY>\n"); + *pcallno = 1; + new_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (new_parser == NULL) + return XML_STATUS_ERROR; + rv = _XML_Parse_SINGLE_BYTES(new_parser, text, (int)strlen(text), XML_TRUE); + } else { + /* Just run through once */ + text = ("<?xml version='1.0' encoding='us-ascii'?>" + "<e/>"); + new_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (new_parser == NULL) + return XML_STATUS_ERROR; + rv = _XML_Parse_SINGLE_BYTES(new_parser, text, (int)strlen(text), XML_TRUE); + } + XML_ParserFree(new_parser); + if (rv == XML_STATUS_ERROR) + return XML_STATUS_ERROR; + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_alloc_set_encoding(XML_Parser parser, const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId) { + /* As for external_entity_loader() */ + const char *text = "<?xml encoding='iso-8859-3'?>" + "\xC3\xA9"; + XML_Parser ext_parser; + enum XML_Status status; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + return XML_STATUS_ERROR; + if (! XML_SetEncoding(ext_parser, XCS("utf-8"))) { + XML_ParserFree(ext_parser); + return XML_STATUS_ERROR; + } + status + = _XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE); + XML_ParserFree(ext_parser); + if (status == XML_STATUS_ERROR) + return XML_STATUS_ERROR; + return XML_STATUS_OK; +} + +int XMLCALL +external_entity_reallocator(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text = get_buffer_test_text; + XML_Parser ext_parser; + void *buffer; + enum XML_Status status; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + fail("Could not create external entity parser"); + + g_reallocation_count = *(int *)XML_GetUserData(parser); + buffer = XML_GetBuffer(ext_parser, 1536); + if (buffer == NULL) + fail("Buffer allocation failed"); + assert(buffer != NULL); + memcpy(buffer, text, strlen(text)); + status = XML_ParseBuffer(ext_parser, (int)strlen(text), XML_FALSE); + g_reallocation_count = -1; + XML_ParserFree(ext_parser); + return (status == XML_STATUS_OK) ? XML_STATUS_OK : XML_STATUS_ERROR; +} + +int XMLCALL +external_entity_alloc(XML_Parser parser, const XML_Char *context, + const XML_Char *base, const XML_Char *systemId, + const XML_Char *publicId) { + const char *text = (const char *)XML_GetUserData(parser); + XML_Parser ext_parser; + int parse_res; + + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); + if (ext_parser == NULL) + return XML_STATUS_ERROR; + parse_res + = _XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE); + XML_ParserFree(ext_parser); + return parse_res; +} + +int XMLCALL +external_entity_parser_create_alloc_fail_handler(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId) { + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + + if (context != NULL) + fail("Unexpected non-NULL context"); + + // The following number intends to fail the upcoming allocation in line + // "parser->m_protocolEncodingName = copyString(encodingName, + // &(parser->m_mem));" in function parserInit. + g_allocation_count = 3; + + const XML_Char *const encodingName = XCS("UTF-8"); // needs something non-NULL + const XML_Parser ext_parser + = XML_ExternalEntityParserCreate(parser, context, encodingName); + if (ext_parser != NULL) + fail( + "Call to XML_ExternalEntityParserCreate was expected to fail out-of-memory"); + + g_allocation_count = ALLOC_ALWAYS_SUCCEED; + return XML_STATUS_ERROR; +} + +#if XML_GE == 1 +int +accounting_external_entity_ref_handler(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId) { + UNUSED_P(base); + UNUSED_P(publicId); + + const struct AccountingTestCase *const testCase + = (const struct AccountingTestCase *)XML_GetUserData(parser); + + const char *externalText = NULL; + if (xcstrcmp(systemId, XCS("first.ent")) == 0) { + externalText = testCase->firstExternalText; + } else if (xcstrcmp(systemId, XCS("second.ent")) == 0) { + externalText = testCase->secondExternalText; + } else { + assert(! "systemId is neither \"first.ent\" nor \"second.ent\""); + } + assert(externalText); + + XML_Parser entParser = XML_ExternalEntityParserCreate(parser, context, 0); + assert(entParser); + + const enum XML_Status status = _XML_Parse_SINGLE_BYTES( + entParser, externalText, (int)strlen(externalText), XML_TRUE); + + XML_ParserFree(entParser); + return status; +} +#endif /* XML_GE == 1 */ + +/* NotStandalone handlers */ + +int XMLCALL +reject_not_standalone_handler(void *userData) { + UNUSED_P(userData); + return XML_STATUS_ERROR; +} + +int XMLCALL +accept_not_standalone_handler(void *userData) { + UNUSED_P(userData); + return XML_STATUS_OK; +} + +/* Attribute List handlers */ +void XMLCALL +verify_attlist_decl_handler(void *userData, const XML_Char *element_name, + const XML_Char *attr_name, + const XML_Char *attr_type, + const XML_Char *default_value, int is_required) { + AttTest *at = (AttTest *)userData; + + if (xcstrcmp(element_name, at->element_name)) + fail("Unexpected element name in attribute declaration"); + if (xcstrcmp(attr_name, at->attr_name)) + fail("Unexpected attribute name in attribute declaration"); + if (xcstrcmp(attr_type, at->attr_type)) + fail("Unexpected attribute type in attribute declaration"); + if ((default_value == NULL && at->default_value != NULL) + || (default_value != NULL && at->default_value == NULL) + || (default_value != NULL && xcstrcmp(default_value, at->default_value))) + fail("Unexpected default value in attribute declaration"); + if (is_required != at->is_required) + fail("Requirement mismatch in attribute declaration"); +} + +/* Character Data handlers */ + +void XMLCALL +clearing_aborting_character_handler(void *userData, const XML_Char *s, + int len) { + UNUSED_P(userData); + UNUSED_P(s); + UNUSED_P(len); + XML_StopParser(g_parser, g_resumable); + XML_SetCharacterDataHandler(g_parser, NULL); +} + +void XMLCALL +parser_stop_character_handler(void *userData, const XML_Char *s, int len) { + UNUSED_P(userData); + UNUSED_P(s); + UNUSED_P(len); + XML_ParsingStatus status; + XML_GetParsingStatus(g_parser, &status); + if (status.parsing == XML_FINISHED) { + return; // the parser was stopped by a previous call to this handler. + } + XML_StopParser(g_parser, g_resumable); + XML_SetCharacterDataHandler(g_parser, NULL); + if (! g_resumable) { + /* Check that aborting an aborted parser is faulted */ + if (XML_StopParser(g_parser, XML_FALSE) != XML_STATUS_ERROR) + fail("Aborting aborted parser not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_FINISHED) + xml_failure(g_parser); + } else if (g_abortable) { + /* Check that aborting a suspended parser works */ + if (XML_StopParser(g_parser, XML_FALSE) == XML_STATUS_ERROR) + xml_failure(g_parser); + } else { + /* Check that suspending a suspended parser works */ + if (XML_StopParser(g_parser, XML_TRUE) != XML_STATUS_ERROR) + fail("Suspending suspended parser not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_SUSPENDED) + xml_failure(g_parser); + } +} + +void XMLCALL +cr_cdata_handler(void *userData, const XML_Char *s, int len) { + int *pfound = (int *)userData; + + /* Internal processing turns the CR into a newline for the + * character data handler, but not for the default handler + */ + if (len == 1 && (*s == XCS('\n') || *s == XCS('\r'))) + *pfound = 1; +} + +void XMLCALL +rsqb_handler(void *userData, const XML_Char *s, int len) { + int *pfound = (int *)userData; + + if (len == 1 && *s == XCS(']')) + *pfound = 1; +} + +void XMLCALL +byte_character_handler(void *userData, const XML_Char *s, int len) { +#if XML_CONTEXT_BYTES > 0 + int offset, size; + const char *buffer; + ByteTestData *data = (ByteTestData *)userData; + + UNUSED_P(s); + buffer = XML_GetInputContext(g_parser, &offset, &size); + if (buffer == NULL) + fail("Failed to get context buffer"); + if (offset != data->start_element_len) + fail("Context offset in unexpected position"); + if (len != data->cdata_len) + fail("CDATA length reported incorrectly"); + if (size != data->total_string_len) + fail("Context size is not full buffer"); + if (XML_GetCurrentByteIndex(g_parser) != offset) + fail("Character byte index incorrect"); + if (XML_GetCurrentByteCount(g_parser) != len) + fail("Character byte count incorrect"); +#else + UNUSED_P(s); + UNUSED_P(userData); + UNUSED_P(len); +#endif +} + +void XMLCALL +ext2_accumulate_characters(void *userData, const XML_Char *s, int len) { + ExtTest2 *test_data = (ExtTest2 *)userData; + accumulate_characters(test_data->storage, s, len); +} + +/* Handlers that record their function name and int arg. */ + +static void +record_call(struct handler_record_list *const rec, const char *funcname, + const int arg) { + const int max_entries = sizeof(rec->entries) / sizeof(rec->entries[0]); + assert_true(rec->count < max_entries); + struct handler_record_entry *const e = &rec->entries[rec->count++]; + e->name = funcname; + e->arg = arg; +} + +void XMLCALL +record_default_handler(void *userData, const XML_Char *s, int len) { + UNUSED_P(s); + record_call((struct handler_record_list *)userData, __func__, len); +} + +void XMLCALL +record_cdata_handler(void *userData, const XML_Char *s, int len) { + UNUSED_P(s); + record_call((struct handler_record_list *)userData, __func__, len); + XML_DefaultCurrent(g_parser); +} + +void XMLCALL +record_cdata_nodefault_handler(void *userData, const XML_Char *s, int len) { + UNUSED_P(s); + record_call((struct handler_record_list *)userData, __func__, len); +} + +void XMLCALL +record_skip_handler(void *userData, const XML_Char *entityName, + int is_parameter_entity) { + UNUSED_P(entityName); + record_call((struct handler_record_list *)userData, __func__, + is_parameter_entity); +} + +void XMLCALL +record_element_start_handler(void *userData, const XML_Char *name, + const XML_Char **atts) { + UNUSED_P(atts); + CharData_AppendXMLChars((CharData *)userData, name, (int)xcstrlen(name)); +} + +void XMLCALL +record_element_end_handler(void *userData, const XML_Char *name) { + CharData *storage = (CharData *)userData; + + CharData_AppendXMLChars(storage, XCS("/"), 1); + CharData_AppendXMLChars(storage, name, -1); +} + +const struct handler_record_entry * +_handler_record_get(const struct handler_record_list *storage, int index, + const char *file, int line) { + if (storage->count <= index) { + _fail(file, line, "too few handler calls"); + } + return &storage->entries[index]; +} + +/* Entity Declaration Handlers */ +static const XML_Char *entity_name_to_match = NULL; +static const XML_Char *entity_value_to_match = NULL; +static int entity_match_flag = ENTITY_MATCH_NOT_FOUND; + +void XMLCALL +param_entity_match_handler(void *userData, const XML_Char *entityName, + int is_parameter_entity, const XML_Char *value, + int value_length, const XML_Char *base, + const XML_Char *systemId, const XML_Char *publicId, + const XML_Char *notationName) { + UNUSED_P(userData); + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + UNUSED_P(notationName); + if (! is_parameter_entity || entity_name_to_match == NULL + || entity_value_to_match == NULL) { + return; + } + if (! xcstrcmp(entityName, entity_name_to_match)) { + /* The cast here is safe because we control the horizontal and + * the vertical, and we therefore know our strings are never + * going to overflow an int. + */ + if (value_length != (int)xcstrlen(entity_value_to_match) + || xcstrncmp(value, entity_value_to_match, value_length)) { + entity_match_flag = ENTITY_MATCH_FAIL; + } else { + entity_match_flag = ENTITY_MATCH_SUCCESS; + } + } + /* Else leave the match flag alone */ +} + +void +param_entity_match_init(const XML_Char *name, const XML_Char *value) { + entity_name_to_match = name; + entity_value_to_match = value; + entity_match_flag = ENTITY_MATCH_NOT_FOUND; +} + +int +get_param_entity_match_flag(void) { + return entity_match_flag; +} + +/* Misc handlers */ + +void XMLCALL +xml_decl_handler(void *userData, const XML_Char *version, + const XML_Char *encoding, int standalone) { + UNUSED_P(version); + UNUSED_P(encoding); + if (userData != g_handler_data) + fail("User data (xml decl) not correctly set"); + if (standalone != -1) + fail("Standalone not flagged as not present in XML decl"); + g_xdecl_count++; +} + +void XMLCALL +param_check_skip_handler(void *userData, const XML_Char *entityName, + int is_parameter_entity) { + UNUSED_P(entityName); + UNUSED_P(is_parameter_entity); + if (userData != g_handler_data) + fail("User data (skip) not correctly set"); + g_skip_count++; +} + +void XMLCALL +data_check_comment_handler(void *userData, const XML_Char *data) { + UNUSED_P(data); + /* Check that the userData passed through is what we expect */ + if (userData != g_handler_data) + fail("User data (parser) not correctly set"); + /* Check that the user data in the parser is appropriate */ + if (XML_GetUserData(userData) != (void *)1) + fail("User data in parser not correctly set"); + g_comment_count++; +} + +void XMLCALL +selective_aborting_default_handler(void *userData, const XML_Char *s, int len) { + const XML_Char trigger_char = *(const XML_Char *)userData; + + int found = 0; + for (int i = 0; i < len; ++i) { + if (s[i] == trigger_char) { + found = 1; + break; + } + } + + if (found) { + XML_StopParser(g_parser, g_resumable); + XML_SetDefaultHandler(g_parser, NULL); + } +} + +void XMLCALL +suspending_comment_handler(void *userData, const XML_Char *data) { + UNUSED_P(data); + XML_Parser parser = (XML_Parser)userData; + XML_StopParser(parser, XML_TRUE); +} + +void XMLCALL +element_decl_suspender(void *userData, const XML_Char *name, + XML_Content *model) { + UNUSED_P(userData); + UNUSED_P(name); + XML_StopParser(g_parser, XML_TRUE); + XML_FreeContentModel(g_parser, model); +} + +void XMLCALL +accumulate_pi_characters(void *userData, const XML_Char *target, + const XML_Char *data) { + CharData *storage = (CharData *)userData; + + CharData_AppendXMLChars(storage, target, -1); + CharData_AppendXMLChars(storage, XCS(": "), 2); + CharData_AppendXMLChars(storage, data, -1); + CharData_AppendXMLChars(storage, XCS("\n"), 1); +} + +void XMLCALL +accumulate_comment(void *userData, const XML_Char *data) { + CharData *storage = (CharData *)userData; + + CharData_AppendXMLChars(storage, data, -1); +} + +void XMLCALL +accumulate_entity_decl(void *userData, const XML_Char *entityName, + int is_parameter_entity, const XML_Char *value, + int value_length, const XML_Char *base, + const XML_Char *systemId, const XML_Char *publicId, + const XML_Char *notationName) { + CharData *storage = (CharData *)userData; + + UNUSED_P(is_parameter_entity); + UNUSED_P(base); + UNUSED_P(systemId); + UNUSED_P(publicId); + UNUSED_P(notationName); + CharData_AppendXMLChars(storage, entityName, -1); + CharData_AppendXMLChars(storage, XCS("="), 1); + if (value == NULL) + CharData_AppendXMLChars(storage, XCS("(null)"), -1); + else + CharData_AppendXMLChars(storage, value, value_length); + CharData_AppendXMLChars(storage, XCS("\n"), 1); +} + +void XMLCALL +accumulate_start_element(void *userData, const XML_Char *name, + const XML_Char **atts) { + CharData *const storage = (CharData *)userData; + CharData_AppendXMLChars(storage, XCS("("), 1); + CharData_AppendXMLChars(storage, name, -1); + + if ((atts != NULL) && (atts[0] != NULL)) { + CharData_AppendXMLChars(storage, XCS("("), 1); + while (atts[0] != NULL) { + CharData_AppendXMLChars(storage, atts[0], -1); + CharData_AppendXMLChars(storage, XCS("="), 1); + CharData_AppendXMLChars(storage, atts[1], -1); + atts += 2; + if (atts[0] != NULL) { + CharData_AppendXMLChars(storage, XCS(","), 1); + } + } + CharData_AppendXMLChars(storage, XCS(")"), 1); + } + + CharData_AppendXMLChars(storage, XCS(")\n"), 2); +} + +void XMLCALL +accumulate_characters(void *userData, const XML_Char *s, int len) { + CharData *const storage = (CharData *)userData; + CharData_AppendXMLChars(storage, s, len); +} + +void XMLCALL +accumulate_attribute(void *userData, const XML_Char *name, + const XML_Char **atts) { + CharData *const storage = (CharData *)userData; + UNUSED_P(name); + /* Check there are attributes to deal with */ + if (atts == NULL) + return; + + while (storage->count < 0 && atts[0] != NULL) { + /* "accumulate" the value of the first attribute we see */ + CharData_AppendXMLChars(storage, atts[1], -1); + atts += 2; + } +} + +void XMLCALL +ext_accumulate_characters(void *userData, const XML_Char *s, int len) { + ExtTest *const test_data = (ExtTest *)userData; + accumulate_characters(test_data->storage, s, len); +} + +void XMLCALL +checking_default_handler(void *userData, const XML_Char *s, int len) { + DefaultCheck *data = (DefaultCheck *)userData; + int i; + + for (i = 0; data[i].expected != NULL; i++) { + if (data[i].expectedLen == len + && ! memcmp(data[i].expected, s, len * sizeof(XML_Char))) { + data[i].seen = XML_TRUE; + break; + } + } +} + +void XMLCALL +accumulate_and_suspend_comment_handler(void *userData, const XML_Char *data) { + ParserPlusStorage *const parserPlusStorage = (ParserPlusStorage *)userData; + accumulate_comment(parserPlusStorage->storage, data); + XML_StopParser(parserPlusStorage->parser, XML_TRUE); +} diff --git a/3rdparty/expat/tests/handlers.h b/3rdparty/expat/tests/handlers.h new file mode 100644 index 00000000000..8850bb948da --- /dev/null +++ b/3rdparty/expat/tests/handlers.h @@ -0,0 +1,606 @@ +/* XML handler functions for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef XML_HANDLERS_H +# define XML_HANDLERS_H + +# include "expat_config.h" + +# include "expat.h" + +/* Variable holding the expected handler userData */ +extern const void *g_handler_data; +/* Count of the number of times the comment handler has been invoked */ +extern int g_comment_count; +/* Count of the number of skipped entities */ +extern int g_skip_count; +/* Count of the number of times the XML declaration handler is invoked */ +extern int g_xdecl_count; + +/* Start/End Element Handlers */ + +extern void XMLCALL start_element_event_handler(void *userData, + const XML_Char *name, + const XML_Char **atts); + +extern void XMLCALL end_element_event_handler(void *userData, + const XML_Char *name); + +# define STRUCT_START_TAG 0 +# define STRUCT_END_TAG 1 + +extern void XMLCALL start_element_event_handler2(void *userData, + const XML_Char *name, + const XML_Char **attr); + +extern void XMLCALL end_element_event_handler2(void *userData, + const XML_Char *name); + +typedef struct attrInfo { + const XML_Char *name; + const XML_Char *value; +} AttrInfo; + +typedef struct elementInfo { + const XML_Char *name; + int attr_count; + const XML_Char *id_name; + AttrInfo *attributes; +} ElementInfo; + +typedef struct StructParserAndElementInfo { + XML_Parser parser; + ElementInfo *info; +} ParserAndElementInfo; + +extern void XMLCALL counting_start_element_handler(void *userData, + const XML_Char *name, + const XML_Char **atts); + +extern void XMLCALL suspending_end_handler(void *userData, const XML_Char *s); + +extern void XMLCALL start_element_suspender(void *userData, + const XML_Char *name, + const XML_Char **atts); + +extern int g_triplet_start_flag; +extern int g_triplet_end_flag; + +extern void XMLCALL triplet_start_checker(void *userData, const XML_Char *name, + const XML_Char **atts); + +extern void XMLCALL triplet_end_checker(void *userData, const XML_Char *name); + +extern void XMLCALL overwrite_start_checker(void *userData, + const XML_Char *name, + const XML_Char **atts); + +extern void XMLCALL overwrite_end_checker(void *userData, const XML_Char *name); + +extern void XMLCALL start_element_fail(void *userData, const XML_Char *name, + const XML_Char **atts); + +extern void XMLCALL start_ns_clearing_start_element(void *userData, + const XML_Char *prefix, + const XML_Char *uri); + +typedef struct { + XML_Parser parser; + int deep; +} DataIssue240; + +extern void XMLCALL start_element_issue_240(void *userData, + const XML_Char *name, + const XML_Char **atts); + +extern void XMLCALL end_element_issue_240(void *userData, const XML_Char *name); + +/* Text encoding handlers */ + +extern int XMLCALL UnknownEncodingHandler(void *data, const XML_Char *encoding, + XML_Encoding *info); + +extern int XMLCALL UnrecognisedEncodingHandler(void *data, + const XML_Char *encoding, + XML_Encoding *info); + +extern int XMLCALL unknown_released_encoding_handler(void *data, + const XML_Char *encoding, + XML_Encoding *info); + +extern int XMLCALL MiscEncodingHandler(void *data, const XML_Char *encoding, + XML_Encoding *info); + +extern int XMLCALL long_encoding_handler(void *userData, + const XML_Char *encoding, + XML_Encoding *info); + +/* External Entity Handlers */ + +typedef struct ExtOption { + const XML_Char *system_id; + const char *parse_text; +} ExtOption; + +extern int XMLCALL external_entity_optioner(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_loader(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +typedef struct ext_faults { + const char *parse_text; + const char *fail_text; + const XML_Char *encoding; + enum XML_Error error; +} ExtFaults; + +extern int XMLCALL external_entity_faulter(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); +extern int XMLCALL external_entity_failer__if_not_xml_ge( + XML_Parser parser, const XML_Char *context, const XML_Char *base, + const XML_Char *systemId, const XML_Char *publicId); +extern int XMLCALL external_entity_null_loader(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_resetter(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_suspender(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_suspend_xmldecl(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_suspending_faulter(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_cr_catcher(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_bad_cr_catcher(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_rsqb_catcher(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_good_cdata_ascii(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +/* Entity declaration handlers */ + +extern void XMLCALL entity_suspending_decl_handler(void *userData, + const XML_Char *name, + XML_Content *model); + +extern void XMLCALL entity_suspending_xdecl_handler(void *userData, + const XML_Char *version, + const XML_Char *encoding, + int standalone); + +extern int XMLCALL external_entity_param_checker(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_ref_param_checker(XML_Parser parameter, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_param(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_load_ignore(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_load_ignore_utf16(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_load_ignore_utf16_be( + XML_Parser parser, const XML_Char *context, const XML_Char *base, + const XML_Char *systemId, const XML_Char *publicId); + +extern int XMLCALL external_entity_valuer(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_not_standalone(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_value_aborter(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_public(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_devaluer(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +typedef struct ext_hdlr_data { + const char *parse_text; + XML_ExternalEntityRefHandler handler; +} ExtHdlrData; + +extern int XMLCALL external_entity_oneshot_loader(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +typedef struct ExtTest2 { + const char *parse_text; + int parse_len; + const XML_Char *encoding; + CharData *storage; +} ExtTest2; + +extern int XMLCALL external_entity_loader2(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +typedef struct ExtFaults2 { + const char *parse_text; + int parse_len; + const char *fail_text; + const XML_Char *encoding; + enum XML_Error error; +} ExtFaults2; + +extern int XMLCALL external_entity_faulter2(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_unfinished_attlist(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_handler(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_duff_loader(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_dbl_handler(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_dbl_handler_2(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_alloc_set_encoding(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_reallocator(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_alloc(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +extern int XMLCALL external_entity_parser_create_alloc_fail_handler( + XML_Parser parser, const XML_Char *context, const XML_Char *base, + const XML_Char *systemId, const XML_Char *publicId); + +struct AccountingTestCase { + const char *primaryText; + const char *firstExternalText; /* often NULL */ + const char *secondExternalText; /* often NULL */ + const unsigned long long expectedCountBytesIndirectExtra; +}; + +extern int accounting_external_entity_ref_handler(XML_Parser parser, + const XML_Char *context, + const XML_Char *base, + const XML_Char *systemId, + const XML_Char *publicId); + +/* NotStandalone handlers */ + +extern int XMLCALL reject_not_standalone_handler(void *userData); + +extern int XMLCALL accept_not_standalone_handler(void *userData); + +/* Attribute List handlers */ + +typedef struct AttTest { + const char *definition; + const XML_Char *element_name; + const XML_Char *attr_name; + const XML_Char *attr_type; + const XML_Char *default_value; + int is_required; +} AttTest; + +extern void XMLCALL verify_attlist_decl_handler( + void *userData, const XML_Char *element_name, const XML_Char *attr_name, + const XML_Char *attr_type, const XML_Char *default_value, int is_required); + +/* Character data handlers */ + +extern void XMLCALL clearing_aborting_character_handler(void *userData, + const XML_Char *s, + int len); + +extern void XMLCALL parser_stop_character_handler(void *userData, + const XML_Char *s, int len); + +extern void XMLCALL cr_cdata_handler(void *userData, const XML_Char *s, + int len); + +extern void XMLCALL rsqb_handler(void *userData, const XML_Char *s, int len); + +typedef struct ByteTestData { + int start_element_len; + int cdata_len; + int total_string_len; +} ByteTestData; + +extern void XMLCALL byte_character_handler(void *userData, const XML_Char *s, + int len); + +extern void XMLCALL ext2_accumulate_characters(void *userData, + const XML_Char *s, int len); + +/* Handlers that record their `len` arg and a single identifying character */ + +struct handler_record_entry { + const char *name; + int arg; +}; +struct handler_record_list { + int count; + struct handler_record_entry entries[50]; // arbitrary big-enough max count +}; + +extern void XMLCALL record_default_handler(void *userData, const XML_Char *s, + int len); + +extern void XMLCALL record_cdata_handler(void *userData, const XML_Char *s, + int len); + +extern void XMLCALL record_cdata_nodefault_handler(void *userData, + const XML_Char *s, int len); + +extern void XMLCALL record_skip_handler(void *userData, + const XML_Char *entityName, + int is_parameter_entity); + +extern void XMLCALL record_element_start_handler(void *userData, + const XML_Char *name, + const XML_Char **atts); + +extern void XMLCALL record_element_end_handler(void *userData, + const XML_Char *name); + +extern const struct handler_record_entry * +_handler_record_get(const struct handler_record_list *storage, int index, + const char *file, int line); + +# define handler_record_get(storage, index) \ + _handler_record_get((storage), (index), __FILE__, __LINE__) + +# define assert_record_handler_called(storage, index, expected_name, \ + expected_arg) \ + do { \ + const struct handler_record_entry *e \ + = handler_record_get(storage, index); \ + assert_true(strcmp(e->name, expected_name) == 0); \ + assert_true(e->arg == (expected_arg)); \ + } while (0) + +/* Entity Declaration Handlers */ +# define ENTITY_MATCH_FAIL (-1) +# define ENTITY_MATCH_NOT_FOUND (0) +# define ENTITY_MATCH_SUCCESS (1) + +extern void XMLCALL param_entity_match_handler( + void *userData, const XML_Char *entityName, int is_parameter_entity, + const XML_Char *value, int value_length, const XML_Char *base, + const XML_Char *systemId, const XML_Char *publicId, + const XML_Char *notationName); + +extern void param_entity_match_init(const XML_Char *name, + const XML_Char *value); + +extern int get_param_entity_match_flag(void); + +/* Misc handlers */ + +extern void XMLCALL xml_decl_handler(void *userData, const XML_Char *version, + const XML_Char *encoding, int standalone); + +extern void XMLCALL param_check_skip_handler(void *userData, + const XML_Char *entityName, + int is_parameter_entity); + +extern void XMLCALL data_check_comment_handler(void *userData, + const XML_Char *data); + +extern void XMLCALL selective_aborting_default_handler(void *userData, + const XML_Char *s, + int len); + +extern void XMLCALL suspending_comment_handler(void *userData, + const XML_Char *data); + +extern void XMLCALL element_decl_suspender(void *userData, const XML_Char *name, + XML_Content *model); + +extern void XMLCALL accumulate_pi_characters(void *userData, + const XML_Char *target, + const XML_Char *data); + +extern void XMLCALL accumulate_comment(void *userData, const XML_Char *data); + +extern void XMLCALL accumulate_entity_decl( + void *userData, const XML_Char *entityName, int is_parameter_entity, + const XML_Char *value, int value_length, const XML_Char *base, + const XML_Char *systemId, const XML_Char *publicId, + const XML_Char *notationName); + +extern void XMLCALL accumulate_start_element(void *userData, + const XML_Char *name, + const XML_Char **atts); + +extern void XMLCALL accumulate_characters(void *userData, const XML_Char *s, + int len); + +extern void XMLCALL accumulate_attribute(void *userData, const XML_Char *name, + const XML_Char **atts); + +extern void XMLCALL ext_accumulate_characters(void *userData, const XML_Char *s, + int len); + +typedef struct default_check { + const XML_Char *expected; + const int expectedLen; + XML_Bool seen; +} DefaultCheck; + +void XMLCALL checking_default_handler(void *userData, const XML_Char *s, + int len); + +typedef struct { + XML_Parser parser; + CharData *storage; +} ParserPlusStorage; + +extern void XMLCALL +accumulate_and_suspend_comment_handler(void *userData, const XML_Char *data); + +#endif /* XML_HANDLERS_H */ + +#ifdef __cplusplus +} +#endif diff --git a/3rdparty/expat/tests/handlers_cxx.cpp b/3rdparty/expat/tests/handlers_cxx.cpp new file mode 100644 index 00000000000..86c62b159cc --- /dev/null +++ b/3rdparty/expat/tests/handlers_cxx.cpp @@ -0,0 +1,32 @@ +/* C++ compilation harness for the test suite. + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "handlers.c" diff --git a/3rdparty/expat/tests/memcheck.c b/3rdparty/expat/tests/memcheck.c index 41355f6c8d9..de925499721 100644 --- a/3rdparty/expat/tests/memcheck.c +++ b/3rdparty/expat/tests/memcheck.c @@ -6,8 +6,9 @@ \___/_/\_\ .__/ \__,_|\__| |_| XML parser - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2022 Sean McBride <sean@rogue-research.com> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -49,12 +50,13 @@ typedef struct allocation_entry { static AllocationEntry *alloc_head = NULL; static AllocationEntry *alloc_tail = NULL; -static AllocationEntry *find_allocation(void *ptr); +static AllocationEntry *find_allocation(const void *ptr); /* Allocate some memory and keep track of it. */ void * tracking_malloc(size_t size) { - AllocationEntry *entry = malloc(sizeof(AllocationEntry)); + AllocationEntry *const entry + = (AllocationEntry *)malloc(sizeof(AllocationEntry)); if (entry == NULL) { printf("Allocator failure\n"); @@ -82,7 +84,7 @@ tracking_malloc(size_t size) { } static AllocationEntry * -find_allocation(void *ptr) { +find_allocation(const void *ptr) { AllocationEntry *entry; for (entry = alloc_head; entry != NULL; entry = entry->next) { @@ -140,7 +142,7 @@ tracking_realloc(void *ptr, size_t size) { entry = find_allocation(ptr); if (entry == NULL) { printf("Attempting to realloc unallocated memory at %p\n", ptr); - entry = malloc(sizeof(AllocationEntry)); + entry = (AllocationEntry *)malloc(sizeof(AllocationEntry)); if (entry == NULL) { printf("Reallocator failure\n"); return NULL; @@ -162,12 +164,11 @@ tracking_realloc(void *ptr, size_t size) { alloc_tail = entry; } } else { - entry->allocation = realloc(ptr, size); - if (entry->allocation == NULL) { - /* Realloc semantics say the original is still allocated */ - entry->allocation = ptr; + void *const reallocated = realloc(ptr, size); + if (reallocated == NULL) { return NULL; } + entry->allocation = reallocated; } entry->num_bytes = size; diff --git a/3rdparty/expat/tests/memcheck.h b/3rdparty/expat/tests/memcheck.h index 4d20f4bb972..4c0cb7281b9 100644 --- a/3rdparty/expat/tests/memcheck.h +++ b/3rdparty/expat/tests/memcheck.h @@ -7,8 +7,8 @@ \___/_/\_\ .__/ \__,_|\__| |_| XML parser - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/tests/memcheck_cxx.cpp b/3rdparty/expat/tests/memcheck_cxx.cpp new file mode 100644 index 00000000000..e62ac98999c --- /dev/null +++ b/3rdparty/expat/tests/memcheck_cxx.cpp @@ -0,0 +1,32 @@ +/* C++ compilation harness for the test suite. + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "memcheck.c" diff --git a/3rdparty/expat/tests/minicheck.c b/3rdparty/expat/tests/minicheck.c index a5a1efb159f..baccd76b441 100644 --- a/3rdparty/expat/tests/minicheck.c +++ b/3rdparty/expat/tests/minicheck.c @@ -10,8 +10,12 @@ \___/_/\_\ .__/ \__,_|\__| |_| XML parser - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2004-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild@sony.com> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -34,6 +38,11 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#if defined(NDEBUG) +# undef NDEBUG /* because test suite relies on assert(...) at the moment */ +#endif + +#include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <setjmp.h> @@ -85,7 +94,8 @@ tcase_add_test(TCase *tc, tcase_test_function test) { if (tc->allocated == tc->ntests) { int nalloc = tc->allocated + 100; size_t new_size = sizeof(tcase_test_function) * nalloc; - tcase_test_function *new_tests = realloc(tc->tests, new_size); + tcase_test_function *const new_tests + = (tcase_test_function *)realloc(tc->tests, new_size); assert(new_tests != NULL); tc->tests = new_tests; tc->allocated = nalloc; @@ -120,7 +130,7 @@ suite_free(Suite *suite) { SRunner * srunner_create(Suite *suite) { - SRunner *runner = calloc(1, sizeof(SRunner)); + SRunner *const runner = (SRunner *)calloc(1, sizeof(SRunner)); if (runner != NULL) { runner->suite = suite; } @@ -129,28 +139,57 @@ srunner_create(Suite *suite) { static jmp_buf env; +#define SUBTEST_LEN (50) // informative, but not too long static char const *_check_current_function = NULL; +static char _check_current_subtest[SUBTEST_LEN]; static int _check_current_lineno = -1; static char const *_check_current_filename = NULL; void _check_set_test_info(char const *function, char const *filename, int lineno) { _check_current_function = function; + set_subtest("%s", ""); _check_current_lineno = lineno; _check_current_filename = filename; } +void +set_subtest(char const *fmt, ...) { + va_list ap; + va_start(ap, fmt); + vsnprintf(_check_current_subtest, SUBTEST_LEN, fmt, ap); + va_end(ap); + // replace line feeds with spaces, for nicer error logs + for (size_t i = 0; i < SUBTEST_LEN; ++i) { + if (_check_current_subtest[i] == '\n') { + _check_current_subtest[i] = ' '; + } + } + _check_current_subtest[SUBTEST_LEN - 1] = '\0'; // ensure termination +} + static void -add_failure(SRunner *runner, int verbosity) { - runner->nfailures++; +handle_success(int verbosity) { if (verbosity >= CK_VERBOSE) { - printf("%s:%d: %s\n", _check_current_filename, _check_current_lineno, - _check_current_function); + printf("PASS: %s\n", _check_current_function); + } +} + +static void +handle_failure(SRunner *runner, int verbosity, const char *context, + const char *phase_info) { + runner->nfailures++; + if (verbosity != CK_SILENT) { + if (strlen(_check_current_subtest) != 0) { + phase_info = _check_current_subtest; + } + printf("FAIL [%s]: %s (%s at %s:%d)\n", context, _check_current_function, + phase_info, _check_current_filename, _check_current_lineno); } } void -srunner_run_all(SRunner *runner, int verbosity) { +srunner_run_all(SRunner *runner, const char *context, int verbosity) { Suite *suite; TCase *volatile tc; assert(runner != NULL); @@ -160,34 +199,42 @@ srunner_run_all(SRunner *runner, int verbosity) { volatile int i; for (i = 0; i < tc->ntests; ++i) { runner->nchecks++; + set_subtest("%s", ""); if (tc->setup != NULL) { /* setup */ if (setjmp(env)) { - add_failure(runner, verbosity); + handle_failure(runner, verbosity, context, "during setup"); continue; } tc->setup(); } /* test */ if (setjmp(env)) { - add_failure(runner, verbosity); + handle_failure(runner, verbosity, context, "during actual test"); continue; } (tc->tests[i])(); + set_subtest("%s", ""); /* teardown */ if (tc->teardown != NULL) { if (setjmp(env)) { - add_failure(runner, verbosity); + handle_failure(runner, verbosity, context, "during teardown"); continue; } tc->teardown(); } + + handle_success(verbosity); } tc = tc->next_tcase; } - if (verbosity) { +} + +void +srunner_summarize(SRunner *runner, int verbosity) { + if (verbosity != CK_SILENT) { int passed = runner->nchecks - runner->nfailures; double percentage = ((double)passed) / runner->nchecks; int display = (int)(percentage * 100); @@ -197,14 +244,13 @@ srunner_run_all(SRunner *runner, int verbosity) { } void -_fail_unless(int condition, const char *file, int line, const char *msg) { +_fail(const char *file, int line, const char *msg) { /* Always print the error message so it isn't lost. In this case, we have a failure, so there's no reason to be quiet about what it is. */ - UNUSED_P(condition); - UNUSED_P(file); - UNUSED_P(line); + _check_current_filename = file; + _check_current_lineno = line; if (msg != NULL) { const int has_newline = (msg[strlen(msg) - 1] == '\n'); fprintf(stderr, "ERROR: %s%s", msg, has_newline ? "" : "\n"); diff --git a/3rdparty/expat/tests/minicheck.h b/3rdparty/expat/tests/minicheck.h index 88a16584fb5..3d888f8d2a3 100644 --- a/3rdparty/expat/tests/minicheck.h +++ b/3rdparty/expat/tests/minicheck.h @@ -12,8 +12,11 @@ \___/_/\_\ .__/ \__,_|\__| |_| XML parser - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2004-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2006-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild@sony.com> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -40,30 +43,54 @@ extern "C" { #endif -#define CK_NOFORK 0 -#define CK_FORK 1 +#ifndef XML_MINICHECK_H +# define XML_MINICHECK_H -#define CK_SILENT 0 -#define CK_NORMAL 1 -#define CK_VERBOSE 2 +# define CK_NOFORK 0 +# define CK_FORK 1 + +# define CK_SILENT 0 +# define CK_NORMAL 1 +# define CK_VERBOSE 2 /* Workaround for Microsoft's compiler and Tru64 Unix systems where the C compiler has a working __func__, but the C++ compiler only has a working __FUNCTION__. This could be fixed in configure.in, but it's not worth it right now. */ -#if defined(_MSC_VER) || (defined(__osf__) && defined(__cplusplus)) -# define __func__ __FUNCTION__ -#endif - -#define START_TEST(testname) \ - static void testname(void) { \ - _check_set_test_info(__func__, __FILE__, __LINE__); \ - { -#define END_TEST \ - } \ - } - -#define fail(msg) _fail_unless(0, __FILE__, __LINE__, msg) +# if defined(_MSC_VER) || (defined(__osf__) && defined(__cplusplus)) +# define __func__ __FUNCTION__ +# endif + +/* PRINTF_LIKE has two effects: + 1. Make clang's -Wformat-nonliteral stop warning about non-literal format + strings in annotated functions' code. + 2. Make both clang and gcc's -Wformat-nonliteral warn about *callers* of + the annotated function that use a non-literal format string. +*/ +# if defined(__GNUC__) +# define PRINTF_LIKE(fmtpos, argspos) \ + __attribute__((format(printf, fmtpos, argspos))) +# else +# define PRINTF_LIKE(fmtpos, argspos) +# endif + +# define START_TEST(testname) \ + static void testname(void) { \ + _check_set_test_info(__func__, __FILE__, __LINE__); \ + { +# define END_TEST \ + } \ + } + +void PRINTF_LIKE(1, 2) set_subtest(char const *fmt, ...); + +# define fail(msg) _fail(__FILE__, __LINE__, msg) +# define assert_true(cond) \ + do { \ + if (! (cond)) { \ + _fail(__FILE__, __LINE__, "check failed: " #cond); \ + } \ + } while (0) typedef void (*tcase_setup_function)(void); typedef void (*tcase_teardown_function)(void); @@ -102,18 +129,25 @@ void _check_set_test_info(char const *function, char const *filename, * Prototypes for the actual implementation. */ -void _fail_unless(int condition, const char *file, int line, const char *msg); +# if defined(__GNUC__) +__attribute__((noreturn)) +# endif +void +_fail(const char *file, int line, const char *msg); Suite *suite_create(const char *name); TCase *tcase_create(const char *name); void suite_add_tcase(Suite *suite, TCase *tc); -void tcase_add_checked_fixture(TCase *, tcase_setup_function, - tcase_teardown_function); +void tcase_add_checked_fixture(TCase *tc, tcase_setup_function setup, + tcase_teardown_function teardown); void tcase_add_test(TCase *tc, tcase_test_function test); SRunner *srunner_create(Suite *suite); -void srunner_run_all(SRunner *runner, int verbosity); +void srunner_run_all(SRunner *runner, const char *context, int verbosity); +void srunner_summarize(SRunner *runner, int verbosity); int srunner_ntests_failed(SRunner *runner); void srunner_free(SRunner *runner); +#endif /* XML_MINICHECK_H */ + #ifdef __cplusplus } #endif diff --git a/3rdparty/expat/tests/minicheck_cxx.cpp b/3rdparty/expat/tests/minicheck_cxx.cpp new file mode 100644 index 00000000000..58881c60ba0 --- /dev/null +++ b/3rdparty/expat/tests/minicheck_cxx.cpp @@ -0,0 +1,32 @@ +/* C++ compilation harness for the test suite. + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "minicheck.c" diff --git a/3rdparty/expat/tests/misc_tests.c b/3rdparty/expat/tests/misc_tests.c new file mode 100644 index 00000000000..9afe0922d6b --- /dev/null +++ b/3rdparty/expat/tests/misc_tests.c @@ -0,0 +1,548 @@ +/* Tests in the "miscellaneous" test case for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#if defined(NDEBUG) +# undef NDEBUG /* because test suite relies on assert(...) at the moment */ +#endif + +#include <assert.h> +#include <string.h> + +#include "expat_config.h" + +#include "expat.h" +#include "internal.h" +#include "minicheck.h" +#include "memcheck.h" +#include "common.h" +#include "ascii.h" /* for ASCII_xxx */ +#include "handlers.h" +#include "misc_tests.h" + +/* Test that a failure to allocate the parser structure fails gracefully */ +START_TEST(test_misc_alloc_create_parser) { + XML_Memory_Handling_Suite memsuite = {duff_allocator, realloc, free}; + unsigned int i; + const unsigned int max_alloc_count = 10; + + /* Something this simple shouldn't need more than 10 allocations */ + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + g_parser = XML_ParserCreate_MM(NULL, &memsuite, NULL); + if (g_parser != NULL) + break; + } + if (i == 0) + fail("Parser unexpectedly ignored failing allocator"); + else if (i == max_alloc_count) + fail("Parser not created with max allocation count"); +} +END_TEST + +/* Test memory allocation failures for a parser with an encoding */ +START_TEST(test_misc_alloc_create_parser_with_encoding) { + XML_Memory_Handling_Suite memsuite = {duff_allocator, realloc, free}; + unsigned int i; + const unsigned int max_alloc_count = 10; + + /* Try several levels of allocation */ + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + g_parser = XML_ParserCreate_MM(XCS("us-ascii"), &memsuite, NULL); + if (g_parser != NULL) + break; + } + if (i == 0) + fail("Parser ignored failing allocator"); + else if (i == max_alloc_count) + fail("Parser not created with max allocation count"); +} +END_TEST + +/* Test that freeing a NULL parser doesn't cause an explosion. + * (Not actually tested anywhere else) + */ +START_TEST(test_misc_null_parser) { + XML_ParserFree(NULL); +} +END_TEST + +#if defined(__has_feature) +# if __has_feature(undefined_behavior_sanitizer) +# define EXPAT_TESTS_UBSAN 1 +# else +# define EXPAT_TESTS_UBSAN 0 +# endif +#else +# define EXPAT_TESTS_UBSAN 0 +#endif + +/* Test that XML_ErrorString rejects out-of-range codes */ +START_TEST(test_misc_error_string) { +#if ! EXPAT_TESTS_UBSAN // because this would trigger UBSan + union { + enum XML_Error xml_error; + int integer; + } trickery; + + assert_true(sizeof(enum XML_Error) == sizeof(int)); // self-test + + trickery.integer = -1; + if (XML_ErrorString(trickery.xml_error) != NULL) + fail("Negative error code not rejected"); + + trickery.integer = 100; + if (XML_ErrorString(trickery.xml_error) != NULL) + fail("Large error code not rejected"); +#endif +} +END_TEST + +/* Test the version information is consistent */ + +/* Since we are working in XML_LChars (potentially 16-bits), we + * can't use the standard C library functions for character + * manipulation and have to roll our own. + */ +static int +parse_version(const XML_LChar *version_text, + XML_Expat_Version *version_struct) { + if (! version_text) + return XML_FALSE; + + while (*version_text != 0x00) { + if (*version_text >= ASCII_0 && *version_text <= ASCII_9) + break; + version_text++; + } + if (*version_text == 0x00) + return XML_FALSE; + + /* version_struct->major = strtoul(version_text, 10, &version_text) */ + version_struct->major = 0; + while (*version_text >= ASCII_0 && *version_text <= ASCII_9) { + version_struct->major + = 10 * version_struct->major + (*version_text++ - ASCII_0); + } + if (*version_text++ != ASCII_PERIOD) + return XML_FALSE; + + /* Now for the minor version number */ + version_struct->minor = 0; + while (*version_text >= ASCII_0 && *version_text <= ASCII_9) { + version_struct->minor + = 10 * version_struct->minor + (*version_text++ - ASCII_0); + } + if (*version_text++ != ASCII_PERIOD) + return XML_FALSE; + + /* Finally the micro version number */ + version_struct->micro = 0; + while (*version_text >= ASCII_0 && *version_text <= ASCII_9) { + version_struct->micro + = 10 * version_struct->micro + (*version_text++ - ASCII_0); + } + if (*version_text != 0x00) + return XML_FALSE; + return XML_TRUE; +} + +static int +versions_equal(const XML_Expat_Version *first, + const XML_Expat_Version *second) { + return (first->major == second->major && first->minor == second->minor + && first->micro == second->micro); +} + +START_TEST(test_misc_version) { + XML_Expat_Version read_version = XML_ExpatVersionInfo(); + /* Silence compiler warning with the following assignment */ + XML_Expat_Version parsed_version = {0, 0, 0}; + const XML_LChar *version_text = XML_ExpatVersion(); + + if (version_text == NULL) + fail("Could not obtain version text"); + assert(version_text != NULL); + if (! parse_version(version_text, &parsed_version)) + fail("Unable to parse version text"); + if (! versions_equal(&read_version, &parsed_version)) + fail("Version mismatch"); + + if (xcstrcmp(version_text, XCS("expat_2.6.4"))) /* needs bump on releases */ + fail("XML_*_VERSION in expat.h out of sync?\n"); +} +END_TEST + +/* Test feature information */ +START_TEST(test_misc_features) { + const XML_Feature *features = XML_GetFeatureList(); + + /* Prevent problems with double-freeing parsers */ + g_parser = NULL; + if (features == NULL) { + fail("Failed to get feature information"); + } else { + /* Loop through the features checking what we can */ + while (features->feature != XML_FEATURE_END) { + switch (features->feature) { + case XML_FEATURE_SIZEOF_XML_CHAR: + if (features->value != sizeof(XML_Char)) + fail("Incorrect size of XML_Char"); + break; + case XML_FEATURE_SIZEOF_XML_LCHAR: + if (features->value != sizeof(XML_LChar)) + fail("Incorrect size of XML_LChar"); + break; + default: + break; + } + features++; + } + } +} +END_TEST + +/* Regression test for GitHub Issue #17: memory leak parsing attribute + * values with mixed bound and unbound namespaces. + */ +START_TEST(test_misc_attribute_leak) { + const char *text = "<D xmlns:L=\"D\" l:a='' L:a=''/>"; + XML_Memory_Handling_Suite memsuite + = {tracking_malloc, tracking_realloc, tracking_free}; + + g_parser = XML_ParserCreate_MM(XCS("UTF-8"), &memsuite, XCS("\n")); + expect_failure(text, XML_ERROR_UNBOUND_PREFIX, "Unbound prefixes not found"); + XML_ParserFree(g_parser); + /* Prevent the teardown trying to double free */ + g_parser = NULL; + + if (! tracking_report()) + fail("Memory leak found"); +} +END_TEST + +/* Test parser created for UTF-16LE is successful */ +START_TEST(test_misc_utf16le) { + const char text[] = + /* <?xml version='1.0'?><q>Hi</q> */ + "<\0?\0x\0m\0l\0 \0" + "v\0e\0r\0s\0i\0o\0n\0=\0'\0\x31\0.\0\x30\0'\0?\0>\0" + "<\0q\0>\0H\0i\0<\0/\0q\0>\0"; + const XML_Char *expected = XCS("Hi"); + CharData storage; + + g_parser = XML_ParserCreate(XCS("UTF-16LE")); + if (g_parser == NULL) + fail("Parser not created"); + + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetCharacterDataHandler(g_parser, accumulate_characters); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_misc_stop_during_end_handler_issue_240_1) { + XML_Parser parser; + DataIssue240 *mydata; + enum XML_Status result; + const char *const doc1 = "<doc><e1/><e><foo/></e></doc>"; + + parser = XML_ParserCreate(NULL); + XML_SetElementHandler(parser, start_element_issue_240, end_element_issue_240); + mydata = (DataIssue240 *)malloc(sizeof(DataIssue240)); + mydata->parser = parser; + mydata->deep = 0; + XML_SetUserData(parser, mydata); + + result = _XML_Parse_SINGLE_BYTES(parser, doc1, (int)strlen(doc1), 1); + XML_ParserFree(parser); + free(mydata); + if (result != XML_STATUS_ERROR) + fail("Stopping the parser did not work as expected"); +} +END_TEST + +START_TEST(test_misc_stop_during_end_handler_issue_240_2) { + XML_Parser parser; + DataIssue240 *mydata; + enum XML_Status result; + const char *const doc2 = "<doc><elem/></doc>"; + + parser = XML_ParserCreate(NULL); + XML_SetElementHandler(parser, start_element_issue_240, end_element_issue_240); + mydata = (DataIssue240 *)malloc(sizeof(DataIssue240)); + mydata->parser = parser; + mydata->deep = 0; + XML_SetUserData(parser, mydata); + + result = _XML_Parse_SINGLE_BYTES(parser, doc2, (int)strlen(doc2), 1); + XML_ParserFree(parser); + free(mydata); + if (result != XML_STATUS_ERROR) + fail("Stopping the parser did not work as expected"); +} +END_TEST + +START_TEST(test_misc_deny_internal_entity_closing_doctype_issue_317) { + const char *const inputOne = "<!DOCTYPE d [\n" + "<!ENTITY % e ']><d/>'>\n" + "\n" + "%e;"; + const char *const inputTwo + = "<!DOCTYPE d [\n" + "<!ENTITY % e1 ']><d/>'><!ENTITY % e2 '%e1;'>\n" + "\n" + "%e2;"; + const char *const inputThree = "<!DOCTYPE d [\n" + "<!ENTITY % e ']><d'>\n" + "\n" + "%e;/>"; + const char *const inputIssue317 = "<!DOCTYPE doc [\n" + "<!ENTITY % foo ']>\n" + "<doc>Hell<oc (#PCDATA)*>'>\n" + "%foo;\n" + "]>\n" + "<doc>Hello, world</dVc>"; + + const char *const inputs[] = {inputOne, inputTwo, inputThree, inputIssue317}; + size_t inputIndex = 0; + + for (; inputIndex < sizeof(inputs) / sizeof(inputs[0]); inputIndex++) { + set_subtest("%s", inputs[inputIndex]); + XML_Parser parser; + enum XML_Status parseResult; + int setParamEntityResult; + XML_Size lineNumber; + XML_Size columnNumber; + const char *const input = inputs[inputIndex]; + + parser = XML_ParserCreate(NULL); + setParamEntityResult + = XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + if (setParamEntityResult != 1) + fail("Failed to set XML_PARAM_ENTITY_PARSING_ALWAYS."); + + parseResult = _XML_Parse_SINGLE_BYTES(parser, input, (int)strlen(input), 0); + if (parseResult != XML_STATUS_ERROR) { + parseResult = _XML_Parse_SINGLE_BYTES(parser, "", 0, 1); + if (parseResult != XML_STATUS_ERROR) { + fail("Parsing was expected to fail but succeeded."); + } + } + + if (XML_GetErrorCode(parser) != XML_ERROR_INVALID_TOKEN) + fail("Error code does not match XML_ERROR_INVALID_TOKEN"); + + lineNumber = XML_GetCurrentLineNumber(parser); + if (lineNumber != 4) + fail("XML_GetCurrentLineNumber does not work as expected."); + + columnNumber = XML_GetCurrentColumnNumber(parser); + if (columnNumber != 0) + fail("XML_GetCurrentColumnNumber does not work as expected."); + + XML_ParserFree(parser); + } +} +END_TEST + +START_TEST(test_misc_tag_mismatch_reset_leak) { +#ifdef XML_NS + const char *const text = "<open xmlns='https://namespace1.test'></close>"; + XML_Parser parser = XML_ParserCreateNS(NULL, XCS('\n')); + + if (_XML_Parse_SINGLE_BYTES(parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Call to parse was expected to fail"); + if (XML_GetErrorCode(parser) != XML_ERROR_TAG_MISMATCH) + fail("Call to parse was expected to fail from a closing tag mismatch"); + + XML_ParserReset(parser, NULL); + + if (_XML_Parse_SINGLE_BYTES(parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Call to parse was expected to fail"); + if (XML_GetErrorCode(parser) != XML_ERROR_TAG_MISMATCH) + fail("Call to parse was expected to fail from a closing tag mismatch"); + + XML_ParserFree(parser); +#endif +} +END_TEST + +START_TEST(test_misc_create_external_entity_parser_with_null_context) { + // With XML_DTD undefined, the only supported case of external entities + // is pattern "<!ENTITY entity123 SYSTEM 'filename123'>". A NULL context + // was causing a segfault through a null pointer dereference in function + // setContext, previously. + XML_Parser parser = XML_ParserCreate(NULL); + XML_Parser ext_parser = XML_ExternalEntityParserCreate(parser, NULL, NULL); +#ifdef XML_DTD + assert_true(ext_parser != NULL); + XML_ParserFree(ext_parser); +#else + assert_true(ext_parser == NULL); +#endif /* XML_DTD */ + XML_ParserFree(parser); +} +END_TEST + +START_TEST(test_misc_general_entities_support) { + const char *const doc + = "<!DOCTYPE r [\n" + "<!ENTITY e1 'v1'>\n" + "<!ENTITY e2 SYSTEM 'v2'>\n" + "]>\n" + "<r a1='[&e1;]'>[&e1;][&e2;][&'><"]</r>"; + + CharData storage; + CharData_Init(&storage); + + XML_Parser parser = XML_ParserCreate(NULL); + XML_SetUserData(parser, &storage); + XML_SetStartElementHandler(parser, accumulate_start_element); + XML_SetExternalEntityRefHandler(parser, + external_entity_failer__if_not_xml_ge); + XML_SetEntityDeclHandler(parser, accumulate_entity_decl); + XML_SetCharacterDataHandler(parser, accumulate_characters); + + if (_XML_Parse_SINGLE_BYTES(parser, doc, (int)strlen(doc), XML_TRUE) + != XML_STATUS_OK) { + xml_failure(parser); + } + + XML_ParserFree(parser); + + CharData_CheckXMLChars(&storage, + /* clang-format off */ +#if XML_GE == 1 + XCS("e1=v1\n") + XCS("e2=(null)\n") + XCS("(r(a1=[v1]))\n") + XCS("[v1][][&'><\"]") +#else + XCS("e1=&e1;\n") + XCS("e2=(null)\n") + XCS("(r(a1=[&e1;]))\n") + XCS("[&e1;][&e2;][&'><\"]") +#endif + ); + /* clang-format on */ +} +END_TEST + +static void XMLCALL +resumable_stopping_character_handler(void *userData, const XML_Char *s, + int len) { + UNUSED_P(s); + UNUSED_P(len); + XML_Parser parser = (XML_Parser)userData; + XML_StopParser(parser, XML_TRUE); +} + +// NOTE: This test needs active LeakSanitizer to be of actual use +START_TEST(test_misc_char_handler_stop_without_leak) { + const char *const data + = "<!DOCTYPE t1[<!ENTITY e1 'angle<'><!ENTITY e2 '&e1;'>]><t1>&e2;"; + XML_Parser parser = XML_ParserCreate(NULL); + assert_true(parser != NULL); + XML_SetUserData(parser, parser); + XML_SetCharacterDataHandler(parser, resumable_stopping_character_handler); + _XML_Parse_SINGLE_BYTES(parser, data, (int)strlen(data), XML_FALSE); + XML_ParserFree(parser); +} +END_TEST + +START_TEST(test_misc_resumeparser_not_crashing) { + XML_Parser parser = XML_ParserCreate(NULL); + XML_GetBuffer(parser, 1); + XML_StopParser(parser, /*resumable=*/XML_TRUE); + XML_ResumeParser(parser); // could crash here, previously + XML_ParserFree(parser); +} +END_TEST + +START_TEST(test_misc_stopparser_rejects_unstarted_parser) { + const XML_Bool cases[] = {XML_TRUE, XML_FALSE}; + for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { + const XML_Bool resumable = cases[i]; + XML_Parser parser = XML_ParserCreate(NULL); + assert_true(XML_GetErrorCode(parser) == XML_ERROR_NONE); + assert_true(XML_StopParser(parser, resumable) == XML_STATUS_ERROR); + assert_true(XML_GetErrorCode(parser) == XML_ERROR_NOT_STARTED); + XML_ParserFree(parser); + } +} +END_TEST + +void +make_miscellaneous_test_case(Suite *s) { + TCase *tc_misc = tcase_create("miscellaneous tests"); + + suite_add_tcase(s, tc_misc); + tcase_add_checked_fixture(tc_misc, NULL, basic_teardown); + + tcase_add_test(tc_misc, test_misc_alloc_create_parser); + tcase_add_test(tc_misc, test_misc_alloc_create_parser_with_encoding); + tcase_add_test(tc_misc, test_misc_null_parser); + tcase_add_test(tc_misc, test_misc_error_string); + tcase_add_test(tc_misc, test_misc_version); + tcase_add_test(tc_misc, test_misc_features); + tcase_add_test(tc_misc, test_misc_attribute_leak); + tcase_add_test(tc_misc, test_misc_utf16le); + tcase_add_test(tc_misc, test_misc_stop_during_end_handler_issue_240_1); + tcase_add_test(tc_misc, test_misc_stop_during_end_handler_issue_240_2); + tcase_add_test__ifdef_xml_dtd( + tc_misc, test_misc_deny_internal_entity_closing_doctype_issue_317); + tcase_add_test(tc_misc, test_misc_tag_mismatch_reset_leak); + tcase_add_test(tc_misc, + test_misc_create_external_entity_parser_with_null_context); + tcase_add_test(tc_misc, test_misc_general_entities_support); + tcase_add_test(tc_misc, test_misc_char_handler_stop_without_leak); + tcase_add_test(tc_misc, test_misc_resumeparser_not_crashing); + tcase_add_test(tc_misc, test_misc_stopparser_rejects_unstarted_parser); +} diff --git a/3rdparty/expat/tests/misc_tests.h b/3rdparty/expat/tests/misc_tests.h new file mode 100644 index 00000000000..3d9c4b8a406 --- /dev/null +++ b/3rdparty/expat/tests/misc_tests.h @@ -0,0 +1,56 @@ +/* Tests in the "miscellaneous" test case for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef XML_MISC_TESTS_H +# define XML_MISC_TESTS_H + +extern void make_miscellaneous_test_case(Suite *s); + +#endif /* XML_MISC_TESTS_H */ + +#ifdef __cplusplus +} +#endif diff --git a/3rdparty/expat/tests/misc_tests_cxx.cpp b/3rdparty/expat/tests/misc_tests_cxx.cpp new file mode 100644 index 00000000000..0b84c1b1f4d --- /dev/null +++ b/3rdparty/expat/tests/misc_tests_cxx.cpp @@ -0,0 +1,32 @@ +/* C++ compilation harness for the test suite. + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "misc_tests.c" diff --git a/3rdparty/expat/tests/ns_tests.c b/3rdparty/expat/tests/ns_tests.c new file mode 100644 index 00000000000..411e1d3c974 --- /dev/null +++ b/3rdparty/expat/tests/ns_tests.c @@ -0,0 +1,754 @@ +/* Tests in the "namespace" test case for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "expat_config.h" + +#include <string.h> + +#include "expat.h" +#include "internal.h" +#include "minicheck.h" +#include "common.h" +#include "dummy.h" +#include "handlers.h" +#include "ns_tests.h" + +static void +namespace_setup(void) { + g_parser = XML_ParserCreateNS(NULL, XCS(' ')); + if (g_parser == NULL) + fail("Parser not created."); +} + +static void +namespace_teardown(void) { + basic_teardown(); +} + +START_TEST(test_return_ns_triplet) { + const char *text = "<foo:e xmlns:foo='http://example.org/' bar:a='12'\n" + " xmlns:bar='http://example.org/'>"; + const char *epilog = "</foo:e>"; + const XML_Char *elemstr[] + = {XCS("http://example.org/ e foo"), XCS("http://example.org/ a bar")}; + XML_SetReturnNSTriplet(g_parser, XML_TRUE); + XML_SetUserData(g_parser, (void *)elemstr); + XML_SetElementHandler(g_parser, triplet_start_checker, triplet_end_checker); + XML_SetNamespaceDeclHandler(g_parser, dummy_start_namespace_decl_handler, + dummy_end_namespace_decl_handler); + g_triplet_start_flag = XML_FALSE; + g_triplet_end_flag = XML_FALSE; + init_dummy_handlers(); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + /* Check that unsetting "return triplets" fails while still parsing */ + XML_SetReturnNSTriplet(g_parser, XML_FALSE); + if (_XML_Parse_SINGLE_BYTES(g_parser, epilog, (int)strlen(epilog), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + if (! g_triplet_start_flag) + fail("triplet_start_checker not invoked"); + if (! g_triplet_end_flag) + fail("triplet_end_checker not invoked"); + if (get_dummy_handler_flags() + != (DUMMY_START_NS_DECL_HANDLER_FLAG | DUMMY_END_NS_DECL_HANDLER_FLAG)) + fail("Namespace handlers not called"); +} +END_TEST + +/* Test that the parsing status is correctly reset by XML_ParserReset(). + * We use test_return_ns_triplet() for our example parse to improve + * coverage of tidying up code executed. + */ +START_TEST(test_ns_parser_reset) { + XML_ParsingStatus status; + + XML_GetParsingStatus(g_parser, &status); + if (status.parsing != XML_INITIALIZED) + fail("parsing status doesn't start INITIALIZED"); + test_return_ns_triplet(); + XML_GetParsingStatus(g_parser, &status); + if (status.parsing != XML_FINISHED) + fail("parsing status doesn't end FINISHED"); + XML_ParserReset(g_parser, NULL); + XML_GetParsingStatus(g_parser, &status); + if (status.parsing != XML_INITIALIZED) + fail("parsing status doesn't reset to INITIALIZED"); +} +END_TEST + +static void +run_ns_tagname_overwrite_test(const char *text, const XML_Char *result) { + CharData storage; + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetElementHandler(g_parser, overwrite_start_checker, + overwrite_end_checker); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, result); +} + +/* Regression test for SF bug #566334. */ +START_TEST(test_ns_tagname_overwrite) { + const char *text = "<n:e xmlns:n='http://example.org/'>\n" + " <n:f n:attr='foo'/>\n" + " <n:g n:attr2='bar'/>\n" + "</n:e>"; + const XML_Char *result = XCS("start http://example.org/ e\n") + XCS("start http://example.org/ f\n") + XCS("attribute http://example.org/ attr\n") + XCS("end http://example.org/ f\n") + XCS("start http://example.org/ g\n") + XCS("attribute http://example.org/ attr2\n") + XCS("end http://example.org/ g\n") + XCS("end http://example.org/ e\n"); + run_ns_tagname_overwrite_test(text, result); +} +END_TEST + +/* Regression test for SF bug #566334. */ +START_TEST(test_ns_tagname_overwrite_triplet) { + const char *text = "<n:e xmlns:n='http://example.org/'>\n" + " <n:f n:attr='foo'/>\n" + " <n:g n:attr2='bar'/>\n" + "</n:e>"; + const XML_Char *result = XCS("start http://example.org/ e n\n") + XCS("start http://example.org/ f n\n") + XCS("attribute http://example.org/ attr n\n") + XCS("end http://example.org/ f n\n") + XCS("start http://example.org/ g n\n") + XCS("attribute http://example.org/ attr2 n\n") + XCS("end http://example.org/ g n\n") + XCS("end http://example.org/ e n\n"); + XML_SetReturnNSTriplet(g_parser, XML_TRUE); + run_ns_tagname_overwrite_test(text, result); +} +END_TEST + +/* Regression test for SF bug #620343. */ +START_TEST(test_start_ns_clears_start_element) { + /* This needs to use separate start/end tags; using the empty tag + syntax doesn't cause the problematic path through Expat to be + taken. + */ + const char *text = "<e xmlns='http://example.org/'></e>"; + + XML_SetStartElementHandler(g_parser, start_element_fail); + XML_SetStartNamespaceDeclHandler(g_parser, start_ns_clearing_start_element); + XML_SetEndNamespaceDeclHandler(g_parser, dummy_end_namespace_decl_handler); + XML_UseParserAsHandlerArg(g_parser); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Regression test for SF bug #616863. */ +START_TEST(test_default_ns_from_ext_subset_and_ext_ge) { + const char *text = "<?xml version='1.0'?>\n" + "<!DOCTYPE doc SYSTEM 'http://example.org/doc.dtd' [\n" + " <!ENTITY en SYSTEM 'http://example.org/entity.ent'>\n" + "]>\n" + "<doc xmlns='http://example.org/ns1'>\n" + "&en;\n" + "</doc>"; + + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_handler); + /* We actually need to set this handler to tickle this bug. */ + XML_SetStartElementHandler(g_parser, dummy_start_element); + XML_SetUserData(g_parser, NULL); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Regression test #1 for SF bug #673791. */ +START_TEST(test_ns_prefix_with_empty_uri_1) { + const char *text = "<doc xmlns:prefix='http://example.org/'>\n" + " <e xmlns:prefix=''/>\n" + "</doc>"; + + expect_failure(text, XML_ERROR_UNDECLARING_PREFIX, + "Did not report re-setting namespace" + " URI with prefix to ''."); +} +END_TEST + +/* Regression test #2 for SF bug #673791. */ +START_TEST(test_ns_prefix_with_empty_uri_2) { + const char *text = "<?xml version='1.0'?>\n" + "<docelem xmlns:pre=''/>"; + + expect_failure(text, XML_ERROR_UNDECLARING_PREFIX, + "Did not report setting namespace URI with prefix to ''."); +} +END_TEST + +/* Regression test #3 for SF bug #673791. */ +START_TEST(test_ns_prefix_with_empty_uri_3) { + const char *text = "<!DOCTYPE doc [\n" + " <!ELEMENT doc EMPTY>\n" + " <!ATTLIST doc\n" + " xmlns:prefix CDATA ''>\n" + "]>\n" + "<doc/>"; + + expect_failure(text, XML_ERROR_UNDECLARING_PREFIX, + "Didn't report attr default setting NS w/ prefix to ''."); +} +END_TEST + +/* Regression test #4 for SF bug #673791. */ +START_TEST(test_ns_prefix_with_empty_uri_4) { + const char *text = "<!DOCTYPE doc [\n" + " <!ELEMENT prefix:doc EMPTY>\n" + " <!ATTLIST prefix:doc\n" + " xmlns:prefix CDATA 'http://example.org/'>\n" + "]>\n" + "<prefix:doc/>"; + /* Packaged info expected by the end element handler; + the weird structuring lets us reuse the triplet_end_checker() + function also used for another test. */ + const XML_Char *elemstr[] = {XCS("http://example.org/ doc prefix")}; + XML_SetReturnNSTriplet(g_parser, XML_TRUE); + XML_SetUserData(g_parser, (void *)elemstr); + XML_SetEndElementHandler(g_parser, triplet_end_checker); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test with non-xmlns prefix */ +START_TEST(test_ns_unbound_prefix) { + const char *text = "<!DOCTYPE doc [\n" + " <!ELEMENT prefix:doc EMPTY>\n" + " <!ATTLIST prefix:doc\n" + " notxmlns:prefix CDATA 'http://example.org/'>\n" + "]>\n" + "<prefix:doc/>"; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Unbound prefix incorrectly passed"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_UNBOUND_PREFIX) + xml_failure(g_parser); +} +END_TEST + +START_TEST(test_ns_default_with_empty_uri) { + const char *text = "<doc xmlns='http://example.org/'>\n" + " <e xmlns=''/>\n" + "</doc>"; + /* Add some handlers to exercise extra code paths */ + XML_SetStartNamespaceDeclHandler(g_parser, + dummy_start_namespace_decl_handler); + XML_SetEndNamespaceDeclHandler(g_parser, dummy_end_namespace_decl_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Regression test for SF bug #692964: two prefixes for one namespace. */ +START_TEST(test_ns_duplicate_attrs_diff_prefixes) { + const char *text = "<doc xmlns:a='http://example.org/a'\n" + " xmlns:b='http://example.org/a'\n" + " a:a='v' b:a='v' />"; + expect_failure(text, XML_ERROR_DUPLICATE_ATTRIBUTE, + "did not report multiple attributes with same URI+name"); +} +END_TEST + +START_TEST(test_ns_duplicate_hashes) { + /* The hash of an attribute is calculated as the hash of its URI + * concatenated with a space followed by its name (after the + * colon). We wish to generate attributes with the same hash + * value modulo the attribute table size so that we can check that + * the attribute hash table works correctly. The attribute hash + * table size will be the smallest power of two greater than the + * number of attributes, but at least eight. There is + * unfortunately no programmatic way of getting the hash or the + * table size at user level, but the test code coverage percentage + * will drop if the hashes cease to point to the same row. + * + * The cunning plan is to have few enough attributes to have a + * reliable table size of 8, and have the single letter attribute + * names be 8 characters apart, producing a hash which will be the + * same modulo 8. + */ + const char *text = "<doc xmlns:a='http://example.org/a'\n" + " a:a='v' a:i='w' />"; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Regression test for SF bug #695401: unbound prefix. */ +START_TEST(test_ns_unbound_prefix_on_attribute) { + const char *text = "<doc a:attr=''/>"; + expect_failure(text, XML_ERROR_UNBOUND_PREFIX, + "did not report unbound prefix on attribute"); +} +END_TEST + +/* Regression test for SF bug #695401: unbound prefix. */ +START_TEST(test_ns_unbound_prefix_on_element) { + const char *text = "<a:doc/>"; + expect_failure(text, XML_ERROR_UNBOUND_PREFIX, + "did not report unbound prefix on element"); +} +END_TEST + +/* Test that long element names with namespaces are handled correctly */ +START_TEST(test_ns_long_element) { + const char *text + = "<foo:thisisalongenoughelementnametotriggerareallocation\n" + " xmlns:foo='http://example.org/' bar:a='12'\n" + " xmlns:bar='http://example.org/'>" + "</foo:thisisalongenoughelementnametotriggerareallocation>"; + const XML_Char *elemstr[] + = {XCS("http://example.org/") + XCS(" thisisalongenoughelementnametotriggerareallocation foo"), + XCS("http://example.org/ a bar")}; + + XML_SetReturnNSTriplet(g_parser, XML_TRUE); + XML_SetUserData(g_parser, (void *)elemstr); + XML_SetElementHandler(g_parser, triplet_start_checker, triplet_end_checker); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test mixed population of prefixed and unprefixed attributes */ +START_TEST(test_ns_mixed_prefix_atts) { + const char *text = "<e a='12' bar:b='13'\n" + " xmlns:bar='http://example.org/'>" + "</e>"; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test having a long namespaced element name inside a short one. + * This exercises some internal buffer reallocation that is shared + * across elements with the same namespace URI. + */ +START_TEST(test_ns_extend_uri_buffer) { + const char *text = "<foo:e xmlns:foo='http://example.org/'>" + " <foo:thisisalongenoughnametotriggerallocationaction" + " foo:a='12' />" + "</foo:e>"; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test that xmlns is correctly rejected as an attribute in the xmlns + * namespace, but not in other namespaces + */ +START_TEST(test_ns_reserved_attributes) { + const char *text1 + = "<foo:e xmlns:foo='http://example.org/' xmlns:xmlns='12' />"; + const char *text2 + = "<foo:e xmlns:foo='http://example.org/' foo:xmlns='12' />"; + expect_failure(text1, XML_ERROR_RESERVED_PREFIX_XMLNS, + "xmlns not rejected as an attribute"); + XML_ParserReset(g_parser, NULL); + if (_XML_Parse_SINGLE_BYTES(g_parser, text2, (int)strlen(text2), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test more reserved attributes */ +START_TEST(test_ns_reserved_attributes_2) { + const char *text1 = "<foo:e xmlns:foo='http://example.org/'" + " xmlns:xml='http://example.org/' />"; + const char *text2 + = "<foo:e xmlns:foo='http://www.w3.org/XML/1998/namespace' />"; + const char *text3 = "<foo:e xmlns:foo='http://www.w3.org/2000/xmlns/' />"; + + expect_failure(text1, XML_ERROR_RESERVED_PREFIX_XML, + "xml not rejected as an attribute"); + XML_ParserReset(g_parser, NULL); + expect_failure(text2, XML_ERROR_RESERVED_NAMESPACE_URI, + "Use of w3.org URL not faulted"); + XML_ParserReset(g_parser, NULL); + expect_failure(text3, XML_ERROR_RESERVED_NAMESPACE_URI, + "Use of w3.org xmlns URL not faulted"); +} +END_TEST + +/* Test string pool handling of namespace names of 2048 characters */ +/* Exercises a particular string pool growth path */ +START_TEST(test_ns_extremely_long_prefix) { + /* C99 compilers are only required to support 4095-character + * strings, so the following needs to be split in two to be safe + * for all compilers. + */ + const char *text1 + = "<doc " + /* 64 character on each line */ + /* ...gives a total length of 2048 */ + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + ":a='12'"; + const char *text2 + = " xmlns:" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "='foo'\n>" + "</doc>"; + + if (_XML_Parse_SINGLE_BYTES(g_parser, text1, (int)strlen(text1), XML_FALSE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + if (_XML_Parse_SINGLE_BYTES(g_parser, text2, (int)strlen(text2), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); +} +END_TEST + +/* Test unknown encoding handlers in namespace setup */ +START_TEST(test_ns_unknown_encoding_success) { + const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n" + "<foo:e xmlns:foo='http://example.org/'>Hi</foo:e>"; + + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + run_character_check(text, XCS("Hi")); +} +END_TEST + +/* Test that too many colons are rejected */ +START_TEST(test_ns_double_colon) { + const char *text = "<foo:e xmlns:foo='http://example.org/' foo:a:b='bar' />"; + const enum XML_Status status + = _XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE); +#ifdef XML_NS + if ((status == XML_STATUS_OK) + || (XML_GetErrorCode(g_parser) != XML_ERROR_INVALID_TOKEN)) { + fail("Double colon in attribute name not faulted" + " (despite active namespace support)"); + } +#else + if (status != XML_STATUS_OK) { + fail("Double colon in attribute name faulted" + " (despite inactive namespace support"); + } +#endif +} +END_TEST + +START_TEST(test_ns_double_colon_element) { + const char *text = "<foo:bar:e xmlns:foo='http://example.org/' />"; + const enum XML_Status status + = _XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE); +#ifdef XML_NS + if ((status == XML_STATUS_OK) + || (XML_GetErrorCode(g_parser) != XML_ERROR_INVALID_TOKEN)) { + fail("Double colon in element name not faulted" + " (despite active namespace support)"); + } +#else + if (status != XML_STATUS_OK) { + fail("Double colon in element name faulted" + " (despite inactive namespace support"); + } +#endif +} +END_TEST + +/* Test that non-name characters after a colon are rejected */ +START_TEST(test_ns_bad_attr_leafname) { + const char *text = "<foo:e xmlns:foo='http://example.org/' foo:?ar='baz' />"; + + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "Invalid character in leafname not faulted"); +} +END_TEST + +START_TEST(test_ns_bad_element_leafname) { + const char *text = "<foo:?oc xmlns:foo='http://example.org/' />"; + + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "Invalid character in element leafname not faulted"); +} +END_TEST + +/* Test high-byte-set UTF-16 characters are valid in a leafname */ +START_TEST(test_ns_utf16_leafname) { + const char text[] = + /* <n:e xmlns:n='URI' n:{KHO KHWAI}='a' /> + * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8 + */ + "<\0n\0:\0e\0 \0x\0m\0l\0n\0s\0:\0n\0=\0'\0U\0R\0I\0'\0 \0" + "n\0:\0\x04\x0e=\0'\0a\0'\0 \0/\0>\0"; + const XML_Char *expected = XCS("a"); + CharData storage; + + CharData_Init(&storage); + XML_SetStartElementHandler(g_parser, accumulate_attribute); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_ns_utf16_element_leafname) { + const char text[] = + /* <n:{KHO KHWAI} xmlns:n='URI'/> + * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8 + */ + "\0<\0n\0:\x0e\x04\0 \0x\0m\0l\0n\0s\0:\0n\0=\0'\0U\0R\0I\0'\0/\0>"; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("URI \x0e04"); +#else + const XML_Char *expected = XCS("URI \xe0\xb8\x84"); +#endif + CharData storage; + + CharData_Init(&storage); + XML_SetStartElementHandler(g_parser, start_element_event_handler); + XML_SetUserData(g_parser, &storage); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_ns_utf16_doctype) { + const char text[] = + /* <!DOCTYPE foo:{KHO KHWAI} [ <!ENTITY bar 'baz'> ]>\n + * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8 + */ + "\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0f\0o\0o\0:\x0e\x04\0 " + "\0[\0 \0<\0!\0E\0N\0T\0I\0T\0Y\0 \0b\0a\0r\0 \0'\0b\0a\0z\0'\0>\0 " + "\0]\0>\0\n" + /* <foo:{KHO KHWAI} xmlns:foo='URI'>&bar;</foo:{KHO KHWAI}> */ + "\0<\0f\0o\0o\0:\x0e\x04\0 " + "\0x\0m\0l\0n\0s\0:\0f\0o\0o\0=\0'\0U\0R\0I\0'\0>" + "\0&\0b\0a\0r\0;" + "\0<\0/\0f\0o\0o\0:\x0e\x04\0>"; +#ifdef XML_UNICODE + const XML_Char *expected = XCS("URI \x0e04"); +#else + const XML_Char *expected = XCS("URI \xe0\xb8\x84"); +#endif + CharData storage; + + CharData_Init(&storage); + XML_SetUserData(g_parser, &storage); + XML_SetStartElementHandler(g_parser, start_element_event_handler); + XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + CharData_CheckXMLChars(&storage, expected); +} +END_TEST + +START_TEST(test_ns_invalid_doctype) { + const char *text = "<!DOCTYPE foo:!bad [ <!ENTITY bar 'baz' ]>\n" + "<foo:!bad>&bar;</foo:!bad>"; + + expect_failure(text, XML_ERROR_INVALID_TOKEN, + "Invalid character in document local name not faulted"); +} +END_TEST + +START_TEST(test_ns_double_colon_doctype) { + const char *text = "<!DOCTYPE foo:a:doc [ <!ENTITY bar 'baz' ]>\n" + "<foo:a:doc>&bar;</foo:a:doc>"; + + expect_failure(text, XML_ERROR_SYNTAX, + "Double colon in document name not faulted"); +} +END_TEST + +START_TEST(test_ns_separator_in_uri) { + struct test_case { + enum XML_Status expectedStatus; + const char *doc; + XML_Char namesep; + }; + struct test_case cases[] = { + {XML_STATUS_OK, "<doc xmlns='one_two' />", XCS('\n')}, + {XML_STATUS_ERROR, "<doc xmlns='one
two' />", XCS('\n')}, + {XML_STATUS_OK, "<doc xmlns='one:two' />", XCS(':')}, + }; + + size_t i = 0; + size_t failCount = 0; + for (; i < sizeof(cases) / sizeof(cases[0]); i++) { + set_subtest("%s", cases[i].doc); + XML_Parser parser = XML_ParserCreateNS(NULL, cases[i].namesep); + XML_SetElementHandler(parser, dummy_start_element, dummy_end_element); + if (_XML_Parse_SINGLE_BYTES(parser, cases[i].doc, (int)strlen(cases[i].doc), + /*isFinal*/ XML_TRUE) + != cases[i].expectedStatus) { + failCount++; + } + XML_ParserFree(parser); + } + + if (failCount) { + fail("Namespace separator handling is broken"); + } +} +END_TEST + +void +make_namespace_test_case(Suite *s) { + TCase *tc_namespace = tcase_create("XML namespaces"); + + suite_add_tcase(s, tc_namespace); + tcase_add_checked_fixture(tc_namespace, namespace_setup, namespace_teardown); + tcase_add_test(tc_namespace, test_return_ns_triplet); + tcase_add_test(tc_namespace, test_ns_parser_reset); + tcase_add_test(tc_namespace, test_ns_tagname_overwrite); + tcase_add_test(tc_namespace, test_ns_tagname_overwrite_triplet); + tcase_add_test(tc_namespace, test_start_ns_clears_start_element); + tcase_add_test__ifdef_xml_dtd(tc_namespace, + test_default_ns_from_ext_subset_and_ext_ge); + tcase_add_test(tc_namespace, test_ns_prefix_with_empty_uri_1); + tcase_add_test(tc_namespace, test_ns_prefix_with_empty_uri_2); + tcase_add_test(tc_namespace, test_ns_prefix_with_empty_uri_3); + tcase_add_test(tc_namespace, test_ns_prefix_with_empty_uri_4); + tcase_add_test(tc_namespace, test_ns_unbound_prefix); + tcase_add_test(tc_namespace, test_ns_default_with_empty_uri); + tcase_add_test(tc_namespace, test_ns_duplicate_attrs_diff_prefixes); + tcase_add_test(tc_namespace, test_ns_duplicate_hashes); + tcase_add_test(tc_namespace, test_ns_unbound_prefix_on_attribute); + tcase_add_test(tc_namespace, test_ns_unbound_prefix_on_element); + tcase_add_test(tc_namespace, test_ns_long_element); + tcase_add_test(tc_namespace, test_ns_mixed_prefix_atts); + tcase_add_test(tc_namespace, test_ns_extend_uri_buffer); + tcase_add_test(tc_namespace, test_ns_reserved_attributes); + tcase_add_test(tc_namespace, test_ns_reserved_attributes_2); + tcase_add_test(tc_namespace, test_ns_extremely_long_prefix); + tcase_add_test(tc_namespace, test_ns_unknown_encoding_success); + tcase_add_test(tc_namespace, test_ns_double_colon); + tcase_add_test(tc_namespace, test_ns_double_colon_element); + tcase_add_test(tc_namespace, test_ns_bad_attr_leafname); + tcase_add_test(tc_namespace, test_ns_bad_element_leafname); + tcase_add_test(tc_namespace, test_ns_utf16_leafname); + tcase_add_test(tc_namespace, test_ns_utf16_element_leafname); + tcase_add_test__if_xml_ge(tc_namespace, test_ns_utf16_doctype); + tcase_add_test(tc_namespace, test_ns_invalid_doctype); + tcase_add_test(tc_namespace, test_ns_double_colon_doctype); + tcase_add_test(tc_namespace, test_ns_separator_in_uri); +} diff --git a/3rdparty/expat/tests/ns_tests.h b/3rdparty/expat/tests/ns_tests.h new file mode 100644 index 00000000000..acb0db786a4 --- /dev/null +++ b/3rdparty/expat/tests/ns_tests.h @@ -0,0 +1,56 @@ +/* Tests in the "namespace" test case for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef XML_NS_TESTS_H +# define XML_NS_TESTS_H + +extern void make_namespace_test_case(Suite *s); + +#endif /* XML_NS_TESTS_H */ + +#ifdef __cplusplus +} +#endif diff --git a/3rdparty/expat/tests/ns_tests_cxx.cpp b/3rdparty/expat/tests/ns_tests_cxx.cpp new file mode 100644 index 00000000000..b2fe187bb8b --- /dev/null +++ b/3rdparty/expat/tests/ns_tests_cxx.cpp @@ -0,0 +1,32 @@ +/* C++ compilation harness for the test suite. + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "ns_tests.c" diff --git a/3rdparty/expat/tests/nsalloc_tests.c b/3rdparty/expat/tests/nsalloc_tests.c new file mode 100644 index 00000000000..ec88586af1d --- /dev/null +++ b/3rdparty/expat/tests/nsalloc_tests.c @@ -0,0 +1,1537 @@ +/* Tests in the "namespace allocation" test case for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#if defined(NDEBUG) +# undef NDEBUG /* because test suite relies on assert(...) at the moment */ +#endif + +#include <string.h> +#include <assert.h> + +#include "expat.h" +#include "common.h" +#include "minicheck.h" +#include "dummy.h" +#include "handlers.h" +#include "nsalloc_tests.h" + +static void +nsalloc_setup(void) { + XML_Memory_Handling_Suite memsuite = {duff_allocator, duff_reallocator, free}; + XML_Char ns_sep[2] = {' ', '\0'}; + + /* Ensure the parser creation will go through */ + g_allocation_count = ALLOC_ALWAYS_SUCCEED; + g_reallocation_count = REALLOC_ALWAYS_SUCCEED; + g_parser = XML_ParserCreate_MM(NULL, &memsuite, ns_sep); + if (g_parser == NULL) + fail("Parser not created"); +} + +static void +nsalloc_teardown(void) { + basic_teardown(); +} + +/* Test the effects of allocation failure in simple namespace parsing. + * Based on test_ns_default_with_empty_uri() + */ +START_TEST(test_nsalloc_xmlns) { + const char *text = "<doc xmlns='http://example.org/'>\n" + " <e xmlns=''/>\n" + "</doc>"; + unsigned int i; + const unsigned int max_alloc_count = 30; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + /* Exercise more code paths with a default handler */ + XML_SetDefaultHandler(g_parser, dummy_default_handler); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* Resetting the parser is insufficient, because some memory + * allocations are cached within the parser. Instead we use + * the teardown and setup routines to ensure that we have the + * right sort of parser back in our hands. + */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing allocations"); + else if (i == max_alloc_count) + fail("Parsing failed even at maximum allocation count"); +} +END_TEST + +/* Test XML_ParseBuffer interface with namespace and a dicky allocator */ +START_TEST(test_nsalloc_parse_buffer) { + const char *text = "<doc>Hello</doc>"; + void *buffer; + + /* Try a parse before the start of the world */ + /* (Exercises new code path) */ + if (XML_ParseBuffer(g_parser, 0, XML_FALSE) != XML_STATUS_ERROR) + fail("Pre-init XML_ParseBuffer not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_NO_BUFFER) + fail("Pre-init XML_ParseBuffer faulted for wrong reason"); + + buffer = XML_GetBuffer(g_parser, 1 /* any small number greater than 0 */); + if (buffer == NULL) + fail("Could not acquire parse buffer"); + + g_allocation_count = 0; + if (XML_ParseBuffer(g_parser, 0, XML_FALSE) != XML_STATUS_ERROR) + fail("Pre-init XML_ParseBuffer not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_NO_MEMORY) + fail("Pre-init XML_ParseBuffer faulted for wrong reason"); + + /* Now with actual memory allocation */ + g_allocation_count = ALLOC_ALWAYS_SUCCEED; + if (XML_ParseBuffer(g_parser, 0, XML_FALSE) != XML_STATUS_OK) + xml_failure(g_parser); + + /* Check that resuming an unsuspended parser is faulted */ + if (XML_ResumeParser(g_parser) != XML_STATUS_ERROR) + fail("Resuming unsuspended parser not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_NOT_SUSPENDED) + xml_failure(g_parser); + + /* Get the parser into suspended state */ + XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); + g_resumable = XML_TRUE; + buffer = XML_GetBuffer(g_parser, (int)strlen(text)); + if (buffer == NULL) + fail("Could not acquire parse buffer"); + assert(buffer != NULL); + memcpy(buffer, text, strlen(text)); + if (XML_ParseBuffer(g_parser, (int)strlen(text), XML_TRUE) + != XML_STATUS_SUSPENDED) + xml_failure(g_parser); + if (XML_GetErrorCode(g_parser) != XML_ERROR_NONE) + xml_failure(g_parser); + if (XML_ParseBuffer(g_parser, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Suspended XML_ParseBuffer not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_SUSPENDED) + xml_failure(g_parser); + if (XML_GetBuffer(g_parser, (int)strlen(text)) != NULL) + fail("Suspended XML_GetBuffer not faulted"); + + /* Get it going again and complete the world */ + XML_SetCharacterDataHandler(g_parser, NULL); + if (XML_ResumeParser(g_parser) != XML_STATUS_OK) + xml_failure(g_parser); + if (XML_ParseBuffer(g_parser, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + fail("Post-finishing XML_ParseBuffer not faulted"); + if (XML_GetErrorCode(g_parser) != XML_ERROR_FINISHED) + xml_failure(g_parser); + if (XML_GetBuffer(g_parser, (int)strlen(text)) != NULL) + fail("Post-finishing XML_GetBuffer not faulted"); +} +END_TEST + +/* Check handling of long prefix names (pool growth) */ +START_TEST(test_nsalloc_long_prefix) { + const char *text + = "<" + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + ":foo xmlns:" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "='http://example.org/'>" + "</" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + ":foo>"; + int i; + const int max_alloc_count = 40; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing allocations"); + else if (i == max_alloc_count) + fail("Parsing failed even at max allocation count"); +} +END_TEST + +/* Check handling of long uri names (pool growth) */ +START_TEST(test_nsalloc_long_uri) { + const char *text + = "<foo:e xmlns:foo='http://example.org/" + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "' bar:a='12'\n" + "xmlns:bar='http://example.org/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" + "'>" + "</foo:e>"; + int i; + const int max_alloc_count = 40; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing allocations"); + else if (i == max_alloc_count) + fail("Parsing failed even at max allocation count"); +} +END_TEST + +/* Test handling of long attribute names with prefixes */ +START_TEST(test_nsalloc_long_attr) { + const char *text + = "<foo:e xmlns:foo='http://example.org/' bar:" + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "='12'\n" + "xmlns:bar='http://example.org/'>" + "</foo:e>"; + int i; + const int max_alloc_count = 40; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing allocations"); + else if (i == max_alloc_count) + fail("Parsing failed even at max allocation count"); +} +END_TEST + +/* Test handling of an attribute name with a long namespace prefix */ +START_TEST(test_nsalloc_long_attr_prefix) { + const char *text + = "<foo:e xmlns:foo='http://example.org/' " + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + ":a='12'\n" + "xmlns:" + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "='http://example.org/'>" + "</foo:e>"; + const XML_Char *elemstr[] = { + /* clang-format off */ + XCS("http://example.org/ e foo"), + XCS("http://example.org/ a ") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") + XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") + /* clang-format on */ + }; + int i; + const int max_alloc_count = 40; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetReturnNSTriplet(g_parser, XML_TRUE); + XML_SetUserData(g_parser, (void *)elemstr); + XML_SetElementHandler(g_parser, triplet_start_checker, triplet_end_checker); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing allocations"); + else if (i == max_alloc_count) + fail("Parsing failed even at max allocation count"); +} +END_TEST + +/* Test attribute handling in the face of a dodgy reallocator */ +START_TEST(test_nsalloc_realloc_attributes) { + const char *text = "<foo:e xmlns:foo='http://example.org/' bar:a='12'\n" + " xmlns:bar='http://example.org/'>" + "</foo:e>"; + int i; + const int max_realloc_count = 10; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing reallocations"); + else if (i == max_realloc_count) + fail("Parsing failed at max reallocation count"); +} +END_TEST + +/* Test long element names with namespaces under a failing allocator */ +START_TEST(test_nsalloc_long_element) { + const char *text + = "<foo:thisisalongenoughelementnametotriggerareallocation\n" + " xmlns:foo='http://example.org/' bar:a='12'\n" + " xmlns:bar='http://example.org/'>" + "</foo:thisisalongenoughelementnametotriggerareallocation>"; + const XML_Char *elemstr[] + = {XCS("http://example.org/") + XCS(" thisisalongenoughelementnametotriggerareallocation foo"), + XCS("http://example.org/ a bar")}; + int i; + const int max_alloc_count = 30; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetReturnNSTriplet(g_parser, XML_TRUE); + XML_SetUserData(g_parser, (void *)elemstr); + XML_SetElementHandler(g_parser, triplet_start_checker, triplet_end_checker); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing reallocations"); + else if (i == max_alloc_count) + fail("Parsing failed at max reallocation count"); +} +END_TEST + +/* Test the effects of reallocation failure when reassigning a + * binding. + * + * XML_ParserReset does not free the BINDING structures used by a + * parser, but instead adds them to an internal free list to be reused + * as necessary. Likewise the URI buffers allocated for the binding + * aren't freed, but kept attached to their existing binding. If the + * new binding has a longer URI, it will need reallocation. This test + * provokes that reallocation, and tests the control path if it fails. + */ +START_TEST(test_nsalloc_realloc_binding_uri) { + const char *first = "<doc xmlns='http://example.org/'>\n" + " <e xmlns='' />\n" + "</doc>"; + const char *second + = "<doc xmlns='http://example.org/long/enough/URI/to/reallocate/'>\n" + " <e xmlns='' />\n" + "</doc>"; + unsigned i; + const unsigned max_realloc_count = 10; + + /* First, do a full parse that will leave bindings around */ + if (_XML_Parse_SINGLE_BYTES(g_parser, first, (int)strlen(first), XML_TRUE) + == XML_STATUS_ERROR) + xml_failure(g_parser); + + /* Now repeat with a longer URI and a duff reallocator */ + for (i = 0; i < max_realloc_count; i++) { + XML_ParserReset(g_parser, NULL); + g_reallocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, second, (int)strlen(second), XML_TRUE) + != XML_STATUS_ERROR) + break; + } + if (i == 0) + fail("Parsing worked despite failing reallocation"); + else if (i == max_realloc_count) + fail("Parsing failed at max reallocation count"); +} +END_TEST + +/* Check handling of long prefix names (pool growth) */ +START_TEST(test_nsalloc_realloc_long_prefix) { + const char *text + = "<" + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + ":foo xmlns:" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "='http://example.org/'>" + "</" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + ":foo>"; + int i; + const int max_realloc_count = 12; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing reallocations"); + else if (i == max_realloc_count) + fail("Parsing failed even at max reallocation count"); +} +END_TEST + +/* Check handling of even long prefix names (different code path) */ +START_TEST(test_nsalloc_realloc_longer_prefix) { + const char *text + = "<" + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "Q:foo xmlns:" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "Q='http://example.org/'>" + "</" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "Q:foo>"; + int i; + const int max_realloc_count = 12; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing reallocations"); + else if (i == max_realloc_count) + fail("Parsing failed even at max reallocation count"); +} +END_TEST + +START_TEST(test_nsalloc_long_namespace) { + const char *text1 + = "<" + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + ":e xmlns:" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "='http://example.org/'>\n"; + const char *text2 + = "<" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + ":f " + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + ":attr='foo'/>\n" + "</" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + ":e>"; + int i; + const int max_alloc_count = 40; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text1, (int)strlen(text1), XML_FALSE) + != XML_STATUS_ERROR + && _XML_Parse_SINGLE_BYTES(g_parser, text2, (int)strlen(text2), + XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing allocations"); + else if (i == max_alloc_count) + fail("Parsing failed even at max allocation count"); +} +END_TEST + +/* Using a slightly shorter namespace name provokes allocations in + * slightly different places in the code. + */ +START_TEST(test_nsalloc_less_long_namespace) { + const char *text + = "<" + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678" + ":e xmlns:" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678" + "='http://example.org/'>\n" + "<" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678" + ":f " + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678" + ":att='foo'/>\n" + "</" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678" + ":e>"; + int i; + const int max_alloc_count = 40; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing allocations"); + else if (i == max_alloc_count) + fail("Parsing failed even at max allocation count"); +} +END_TEST + +START_TEST(test_nsalloc_long_context) { + const char *text + = "<!DOCTYPE doc SYSTEM 'foo' [\n" + " <!ATTLIST doc baz ID #REQUIRED>\n" + " <!ENTITY en SYSTEM 'bar'>\n" + "]>\n" + "<doc xmlns='http://example.org/" + /* 64 characters per line */ + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKL" + "' baz='2'>\n" + "&en;" + "</doc>"; + ExtOption options[] = { + {XCS("foo"), "<!ELEMENT e EMPTY>"}, {XCS("bar"), "<e/>"}, {NULL, NULL}}; + int i; + const int max_alloc_count = 70; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetUserData(g_parser, options); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_optioner); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing allocations"); + else if (i == max_alloc_count) + fail("Parsing failed even at max allocation count"); +} +END_TEST + +/* This function is void; it will throw a fail() on error, so if it + * returns normally it must have succeeded. + */ +static void +context_realloc_test(const char *text) { + ExtOption options[] = { + {XCS("foo"), "<!ELEMENT e EMPTY>"}, {XCS("bar"), "<e/>"}, {NULL, NULL}}; + int i; + const int max_realloc_count = 6; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + XML_SetUserData(g_parser, options); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_optioner); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing reallocations"); + else if (i == max_realloc_count) + fail("Parsing failed even at max reallocation count"); +} + +START_TEST(test_nsalloc_realloc_long_context) { + const char *text + = "<!DOCTYPE doc SYSTEM 'foo' [\n" + " <!ENTITY en SYSTEM 'bar'>\n" + "]>\n" + "<doc xmlns='http://example.org/" + /* 64 characters per line */ + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKL" + "'>\n" + "&en;" + "</doc>"; + + context_realloc_test(text); +} +END_TEST + +START_TEST(test_nsalloc_realloc_long_context_2) { + const char *text + = "<!DOCTYPE doc SYSTEM 'foo' [\n" + " <!ENTITY en SYSTEM 'bar'>\n" + "]>\n" + "<doc xmlns='http://example.org/" + /* 64 characters per line */ + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJK" + "'>\n" + "&en;" + "</doc>"; + + context_realloc_test(text); +} +END_TEST + +START_TEST(test_nsalloc_realloc_long_context_3) { + const char *text + = "<!DOCTYPE doc SYSTEM 'foo' [\n" + " <!ENTITY en SYSTEM 'bar'>\n" + "]>\n" + "<doc xmlns='http://example.org/" + /* 64 characters per line */ + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGH" + "'>\n" + "&en;" + "</doc>"; + + context_realloc_test(text); +} +END_TEST + +START_TEST(test_nsalloc_realloc_long_context_4) { + const char *text + = "<!DOCTYPE doc SYSTEM 'foo' [\n" + " <!ENTITY en SYSTEM 'bar'>\n" + "]>\n" + "<doc xmlns='http://example.org/" + /* 64 characters per line */ + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO" + "'>\n" + "&en;" + "</doc>"; + + context_realloc_test(text); +} +END_TEST + +START_TEST(test_nsalloc_realloc_long_context_5) { + const char *text + = "<!DOCTYPE doc SYSTEM 'foo' [\n" + " <!ENTITY en SYSTEM 'bar'>\n" + "]>\n" + "<doc xmlns='http://example.org/" + /* 64 characters per line */ + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABC" + "'>\n" + "&en;" + "</doc>"; + + context_realloc_test(text); +} +END_TEST + +START_TEST(test_nsalloc_realloc_long_context_6) { + const char *text + = "<!DOCTYPE doc SYSTEM 'foo' [\n" + " <!ENTITY en SYSTEM 'bar'>\n" + "]>\n" + "<doc xmlns='http://example.org/" + /* 64 characters per line */ + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" + "'>\n" + "&en;" + "</doc>"; + + context_realloc_test(text); +} +END_TEST + +START_TEST(test_nsalloc_realloc_long_context_7) { + const char *text + = "<!DOCTYPE doc SYSTEM 'foo' [\n" + " <!ENTITY en SYSTEM 'bar'>\n" + "]>\n" + "<doc xmlns='http://example.org/" + /* 64 characters per line */ + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLM" + "'>\n" + "&en;" + "</doc>"; + + context_realloc_test(text); +} +END_TEST + +START_TEST(test_nsalloc_realloc_long_ge_name) { + const char *text + = "<!DOCTYPE doc SYSTEM 'foo' [\n" + " <!ENTITY " + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + " SYSTEM 'bar'>\n" + "]>\n" + "<doc xmlns='http://example.org/baz'>\n" + "&" + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + ";" + "</doc>"; + ExtOption options[] = { + {XCS("foo"), "<!ELEMENT el EMPTY>"}, {XCS("bar"), "<el/>"}, {NULL, NULL}}; + int i; + const int max_realloc_count = 10; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + XML_SetUserData(g_parser, options); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_optioner); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing reallocations"); + else if (i == max_realloc_count) + fail("Parsing failed even at max reallocation count"); +} +END_TEST + +/* Test that when a namespace is passed through the context mechanism + * to an external entity parser, the parsers handle reallocation + * failures correctly. The prefix is exactly the right length to + * provoke particular uncommon code paths. + */ +START_TEST(test_nsalloc_realloc_long_context_in_dtd) { + const char *text1 + = "<!DOCTYPE " + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + ":doc [\n" + " <!ENTITY First SYSTEM 'foo/First'>\n" + "]>\n" + "<" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + ":doc xmlns:" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "='foo/Second'>&First;"; + const char *text2 + = "</" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + ":doc>"; + ExtOption options[] = {{XCS("foo/First"), "Hello world"}, {NULL, NULL}}; + int i; + const int max_realloc_count = 20; + + for (i = 0; i < max_realloc_count; i++) { + g_reallocation_count = i; + XML_SetUserData(g_parser, options); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_optioner); + if (_XML_Parse_SINGLE_BYTES(g_parser, text1, (int)strlen(text1), XML_FALSE) + != XML_STATUS_ERROR + && _XML_Parse_SINGLE_BYTES(g_parser, text2, (int)strlen(text2), + XML_TRUE) + != XML_STATUS_ERROR) + break; + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing reallocations"); + else if (i == max_realloc_count) + fail("Parsing failed even at max reallocation count"); +} +END_TEST + +START_TEST(test_nsalloc_long_default_in_ext) { + const char *text + = "<!DOCTYPE doc [\n" + " <!ATTLIST e a1 CDATA '" + /* 64 characters per line */ + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" + "'>\n" + " <!ENTITY x SYSTEM 'foo'>\n" + "]>\n" + "<doc>&x;</doc>"; + ExtOption options[] = {{XCS("foo"), "<e/>"}, {NULL, NULL}}; + int i; + const int max_alloc_count = 50; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetUserData(g_parser, options); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_optioner); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing allocations"); + else if (i == max_alloc_count) + fail("Parsing failed even at max allocation count"); +} +END_TEST + +START_TEST(test_nsalloc_long_systemid_in_ext) { + const char *text + = "<!DOCTYPE doc SYSTEM 'foo' [\n" + " <!ENTITY en SYSTEM '" + /* 64 characters per line */ + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" + "'>\n" + "]>\n" + "<doc>&en;</doc>"; + ExtOption options[] = { + {XCS("foo"), "<!ELEMENT e EMPTY>"}, + {/* clang-format off */ + XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") + XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") + XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") + XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") + XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") + XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") + XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") + XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") + XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") + XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") + XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") + XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") + XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") + XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") + XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") + XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/"), + /* clang-format on */ + "<e/>"}, + {NULL, NULL}}; + int i; + const int max_alloc_count = 55; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetUserData(g_parser, options); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_optioner); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Parsing worked despite failing allocations"); + else if (i == max_alloc_count) + fail("Parsing failed even at max allocation count"); +} +END_TEST + +/* Test the effects of allocation failure on parsing an element in a + * namespace. Based on test_nsalloc_long_context. + */ +START_TEST(test_nsalloc_prefixed_element) { + const char *text = "<!DOCTYPE pfx:element SYSTEM 'foo' [\n" + " <!ATTLIST pfx:element baz ID #REQUIRED>\n" + " <!ENTITY en SYSTEM 'bar'>\n" + "]>\n" + "<pfx:element xmlns:pfx='http://example.org/' baz='2'>\n" + "&en;" + "</pfx:element>"; + ExtOption options[] = { + {XCS("foo"), "<!ELEMENT e EMPTY>"}, {XCS("bar"), "<e/>"}, {NULL, NULL}}; + int i; + const int max_alloc_count = 70; + + for (i = 0; i < max_alloc_count; i++) { + g_allocation_count = i; + XML_SetUserData(g_parser, options); + XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); + XML_SetExternalEntityRefHandler(g_parser, external_entity_optioner); + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) + != XML_STATUS_ERROR) + break; + + /* See comment in test_nsalloc_xmlns() */ + nsalloc_teardown(); + nsalloc_setup(); + } + if (i == 0) + fail("Success despite failing allocator"); + else if (i == max_alloc_count) + fail("Failed even at full allocation count"); +} +END_TEST + +void +make_nsalloc_test_case(Suite *s) { + TCase *tc_nsalloc = tcase_create("namespace allocation tests"); + + suite_add_tcase(s, tc_nsalloc); + tcase_add_checked_fixture(tc_nsalloc, nsalloc_setup, nsalloc_teardown); + + tcase_add_test(tc_nsalloc, test_nsalloc_xmlns); + tcase_add_test(tc_nsalloc, test_nsalloc_parse_buffer); + tcase_add_test(tc_nsalloc, test_nsalloc_long_prefix); + tcase_add_test(tc_nsalloc, test_nsalloc_long_uri); + tcase_add_test(tc_nsalloc, test_nsalloc_long_attr); + tcase_add_test(tc_nsalloc, test_nsalloc_long_attr_prefix); + tcase_add_test(tc_nsalloc, test_nsalloc_realloc_attributes); + tcase_add_test(tc_nsalloc, test_nsalloc_long_element); + tcase_add_test(tc_nsalloc, test_nsalloc_realloc_binding_uri); + tcase_add_test(tc_nsalloc, test_nsalloc_realloc_long_prefix); + tcase_add_test(tc_nsalloc, test_nsalloc_realloc_longer_prefix); + tcase_add_test(tc_nsalloc, test_nsalloc_long_namespace); + tcase_add_test(tc_nsalloc, test_nsalloc_less_long_namespace); + tcase_add_test(tc_nsalloc, test_nsalloc_long_context); + tcase_add_test__if_xml_ge(tc_nsalloc, test_nsalloc_realloc_long_context); + tcase_add_test__if_xml_ge(tc_nsalloc, test_nsalloc_realloc_long_context_2); + tcase_add_test__if_xml_ge(tc_nsalloc, test_nsalloc_realloc_long_context_3); + tcase_add_test__if_xml_ge(tc_nsalloc, test_nsalloc_realloc_long_context_4); + tcase_add_test__if_xml_ge(tc_nsalloc, test_nsalloc_realloc_long_context_5); + tcase_add_test__if_xml_ge(tc_nsalloc, test_nsalloc_realloc_long_context_6); + tcase_add_test__if_xml_ge(tc_nsalloc, test_nsalloc_realloc_long_context_7); + tcase_add_test(tc_nsalloc, test_nsalloc_realloc_long_ge_name); + tcase_add_test__if_xml_ge(tc_nsalloc, + test_nsalloc_realloc_long_context_in_dtd); + tcase_add_test__if_xml_ge(tc_nsalloc, test_nsalloc_long_default_in_ext); + tcase_add_test(tc_nsalloc, test_nsalloc_long_systemid_in_ext); + tcase_add_test(tc_nsalloc, test_nsalloc_prefixed_element); +} diff --git a/3rdparty/expat/tests/nsalloc_tests.h b/3rdparty/expat/tests/nsalloc_tests.h new file mode 100644 index 00000000000..026a2a21a95 --- /dev/null +++ b/3rdparty/expat/tests/nsalloc_tests.h @@ -0,0 +1,56 @@ +/* Tests in the "namespace allocation" test case for the Expat test suite + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef XML_NSALLOC_TESTS_H +# define XML_NSALLOC_TESTS_H + +extern void make_nsalloc_test_case(Suite *s); + +#endif /* XML_NSALLOC_TESTS_H */ + +#ifdef __cplusplus +} +#endif diff --git a/3rdparty/expat/tests/nsalloc_tests_cxx.cpp b/3rdparty/expat/tests/nsalloc_tests_cxx.cpp new file mode 100644 index 00000000000..9ba75d1c536 --- /dev/null +++ b/3rdparty/expat/tests/nsalloc_tests_cxx.cpp @@ -0,0 +1,32 @@ +/* C++ compilation harness for the test suite. + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "nsalloc_tests.c" diff --git a/3rdparty/expat/tests/runtests.c b/3rdparty/expat/tests/runtests.c index 2490d86b9ab..5feaaabe226 100644 --- a/3rdparty/expat/tests/runtests.c +++ b/3rdparty/expat/tests/runtests.c @@ -6,8 +6,20 @@ \___/_/\_\ .__/ \__,_|\__| |_| XML parser - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Joe Orton <jorton@redhat.com> + Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Tim Gates <tim.gates@iress.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Copyright (c) 2022 Sean McBride <sean@rogue-research.com> + Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -30,11578 +42,37 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#if defined(NDEBUG) -# undef NDEBUG /* because test suite relies on assert(...) at the moment */ -#endif - -#ifdef HAVE_EXPAT_CONFIG_H -# include <expat_config.h> -#endif +#include "expat_config.h" -#include <assert.h> -#include <stdlib.h> #include <stdio.h> #include <string.h> -#include <stddef.h> /* ptrdiff_t */ -#include <ctype.h> -#include <limits.h> - -#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER < 1600) -/* For vs2003/7.1 up to vs2008/9.0; _MSC_VER 1600 is vs2010/10.0 */ -# if defined(_WIN64) -typedef __int64 intptr_t; -# else -typedef __int32 intptr_t; -# endif -typedef unsigned __int64 uint64_t; -#else -# include <stdint.h> /* intptr_t uint64_t */ -#endif - -#if ! defined(__cplusplus) -# if defined(_MSC_VER) && (_MSC_VER <= 1700) -/* for vs2012/11.0/1700 and earlier Visual Studio compilers */ -# define bool int -# define false 0 -# define true 1 -# else -# include <stdbool.h> -# endif -#endif #include "expat.h" -#include "chardata.h" -#include "structdata.h" -#include "internal.h" /* for UNUSED_P only */ +#include "internal.h" #include "minicheck.h" -#include "memcheck.h" -#include "siphash.h" -#include "ascii.h" /* for ASCII_xxx */ - -#ifdef XML_LARGE_SIZE -# define XML_FMT_INT_MOD "ll" -#else -# define XML_FMT_INT_MOD "l" -#endif - -#ifdef XML_UNICODE_WCHAR_T -# define XML_FMT_CHAR "lc" -# define XML_FMT_STR "ls" -# include <wchar.h> -# define xcstrlen(s) wcslen(s) -# define xcstrcmp(s, t) wcscmp((s), (t)) -# define xcstrncmp(s, t, n) wcsncmp((s), (t), (n)) -# define XCS(s) _XCS(s) -# define _XCS(s) L##s -#else -# ifdef XML_UNICODE -# error "No support for UTF-16 character without wchar_t in tests" -# else -# define XML_FMT_CHAR "c" -# define XML_FMT_STR "s" -# define xcstrlen(s) strlen(s) -# define xcstrcmp(s, t) strcmp((s), (t)) -# define xcstrncmp(s, t, n) strncmp((s), (t), (n)) -# define XCS(s) s -# endif /* XML_UNICODE */ -#endif /* XML_UNICODE_WCHAR_T */ - -static XML_Parser g_parser = NULL; - -static void -tcase_add_test__ifdef_xml_dtd(TCase *tc, tcase_test_function test) { -#ifdef XML_DTD - tcase_add_test(tc, test); -#else - UNUSED_P(tc); - UNUSED_P(test); -#endif -} - -static void -basic_setup(void) { - g_parser = XML_ParserCreate(NULL); - if (g_parser == NULL) - fail("Parser not created."); -} - -static void -basic_teardown(void) { - if (g_parser != NULL) { - XML_ParserFree(g_parser); - g_parser = NULL; - } -} - -/* Generate a failure using the parser state to create an error message; - this should be used when the parser reports an error we weren't - expecting. -*/ -static void -_xml_failure(XML_Parser parser, const char *file, int line) { - char buffer[1024]; - enum XML_Error err = XML_GetErrorCode(parser); - sprintf(buffer, - " %d: %" XML_FMT_STR " (line %" XML_FMT_INT_MOD - "u, offset %" XML_FMT_INT_MOD "u)\n reported from %s, line %d\n", - err, XML_ErrorString(err), XML_GetCurrentLineNumber(parser), - XML_GetCurrentColumnNumber(parser), file, line); - _fail_unless(0, file, line, buffer); -} - -static enum XML_Status -_XML_Parse_SINGLE_BYTES(XML_Parser parser, const char *s, int len, - int isFinal) { - enum XML_Status res = XML_STATUS_ERROR; - int offset = 0; - - if (len == 0) { - return XML_Parse(parser, s, len, isFinal); - } - - for (; offset < len; offset++) { - const int innerIsFinal = (offset == len - 1) && isFinal; - const char c = s[offset]; /* to help out-of-bounds detection */ - res = XML_Parse(parser, &c, sizeof(char), innerIsFinal); - if (res != XML_STATUS_OK) { - return res; - } - } - return res; -} - -#define xml_failure(parser) _xml_failure((parser), __FILE__, __LINE__) - -static void -_expect_failure(const char *text, enum XML_Error errorCode, - const char *errorMessage, const char *file, int lineno) { - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_OK) - /* Hackish use of _fail_unless() macro, but let's us report - the right filename and line number. */ - _fail_unless(0, file, lineno, errorMessage); - if (XML_GetErrorCode(g_parser) != errorCode) - _xml_failure(g_parser, file, lineno); -} - -#define expect_failure(text, errorCode, errorMessage) \ - _expect_failure((text), (errorCode), (errorMessage), __FILE__, __LINE__) - -/* Dummy handlers for when we need to set a handler to tickle a bug, - but it doesn't need to do anything. -*/ -static unsigned long dummy_handler_flags = 0; - -#define DUMMY_START_DOCTYPE_HANDLER_FLAG (1UL << 0) -#define DUMMY_END_DOCTYPE_HANDLER_FLAG (1UL << 1) -#define DUMMY_ENTITY_DECL_HANDLER_FLAG (1UL << 2) -#define DUMMY_NOTATION_DECL_HANDLER_FLAG (1UL << 3) -#define DUMMY_ELEMENT_DECL_HANDLER_FLAG (1UL << 4) -#define DUMMY_ATTLIST_DECL_HANDLER_FLAG (1UL << 5) -#define DUMMY_COMMENT_HANDLER_FLAG (1UL << 6) -#define DUMMY_PI_HANDLER_FLAG (1UL << 7) -#define DUMMY_START_ELEMENT_HANDLER_FLAG (1UL << 8) -#define DUMMY_START_CDATA_HANDLER_FLAG (1UL << 9) -#define DUMMY_END_CDATA_HANDLER_FLAG (1UL << 10) -#define DUMMY_UNPARSED_ENTITY_DECL_HANDLER_FLAG (1UL << 11) -#define DUMMY_START_NS_DECL_HANDLER_FLAG (1UL << 12) -#define DUMMY_END_NS_DECL_HANDLER_FLAG (1UL << 13) -#define DUMMY_START_DOCTYPE_DECL_HANDLER_FLAG (1UL << 14) -#define DUMMY_END_DOCTYPE_DECL_HANDLER_FLAG (1UL << 15) -#define DUMMY_SKIP_HANDLER_FLAG (1UL << 16) -#define DUMMY_DEFAULT_HANDLER_FLAG (1UL << 17) - -static void XMLCALL -dummy_xdecl_handler(void *userData, const XML_Char *version, - const XML_Char *encoding, int standalone) { - UNUSED_P(userData); - UNUSED_P(version); - UNUSED_P(encoding); - UNUSED_P(standalone); -} - -static void XMLCALL -dummy_start_doctype_handler(void *userData, const XML_Char *doctypeName, - const XML_Char *sysid, const XML_Char *pubid, - int has_internal_subset) { - UNUSED_P(userData); - UNUSED_P(doctypeName); - UNUSED_P(sysid); - UNUSED_P(pubid); - UNUSED_P(has_internal_subset); - dummy_handler_flags |= DUMMY_START_DOCTYPE_HANDLER_FLAG; -} - -static void XMLCALL -dummy_end_doctype_handler(void *userData) { - UNUSED_P(userData); - dummy_handler_flags |= DUMMY_END_DOCTYPE_HANDLER_FLAG; -} - -static void XMLCALL -dummy_entity_decl_handler(void *userData, const XML_Char *entityName, - int is_parameter_entity, const XML_Char *value, - int value_length, const XML_Char *base, - const XML_Char *systemId, const XML_Char *publicId, - const XML_Char *notationName) { - UNUSED_P(userData); - UNUSED_P(entityName); - UNUSED_P(is_parameter_entity); - UNUSED_P(value); - UNUSED_P(value_length); - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - UNUSED_P(notationName); - dummy_handler_flags |= DUMMY_ENTITY_DECL_HANDLER_FLAG; -} - -static void XMLCALL -dummy_notation_decl_handler(void *userData, const XML_Char *notationName, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - UNUSED_P(userData); - UNUSED_P(notationName); - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - dummy_handler_flags |= DUMMY_NOTATION_DECL_HANDLER_FLAG; -} - -static void XMLCALL -dummy_element_decl_handler(void *userData, const XML_Char *name, - XML_Content *model) { - UNUSED_P(userData); - UNUSED_P(name); - /* The content model must be freed by the handler. Unfortunately - * we cannot pass the parser as the userData because this is used - * with other handlers that require other userData. - */ - XML_FreeContentModel(g_parser, model); - dummy_handler_flags |= DUMMY_ELEMENT_DECL_HANDLER_FLAG; -} - -static void XMLCALL -dummy_attlist_decl_handler(void *userData, const XML_Char *elname, - const XML_Char *attname, const XML_Char *att_type, - const XML_Char *dflt, int isrequired) { - UNUSED_P(userData); - UNUSED_P(elname); - UNUSED_P(attname); - UNUSED_P(att_type); - UNUSED_P(dflt); - UNUSED_P(isrequired); - dummy_handler_flags |= DUMMY_ATTLIST_DECL_HANDLER_FLAG; -} - -static void XMLCALL -dummy_comment_handler(void *userData, const XML_Char *data) { - UNUSED_P(userData); - UNUSED_P(data); - dummy_handler_flags |= DUMMY_COMMENT_HANDLER_FLAG; -} - -static void XMLCALL -dummy_pi_handler(void *userData, const XML_Char *target, const XML_Char *data) { - UNUSED_P(userData); - UNUSED_P(target); - UNUSED_P(data); - dummy_handler_flags |= DUMMY_PI_HANDLER_FLAG; -} - -static void XMLCALL -dummy_start_element(void *userData, const XML_Char *name, - const XML_Char **atts) { - UNUSED_P(userData); - UNUSED_P(name); - UNUSED_P(atts); - dummy_handler_flags |= DUMMY_START_ELEMENT_HANDLER_FLAG; -} - -static void XMLCALL -dummy_end_element(void *userData, const XML_Char *name) { - UNUSED_P(userData); - UNUSED_P(name); -} - -static void XMLCALL -dummy_start_cdata_handler(void *userData) { - UNUSED_P(userData); - dummy_handler_flags |= DUMMY_START_CDATA_HANDLER_FLAG; -} - -static void XMLCALL -dummy_end_cdata_handler(void *userData) { - UNUSED_P(userData); - dummy_handler_flags |= DUMMY_END_CDATA_HANDLER_FLAG; -} - -static void XMLCALL -dummy_cdata_handler(void *userData, const XML_Char *s, int len) { - UNUSED_P(userData); - UNUSED_P(s); - UNUSED_P(len); -} - -static void XMLCALL -dummy_start_namespace_decl_handler(void *userData, const XML_Char *prefix, - const XML_Char *uri) { - UNUSED_P(userData); - UNUSED_P(prefix); - UNUSED_P(uri); - dummy_handler_flags |= DUMMY_START_NS_DECL_HANDLER_FLAG; -} - -static void XMLCALL -dummy_end_namespace_decl_handler(void *userData, const XML_Char *prefix) { - UNUSED_P(userData); - UNUSED_P(prefix); - dummy_handler_flags |= DUMMY_END_NS_DECL_HANDLER_FLAG; -} - -/* This handler is obsolete, but while the code exists we should - * ensure that dealing with the handler is covered by tests. - */ -static void XMLCALL -dummy_unparsed_entity_decl_handler(void *userData, const XML_Char *entityName, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId, - const XML_Char *notationName) { - UNUSED_P(userData); - UNUSED_P(entityName); - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - UNUSED_P(notationName); - dummy_handler_flags |= DUMMY_UNPARSED_ENTITY_DECL_HANDLER_FLAG; -} - -static void XMLCALL -dummy_default_handler(void *userData, const XML_Char *s, int len) { - UNUSED_P(userData); - UNUSED_P(s); - UNUSED_P(len); -} - -static void XMLCALL -dummy_start_doctype_decl_handler(void *userData, const XML_Char *doctypeName, - const XML_Char *sysid, const XML_Char *pubid, - int has_internal_subset) { - UNUSED_P(userData); - UNUSED_P(doctypeName); - UNUSED_P(sysid); - UNUSED_P(pubid); - UNUSED_P(has_internal_subset); - dummy_handler_flags |= DUMMY_START_DOCTYPE_DECL_HANDLER_FLAG; -} - -static void XMLCALL -dummy_end_doctype_decl_handler(void *userData) { - UNUSED_P(userData); - dummy_handler_flags |= DUMMY_END_DOCTYPE_DECL_HANDLER_FLAG; -} - -static void XMLCALL -dummy_skip_handler(void *userData, const XML_Char *entityName, - int is_parameter_entity) { - UNUSED_P(userData); - UNUSED_P(entityName); - UNUSED_P(is_parameter_entity); - dummy_handler_flags |= DUMMY_SKIP_HANDLER_FLAG; -} - -/* Useful external entity handler */ -typedef struct ExtOption { - const XML_Char *system_id; - const char *parse_text; -} ExtOption; - -static int XMLCALL -external_entity_optioner(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - ExtOption *options = (ExtOption *)XML_GetUserData(parser); - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(publicId); - while (options->parse_text != NULL) { - if (! xcstrcmp(systemId, options->system_id)) { - enum XML_Status rc; - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - return XML_STATUS_ERROR; - rc = _XML_Parse_SINGLE_BYTES(ext_parser, options->parse_text, - (int)strlen(options->parse_text), XML_TRUE); - XML_ParserFree(ext_parser); - return rc; - } - options++; - } - fail("No suitable option found"); - return XML_STATUS_ERROR; -} - -/* - * Parameter entity evaluation support. - */ -#define ENTITY_MATCH_FAIL (-1) -#define ENTITY_MATCH_NOT_FOUND (0) -#define ENTITY_MATCH_SUCCESS (1) -static const XML_Char *entity_name_to_match = NULL; -static const XML_Char *entity_value_to_match = NULL; -static int entity_match_flag = ENTITY_MATCH_NOT_FOUND; - -static void XMLCALL -param_entity_match_handler(void *userData, const XML_Char *entityName, - int is_parameter_entity, const XML_Char *value, - int value_length, const XML_Char *base, - const XML_Char *systemId, const XML_Char *publicId, - const XML_Char *notationName) { - UNUSED_P(userData); - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - UNUSED_P(notationName); - if (! is_parameter_entity || entity_name_to_match == NULL - || entity_value_to_match == NULL) { - return; - } - if (! xcstrcmp(entityName, entity_name_to_match)) { - /* The cast here is safe because we control the horizontal and - * the vertical, and we therefore know our strings are never - * going to overflow an int. - */ - if (value_length != (int)xcstrlen(entity_value_to_match) - || xcstrncmp(value, entity_value_to_match, value_length)) { - entity_match_flag = ENTITY_MATCH_FAIL; - } else { - entity_match_flag = ENTITY_MATCH_SUCCESS; - } - } - /* Else leave the match flag alone */ -} - -/* - * Character & encoding tests. - */ - -START_TEST(test_nul_byte) { - char text[] = "<doc>\0</doc>"; - - /* test that a NUL byte (in US-ASCII data) is an error */ - if (_XML_Parse_SINGLE_BYTES(g_parser, text, sizeof(text) - 1, XML_TRUE) - == XML_STATUS_OK) - fail("Parser did not report error on NUL-byte."); - if (XML_GetErrorCode(g_parser) != XML_ERROR_INVALID_TOKEN) - xml_failure(g_parser); -} -END_TEST - -START_TEST(test_u0000_char) { - /* test that a NUL byte (in US-ASCII data) is an error */ - expect_failure("<doc>�</doc>", XML_ERROR_BAD_CHAR_REF, - "Parser did not report error on NUL-byte."); -} -END_TEST - -START_TEST(test_siphash_self) { - if (! sip24_valid()) - fail("SipHash self-test failed"); -} -END_TEST - -START_TEST(test_siphash_spec) { - /* https://131002.net/siphash/siphash.pdf (page 19, "Test values") */ - const char message[] = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09" - "\x0a\x0b\x0c\x0d\x0e"; - const size_t len = sizeof(message) - 1; - const uint64_t expected = _SIP_ULL(0xa129ca61U, 0x49be45e5U); - struct siphash state; - struct sipkey key; - - sip_tokey(&key, "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09" - "\x0a\x0b\x0c\x0d\x0e\x0f"); - sip24_init(&state, &key); - - /* Cover spread across calls */ - sip24_update(&state, message, 4); - sip24_update(&state, message + 4, len - 4); - - /* Cover null length */ - sip24_update(&state, message, 0); - - if (sip24_final(&state) != expected) - fail("sip24_final failed spec test\n"); - - /* Cover wrapper */ - if (siphash24(message, len, &key) != expected) - fail("siphash24 failed spec test\n"); -} -END_TEST - -START_TEST(test_bom_utf8) { - /* This test is really just making sure we don't core on a UTF-8 BOM. */ - const char *text = "\357\273\277<e/>"; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -START_TEST(test_bom_utf16_be) { - char text[] = "\376\377\0<\0e\0/\0>"; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -START_TEST(test_bom_utf16_le) { - char text[] = "\377\376<\0e\0/\0>\0"; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Parse whole buffer at once to exercise a different code path */ -START_TEST(test_nobom_utf16_le) { - char text[] = " \0<\0e\0/\0>\0"; - - if (XML_Parse(g_parser, text, sizeof(text) - 1, XML_TRUE) == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -static void XMLCALL -accumulate_characters(void *userData, const XML_Char *s, int len) { - CharData_AppendXMLChars((CharData *)userData, s, len); -} - -static void XMLCALL -accumulate_attribute(void *userData, const XML_Char *name, - const XML_Char **atts) { - CharData *storage = (CharData *)userData; - UNUSED_P(name); - /* Check there are attributes to deal with */ - if (atts == NULL) - return; - - while (storage->count < 0 && atts[0] != NULL) { - /* "accumulate" the value of the first attribute we see */ - CharData_AppendXMLChars(storage, atts[1], -1); - atts += 2; - } -} - -static void -_run_character_check(const char *text, const XML_Char *expected, - const char *file, int line) { - CharData storage; - - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetCharacterDataHandler(g_parser, accumulate_characters); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - _xml_failure(g_parser, file, line); - CharData_CheckXMLChars(&storage, expected); -} - -#define run_character_check(text, expected) \ - _run_character_check(text, expected, __FILE__, __LINE__) - -static void -_run_attribute_check(const char *text, const XML_Char *expected, - const char *file, int line) { - CharData storage; - - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetStartElementHandler(g_parser, accumulate_attribute); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - _xml_failure(g_parser, file, line); - CharData_CheckXMLChars(&storage, expected); -} - -#define run_attribute_check(text, expected) \ - _run_attribute_check(text, expected, __FILE__, __LINE__) - -typedef struct ExtTest { - const char *parse_text; - const XML_Char *encoding; - CharData *storage; -} ExtTest; - -static void XMLCALL -ext_accumulate_characters(void *userData, const XML_Char *s, int len) { - ExtTest *test_data = (ExtTest *)userData; - accumulate_characters(test_data->storage, s, len); -} - -static void -_run_ext_character_check(const char *text, ExtTest *test_data, - const XML_Char *expected, const char *file, int line) { - CharData *const storage = (CharData *)malloc(sizeof(CharData)); - - CharData_Init(storage); - test_data->storage = storage; - XML_SetUserData(g_parser, test_data); - XML_SetCharacterDataHandler(g_parser, ext_accumulate_characters); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - _xml_failure(g_parser, file, line); - CharData_CheckXMLChars(storage, expected); - - free(storage); -} - -#define run_ext_character_check(text, test_data, expected) \ - _run_ext_character_check(text, test_data, expected, __FILE__, __LINE__) - -/* Regression test for SF bug #491986. */ -START_TEST(test_danish_latin1) { - const char *text = "<?xml version='1.0' encoding='iso-8859-1'?>\n" - "<e>J\xF8rgen \xE6\xF8\xE5\xC6\xD8\xC5</e>"; -#ifdef XML_UNICODE - const XML_Char *expected - = XCS("J\x00f8rgen \x00e6\x00f8\x00e5\x00c6\x00d8\x00c5"); -#else - const XML_Char *expected - = XCS("J\xC3\xB8rgen \xC3\xA6\xC3\xB8\xC3\xA5\xC3\x86\xC3\x98\xC3\x85"); -#endif - run_character_check(text, expected); -} -END_TEST - -/* Regression test for SF bug #514281. */ -START_TEST(test_french_charref_hexidecimal) { - const char *text = "<?xml version='1.0' encoding='iso-8859-1'?>\n" - "<doc>éèàçêÈ</doc>"; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x00e9\x00e8\x00e0\x00e7\x00ea\x00c8"); -#else - const XML_Char *expected - = XCS("\xC3\xA9\xC3\xA8\xC3\xA0\xC3\xA7\xC3\xAA\xC3\x88"); -#endif - run_character_check(text, expected); -} -END_TEST - -START_TEST(test_french_charref_decimal) { - const char *text = "<?xml version='1.0' encoding='iso-8859-1'?>\n" - "<doc>éèàçêÈ</doc>"; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x00e9\x00e8\x00e0\x00e7\x00ea\x00c8"); -#else - const XML_Char *expected - = XCS("\xC3\xA9\xC3\xA8\xC3\xA0\xC3\xA7\xC3\xAA\xC3\x88"); -#endif - run_character_check(text, expected); -} -END_TEST - -START_TEST(test_french_latin1) { - const char *text = "<?xml version='1.0' encoding='iso-8859-1'?>\n" - "<doc>\xE9\xE8\xE0\xE7\xEa\xC8</doc>"; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x00e9\x00e8\x00e0\x00e7\x00ea\x00c8"); -#else - const XML_Char *expected - = XCS("\xC3\xA9\xC3\xA8\xC3\xA0\xC3\xA7\xC3\xAA\xC3\x88"); -#endif - run_character_check(text, expected); -} -END_TEST - -START_TEST(test_french_utf8) { - const char *text = "<?xml version='1.0' encoding='utf-8'?>\n" - "<doc>\xC3\xA9</doc>"; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x00e9"); -#else - const XML_Char *expected = XCS("\xC3\xA9"); -#endif - run_character_check(text, expected); -} -END_TEST - -/* Regression test for SF bug #600479. - XXX There should be a test that exercises all legal XML Unicode - characters as PCDATA and attribute value content, and XML Name - characters as part of element and attribute names. -*/ -START_TEST(test_utf8_false_rejection) { - const char *text = "<doc>\xEF\xBA\xBF</doc>"; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\xfebf"); -#else - const XML_Char *expected = XCS("\xEF\xBA\xBF"); -#endif - run_character_check(text, expected); -} -END_TEST - -/* Regression test for SF bug #477667. - This test assures that any 8-bit character followed by a 7-bit - character will not be mistakenly interpreted as a valid UTF-8 - sequence. -*/ -START_TEST(test_illegal_utf8) { - char text[100]; - int i; - - for (i = 128; i <= 255; ++i) { - sprintf(text, "<e>%ccd</e>", i); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_OK) { - sprintf(text, "expected token error for '%c' (ordinal %d) in UTF-8 text", - i, i); - fail(text); - } else if (XML_GetErrorCode(g_parser) != XML_ERROR_INVALID_TOKEN) - xml_failure(g_parser); - /* Reset the parser since we use the same parser repeatedly. */ - XML_ParserReset(g_parser, NULL); - } -} -END_TEST - -/* Examples, not masks: */ -#define UTF8_LEAD_1 "\x7f" /* 0b01111111 */ -#define UTF8_LEAD_2 "\xdf" /* 0b11011111 */ -#define UTF8_LEAD_3 "\xef" /* 0b11101111 */ -#define UTF8_LEAD_4 "\xf7" /* 0b11110111 */ -#define UTF8_FOLLOW "\xbf" /* 0b10111111 */ - -START_TEST(test_utf8_auto_align) { - struct TestCase { - ptrdiff_t expectedMovementInChars; - const char *input; - }; - - struct TestCase cases[] = { - {00, ""}, - - {00, UTF8_LEAD_1}, - - {-1, UTF8_LEAD_2}, - {00, UTF8_LEAD_2 UTF8_FOLLOW}, - - {-1, UTF8_LEAD_3}, - {-2, UTF8_LEAD_3 UTF8_FOLLOW}, - {00, UTF8_LEAD_3 UTF8_FOLLOW UTF8_FOLLOW}, - - {-1, UTF8_LEAD_4}, - {-2, UTF8_LEAD_4 UTF8_FOLLOW}, - {-3, UTF8_LEAD_4 UTF8_FOLLOW UTF8_FOLLOW}, - {00, UTF8_LEAD_4 UTF8_FOLLOW UTF8_FOLLOW UTF8_FOLLOW}, - }; - - size_t i = 0; - bool success = true; - for (; i < sizeof(cases) / sizeof(*cases); i++) { - const char *fromLim = cases[i].input + strlen(cases[i].input); - const char *const fromLimInitially = fromLim; - ptrdiff_t actualMovementInChars; - - _INTERNAL_trim_to_complete_utf8_characters(cases[i].input, &fromLim); - - actualMovementInChars = (fromLim - fromLimInitially); - if (actualMovementInChars != cases[i].expectedMovementInChars) { - size_t j = 0; - success = false; - printf("[-] UTF-8 case %2u: Expected movement by %2d chars" - ", actually moved by %2d chars: \"", - (unsigned)(i + 1), (int)cases[i].expectedMovementInChars, - (int)actualMovementInChars); - for (; j < strlen(cases[i].input); j++) { - printf("\\x%02x", (unsigned char)cases[i].input[j]); - } - printf("\"\n"); - } - } - - if (! success) { - fail("UTF-8 auto-alignment is not bullet-proof\n"); - } -} -END_TEST - -START_TEST(test_utf16) { - /* <?xml version="1.0" encoding="UTF-16"?> - * <doc a='123'>some {A} text</doc> - * - * where {A} is U+FF21, FULLWIDTH LATIN CAPITAL LETTER A - */ - char text[] - = "\000<\000?\000x\000m\000\154\000 \000v\000e\000r\000s\000i\000o" - "\000n\000=\000'\0001\000.\000\060\000'\000 \000e\000n\000c\000o" - "\000d\000i\000n\000g\000=\000'\000U\000T\000F\000-\0001\000\066" - "\000'\000?\000>\000\n" - "\000<\000d\000o\000c\000 \000a\000=\000'\0001\0002\0003\000'\000>" - "\000s\000o\000m\000e\000 \xff\x21\000 \000t\000e\000x\000t\000" - "<\000/\000d\000o\000c\000>"; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("some \xff21 text"); -#else - const XML_Char *expected = XCS("some \357\274\241 text"); -#endif - CharData storage; - - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetCharacterDataHandler(g_parser, accumulate_characters); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_utf16_le_epilog_newline) { - unsigned int first_chunk_bytes = 17; - char text[] = "\xFF\xFE" /* BOM */ - "<\000e\000/\000>\000" /* document element */ - "\r\000\n\000\r\000\n\000"; /* epilog */ - - if (first_chunk_bytes >= sizeof(text) - 1) - fail("bad value of first_chunk_bytes"); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, first_chunk_bytes, XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - else { - enum XML_Status rc; - rc = _XML_Parse_SINGLE_BYTES(g_parser, text + first_chunk_bytes, - sizeof(text) - first_chunk_bytes - 1, - XML_TRUE); - if (rc == XML_STATUS_ERROR) - xml_failure(g_parser); - } -} -END_TEST - -/* Test that an outright lie in the encoding is faulted */ -START_TEST(test_not_utf16) { - const char *text = "<?xml version='1.0' encoding='utf-16'?>" - "<doc>Hi</doc>"; - - /* Use a handler to provoke the appropriate code paths */ - XML_SetXmlDeclHandler(g_parser, dummy_xdecl_handler); - expect_failure(text, XML_ERROR_INCORRECT_ENCODING, - "UTF-16 declared in UTF-8 not faulted"); -} -END_TEST - -/* Test that an unknown encoding is rejected */ -START_TEST(test_bad_encoding) { - const char *text = "<doc>Hi</doc>"; - - if (! XML_SetEncoding(g_parser, XCS("unknown-encoding"))) - fail("XML_SetEncoding failed"); - expect_failure(text, XML_ERROR_UNKNOWN_ENCODING, - "Unknown encoding not faulted"); -} -END_TEST - -/* Regression test for SF bug #481609, #774028. */ -START_TEST(test_latin1_umlauts) { - const char *text - = "<?xml version='1.0' encoding='iso-8859-1'?>\n" - "<e a='\xE4 \xF6 \xFC ä ö ü ä ö ü >'\n" - " >\xE4 \xF6 \xFC ä ö ü ä ö ü ></e>"; -#ifdef XML_UNICODE - /* Expected results in UTF-16 */ - const XML_Char *expected = XCS("\x00e4 \x00f6 \x00fc ") - XCS("\x00e4 \x00f6 \x00fc ") XCS("\x00e4 \x00f6 \x00fc >"); -#else - /* Expected results in UTF-8 */ - const XML_Char *expected = XCS("\xC3\xA4 \xC3\xB6 \xC3\xBC ") - XCS("\xC3\xA4 \xC3\xB6 \xC3\xBC ") XCS("\xC3\xA4 \xC3\xB6 \xC3\xBC >"); -#endif - - run_character_check(text, expected); - XML_ParserReset(g_parser, NULL); - run_attribute_check(text, expected); - /* Repeat with a default handler */ - XML_ParserReset(g_parser, NULL); - XML_SetDefaultHandler(g_parser, dummy_default_handler); - run_character_check(text, expected); - XML_ParserReset(g_parser, NULL); - XML_SetDefaultHandler(g_parser, dummy_default_handler); - run_attribute_check(text, expected); -} -END_TEST - -/* Test that an element name with a 4-byte UTF-8 character is rejected */ -START_TEST(test_long_utf8_character) { - const char *text - = "<?xml version='1.0' encoding='utf-8'?>\n" - /* 0xf0 0x90 0x80 0x80 = U+10000, the first Linear B character */ - "<do\xf0\x90\x80\x80/>"; - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "4-byte UTF-8 character in element name not faulted"); -} -END_TEST - -/* Test that a long latin-1 attribute (too long to convert in one go) - * is correctly converted - */ -START_TEST(test_long_latin1_attribute) { - const char *text - = "<?xml version='1.0' encoding='iso-8859-1'?>\n" - "<doc att='" - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - /* Last character splits across a buffer boundary */ - "\xe4'>\n</doc>"; - - const XML_Char *expected = - /* 64 characters per line */ - /* clang-format off */ - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO") - /* clang-format on */ -#ifdef XML_UNICODE - XCS("\x00e4"); -#else - XCS("\xc3\xa4"); -#endif - - run_attribute_check(text, expected); -} -END_TEST - -/* Test that a long ASCII attribute (too long to convert in one go) - * is correctly converted - */ -START_TEST(test_long_ascii_attribute) { - const char *text - = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<doc att='" - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "01234'>\n</doc>"; - const XML_Char *expected = - /* 64 characters per line */ - /* clang-format off */ - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("01234"); - /* clang-format on */ - - run_attribute_check(text, expected); -} -END_TEST - -/* Regression test #1 for SF bug #653180. */ -START_TEST(test_line_number_after_parse) { - const char *text = "<tag>\n" - "\n" - "\n</tag>"; - XML_Size lineno; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - lineno = XML_GetCurrentLineNumber(g_parser); - if (lineno != 4) { - char buffer[100]; - sprintf(buffer, "expected 4 lines, saw %" XML_FMT_INT_MOD "u", lineno); - fail(buffer); - } -} -END_TEST - -/* Regression test #2 for SF bug #653180. */ -START_TEST(test_column_number_after_parse) { - const char *text = "<tag></tag>"; - XML_Size colno; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - colno = XML_GetCurrentColumnNumber(g_parser); - if (colno != 11) { - char buffer[100]; - sprintf(buffer, "expected 11 columns, saw %" XML_FMT_INT_MOD "u", colno); - fail(buffer); - } -} -END_TEST - -#define STRUCT_START_TAG 0 -#define STRUCT_END_TAG 1 -static void XMLCALL -start_element_event_handler2(void *userData, const XML_Char *name, - const XML_Char **attr) { - StructData *storage = (StructData *)userData; - UNUSED_P(attr); - StructData_AddItem(storage, name, XML_GetCurrentColumnNumber(g_parser), - XML_GetCurrentLineNumber(g_parser), STRUCT_START_TAG); -} - -static void XMLCALL -end_element_event_handler2(void *userData, const XML_Char *name) { - StructData *storage = (StructData *)userData; - StructData_AddItem(storage, name, XML_GetCurrentColumnNumber(g_parser), - XML_GetCurrentLineNumber(g_parser), STRUCT_END_TAG); -} - -/* Regression test #3 for SF bug #653180. */ -START_TEST(test_line_and_column_numbers_inside_handlers) { - const char *text = "<a>\n" /* Unix end-of-line */ - " <b>\r\n" /* Windows end-of-line */ - " <c/>\r" /* Mac OS end-of-line */ - " </b>\n" - " <d>\n" - " <f/>\n" - " </d>\n" - "</a>"; - const StructDataEntry expected[] - = {{XCS("a"), 0, 1, STRUCT_START_TAG}, {XCS("b"), 2, 2, STRUCT_START_TAG}, - {XCS("c"), 4, 3, STRUCT_START_TAG}, {XCS("c"), 8, 3, STRUCT_END_TAG}, - {XCS("b"), 2, 4, STRUCT_END_TAG}, {XCS("d"), 2, 5, STRUCT_START_TAG}, - {XCS("f"), 4, 6, STRUCT_START_TAG}, {XCS("f"), 8, 6, STRUCT_END_TAG}, - {XCS("d"), 2, 7, STRUCT_END_TAG}, {XCS("a"), 0, 8, STRUCT_END_TAG}}; - const int expected_count = sizeof(expected) / sizeof(StructDataEntry); - StructData storage; - - StructData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetStartElementHandler(g_parser, start_element_event_handler2); - XML_SetEndElementHandler(g_parser, end_element_event_handler2); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - - StructData_CheckItems(&storage, expected, expected_count); - StructData_Dispose(&storage); -} -END_TEST - -/* Regression test #4 for SF bug #653180. */ -START_TEST(test_line_number_after_error) { - const char *text = "<a>\n" - " <b>\n" - " </a>"; /* missing </b> */ - XML_Size lineno; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) - != XML_STATUS_ERROR) - fail("Expected a parse error"); - - lineno = XML_GetCurrentLineNumber(g_parser); - if (lineno != 3) { - char buffer[100]; - sprintf(buffer, "expected 3 lines, saw %" XML_FMT_INT_MOD "u", lineno); - fail(buffer); - } -} -END_TEST - -/* Regression test #5 for SF bug #653180. */ -START_TEST(test_column_number_after_error) { - const char *text = "<a>\n" - " <b>\n" - " </a>"; /* missing </b> */ - XML_Size colno; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) - != XML_STATUS_ERROR) - fail("Expected a parse error"); - - colno = XML_GetCurrentColumnNumber(g_parser); - if (colno != 4) { - char buffer[100]; - sprintf(buffer, "expected 4 columns, saw %" XML_FMT_INT_MOD "u", colno); - fail(buffer); - } -} -END_TEST - -/* Regression test for SF bug #478332. */ -START_TEST(test_really_long_lines) { - /* This parses an input line longer than INIT_DATA_BUF_SIZE - characters long (defined to be 1024 in xmlparse.c). We take a - really cheesy approach to building the input buffer, because - this avoids writing bugs in buffer-filling code. - */ - const char *text - = "<e>" - /* 64 chars */ - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - /* until we have at least 1024 characters on the line: */ - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "</e>"; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test cdata processing across a buffer boundary */ -START_TEST(test_really_long_encoded_lines) { - /* As above, except that we want to provoke an output buffer - * overflow with a non-trivial encoding. For this we need to pass - * the whole cdata in one go, not byte-by-byte. - */ - void *buffer; - const char *text - = "<?xml version='1.0' encoding='iso-8859-1'?>" - "<e>" - /* 64 chars */ - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - /* until we have at least 1024 characters on the line: */ - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+" - "</e>"; - int parse_len = (int)strlen(text); - - /* Need a cdata handler to provoke the code path we want to test */ - XML_SetCharacterDataHandler(g_parser, dummy_cdata_handler); - buffer = XML_GetBuffer(g_parser, parse_len); - if (buffer == NULL) - fail("Could not allocate parse buffer"); - assert(buffer != NULL); - memcpy(buffer, text, parse_len); - if (XML_ParseBuffer(g_parser, parse_len, XML_TRUE) == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* - * Element event tests. - */ - -static void XMLCALL -start_element_event_handler(void *userData, const XML_Char *name, - const XML_Char **atts) { - UNUSED_P(atts); - CharData_AppendXMLChars((CharData *)userData, name, -1); -} - -static void XMLCALL -end_element_event_handler(void *userData, const XML_Char *name) { - CharData *storage = (CharData *)userData; - CharData_AppendXMLChars(storage, XCS("/"), 1); - CharData_AppendXMLChars(storage, name, -1); -} - -START_TEST(test_end_element_events) { - const char *text = "<a><b><c/></b><d><f/></d></a>"; - const XML_Char *expected = XCS("/c/b/f/d/a"); - CharData storage; - - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetEndElementHandler(g_parser, end_element_event_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* - * Attribute tests. - */ - -/* Helpers used by the following test; this checks any "attr" and "refs" - attributes to make sure whitespace has been normalized. - - Return true if whitespace has been normalized in a string, using - the rules for attribute value normalization. The 'is_cdata' flag - is needed since CDATA attributes don't need to have multiple - whitespace characters collapsed to a single space, while other - attribute data types do. (Section 3.3.3 of the recommendation.) -*/ -static int -is_whitespace_normalized(const XML_Char *s, int is_cdata) { - int blanks = 0; - int at_start = 1; - while (*s) { - if (*s == XCS(' ')) - ++blanks; - else if (*s == XCS('\t') || *s == XCS('\n') || *s == XCS('\r')) - return 0; - else { - if (at_start) { - at_start = 0; - if (blanks && ! is_cdata) - /* illegal leading blanks */ - return 0; - } else if (blanks > 1 && ! is_cdata) - return 0; - blanks = 0; - } - ++s; - } - if (blanks && ! is_cdata) - return 0; - return 1; -} - -/* Check the attribute whitespace checker: */ -static void -testhelper_is_whitespace_normalized(void) { - assert(is_whitespace_normalized(XCS("abc"), 0)); - assert(is_whitespace_normalized(XCS("abc"), 1)); - assert(is_whitespace_normalized(XCS("abc def ghi"), 0)); - assert(is_whitespace_normalized(XCS("abc def ghi"), 1)); - assert(! is_whitespace_normalized(XCS(" abc def ghi"), 0)); - assert(is_whitespace_normalized(XCS(" abc def ghi"), 1)); - assert(! is_whitespace_normalized(XCS("abc def ghi"), 0)); - assert(is_whitespace_normalized(XCS("abc def ghi"), 1)); - assert(! is_whitespace_normalized(XCS("abc def ghi "), 0)); - assert(is_whitespace_normalized(XCS("abc def ghi "), 1)); - assert(! is_whitespace_normalized(XCS(" "), 0)); - assert(is_whitespace_normalized(XCS(" "), 1)); - assert(! is_whitespace_normalized(XCS("\t"), 0)); - assert(! is_whitespace_normalized(XCS("\t"), 1)); - assert(! is_whitespace_normalized(XCS("\n"), 0)); - assert(! is_whitespace_normalized(XCS("\n"), 1)); - assert(! is_whitespace_normalized(XCS("\r"), 0)); - assert(! is_whitespace_normalized(XCS("\r"), 1)); - assert(! is_whitespace_normalized(XCS("abc\t def"), 1)); -} - -static void XMLCALL -check_attr_contains_normalized_whitespace(void *userData, const XML_Char *name, - const XML_Char **atts) { - int i; - UNUSED_P(userData); - UNUSED_P(name); - for (i = 0; atts[i] != NULL; i += 2) { - const XML_Char *attrname = atts[i]; - const XML_Char *value = atts[i + 1]; - if (xcstrcmp(XCS("attr"), attrname) == 0 - || xcstrcmp(XCS("ents"), attrname) == 0 - || xcstrcmp(XCS("refs"), attrname) == 0) { - if (! is_whitespace_normalized(value, 0)) { - char buffer[256]; - sprintf(buffer, - "attribute value not normalized: %" XML_FMT_STR - "='%" XML_FMT_STR "'", - attrname, value); - fail(buffer); - } - } - } -} - -START_TEST(test_attr_whitespace_normalization) { - const char *text - = "<!DOCTYPE doc [\n" - " <!ATTLIST doc\n" - " attr NMTOKENS #REQUIRED\n" - " ents ENTITIES #REQUIRED\n" - " refs IDREFS #REQUIRED>\n" - "]>\n" - "<doc attr=' a b c\t\td\te\t' refs=' id-1 \t id-2\t\t' \n" - " ents=' ent-1 \t\r\n" - " ent-2 ' >\n" - " <e id='id-1'/>\n" - " <e id='id-2'/>\n" - "</doc>"; - - XML_SetStartElementHandler(g_parser, - check_attr_contains_normalized_whitespace); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* - * XML declaration tests. - */ - -START_TEST(test_xmldecl_misplaced) { - expect_failure("\n" - "<?xml version='1.0'?>\n" - "<a/>", - XML_ERROR_MISPLACED_XML_PI, - "failed to report misplaced XML declaration"); -} -END_TEST - -START_TEST(test_xmldecl_invalid) { - expect_failure("<?xml version='1.0' \xc3\xa7?>\n<doc/>", XML_ERROR_XML_DECL, - "Failed to report invalid XML declaration"); -} -END_TEST - -START_TEST(test_xmldecl_missing_attr) { - expect_failure("<?xml ='1.0'?>\n<doc/>\n", XML_ERROR_XML_DECL, - "Failed to report missing XML declaration attribute"); -} -END_TEST - -START_TEST(test_xmldecl_missing_value) { - expect_failure("<?xml version='1.0' encoding='us-ascii' standalone?>\n" - "<doc/>", - XML_ERROR_XML_DECL, - "Failed to report missing attribute value"); -} -END_TEST - -/* Regression test for SF bug #584832. */ -static int XMLCALL -UnknownEncodingHandler(void *data, const XML_Char *encoding, - XML_Encoding *info) { - UNUSED_P(data); - if (xcstrcmp(encoding, XCS("unsupported-encoding")) == 0) { - int i; - for (i = 0; i < 256; ++i) - info->map[i] = i; - info->data = NULL; - info->convert = NULL; - info->release = NULL; - return XML_STATUS_OK; - } - return XML_STATUS_ERROR; -} - -START_TEST(test_unknown_encoding_internal_entity) { - const char *text = "<?xml version='1.0' encoding='unsupported-encoding'?>\n" - "<!DOCTYPE test [<!ENTITY foo 'bar'>]>\n" - "<test a='&foo;'/>"; - - XML_SetUnknownEncodingHandler(g_parser, UnknownEncodingHandler, NULL); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test unrecognised encoding handler */ -static void -dummy_release(void *data) { - UNUSED_P(data); -} - -static int XMLCALL -UnrecognisedEncodingHandler(void *data, const XML_Char *encoding, - XML_Encoding *info) { - UNUSED_P(data); - UNUSED_P(encoding); - info->data = NULL; - info->convert = NULL; - info->release = dummy_release; - return XML_STATUS_ERROR; -} - -START_TEST(test_unrecognised_encoding_internal_entity) { - const char *text = "<?xml version='1.0' encoding='unsupported-encoding'?>\n" - "<!DOCTYPE test [<!ENTITY foo 'bar'>]>\n" - "<test a='&foo;'/>"; - - XML_SetUnknownEncodingHandler(g_parser, UnrecognisedEncodingHandler, NULL); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - fail("Unrecognised encoding not rejected"); -} -END_TEST - -/* Regression test for SF bug #620106. */ -static int XMLCALL -external_entity_loader(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - ExtTest *test_data = (ExtTest *)XML_GetUserData(parser); - XML_Parser extparser; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - extparser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (extparser == NULL) - fail("Could not create external entity parser."); - if (test_data->encoding != NULL) { - if (! XML_SetEncoding(extparser, test_data->encoding)) - fail("XML_SetEncoding() ignored for external entity"); - } - if (_XML_Parse_SINGLE_BYTES(extparser, test_data->parse_text, - (int)strlen(test_data->parse_text), XML_TRUE) - == XML_STATUS_ERROR) { - xml_failure(extparser); - return XML_STATUS_ERROR; - } - XML_ParserFree(extparser); - return XML_STATUS_OK; -} - -START_TEST(test_ext_entity_set_encoding) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - ExtTest test_data - = {/* This text says it's an unsupported encoding, but it's really - UTF-8, which we tell Expat using XML_SetEncoding(). - */ - "<?xml encoding='iso-8859-3'?>\xC3\xA9", XCS("utf-8"), NULL}; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x00e9"); -#else - const XML_Char *expected = XCS("\xc3\xa9"); -#endif - - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); - run_ext_character_check(text, &test_data, expected); -} -END_TEST - -/* Test external entities with no handler */ -START_TEST(test_ext_entity_no_handler) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - - XML_SetDefaultHandler(g_parser, dummy_default_handler); - run_character_check(text, XCS("")); -} -END_TEST - -/* Test UTF-8 BOM is accepted */ -START_TEST(test_ext_entity_set_bom) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - ExtTest test_data = {"\xEF\xBB\xBF" /* BOM */ - "<?xml encoding='iso-8859-3'?>" - "\xC3\xA9", - XCS("utf-8"), NULL}; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x00e9"); -#else - const XML_Char *expected = XCS("\xc3\xa9"); -#endif - - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); - run_ext_character_check(text, &test_data, expected); -} -END_TEST - -/* Test that bad encodings are faulted */ -typedef struct ext_faults { - const char *parse_text; - const char *fail_text; - const XML_Char *encoding; - enum XML_Error error; -} ExtFaults; - -static int XMLCALL -external_entity_faulter(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - XML_Parser ext_parser; - ExtFaults *fault = (ExtFaults *)XML_GetUserData(parser); - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - if (fault->encoding != NULL) { - if (! XML_SetEncoding(ext_parser, fault->encoding)) - fail("XML_SetEncoding failed"); - } - if (_XML_Parse_SINGLE_BYTES(ext_parser, fault->parse_text, - (int)strlen(fault->parse_text), XML_TRUE) - != XML_STATUS_ERROR) - fail(fault->fail_text); - if (XML_GetErrorCode(ext_parser) != fault->error) - xml_failure(ext_parser); - - XML_ParserFree(ext_parser); - return XML_STATUS_ERROR; -} - -START_TEST(test_ext_entity_bad_encoding) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - ExtFaults fault - = {"<?xml encoding='iso-8859-3'?>u", "Unsupported encoding not faulted", - XCS("unknown"), XML_ERROR_UNKNOWN_ENCODING}; - - XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter); - XML_SetUserData(g_parser, &fault); - expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, - "Bad encoding should not have been accepted"); -} -END_TEST - -/* Try handing an invalid encoding to an external entity parser */ -START_TEST(test_ext_entity_bad_encoding_2) { - const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc>&entity;</doc>"; - ExtFaults fault - = {"<!ELEMENT doc (#PCDATA)*>", "Unknown encoding not faulted", - XCS("unknown-encoding"), XML_ERROR_UNKNOWN_ENCODING}; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter); - XML_SetUserData(g_parser, &fault); - expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, - "Bad encoding not faulted in external entity handler"); -} -END_TEST - -/* Test that no error is reported for unknown entities if we don't - read an external subset. This was fixed in Expat 1.95.5. -*/ -START_TEST(test_wfc_undeclared_entity_unread_external_subset) { - const char *text = "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc>&entity;</doc>"; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test that an error is reported for unknown entities if we don't - have an external subset. -*/ -START_TEST(test_wfc_undeclared_entity_no_external_subset) { - expect_failure("<doc>&entity;</doc>", XML_ERROR_UNDEFINED_ENTITY, - "Parser did not report undefined entity w/out a DTD."); -} -END_TEST - -/* Test that an error is reported for unknown entities if we don't - read an external subset, but have been declared standalone. -*/ -START_TEST(test_wfc_undeclared_entity_standalone) { - const char *text - = "<?xml version='1.0' encoding='us-ascii' standalone='yes'?>\n" - "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc>&entity;</doc>"; - - expect_failure(text, XML_ERROR_UNDEFINED_ENTITY, - "Parser did not report undefined entity (standalone)."); -} -END_TEST - -/* Test that an error is reported for unknown entities if we have read - an external subset, and standalone is true. -*/ -START_TEST(test_wfc_undeclared_entity_with_external_subset_standalone) { - const char *text - = "<?xml version='1.0' encoding='us-ascii' standalone='yes'?>\n" - "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc>&entity;</doc>"; - ExtTest test_data = {"<!ELEMENT doc (#PCDATA)*>", NULL, NULL}; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetUserData(g_parser, &test_data); - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); - expect_failure(text, XML_ERROR_UNDEFINED_ENTITY, - "Parser did not report undefined entity (external DTD)."); -} -END_TEST - -/* Test that external entity handling is not done if the parsing flag - * is set to UNLESS_STANDALONE - */ -START_TEST(test_entity_with_external_subset_unless_standalone) { - const char *text - = "<?xml version='1.0' encoding='us-ascii' standalone='yes'?>\n" - "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc>&entity;</doc>"; - ExtTest test_data = {"<!ENTITY entity 'bar'>", NULL, NULL}; - - XML_SetParamEntityParsing(g_parser, - XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE); - XML_SetUserData(g_parser, &test_data); - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); - expect_failure(text, XML_ERROR_UNDEFINED_ENTITY, - "Parser did not report undefined entity"); -} -END_TEST - -/* Test that no error is reported for unknown entities if we have read - an external subset, and standalone is false. -*/ -START_TEST(test_wfc_undeclared_entity_with_external_subset) { - const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc>&entity;</doc>"; - ExtTest test_data = {"<!ELEMENT doc (#PCDATA)*>", NULL, NULL}; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); - run_ext_character_check(text, &test_data, XCS("")); -} -END_TEST - -/* Test that an error is reported if our NotStandalone handler fails */ -static int XMLCALL -reject_not_standalone_handler(void *userData) { - UNUSED_P(userData); - return XML_STATUS_ERROR; -} - -START_TEST(test_not_standalone_handler_reject) { - const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc>&entity;</doc>"; - ExtTest test_data = {"<!ELEMENT doc (#PCDATA)*>", NULL, NULL}; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetUserData(g_parser, &test_data); - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); - XML_SetNotStandaloneHandler(g_parser, reject_not_standalone_handler); - expect_failure(text, XML_ERROR_NOT_STANDALONE, - "NotStandalone handler failed to reject"); - - /* Try again but without external entity handling */ - XML_ParserReset(g_parser, NULL); - XML_SetNotStandaloneHandler(g_parser, reject_not_standalone_handler); - expect_failure(text, XML_ERROR_NOT_STANDALONE, - "NotStandalone handler failed to reject"); -} -END_TEST - -/* Test that no error is reported if our NotStandalone handler succeeds */ -static int XMLCALL -accept_not_standalone_handler(void *userData) { - UNUSED_P(userData); - return XML_STATUS_OK; -} - -START_TEST(test_not_standalone_handler_accept) { - const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc>&entity;</doc>"; - ExtTest test_data = {"<!ELEMENT doc (#PCDATA)*>", NULL, NULL}; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); - XML_SetNotStandaloneHandler(g_parser, accept_not_standalone_handler); - run_ext_character_check(text, &test_data, XCS("")); - - /* Repeat wtihout the external entity handler */ - XML_ParserReset(g_parser, NULL); - XML_SetNotStandaloneHandler(g_parser, accept_not_standalone_handler); - run_character_check(text, XCS("")); -} -END_TEST - -START_TEST(test_wfc_no_recursive_entity_refs) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY entity '&entity;'>\n" - "]>\n" - "<doc>&entity;</doc>"; - - expect_failure(text, XML_ERROR_RECURSIVE_ENTITY_REF, - "Parser did not report recursive entity reference."); -} -END_TEST - -/* Test incomplete external entities are faulted */ -START_TEST(test_ext_entity_invalid_parse) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - const ExtFaults faults[] - = {{"<", "Incomplete element declaration not faulted", NULL, - XML_ERROR_UNCLOSED_TOKEN}, - {"<\xe2\x82", /* First two bytes of a three-byte char */ - "Incomplete character not faulted", NULL, XML_ERROR_PARTIAL_CHAR}, - {"<tag>\xe2\x82", "Incomplete character in CDATA not faulted", NULL, - XML_ERROR_PARTIAL_CHAR}, - {NULL, NULL, NULL, XML_ERROR_NONE}}; - const ExtFaults *fault = faults; - - for (; fault->parse_text != NULL; fault++) { - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter); - XML_SetUserData(g_parser, (void *)fault); - expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, - "Parser did not report external entity error"); - XML_ParserReset(g_parser, NULL); - } -} -END_TEST - -/* Regression test for SF bug #483514. */ -START_TEST(test_dtd_default_handling) { - const char *text = "<!DOCTYPE doc [\n" - "<!ENTITY e SYSTEM 'http://example.org/e'>\n" - "<!NOTATION n SYSTEM 'http://example.org/n'>\n" - "<!ELEMENT doc EMPTY>\n" - "<!ATTLIST doc a CDATA #IMPLIED>\n" - "<?pi in dtd?>\n" - "<!--comment in dtd-->\n" - "]><doc/>"; - - XML_SetDefaultHandler(g_parser, accumulate_characters); - XML_SetStartDoctypeDeclHandler(g_parser, dummy_start_doctype_handler); - XML_SetEndDoctypeDeclHandler(g_parser, dummy_end_doctype_handler); - XML_SetEntityDeclHandler(g_parser, dummy_entity_decl_handler); - XML_SetNotationDeclHandler(g_parser, dummy_notation_decl_handler); - XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); - XML_SetAttlistDeclHandler(g_parser, dummy_attlist_decl_handler); - XML_SetProcessingInstructionHandler(g_parser, dummy_pi_handler); - XML_SetCommentHandler(g_parser, dummy_comment_handler); - XML_SetStartCdataSectionHandler(g_parser, dummy_start_cdata_handler); - XML_SetEndCdataSectionHandler(g_parser, dummy_end_cdata_handler); - run_character_check(text, XCS("\n\n\n\n\n\n\n<doc/>")); -} -END_TEST - -/* Test handling of attribute declarations */ -typedef struct AttTest { - const char *definition; - const XML_Char *element_name; - const XML_Char *attr_name; - const XML_Char *attr_type; - const XML_Char *default_value; - int is_required; -} AttTest; - -static void XMLCALL -verify_attlist_decl_handler(void *userData, const XML_Char *element_name, - const XML_Char *attr_name, - const XML_Char *attr_type, - const XML_Char *default_value, int is_required) { - AttTest *at = (AttTest *)userData; - - if (xcstrcmp(element_name, at->element_name)) - fail("Unexpected element name in attribute declaration"); - if (xcstrcmp(attr_name, at->attr_name)) - fail("Unexpected attribute name in attribute declaration"); - if (xcstrcmp(attr_type, at->attr_type)) - fail("Unexpected attribute type in attribute declaration"); - if ((default_value == NULL && at->default_value != NULL) - || (default_value != NULL && at->default_value == NULL) - || (default_value != NULL && xcstrcmp(default_value, at->default_value))) - fail("Unexpected default value in attribute declaration"); - if (is_required != at->is_required) - fail("Requirement mismatch in attribute declaration"); -} - -START_TEST(test_dtd_attr_handling) { - const char *prolog = "<!DOCTYPE doc [\n" - "<!ELEMENT doc EMPTY>\n"; - AttTest attr_data[] - = {{"<!ATTLIST doc a ( one | two | three ) #REQUIRED>\n" - "]>" - "<doc a='two'/>", - XCS("doc"), XCS("a"), - XCS("(one|two|three)"), /* Extraneous spaces will be removed */ - NULL, XML_TRUE}, - {"<!NOTATION foo SYSTEM 'http://example.org/foo'>\n" - "<!ATTLIST doc a NOTATION (foo) #IMPLIED>\n" - "]>" - "<doc/>", - XCS("doc"), XCS("a"), XCS("NOTATION(foo)"), NULL, XML_FALSE}, - {"<!ATTLIST doc a NOTATION (foo) 'bar'>\n" - "]>" - "<doc/>", - XCS("doc"), XCS("a"), XCS("NOTATION(foo)"), XCS("bar"), XML_FALSE}, - {"<!ATTLIST doc a CDATA '\xdb\xb2'>\n" - "]>" - "<doc/>", - XCS("doc"), XCS("a"), XCS("CDATA"), -#ifdef XML_UNICODE - XCS("\x06f2"), -#else - XCS("\xdb\xb2"), -#endif - XML_FALSE}, - {NULL, NULL, NULL, NULL, NULL, XML_FALSE}}; - AttTest *test; - - for (test = attr_data; test->definition != NULL; test++) { - XML_SetAttlistDeclHandler(g_parser, verify_attlist_decl_handler); - XML_SetUserData(g_parser, test); - if (_XML_Parse_SINGLE_BYTES(g_parser, prolog, (int)strlen(prolog), - XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - if (_XML_Parse_SINGLE_BYTES(g_parser, test->definition, - (int)strlen(test->definition), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - XML_ParserReset(g_parser, NULL); - } -} -END_TEST - -/* See related SF bug #673791. - When namespace processing is enabled, setting the namespace URI for - a prefix is not allowed; this test ensures that it *is* allowed - when namespace processing is not enabled. - (See Namespaces in XML, section 2.) -*/ -START_TEST(test_empty_ns_without_namespaces) { - const char *text = "<doc xmlns:prefix='http://example.org/'>\n" - " <e xmlns:prefix=''/>\n" - "</doc>"; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Regression test for SF bug #824420. - Checks that an xmlns:prefix attribute set in an attribute's default - value isn't misinterpreted. -*/ -START_TEST(test_ns_in_attribute_default_without_namespaces) { - const char *text = "<!DOCTYPE e:element [\n" - " <!ATTLIST e:element\n" - " xmlns:e CDATA 'http://example.org/'>\n" - " ]>\n" - "<e:element/>"; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -static const char *long_character_data_text - = "<?xml version='1.0' encoding='iso-8859-1'?><s>" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "</s>"; - -static XML_Bool resumable = XML_FALSE; - -static void -clearing_aborting_character_handler(void *userData, const XML_Char *s, - int len) { - UNUSED_P(userData); - UNUSED_P(s); - UNUSED_P(len); - XML_StopParser(g_parser, resumable); - XML_SetCharacterDataHandler(g_parser, NULL); -} - -/* Regression test for SF bug #1515266: missing check of stopped - parser in doContext() 'for' loop. */ -START_TEST(test_stop_parser_between_char_data_calls) { - /* The sample data must be big enough that there are two calls to - the character data handler from within the inner "for" loop of - the XML_TOK_DATA_CHARS case in doContent(), and the character - handler must stop the parser and clear the character data - handler. - */ - const char *text = long_character_data_text; - - XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); - resumable = XML_FALSE; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - xml_failure(g_parser); - if (XML_GetErrorCode(g_parser) != XML_ERROR_ABORTED) - xml_failure(g_parser); -} -END_TEST - -/* Regression test for SF bug #1515266: missing check of stopped - parser in doContext() 'for' loop. */ -START_TEST(test_suspend_parser_between_char_data_calls) { - /* The sample data must be big enough that there are two calls to - the character data handler from within the inner "for" loop of - the XML_TOK_DATA_CHARS case in doContent(), and the character - handler must stop the parser and clear the character data - handler. - */ - const char *text = long_character_data_text; - - XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); - resumable = XML_TRUE; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_SUSPENDED) - xml_failure(g_parser); - if (XML_GetErrorCode(g_parser) != XML_ERROR_NONE) - xml_failure(g_parser); - /* Try parsing directly */ - if (XML_Parse(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - fail("Attempt to continue parse while suspended not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_SUSPENDED) - fail("Suspended parse not faulted with correct error"); -} -END_TEST - -static XML_Bool abortable = XML_FALSE; - -static void -parser_stop_character_handler(void *userData, const XML_Char *s, int len) { - UNUSED_P(userData); - UNUSED_P(s); - UNUSED_P(len); - XML_StopParser(g_parser, resumable); - XML_SetCharacterDataHandler(g_parser, NULL); - if (! resumable) { - /* Check that aborting an aborted parser is faulted */ - if (XML_StopParser(g_parser, XML_FALSE) != XML_STATUS_ERROR) - fail("Aborting aborted parser not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_FINISHED) - xml_failure(g_parser); - } else if (abortable) { - /* Check that aborting a suspended parser works */ - if (XML_StopParser(g_parser, XML_FALSE) == XML_STATUS_ERROR) - xml_failure(g_parser); - } else { - /* Check that suspending a suspended parser works */ - if (XML_StopParser(g_parser, XML_TRUE) != XML_STATUS_ERROR) - fail("Suspending suspended parser not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_SUSPENDED) - xml_failure(g_parser); - } -} - -/* Test repeated calls to XML_StopParser are handled correctly */ -START_TEST(test_repeated_stop_parser_between_char_data_calls) { - const char *text = long_character_data_text; - - XML_SetCharacterDataHandler(g_parser, parser_stop_character_handler); - resumable = XML_FALSE; - abortable = XML_FALSE; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - fail("Failed to double-stop parser"); - - XML_ParserReset(g_parser, NULL); - XML_SetCharacterDataHandler(g_parser, parser_stop_character_handler); - resumable = XML_TRUE; - abortable = XML_FALSE; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_SUSPENDED) - fail("Failed to double-suspend parser"); - - XML_ParserReset(g_parser, NULL); - XML_SetCharacterDataHandler(g_parser, parser_stop_character_handler); - resumable = XML_TRUE; - abortable = XML_TRUE; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - fail("Failed to suspend-abort parser"); -} -END_TEST - -START_TEST(test_good_cdata_ascii) { - const char *text = "<a><![CDATA[<greeting>Hello, world!</greeting>]]></a>"; - const XML_Char *expected = XCS("<greeting>Hello, world!</greeting>"); - - CharData storage; - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetCharacterDataHandler(g_parser, accumulate_characters); - /* Add start and end handlers for coverage */ - XML_SetStartCdataSectionHandler(g_parser, dummy_start_cdata_handler); - XML_SetEndCdataSectionHandler(g_parser, dummy_end_cdata_handler); - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); - - /* Try again, this time with a default handler */ - XML_ParserReset(g_parser, NULL); - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetCharacterDataHandler(g_parser, accumulate_characters); - XML_SetDefaultHandler(g_parser, dummy_default_handler); - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_good_cdata_utf16) { - /* Test data is: - * <?xml version='1.0' encoding='utf-16'?> - * <a><![CDATA[hello]]></a> - */ - const char text[] - = "\0<\0?\0x\0m\0l\0" - " \0v\0e\0r\0s\0i\0o\0n\0=\0'\0\x31\0.\0\x30\0'\0" - " \0e\0n\0c\0o\0d\0i\0n\0g\0=\0'\0u\0t\0f\0-\0" - "1\0" - "6\0'" - "\0?\0>\0\n" - "\0<\0a\0>\0<\0!\0[\0C\0D\0A\0T\0A\0[\0h\0e\0l\0l\0o\0]\0]\0>\0<\0/\0a\0>"; - const XML_Char *expected = XCS("hello"); - - CharData storage; - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetCharacterDataHandler(g_parser, accumulate_characters); - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_good_cdata_utf16_le) { - /* Test data is: - * <?xml version='1.0' encoding='utf-16'?> - * <a><![CDATA[hello]]></a> - */ - const char text[] - = "<\0?\0x\0m\0l\0" - " \0v\0e\0r\0s\0i\0o\0n\0=\0'\0\x31\0.\0\x30\0'\0" - " \0e\0n\0c\0o\0d\0i\0n\0g\0=\0'\0u\0t\0f\0-\0" - "1\0" - "6\0'" - "\0?\0>\0\n" - "\0<\0a\0>\0<\0!\0[\0C\0D\0A\0T\0A\0[\0h\0e\0l\0l\0o\0]\0]\0>\0<\0/\0a\0>\0"; - const XML_Char *expected = XCS("hello"); - - CharData storage; - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetCharacterDataHandler(g_parser, accumulate_characters); - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Test UTF16 conversion of a long cdata string */ - -/* 16 characters: handy macro to reduce visual clutter */ -#define A_TO_P_IN_UTF16 "\0A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P" - -START_TEST(test_long_cdata_utf16) { - /* Test data is: - * <?xlm version='1.0' encoding='utf-16'?> - * <a><![CDATA[ - * ABCDEFGHIJKLMNOP - * ]]></a> - */ - const char text[] - = "\0<\0?\0x\0m\0l\0 " - "\0v\0e\0r\0s\0i\0o\0n\0=\0'\0\x31\0.\0\x30\0'\0 " - "\0e\0n\0c\0o\0d\0i\0n\0g\0=\0'\0u\0t\0f\0-\0\x31\0\x36\0'\0?\0>" - "\0<\0a\0>\0<\0!\0[\0C\0D\0A\0T\0A\0[" - /* 64 characters per line */ - /* clang-format off */ - A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 - A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 - A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 - A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 - A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 - A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 - A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 - A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 - A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 - A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 - A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 - A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 - A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 - A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 - A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 - A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 A_TO_P_IN_UTF16 - A_TO_P_IN_UTF16 - /* clang-format on */ - "\0]\0]\0>\0<\0/\0a\0>"; - const XML_Char *expected = - /* clang-format off */ - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP") - XCS("ABCDEFGHIJKLMNOP"); - /* clang-format on */ - CharData storage; - void *buffer; - - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetCharacterDataHandler(g_parser, accumulate_characters); - buffer = XML_GetBuffer(g_parser, sizeof(text) - 1); - if (buffer == NULL) - fail("Could not allocate parse buffer"); - assert(buffer != NULL); - memcpy(buffer, text, sizeof(text) - 1); - if (XML_ParseBuffer(g_parser, sizeof(text) - 1, XML_TRUE) == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Test handling of multiple unit UTF-16 characters */ -#ifndef XML_MIN_SIZE /* FIXME workaround -DXML_MIN_SIZE + ASan (issue #332) */ -START_TEST(test_multichar_cdata_utf16) { - /* Test data is: - * <?xml version='1.0' encoding='utf-16'?> - * <a><![CDATA[{MINIM}{CROTCHET}]]></a> - * - * where {MINIM} is U+1d15e (a minim or half-note) - * UTF-16: 0xd834 0xdd5e - * UTF-8: 0xf0 0x9d 0x85 0x9e - * and {CROTCHET} is U+1d15f (a crotchet or quarter-note) - * UTF-16: 0xd834 0xdd5f - * UTF-8: 0xf0 0x9d 0x85 0x9f - */ - const char text[] = "\0<\0?\0x\0m\0l\0" - " \0v\0e\0r\0s\0i\0o\0n\0=\0'\0\x31\0.\0\x30\0'\0" - " \0e\0n\0c\0o\0d\0i\0n\0g\0=\0'\0u\0t\0f\0-\0" - "1\0" - "6\0'" - "\0?\0>\0\n" - "\0<\0a\0>\0<\0!\0[\0C\0D\0A\0T\0A\0[" - "\xd8\x34\xdd\x5e\xd8\x34\xdd\x5f" - "\0]\0]\0>\0<\0/\0a\0>"; -# ifdef XML_UNICODE - const XML_Char *expected = XCS("\xd834\xdd5e\xd834\xdd5f"); -# else - const XML_Char *expected = XCS("\xf0\x9d\x85\x9e\xf0\x9d\x85\x9f"); -# endif - CharData storage; - - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetCharacterDataHandler(g_parser, accumulate_characters); - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST -#endif /* ifndef XML_MIN_SIZE */ - -/* Test that an element name with a UTF-16 surrogate pair is rejected */ -START_TEST(test_utf16_bad_surrogate_pair) { - /* Test data is: - * <?xml version='1.0' encoding='utf-16'?> - * <a><![CDATA[{BADLINB}]]></a> - * - * where {BADLINB} is U+10000 (the first Linear B character) - * with the UTF-16 surrogate pair in the wrong order, i.e. - * 0xdc00 0xd800 - */ - const char text[] = "\0<\0?\0x\0m\0l\0" - " \0v\0e\0r\0s\0i\0o\0n\0=\0'\0\x31\0.\0\x30\0'\0" - " \0e\0n\0c\0o\0d\0i\0n\0g\0=\0'\0u\0t\0f\0-\0" - "1\0" - "6\0'" - "\0?\0>\0\n" - "\0<\0a\0>\0<\0!\0[\0C\0D\0A\0T\0A\0[" - "\xdc\x00\xd8\x00" - "\0]\0]\0>\0<\0/\0a\0>"; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - != XML_STATUS_ERROR) - fail("Reversed UTF-16 surrogate pair not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_INVALID_TOKEN) - xml_failure(g_parser); -} -END_TEST - -START_TEST(test_bad_cdata) { - struct CaseData { - const char *text; - enum XML_Error expectedError; - }; - - struct CaseData cases[] - = {{"<a><", XML_ERROR_UNCLOSED_TOKEN}, - {"<a><!", XML_ERROR_UNCLOSED_TOKEN}, - {"<a><![", XML_ERROR_UNCLOSED_TOKEN}, - {"<a><![C", XML_ERROR_UNCLOSED_TOKEN}, - {"<a><![CD", XML_ERROR_UNCLOSED_TOKEN}, - {"<a><![CDA", XML_ERROR_UNCLOSED_TOKEN}, - {"<a><![CDAT", XML_ERROR_UNCLOSED_TOKEN}, - {"<a><![CDATA", XML_ERROR_UNCLOSED_TOKEN}, - - {"<a><![CDATA[", XML_ERROR_UNCLOSED_CDATA_SECTION}, - {"<a><![CDATA[]", XML_ERROR_UNCLOSED_CDATA_SECTION}, - {"<a><![CDATA[]]", XML_ERROR_UNCLOSED_CDATA_SECTION}, - - {"<a><!<a/>", XML_ERROR_INVALID_TOKEN}, - {"<a><![<a/>", XML_ERROR_UNCLOSED_TOKEN}, /* ?! */ - {"<a><![C<a/>", XML_ERROR_UNCLOSED_TOKEN}, /* ?! */ - {"<a><![CD<a/>", XML_ERROR_INVALID_TOKEN}, - {"<a><![CDA<a/>", XML_ERROR_INVALID_TOKEN}, - {"<a><![CDAT<a/>", XML_ERROR_INVALID_TOKEN}, - {"<a><![CDATA<a/>", XML_ERROR_INVALID_TOKEN}, - - {"<a><![CDATA[<a/>", XML_ERROR_UNCLOSED_CDATA_SECTION}, - {"<a><![CDATA[]<a/>", XML_ERROR_UNCLOSED_CDATA_SECTION}, - {"<a><![CDATA[]]<a/>", XML_ERROR_UNCLOSED_CDATA_SECTION}}; - - size_t i = 0; - for (; i < sizeof(cases) / sizeof(struct CaseData); i++) { - const enum XML_Status actualStatus = _XML_Parse_SINGLE_BYTES( - g_parser, cases[i].text, (int)strlen(cases[i].text), XML_TRUE); - const enum XML_Error actualError = XML_GetErrorCode(g_parser); - - assert(actualStatus == XML_STATUS_ERROR); - - if (actualError != cases[i].expectedError) { - char message[100]; - sprintf(message, - "Expected error %d but got error %d for case %u: \"%s\"\n", - cases[i].expectedError, actualError, (unsigned int)i + 1, - cases[i].text); - fail(message); - } - - XML_ParserReset(g_parser, NULL); - } -} -END_TEST - -/* Test failures in UTF-16 CDATA */ -#ifndef XML_MIN_SIZE /* FIXME workaround -DXML_MIN_SIZE + ASan (issue #332) */ -START_TEST(test_bad_cdata_utf16) { - struct CaseData { - size_t text_bytes; - const char *text; - enum XML_Error expected_error; - }; - - const char prolog[] = "\0<\0?\0x\0m\0l\0" - " \0v\0e\0r\0s\0i\0o\0n\0=\0'\0\x31\0.\0\x30\0'\0" - " \0e\0n\0c\0o\0d\0i\0n\0g\0=\0'\0u\0t\0f\0-\0" - "1\0" - "6\0'" - "\0?\0>\0\n" - "\0<\0a\0>"; - struct CaseData cases[] = { - {1, "\0", XML_ERROR_UNCLOSED_TOKEN}, - {2, "\0<", XML_ERROR_UNCLOSED_TOKEN}, - {3, "\0<\0", XML_ERROR_UNCLOSED_TOKEN}, - {4, "\0<\0!", XML_ERROR_UNCLOSED_TOKEN}, - {5, "\0<\0!\0", XML_ERROR_UNCLOSED_TOKEN}, - {6, "\0<\0!\0[", XML_ERROR_UNCLOSED_TOKEN}, - {7, "\0<\0!\0[\0", XML_ERROR_UNCLOSED_TOKEN}, - {8, "\0<\0!\0[\0C", XML_ERROR_UNCLOSED_TOKEN}, - {9, "\0<\0!\0[\0C\0", XML_ERROR_UNCLOSED_TOKEN}, - {10, "\0<\0!\0[\0C\0D", XML_ERROR_UNCLOSED_TOKEN}, - {11, "\0<\0!\0[\0C\0D\0", XML_ERROR_UNCLOSED_TOKEN}, - {12, "\0<\0!\0[\0C\0D\0A", XML_ERROR_UNCLOSED_TOKEN}, - {13, "\0<\0!\0[\0C\0D\0A\0", XML_ERROR_UNCLOSED_TOKEN}, - {14, "\0<\0!\0[\0C\0D\0A\0T", XML_ERROR_UNCLOSED_TOKEN}, - {15, "\0<\0!\0[\0C\0D\0A\0T\0", XML_ERROR_UNCLOSED_TOKEN}, - {16, "\0<\0!\0[\0C\0D\0A\0T\0A", XML_ERROR_UNCLOSED_TOKEN}, - {17, "\0<\0!\0[\0C\0D\0A\0T\0A\0", XML_ERROR_UNCLOSED_TOKEN}, - {18, "\0<\0!\0[\0C\0D\0A\0T\0A\0[", XML_ERROR_UNCLOSED_CDATA_SECTION}, - {19, "\0<\0!\0[\0C\0D\0A\0T\0A\0[\0", XML_ERROR_UNCLOSED_CDATA_SECTION}, - {20, "\0<\0!\0[\0C\0D\0A\0T\0A\0[\0Z", XML_ERROR_UNCLOSED_CDATA_SECTION}, - /* Now add a four-byte UTF-16 character */ - {21, "\0<\0!\0[\0C\0D\0A\0T\0A\0[\0Z\xd8", - XML_ERROR_UNCLOSED_CDATA_SECTION}, - {22, "\0<\0!\0[\0C\0D\0A\0T\0A\0[\0Z\xd8\x34", XML_ERROR_PARTIAL_CHAR}, - {23, "\0<\0!\0[\0C\0D\0A\0T\0A\0[\0Z\xd8\x34\xdd", - XML_ERROR_PARTIAL_CHAR}, - {24, "\0<\0!\0[\0C\0D\0A\0T\0A\0[\0Z\xd8\x34\xdd\x5e", - XML_ERROR_UNCLOSED_CDATA_SECTION}}; - size_t i; - - for (i = 0; i < sizeof(cases) / sizeof(struct CaseData); i++) { - enum XML_Status actual_status; - enum XML_Error actual_error; - - if (_XML_Parse_SINGLE_BYTES(g_parser, prolog, (int)sizeof(prolog) - 1, - XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - actual_status = _XML_Parse_SINGLE_BYTES(g_parser, cases[i].text, - (int)cases[i].text_bytes, XML_TRUE); - assert(actual_status == XML_STATUS_ERROR); - actual_error = XML_GetErrorCode(g_parser); - if (actual_error != cases[i].expected_error) { - char message[1024]; - - sprintf(message, - "Expected error %d (%" XML_FMT_STR "), got %d (%" XML_FMT_STR - ") for case %lu\n", - cases[i].expected_error, XML_ErrorString(cases[i].expected_error), - actual_error, XML_ErrorString(actual_error), - (long unsigned)(i + 1)); - fail(message); - } - XML_ParserReset(g_parser, NULL); - } -} -END_TEST -#endif /* ifndef XML_MIN_SIZE */ - -static const char *long_cdata_text - = "<s><![CDATA[" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "012345678901234567890123456789012345678901234567890123456789" - "]]></s>"; - -/* Test stopping the parser in cdata handler */ -START_TEST(test_stop_parser_between_cdata_calls) { - const char *text = long_cdata_text; - - XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); - resumable = XML_FALSE; - expect_failure(text, XML_ERROR_ABORTED, "Parse not aborted in CDATA handler"); -} -END_TEST - -/* Test suspending the parser in cdata handler */ -START_TEST(test_suspend_parser_between_cdata_calls) { - const char *text = long_cdata_text; - enum XML_Status result; - - XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); - resumable = XML_TRUE; - result = _XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE); - if (result != XML_STATUS_SUSPENDED) { - if (result == XML_STATUS_ERROR) - xml_failure(g_parser); - fail("Parse not suspended in CDATA handler"); - } - if (XML_GetErrorCode(g_parser) != XML_ERROR_NONE) - xml_failure(g_parser); -} -END_TEST - -/* Test memory allocation functions */ -START_TEST(test_memory_allocation) { - char *buffer = (char *)XML_MemMalloc(g_parser, 256); - char *p; - - if (buffer == NULL) { - fail("Allocation failed"); - } else { - /* Try writing to memory; some OSes try to cheat! */ - buffer[0] = 'T'; - buffer[1] = 'E'; - buffer[2] = 'S'; - buffer[3] = 'T'; - buffer[4] = '\0'; - if (strcmp(buffer, "TEST") != 0) { - fail("Memory not writable"); - } else { - p = (char *)XML_MemRealloc(g_parser, buffer, 512); - if (p == NULL) { - fail("Reallocation failed"); - } else { - /* Write again, just to be sure */ - buffer = p; - buffer[0] = 'V'; - if (strcmp(buffer, "VEST") != 0) { - fail("Reallocated memory not writable"); - } - } - } - XML_MemFree(g_parser, buffer); - } -} -END_TEST - -static void XMLCALL -record_default_handler(void *userData, const XML_Char *s, int len) { - UNUSED_P(s); - UNUSED_P(len); - CharData_AppendXMLChars((CharData *)userData, XCS("D"), 1); -} - -static void XMLCALL -record_cdata_handler(void *userData, const XML_Char *s, int len) { - UNUSED_P(s); - UNUSED_P(len); - CharData_AppendXMLChars((CharData *)userData, XCS("C"), 1); - XML_DefaultCurrent(g_parser); -} - -static void XMLCALL -record_cdata_nodefault_handler(void *userData, const XML_Char *s, int len) { - UNUSED_P(s); - UNUSED_P(len); - CharData_AppendXMLChars((CharData *)userData, XCS("c"), 1); -} - -static void XMLCALL -record_skip_handler(void *userData, const XML_Char *entityName, - int is_parameter_entity) { - UNUSED_P(entityName); - CharData_AppendXMLChars((CharData *)userData, - is_parameter_entity ? XCS("E") : XCS("e"), 1); -} - -/* Test XML_DefaultCurrent() passes handling on correctly */ -START_TEST(test_default_current) { - const char *text = "<doc>hell]</doc>"; - const char *entity_text = "<!DOCTYPE doc [\n" - "<!ENTITY entity '%'>\n" - "]>\n" - "<doc>&entity;</doc>"; - CharData storage; - - XML_SetDefaultHandler(g_parser, record_default_handler); - XML_SetCharacterDataHandler(g_parser, record_cdata_handler); - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, XCS("DCDCDCDCDCDD")); - - /* Again, without the defaulting */ - XML_ParserReset(g_parser, NULL); - XML_SetDefaultHandler(g_parser, record_default_handler); - XML_SetCharacterDataHandler(g_parser, record_cdata_nodefault_handler); - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, XCS("DcccccD")); - - /* Now with an internal entity to complicate matters */ - XML_ParserReset(g_parser, NULL); - XML_SetDefaultHandler(g_parser, record_default_handler); - XML_SetCharacterDataHandler(g_parser, record_cdata_handler); - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, entity_text, (int)strlen(entity_text), - XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - /* The default handler suppresses the entity */ - CharData_CheckXMLChars(&storage, XCS("DDDDDDDDDDDDDDDDDDD")); - - /* Again, with a skip handler */ - XML_ParserReset(g_parser, NULL); - XML_SetDefaultHandler(g_parser, record_default_handler); - XML_SetCharacterDataHandler(g_parser, record_cdata_handler); - XML_SetSkippedEntityHandler(g_parser, record_skip_handler); - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, entity_text, (int)strlen(entity_text), - XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - /* The default handler suppresses the entity */ - CharData_CheckXMLChars(&storage, XCS("DDDDDDDDDDDDDDDDDeD")); - - /* This time, allow the entity through */ - XML_ParserReset(g_parser, NULL); - XML_SetDefaultHandlerExpand(g_parser, record_default_handler); - XML_SetCharacterDataHandler(g_parser, record_cdata_handler); - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, entity_text, (int)strlen(entity_text), - XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, XCS("DDDDDDDDDDDDDDDDDCDD")); - - /* Finally, without passing the cdata to the default handler */ - XML_ParserReset(g_parser, NULL); - XML_SetDefaultHandlerExpand(g_parser, record_default_handler); - XML_SetCharacterDataHandler(g_parser, record_cdata_nodefault_handler); - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, entity_text, (int)strlen(entity_text), - XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, XCS("DDDDDDDDDDDDDDDDDcD")); -} -END_TEST - -/* Test DTD element parsing code paths */ -START_TEST(test_dtd_elements) { - const char *text = "<!DOCTYPE doc [\n" - "<!ELEMENT doc (chapter)>\n" - "<!ELEMENT chapter (#PCDATA)>\n" - "]>\n" - "<doc><chapter>Wombats are go</chapter></doc>"; - - XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test foreign DTD handling */ -START_TEST(test_set_foreign_dtd) { - const char *text1 = "<?xml version='1.0' encoding='us-ascii'?>\n"; - const char *text2 = "<doc>&entity;</doc>"; - ExtTest test_data = {"<!ELEMENT doc (#PCDATA)*>", NULL, NULL}; - - /* Check hash salt is passed through too */ - XML_SetHashSalt(g_parser, 0x12345678); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetUserData(g_parser, &test_data); - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); - /* Add a default handler to exercise more code paths */ - XML_SetDefaultHandler(g_parser, dummy_default_handler); - if (XML_UseForeignDTD(g_parser, XML_TRUE) != XML_ERROR_NONE) - fail("Could not set foreign DTD"); - if (_XML_Parse_SINGLE_BYTES(g_parser, text1, (int)strlen(text1), XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - - /* Ensure that trying to set the DTD after parsing has started - * is faulted, even if it's the same setting. - */ - if (XML_UseForeignDTD(g_parser, XML_TRUE) - != XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING) - fail("Failed to reject late foreign DTD setting"); - /* Ditto for the hash salt */ - if (XML_SetHashSalt(g_parser, 0x23456789)) - fail("Failed to reject late hash salt change"); - - /* Now finish the parse */ - if (_XML_Parse_SINGLE_BYTES(g_parser, text2, (int)strlen(text2), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test foreign DTD handling with a failing NotStandalone handler */ -START_TEST(test_foreign_dtd_not_standalone) { - const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<doc>&entity;</doc>"; - ExtTest test_data = {"<!ELEMENT doc (#PCDATA)*>", NULL, NULL}; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetUserData(g_parser, &test_data); - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); - XML_SetNotStandaloneHandler(g_parser, reject_not_standalone_handler); - if (XML_UseForeignDTD(g_parser, XML_TRUE) != XML_ERROR_NONE) - fail("Could not set foreign DTD"); - expect_failure(text, XML_ERROR_NOT_STANDALONE, - "NotStandalonehandler failed to reject"); -} -END_TEST - -/* Test invalid character in a foreign DTD is faulted */ -START_TEST(test_invalid_foreign_dtd) { - const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<doc>&entity;</doc>"; - ExtFaults test_data - = {"$", "Dollar not faulted", NULL, XML_ERROR_INVALID_TOKEN}; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetUserData(g_parser, &test_data); - XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter); - XML_UseForeignDTD(g_parser, XML_TRUE); - expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, - "Bad DTD should not have been accepted"); -} -END_TEST - -/* Test foreign DTD use with a doctype */ -START_TEST(test_foreign_dtd_with_doctype) { - const char *text1 = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<!DOCTYPE doc [<!ENTITY entity 'hello world'>]>\n"; - const char *text2 = "<doc>&entity;</doc>"; - ExtTest test_data = {"<!ELEMENT doc (#PCDATA)*>", NULL, NULL}; - - /* Check hash salt is passed through too */ - XML_SetHashSalt(g_parser, 0x12345678); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetUserData(g_parser, &test_data); - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); - /* Add a default handler to exercise more code paths */ - XML_SetDefaultHandler(g_parser, dummy_default_handler); - if (XML_UseForeignDTD(g_parser, XML_TRUE) != XML_ERROR_NONE) - fail("Could not set foreign DTD"); - if (_XML_Parse_SINGLE_BYTES(g_parser, text1, (int)strlen(text1), XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - - /* Ensure that trying to set the DTD after parsing has started - * is faulted, even if it's the same setting. - */ - if (XML_UseForeignDTD(g_parser, XML_TRUE) - != XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING) - fail("Failed to reject late foreign DTD setting"); - /* Ditto for the hash salt */ - if (XML_SetHashSalt(g_parser, 0x23456789)) - fail("Failed to reject late hash salt change"); - - /* Now finish the parse */ - if (_XML_Parse_SINGLE_BYTES(g_parser, text2, (int)strlen(text2), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test XML_UseForeignDTD with no external subset present */ -static int XMLCALL -external_entity_null_loader(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - UNUSED_P(parser); - UNUSED_P(context); - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - return XML_STATUS_OK; -} - -START_TEST(test_foreign_dtd_without_external_subset) { - const char *text = "<!DOCTYPE doc [<!ENTITY foo 'bar'>]>\n" - "<doc>&foo;</doc>"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetUserData(g_parser, NULL); - XML_SetExternalEntityRefHandler(g_parser, external_entity_null_loader); - XML_UseForeignDTD(g_parser, XML_TRUE); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -START_TEST(test_empty_foreign_dtd) { - const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<doc>&entity;</doc>"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_null_loader); - XML_UseForeignDTD(g_parser, XML_TRUE); - expect_failure(text, XML_ERROR_UNDEFINED_ENTITY, - "Undefined entity not faulted"); -} -END_TEST - -/* Test XML Base is set and unset appropriately */ -START_TEST(test_set_base) { - const XML_Char *old_base; - const XML_Char *new_base = XCS("/local/file/name.xml"); - - old_base = XML_GetBase(g_parser); - if (XML_SetBase(g_parser, new_base) != XML_STATUS_OK) - fail("Unable to set base"); - if (xcstrcmp(XML_GetBase(g_parser), new_base) != 0) - fail("Base setting not correct"); - if (XML_SetBase(g_parser, NULL) != XML_STATUS_OK) - fail("Unable to NULL base"); - if (XML_GetBase(g_parser) != NULL) - fail("Base setting not nulled"); - XML_SetBase(g_parser, old_base); -} -END_TEST - -/* Test attribute counts, indexing, etc */ -typedef struct attrInfo { - const XML_Char *name; - const XML_Char *value; -} AttrInfo; - -typedef struct elementInfo { - const XML_Char *name; - int attr_count; - const XML_Char *id_name; - AttrInfo *attributes; -} ElementInfo; - -static void XMLCALL -counting_start_element_handler(void *userData, const XML_Char *name, - const XML_Char **atts) { - ElementInfo *info = (ElementInfo *)userData; - AttrInfo *attr; - int count, id, i; - - while (info->name != NULL) { - if (! xcstrcmp(name, info->name)) - break; - info++; - } - if (info->name == NULL) - fail("Element not recognised"); - /* The attribute count is twice what you might expect. It is a - * count of items in atts, an array which contains alternating - * attribute names and attribute values. For the naive user this - * is possibly a little unexpected, but it is what the - * documentation in expat.h tells us to expect. - */ - count = XML_GetSpecifiedAttributeCount(g_parser); - if (info->attr_count * 2 != count) { - fail("Not got expected attribute count"); - return; - } - id = XML_GetIdAttributeIndex(g_parser); - if (id == -1 && info->id_name != NULL) { - fail("ID not present"); - return; - } - if (id != -1 && xcstrcmp(atts[id], info->id_name)) { - fail("ID does not have the correct name"); - return; - } - for (i = 0; i < info->attr_count; i++) { - attr = info->attributes; - while (attr->name != NULL) { - if (! xcstrcmp(atts[0], attr->name)) - break; - attr++; - } - if (attr->name == NULL) { - fail("Attribute not recognised"); - return; - } - if (xcstrcmp(atts[1], attr->value)) { - fail("Attribute has wrong value"); - return; - } - /* Remember, two entries in atts per attribute (see above) */ - atts += 2; - } -} - -START_TEST(test_attributes) { - const char *text = "<!DOCTYPE doc [\n" - "<!ELEMENT doc (tag)>\n" - "<!ATTLIST doc id ID #REQUIRED>\n" - "]>" - "<doc a='1' id='one' b='2'>" - "<tag c='3'/>" - "</doc>"; - AttrInfo doc_info[] = {{XCS("a"), XCS("1")}, - {XCS("b"), XCS("2")}, - {XCS("id"), XCS("one")}, - {NULL, NULL}}; - AttrInfo tag_info[] = {{XCS("c"), XCS("3")}, {NULL, NULL}}; - ElementInfo info[] = {{XCS("doc"), 3, XCS("id"), NULL}, - {XCS("tag"), 1, NULL, NULL}, - {NULL, 0, NULL, NULL}}; - info[0].attributes = doc_info; - info[1].attributes = tag_info; - - XML_SetStartElementHandler(g_parser, counting_start_element_handler); - XML_SetUserData(g_parser, info); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test reset works correctly in the middle of processing an internal - * entity. Exercises some obscure code in XML_ParserReset(). - */ -START_TEST(test_reset_in_entity) { - const char *text = "<!DOCTYPE doc [\n" - "<!ENTITY wombat 'wom'>\n" - "<!ENTITY entity 'hi &wom; there'>\n" - "]>\n" - "<doc>&entity;</doc>"; - XML_ParsingStatus status; - - resumable = XML_TRUE; - XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - XML_GetParsingStatus(g_parser, &status); - if (status.parsing != XML_SUSPENDED) - fail("Parsing status not SUSPENDED"); - XML_ParserReset(g_parser, NULL); - XML_GetParsingStatus(g_parser, &status); - if (status.parsing != XML_INITIALIZED) - fail("Parsing status doesn't reset to INITIALIZED"); -} -END_TEST - -/* Test that resume correctly passes through parse errors */ -START_TEST(test_resume_invalid_parse) { - const char *text = "<doc>Hello</doc"; /* Missing closing wedge */ - - resumable = XML_TRUE; - XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); - if (XML_Parse(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - if (XML_ResumeParser(g_parser) == XML_STATUS_OK) - fail("Resumed invalid parse not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_UNCLOSED_TOKEN) - fail("Invalid parse not correctly faulted"); -} -END_TEST - -/* Test that re-suspended parses are correctly passed through */ -START_TEST(test_resume_resuspended) { - const char *text = "<doc>Hello<meep/>world</doc>"; - - resumable = XML_TRUE; - XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); - if (XML_Parse(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - resumable = XML_TRUE; - XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); - if (XML_ResumeParser(g_parser) != XML_STATUS_SUSPENDED) - fail("Resumption not suspended"); - /* This one should succeed and finish up */ - if (XML_ResumeParser(g_parser) != XML_STATUS_OK) - xml_failure(g_parser); -} -END_TEST - -/* Test that CDATA shows up correctly through a default handler */ -START_TEST(test_cdata_default) { - const char *text = "<doc><![CDATA[Hello\nworld]]></doc>"; - const XML_Char *expected = XCS("<doc><![CDATA[Hello\nworld]]></doc>"); - CharData storage; - - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetDefaultHandler(g_parser, accumulate_characters); - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Test resetting a subordinate parser does exactly nothing */ -static int XMLCALL -external_entity_resetter(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text = "<!ELEMENT doc (#PCDATA)*>"; - XML_Parser ext_parser; - XML_ParsingStatus status; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - XML_GetParsingStatus(ext_parser, &status); - if (status.parsing != XML_INITIALIZED) { - fail("Parsing status is not INITIALIZED"); - return XML_STATUS_ERROR; - } - if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) { - xml_failure(parser); - return XML_STATUS_ERROR; - } - XML_GetParsingStatus(ext_parser, &status); - if (status.parsing != XML_FINISHED) { - fail("Parsing status is not FINISHED"); - return XML_STATUS_ERROR; - } - /* Check we can't parse here */ - if (XML_Parse(ext_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - fail("Parsing when finished not faulted"); - if (XML_GetErrorCode(ext_parser) != XML_ERROR_FINISHED) - fail("Parsing when finished faulted with wrong code"); - XML_ParserReset(ext_parser, NULL); - XML_GetParsingStatus(ext_parser, &status); - if (status.parsing != XML_FINISHED) { - fail("Parsing status not still FINISHED"); - return XML_STATUS_ERROR; - } - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_subordinate_reset) { - const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc>&entity;</doc>"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_resetter); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test suspending a subordinate parser */ - -static void XMLCALL -entity_suspending_decl_handler(void *userData, const XML_Char *name, - XML_Content *model) { - XML_Parser ext_parser = (XML_Parser)userData; - - UNUSED_P(name); - if (XML_StopParser(ext_parser, XML_TRUE) != XML_STATUS_ERROR) - fail("Attempting to suspend a subordinate parser not faulted"); - if (XML_GetErrorCode(ext_parser) != XML_ERROR_SUSPEND_PE) - fail("Suspending subordinate parser get wrong code"); - XML_SetElementDeclHandler(ext_parser, NULL); - XML_FreeContentModel(g_parser, model); -} - -static int XMLCALL -external_entity_suspender(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text = "<!ELEMENT doc (#PCDATA)*>"; - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - XML_SetElementDeclHandler(ext_parser, entity_suspending_decl_handler); - XML_SetUserData(ext_parser, ext_parser); - if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) { - xml_failure(ext_parser); - return XML_STATUS_ERROR; - } - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_subordinate_suspend) { - const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc>&entity;</doc>"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_suspender); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test suspending a subordinate parser from an XML declaration */ -/* Increases code coverage of the tests */ -static void XMLCALL -entity_suspending_xdecl_handler(void *userData, const XML_Char *version, - const XML_Char *encoding, int standalone) { - XML_Parser ext_parser = (XML_Parser)userData; - - UNUSED_P(version); - UNUSED_P(encoding); - UNUSED_P(standalone); - XML_StopParser(ext_parser, resumable); - XML_SetXmlDeclHandler(ext_parser, NULL); -} - -static int XMLCALL -external_entity_suspend_xmldecl(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text = "<?xml version='1.0' encoding='us-ascii'?>"; - XML_Parser ext_parser; - XML_ParsingStatus status; - enum XML_Status rc; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - XML_SetXmlDeclHandler(ext_parser, entity_suspending_xdecl_handler); - XML_SetUserData(ext_parser, ext_parser); - rc = _XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE); - XML_GetParsingStatus(ext_parser, &status); - if (resumable) { - if (rc == XML_STATUS_ERROR) - xml_failure(ext_parser); - if (status.parsing != XML_SUSPENDED) - fail("Ext Parsing status not SUSPENDED"); - } else { - if (rc != XML_STATUS_ERROR) - fail("Ext parsing not aborted"); - if (XML_GetErrorCode(ext_parser) != XML_ERROR_ABORTED) - xml_failure(ext_parser); - if (status.parsing != XML_FINISHED) - fail("Ext Parsing status not FINISHED"); - } - - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_subordinate_xdecl_suspend) { - const char *text - = "<!DOCTYPE doc [\n" - " <!ENTITY entity SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&entity;</doc>"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_suspend_xmldecl); - resumable = XML_TRUE; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -START_TEST(test_subordinate_xdecl_abort) { - const char *text - = "<!DOCTYPE doc [\n" - " <!ENTITY entity SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&entity;</doc>"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_suspend_xmldecl); - resumable = XML_FALSE; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test external entity fault handling with suspension */ -static int XMLCALL -external_entity_suspending_faulter(XML_Parser parser, const XML_Char *context, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId) { - XML_Parser ext_parser; - ExtFaults *fault = (ExtFaults *)XML_GetUserData(parser); - void *buffer; - int parse_len = (int)strlen(fault->parse_text); - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - XML_SetXmlDeclHandler(ext_parser, entity_suspending_xdecl_handler); - XML_SetUserData(ext_parser, ext_parser); - resumable = XML_TRUE; - buffer = XML_GetBuffer(ext_parser, parse_len); - if (buffer == NULL) - fail("Could not allocate parse buffer"); - assert(buffer != NULL); - memcpy(buffer, fault->parse_text, parse_len); - if (XML_ParseBuffer(ext_parser, parse_len, XML_FALSE) != XML_STATUS_SUSPENDED) - fail("XML declaration did not suspend"); - if (XML_ResumeParser(ext_parser) != XML_STATUS_OK) - xml_failure(ext_parser); - if (XML_ParseBuffer(ext_parser, 0, XML_TRUE) != XML_STATUS_ERROR) - fail(fault->fail_text); - if (XML_GetErrorCode(ext_parser) != fault->error) - xml_failure(ext_parser); - - XML_ParserFree(ext_parser); - return XML_STATUS_ERROR; -} - -START_TEST(test_ext_entity_invalid_suspended_parse) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - ExtFaults faults[] - = {{"<?xml version='1.0' encoding='us-ascii'?><", - "Incomplete element declaration not faulted", NULL, - XML_ERROR_UNCLOSED_TOKEN}, - {/* First two bytes of a three-byte char */ - "<?xml version='1.0' encoding='utf-8'?>\xe2\x82", - "Incomplete character not faulted", NULL, XML_ERROR_PARTIAL_CHAR}, - {NULL, NULL, NULL, XML_ERROR_NONE}}; - ExtFaults *fault; - - for (fault = &faults[0]; fault->parse_text != NULL; fault++) { - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, - external_entity_suspending_faulter); - XML_SetUserData(g_parser, fault); - expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, - "Parser did not report external entity error"); - XML_ParserReset(g_parser, NULL); - } -} -END_TEST - -/* Test setting an explicit encoding */ -START_TEST(test_explicit_encoding) { - const char *text1 = "<doc>Hello "; - const char *text2 = " World</doc>"; - - /* Just check that we can set the encoding to NULL before starting */ - if (XML_SetEncoding(g_parser, NULL) != XML_STATUS_OK) - fail("Failed to initialise encoding to NULL"); - /* Say we are UTF-8 */ - if (XML_SetEncoding(g_parser, XCS("utf-8")) != XML_STATUS_OK) - fail("Failed to set explicit encoding"); - if (_XML_Parse_SINGLE_BYTES(g_parser, text1, (int)strlen(text1), XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - /* Try to switch encodings mid-parse */ - if (XML_SetEncoding(g_parser, XCS("us-ascii")) != XML_STATUS_ERROR) - fail("Allowed encoding change"); - if (_XML_Parse_SINGLE_BYTES(g_parser, text2, (int)strlen(text2), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - /* Try now the parse is over */ - if (XML_SetEncoding(g_parser, NULL) != XML_STATUS_OK) - fail("Failed to unset encoding"); -} -END_TEST - -/* Test handling of trailing CR (rather than newline) */ -static void XMLCALL -cr_cdata_handler(void *userData, const XML_Char *s, int len) { - int *pfound = (int *)userData; - - /* Internal processing turns the CR into a newline for the - * character data handler, but not for the default handler - */ - if (len == 1 && (*s == XCS('\n') || *s == XCS('\r'))) - *pfound = 1; -} - -START_TEST(test_trailing_cr) { - const char *text = "<doc>\r"; - int found_cr; - - /* Try with a character handler, for code coverage */ - XML_SetCharacterDataHandler(g_parser, cr_cdata_handler); - XML_SetUserData(g_parser, &found_cr); - found_cr = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_OK) - fail("Failed to fault unclosed doc"); - if (found_cr == 0) - fail("Did not catch the carriage return"); - XML_ParserReset(g_parser, NULL); - - /* Now with a default handler instead */ - XML_SetDefaultHandler(g_parser, cr_cdata_handler); - XML_SetUserData(g_parser, &found_cr); - found_cr = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_OK) - fail("Failed to fault unclosed doc"); - if (found_cr == 0) - fail("Did not catch default carriage return"); -} -END_TEST - -/* Test trailing CR in an external entity parse */ -static int XMLCALL -external_entity_cr_catcher(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text = "\r"; - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - XML_SetCharacterDataHandler(ext_parser, cr_cdata_handler); - if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(ext_parser); - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -static int XMLCALL -external_entity_bad_cr_catcher(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text = "<tag>\r"; - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - XML_SetCharacterDataHandler(ext_parser, cr_cdata_handler); - if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_OK) - fail("Async entity error not caught"); - if (XML_GetErrorCode(ext_parser) != XML_ERROR_ASYNC_ENTITY) - xml_failure(ext_parser); - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_ext_entity_trailing_cr) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - int found_cr; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_cr_catcher); - XML_SetUserData(g_parser, &found_cr); - found_cr = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_OK) - xml_failure(g_parser); - if (found_cr == 0) - fail("No carriage return found"); - XML_ParserReset(g_parser, NULL); - - /* Try again with a different trailing CR */ - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_bad_cr_catcher); - XML_SetUserData(g_parser, &found_cr); - found_cr = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_OK) - xml_failure(g_parser); - if (found_cr == 0) - fail("No carriage return found"); -} -END_TEST - -/* Test handling of trailing square bracket */ -static void XMLCALL -rsqb_handler(void *userData, const XML_Char *s, int len) { - int *pfound = (int *)userData; - - if (len == 1 && *s == XCS(']')) - *pfound = 1; -} - -START_TEST(test_trailing_rsqb) { - const char *text8 = "<doc>]"; - const char text16[] = "\xFF\xFE<\000d\000o\000c\000>\000]\000"; - int found_rsqb; - int text8_len = (int)strlen(text8); - - XML_SetCharacterDataHandler(g_parser, rsqb_handler); - XML_SetUserData(g_parser, &found_rsqb); - found_rsqb = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text8, text8_len, XML_TRUE) - == XML_STATUS_OK) - fail("Failed to fault unclosed doc"); - if (found_rsqb == 0) - fail("Did not catch the right square bracket"); - - /* Try again with a different encoding */ - XML_ParserReset(g_parser, NULL); - XML_SetCharacterDataHandler(g_parser, rsqb_handler); - XML_SetUserData(g_parser, &found_rsqb); - found_rsqb = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text16, (int)sizeof(text16) - 1, - XML_TRUE) - == XML_STATUS_OK) - fail("Failed to fault unclosed doc"); - if (found_rsqb == 0) - fail("Did not catch the right square bracket"); - - /* And finally with a default handler */ - XML_ParserReset(g_parser, NULL); - XML_SetDefaultHandler(g_parser, rsqb_handler); - XML_SetUserData(g_parser, &found_rsqb); - found_rsqb = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text16, (int)sizeof(text16) - 1, - XML_TRUE) - == XML_STATUS_OK) - fail("Failed to fault unclosed doc"); - if (found_rsqb == 0) - fail("Did not catch the right square bracket"); -} -END_TEST - -/* Test trailing right square bracket in an external entity parse */ -static int XMLCALL -external_entity_rsqb_catcher(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text = "<tag>]"; - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - XML_SetCharacterDataHandler(ext_parser, rsqb_handler); - if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - fail("Async entity error not caught"); - if (XML_GetErrorCode(ext_parser) != XML_ERROR_ASYNC_ENTITY) - xml_failure(ext_parser); - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_ext_entity_trailing_rsqb) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - int found_rsqb; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_rsqb_catcher); - XML_SetUserData(g_parser, &found_rsqb); - found_rsqb = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_OK) - xml_failure(g_parser); - if (found_rsqb == 0) - fail("No right square bracket found"); -} -END_TEST - -/* Test CDATA handling in an external entity */ -static int XMLCALL -external_entity_good_cdata_ascii(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text = "<a><![CDATA[<greeting>Hello, world!</greeting>]]></a>"; - const XML_Char *expected = XCS("<greeting>Hello, world!</greeting>"); - CharData storage; - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - CharData_Init(&storage); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - XML_SetUserData(ext_parser, &storage); - XML_SetCharacterDataHandler(ext_parser, accumulate_characters); - - if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(ext_parser); - CharData_CheckXMLChars(&storage, expected); - - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_ext_entity_good_cdata) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_good_cdata_ascii); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_OK) - xml_failure(g_parser); -} -END_TEST - -/* Test user parameter settings */ -/* Variable holding the expected handler userData */ -static void *handler_data = NULL; -/* Count of the number of times the comment handler has been invoked */ -static int comment_count = 0; -/* Count of the number of skipped entities */ -static int skip_count = 0; -/* Count of the number of times the XML declaration handler is invoked */ -static int xdecl_count = 0; - -static void XMLCALL -xml_decl_handler(void *userData, const XML_Char *version, - const XML_Char *encoding, int standalone) { - UNUSED_P(version); - UNUSED_P(encoding); - if (userData != handler_data) - fail("User data (xml decl) not correctly set"); - if (standalone != -1) - fail("Standalone not flagged as not present in XML decl"); - xdecl_count++; -} - -static void XMLCALL -param_check_skip_handler(void *userData, const XML_Char *entityName, - int is_parameter_entity) { - UNUSED_P(entityName); - UNUSED_P(is_parameter_entity); - if (userData != handler_data) - fail("User data (skip) not correctly set"); - skip_count++; -} - -static void XMLCALL -data_check_comment_handler(void *userData, const XML_Char *data) { - UNUSED_P(data); - /* Check that the userData passed through is what we expect */ - if (userData != handler_data) - fail("User data (parser) not correctly set"); - /* Check that the user data in the parser is appropriate */ - if (XML_GetUserData(userData) != (void *)1) - fail("User data in parser not correctly set"); - comment_count++; -} - -static int XMLCALL -external_entity_param_checker(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text = "<!-- Subordinate parser -->\n" - "<!ELEMENT doc (#PCDATA)*>"; - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - handler_data = ext_parser; - if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) { - xml_failure(parser); - return XML_STATUS_ERROR; - } - handler_data = parser; - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_user_parameters) { - const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<!-- Primary parse -->\n" - "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc>&entity;"; - const char *epilog = "<!-- Back to primary parser -->\n" - "</doc>"; - - comment_count = 0; - skip_count = 0; - xdecl_count = 0; - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetXmlDeclHandler(g_parser, xml_decl_handler); - XML_SetExternalEntityRefHandler(g_parser, external_entity_param_checker); - XML_SetCommentHandler(g_parser, data_check_comment_handler); - XML_SetSkippedEntityHandler(g_parser, param_check_skip_handler); - XML_UseParserAsHandlerArg(g_parser); - XML_SetUserData(g_parser, (void *)1); - handler_data = g_parser; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - if (comment_count != 2) - fail("Comment handler not invoked enough times"); - /* Ensure we can't change policy mid-parse */ - if (XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_NEVER)) - fail("Changed param entity parsing policy while parsing"); - if (_XML_Parse_SINGLE_BYTES(g_parser, epilog, (int)strlen(epilog), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - if (comment_count != 3) - fail("Comment handler not invoked enough times"); - if (skip_count != 1) - fail("Skip handler not invoked enough times"); - if (xdecl_count != 1) - fail("XML declaration handler not invoked"); -} -END_TEST - -/* Test that an explicit external entity handler argument replaces - * the parser as the first argument. - * - * We do not call the first parameter to the external entity handler - * 'parser' for once, since the first time the handler is called it - * will actually be a text string. We need to be able to access the - * global 'parser' variable to create our external entity parser from, - * since there are code paths we need to ensure get executed. - */ -static int XMLCALL -external_entity_ref_param_checker(XML_Parser parameter, const XML_Char *context, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId) { - const char *text = "<!ELEMENT doc (#PCDATA)*>"; - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - if ((void *)parameter != handler_data) - fail("External entity ref handler parameter not correct"); - - /* Here we use the global 'parser' variable */ - ext_parser = XML_ExternalEntityParserCreate(g_parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(ext_parser); - - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_ext_entity_ref_parameter) { - const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc>&entity;</doc>"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_ref_param_checker); - /* Set a handler arg that is not NULL and not parser (which is - * what NULL would cause to be passed. - */ - XML_SetExternalEntityRefHandlerArg(g_parser, (void *)text); - handler_data = (void *)text; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - - /* Now try again with unset args */ - XML_ParserReset(g_parser, NULL); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_ref_param_checker); - XML_SetExternalEntityRefHandlerArg(g_parser, NULL); - handler_data = (void *)g_parser; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test the parsing of an empty string */ -START_TEST(test_empty_parse) { - const char *text = "<doc></doc>"; - const char *partial = "<doc>"; - - if (XML_Parse(g_parser, NULL, 0, XML_FALSE) == XML_STATUS_ERROR) - fail("Parsing empty string faulted"); - if (XML_Parse(g_parser, NULL, 0, XML_TRUE) != XML_STATUS_ERROR) - fail("Parsing final empty string not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_NO_ELEMENTS) - fail("Parsing final empty string faulted for wrong reason"); - - /* Now try with valid text before the empty end */ - XML_ParserReset(g_parser, NULL); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - if (XML_Parse(g_parser, NULL, 0, XML_TRUE) == XML_STATUS_ERROR) - fail("Parsing final empty string faulted"); - - /* Now try with invalid text before the empty end */ - XML_ParserReset(g_parser, NULL); - if (_XML_Parse_SINGLE_BYTES(g_parser, partial, (int)strlen(partial), - XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - if (XML_Parse(g_parser, NULL, 0, XML_TRUE) != XML_STATUS_ERROR) - fail("Parsing final incomplete empty string not faulted"); -} -END_TEST - -/* Test odd corners of the XML_GetBuffer interface */ -static enum XML_Status -get_feature(enum XML_FeatureEnum feature_id, long *presult) { - const XML_Feature *feature = XML_GetFeatureList(); - - if (feature == NULL) - return XML_STATUS_ERROR; - for (; feature->feature != XML_FEATURE_END; feature++) { - if (feature->feature == feature_id) { - *presult = feature->value; - return XML_STATUS_OK; - } - } - return XML_STATUS_ERROR; -} - -/* Having an element name longer than 1024 characters exercises some - * of the pool allocation code in the parser that otherwise does not - * get executed. The count at the end of the line is the number of - * characters (bytes) in the element name by that point.x - */ -static const char *get_buffer_test_text - = "<documentwitharidiculouslylongelementnametotease" /* 0x030 */ - "aparticularcorneroftheallocationinXML_GetBuffers" /* 0x060 */ - "othatwecanimprovethecoverageyetagain012345678901" /* 0x090 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x0c0 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x0f0 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x120 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x150 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x180 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x1b0 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x1e0 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x210 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x240 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x270 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x2a0 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x2d0 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x300 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x330 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x360 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x390 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x3c0 */ - "123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x3f0 */ - "123456789abcdef0123456789abcdef0123456789>\n<ef0"; /* 0x420 */ - -/* Test odd corners of the XML_GetBuffer interface */ -START_TEST(test_get_buffer_1) { - const char *text = get_buffer_test_text; - void *buffer; - long context_bytes; - - /* Attempt to allocate a negative length buffer */ - if (XML_GetBuffer(g_parser, -12) != NULL) - fail("Negative length buffer not failed"); - - /* Now get a small buffer and extend it past valid length */ - buffer = XML_GetBuffer(g_parser, 1536); - if (buffer == NULL) - fail("1.5K buffer failed"); - assert(buffer != NULL); - memcpy(buffer, text, strlen(text)); - if (XML_ParseBuffer(g_parser, (int)strlen(text), XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - if (XML_GetBuffer(g_parser, INT_MAX) != NULL) - fail("INT_MAX buffer not failed"); - - /* Now try extending it a more reasonable but still too large - * amount. The allocator in XML_GetBuffer() doubles the buffer - * size until it exceeds the requested amount or INT_MAX. If it - * exceeds INT_MAX, it rejects the request, so we want a request - * between INT_MAX and INT_MAX/2. A gap of 1K seems comfortable, - * with an extra byte just to ensure that the request is off any - * boundary. The request will be inflated internally by - * XML_CONTEXT_BYTES (if defined), so we subtract that from our - * request. - */ - if (get_feature(XML_FEATURE_CONTEXT_BYTES, &context_bytes) != XML_STATUS_OK) - context_bytes = 0; - if (XML_GetBuffer(g_parser, INT_MAX - (context_bytes + 1025)) != NULL) - fail("INT_MAX- buffer not failed"); - - /* Now try extending it a carefully crafted amount */ - if (XML_GetBuffer(g_parser, 1000) == NULL) - fail("1000 buffer failed"); -} -END_TEST - -/* Test more corners of the XML_GetBuffer interface */ -START_TEST(test_get_buffer_2) { - const char *text = get_buffer_test_text; - void *buffer; - - /* Now get a decent buffer */ - buffer = XML_GetBuffer(g_parser, 1536); - if (buffer == NULL) - fail("1.5K buffer failed"); - assert(buffer != NULL); - memcpy(buffer, text, strlen(text)); - if (XML_ParseBuffer(g_parser, (int)strlen(text), XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - - /* Extend it, to catch a different code path */ - if (XML_GetBuffer(g_parser, 1024) == NULL) - fail("1024 buffer failed"); -} -END_TEST - -/* Test position information macros */ -START_TEST(test_byte_info_at_end) { - const char *text = "<doc></doc>"; - - if (XML_GetCurrentByteIndex(g_parser) != -1 - || XML_GetCurrentByteCount(g_parser) != 0) - fail("Byte index/count incorrect at start of parse"); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - /* At end, the count will be zero and the index the end of string */ - if (XML_GetCurrentByteCount(g_parser) != 0) - fail("Terminal byte count incorrect"); - if (XML_GetCurrentByteIndex(g_parser) != (XML_Index)strlen(text)) - fail("Terminal byte index incorrect"); -} -END_TEST - -/* Test position information from errors */ -#define PRE_ERROR_STR "<doc></" -#define POST_ERROR_STR "wombat></doc>" -START_TEST(test_byte_info_at_error) { - const char *text = PRE_ERROR_STR POST_ERROR_STR; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_OK) - fail("Syntax error not faulted"); - if (XML_GetCurrentByteCount(g_parser) != 0) - fail("Error byte count incorrect"); - if (XML_GetCurrentByteIndex(g_parser) != strlen(PRE_ERROR_STR)) - fail("Error byte index incorrect"); -} -END_TEST -#undef PRE_ERROR_STR -#undef POST_ERROR_STR - -/* Test position information in handler */ -typedef struct ByteTestData { - int start_element_len; - int cdata_len; - int total_string_len; -} ByteTestData; - -static void -byte_character_handler(void *userData, const XML_Char *s, int len) { -#ifdef XML_CONTEXT_BYTES - int offset, size; - const char *buffer; - ByteTestData *data = (ByteTestData *)userData; - - UNUSED_P(s); - buffer = XML_GetInputContext(g_parser, &offset, &size); - if (buffer == NULL) - fail("Failed to get context buffer"); - if (offset != data->start_element_len) - fail("Context offset in unexpected position"); - if (len != data->cdata_len) - fail("CDATA length reported incorrectly"); - if (size != data->total_string_len) - fail("Context size is not full buffer"); - if (XML_GetCurrentByteIndex(g_parser) != offset) - fail("Character byte index incorrect"); - if (XML_GetCurrentByteCount(g_parser) != len) - fail("Character byte count incorrect"); -#else - UNUSED_P(s); - UNUSED_P(userData); - UNUSED_P(len); -#endif -} - -#define START_ELEMENT "<e>" -#define CDATA_TEXT "Hello" -#define END_ELEMENT "</e>" -START_TEST(test_byte_info_at_cdata) { - const char *text = START_ELEMENT CDATA_TEXT END_ELEMENT; - int offset, size; - ByteTestData data; - - /* Check initial context is empty */ - if (XML_GetInputContext(g_parser, &offset, &size) != NULL) - fail("Unexpected context at start of parse"); - - data.start_element_len = (int)strlen(START_ELEMENT); - data.cdata_len = (int)strlen(CDATA_TEXT); - data.total_string_len = (int)strlen(text); - XML_SetCharacterDataHandler(g_parser, byte_character_handler); - XML_SetUserData(g_parser, &data); - if (XML_Parse(g_parser, text, (int)strlen(text), XML_TRUE) != XML_STATUS_OK) - xml_failure(g_parser); -} -END_TEST -#undef START_ELEMENT -#undef CDATA_TEXT -#undef END_ELEMENT - -/* Test predefined entities are correctly recognised */ -START_TEST(test_predefined_entities) { - const char *text = "<doc><>&"'</doc>"; - const XML_Char *expected = XCS("<doc><>&"'</doc>"); - const XML_Char *result = XCS("<>&\"'"); - CharData storage; - - XML_SetDefaultHandler(g_parser, accumulate_characters); - /* run_character_check uses XML_SetCharacterDataHandler(), which - * unfortunately heads off a code path that we need to exercise. - */ - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - /* The default handler doesn't translate the entities */ - CharData_CheckXMLChars(&storage, expected); - - /* Now try again and check the translation */ - XML_ParserReset(g_parser, NULL); - run_character_check(text, result); -} -END_TEST - -/* Regression test that an invalid tag in an external parameter - * reference in an external DTD is correctly faulted. - * - * Only a few specific tags are legal in DTDs ignoring comments and - * processing instructions, all of which begin with an exclamation - * mark. "<el/>" is not one of them, so the parser should raise an - * error on encountering it. - */ -static int XMLCALL -external_entity_param(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text1 = "<!ELEMENT doc EMPTY>\n" - "<!ENTITY % e1 SYSTEM '004-2.ent'>\n" - "<!ENTITY % e2 '%e1;'>\n" - "%e1;\n"; - const char *text2 = "<!ELEMENT el EMPTY>\n" - "<el/>\n"; - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(publicId); - if (systemId == NULL) - return XML_STATUS_OK; - - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - - if (! xcstrcmp(systemId, XCS("004-1.ent"))) { - if (_XML_Parse_SINGLE_BYTES(ext_parser, text1, (int)strlen(text1), XML_TRUE) - != XML_STATUS_ERROR) - fail("Inner DTD with invalid tag not rejected"); - if (XML_GetErrorCode(ext_parser) != XML_ERROR_EXTERNAL_ENTITY_HANDLING) - xml_failure(ext_parser); - } else if (! xcstrcmp(systemId, XCS("004-2.ent"))) { - if (_XML_Parse_SINGLE_BYTES(ext_parser, text2, (int)strlen(text2), XML_TRUE) - != XML_STATUS_ERROR) - fail("Invalid tag in external param not rejected"); - if (XML_GetErrorCode(ext_parser) != XML_ERROR_SYNTAX) - xml_failure(ext_parser); - } else { - fail("Unknown system ID"); - } - - XML_ParserFree(ext_parser); - return XML_STATUS_ERROR; -} - -START_TEST(test_invalid_tag_in_dtd) { - const char *text = "<!DOCTYPE doc SYSTEM '004-1.ent'>\n" - "<doc></doc>\n"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_param); - expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, - "Invalid tag IN DTD external param not rejected"); -} -END_TEST - -/* Test entities not quite the predefined ones are not mis-recognised */ -START_TEST(test_not_predefined_entities) { - const char *text[] = {"<doc>&pt;</doc>", "<doc>&amo;</doc>", - "<doc>&quid;</doc>", "<doc>&apod;</doc>", NULL}; - int i = 0; - - while (text[i] != NULL) { - expect_failure(text[i], XML_ERROR_UNDEFINED_ENTITY, - "Undefined entity not rejected"); - XML_ParserReset(g_parser, NULL); - i++; - } -} -END_TEST - -/* Test conditional inclusion (IGNORE) */ -static int XMLCALL -external_entity_load_ignore(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text = "<![IGNORE[<!ELEMENT e (#PCDATA)*>]]>"; - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(parser); - - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_ignore_section) { - const char *text = "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc><e>&entity;</e></doc>"; - const XML_Char *expected - = XCS("<![IGNORE[<!ELEMENT e (#PCDATA)*>]]>\n&entity;"); - CharData storage; - - CharData_Init(&storage); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetUserData(g_parser, &storage); - XML_SetExternalEntityRefHandler(g_parser, external_entity_load_ignore); - XML_SetDefaultHandler(g_parser, accumulate_characters); - XML_SetStartDoctypeDeclHandler(g_parser, dummy_start_doctype_handler); - XML_SetEndDoctypeDeclHandler(g_parser, dummy_end_doctype_handler); - XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); - XML_SetStartElementHandler(g_parser, dummy_start_element); - XML_SetEndElementHandler(g_parser, dummy_end_element); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -static int XMLCALL -external_entity_load_ignore_utf16(XML_Parser parser, const XML_Char *context, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId) { - const char text[] = - /* <![IGNORE[<!ELEMENT e (#PCDATA)*>]]> */ - "<\0!\0[\0I\0G\0N\0O\0R\0E\0[\0" - "<\0!\0E\0L\0E\0M\0E\0N\0T\0 \0e\0 \0" - "(\0#\0P\0C\0D\0A\0T\0A\0)\0*\0>\0]\0]\0>\0"; - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(parser); - - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_ignore_section_utf16) { - const char text[] = - /* <!DOCTYPE d SYSTEM 's'> */ - "<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0d\0 " - "\0S\0Y\0S\0T\0E\0M\0 \0'\0s\0'\0>\0\n\0" - /* <d><e>&en;</e></d> */ - "<\0d\0>\0<\0e\0>\0&\0e\0n\0;\0<\0/\0e\0>\0<\0/\0d\0>\0"; - const XML_Char *expected = XCS("<![IGNORE[<!ELEMENT e (#PCDATA)*>]]>\n&en;"); - CharData storage; - - CharData_Init(&storage); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetUserData(g_parser, &storage); - XML_SetExternalEntityRefHandler(g_parser, external_entity_load_ignore_utf16); - XML_SetDefaultHandler(g_parser, accumulate_characters); - XML_SetStartDoctypeDeclHandler(g_parser, dummy_start_doctype_handler); - XML_SetEndDoctypeDeclHandler(g_parser, dummy_end_doctype_handler); - XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); - XML_SetStartElementHandler(g_parser, dummy_start_element); - XML_SetEndElementHandler(g_parser, dummy_end_element); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -static int XMLCALL -external_entity_load_ignore_utf16_be(XML_Parser parser, const XML_Char *context, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId) { - const char text[] = - /* <![IGNORE[<!ELEMENT e (#PCDATA)*>]]> */ - "\0<\0!\0[\0I\0G\0N\0O\0R\0E\0[" - "\0<\0!\0E\0L\0E\0M\0E\0N\0T\0 \0e\0 " - "\0(\0#\0P\0C\0D\0A\0T\0A\0)\0*\0>\0]\0]\0>"; - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(parser); - - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_ignore_section_utf16_be) { - const char text[] = - /* <!DOCTYPE d SYSTEM 's'> */ - "\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0d\0 " - "\0S\0Y\0S\0T\0E\0M\0 \0'\0s\0'\0>\0\n" - /* <d><e>&en;</e></d> */ - "\0<\0d\0>\0<\0e\0>\0&\0e\0n\0;\0<\0/\0e\0>\0<\0/\0d\0>"; - const XML_Char *expected = XCS("<![IGNORE[<!ELEMENT e (#PCDATA)*>]]>\n&en;"); - CharData storage; - - CharData_Init(&storage); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetUserData(g_parser, &storage); - XML_SetExternalEntityRefHandler(g_parser, - external_entity_load_ignore_utf16_be); - XML_SetDefaultHandler(g_parser, accumulate_characters); - XML_SetStartDoctypeDeclHandler(g_parser, dummy_start_doctype_handler); - XML_SetEndDoctypeDeclHandler(g_parser, dummy_end_doctype_handler); - XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); - XML_SetStartElementHandler(g_parser, dummy_start_element); - XML_SetEndElementHandler(g_parser, dummy_end_element); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Test mis-formatted conditional exclusion */ -START_TEST(test_bad_ignore_section) { - const char *text = "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc><e>&entity;</e></doc>"; - ExtFaults faults[] - = {{"<![IGNORE[<!ELEM", "Broken-off declaration not faulted", NULL, - XML_ERROR_SYNTAX}, - {"<![IGNORE[\x01]]>", "Invalid XML character not faulted", NULL, - XML_ERROR_INVALID_TOKEN}, - {/* FIrst two bytes of a three-byte char */ - "<![IGNORE[\xe2\x82", "Partial XML character not faulted", NULL, - XML_ERROR_PARTIAL_CHAR}, - {NULL, NULL, NULL, XML_ERROR_NONE}}; - ExtFaults *fault; - - for (fault = &faults[0]; fault->parse_text != NULL; fault++) { - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter); - XML_SetUserData(g_parser, fault); - expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, - "Incomplete IGNORE section not failed"); - XML_ParserReset(g_parser, NULL); - } -} -END_TEST - -/* Test recursive parsing */ -static int XMLCALL -external_entity_valuer(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text1 = "<!ELEMENT doc EMPTY>\n" - "<!ENTITY % e1 SYSTEM '004-2.ent'>\n" - "<!ENTITY % e2 '%e1;'>\n" - "%e1;\n"; - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(publicId); - if (systemId == NULL) - return XML_STATUS_OK; - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - if (! xcstrcmp(systemId, XCS("004-1.ent"))) { - if (_XML_Parse_SINGLE_BYTES(ext_parser, text1, (int)strlen(text1), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(ext_parser); - } else if (! xcstrcmp(systemId, XCS("004-2.ent"))) { - ExtFaults *fault = (ExtFaults *)XML_GetUserData(parser); - enum XML_Status status; - enum XML_Error error; - - status = _XML_Parse_SINGLE_BYTES(ext_parser, fault->parse_text, - (int)strlen(fault->parse_text), XML_TRUE); - if (fault->error == XML_ERROR_NONE) { - if (status == XML_STATUS_ERROR) - xml_failure(ext_parser); - } else { - if (status != XML_STATUS_ERROR) - fail(fault->fail_text); - error = XML_GetErrorCode(ext_parser); - if (error != fault->error - && (fault->error != XML_ERROR_XML_DECL - || error != XML_ERROR_TEXT_DECL)) - xml_failure(ext_parser); - } - } - - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_external_entity_values) { - const char *text = "<!DOCTYPE doc SYSTEM '004-1.ent'>\n" - "<doc></doc>\n"; - ExtFaults data_004_2[] = { - {"<!ATTLIST doc a1 CDATA 'value'>", NULL, NULL, XML_ERROR_NONE}, - {"<!ATTLIST $doc a1 CDATA 'value'>", "Invalid token not faulted", NULL, - XML_ERROR_INVALID_TOKEN}, - {"'wombat", "Unterminated string not faulted", NULL, - XML_ERROR_UNCLOSED_TOKEN}, - {"\xe2\x82", "Partial UTF-8 character not faulted", NULL, - XML_ERROR_PARTIAL_CHAR}, - {"<?xml version='1.0' encoding='utf-8'?>\n", NULL, NULL, XML_ERROR_NONE}, - {"<?xml?>", "Malformed XML declaration not faulted", NULL, - XML_ERROR_XML_DECL}, - {/* UTF-8 BOM */ - "\xEF\xBB\xBF<!ATTLIST doc a1 CDATA 'value'>", NULL, NULL, - XML_ERROR_NONE}, - {"<?xml version='1.0' encoding='utf-8'?>\n$", - "Invalid token after text declaration not faulted", NULL, - XML_ERROR_INVALID_TOKEN}, - {"<?xml version='1.0' encoding='utf-8'?>\n'wombat", - "Unterminated string after text decl not faulted", NULL, - XML_ERROR_UNCLOSED_TOKEN}, - {"<?xml version='1.0' encoding='utf-8'?>\n\xe2\x82", - "Partial UTF-8 character after text decl not faulted", NULL, - XML_ERROR_PARTIAL_CHAR}, - {"%e1;", "Recursive parameter entity not faulted", NULL, - XML_ERROR_RECURSIVE_ENTITY_REF}, - {NULL, NULL, NULL, XML_ERROR_NONE}}; - int i; - - for (i = 0; data_004_2[i].parse_text != NULL; i++) { - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_valuer); - XML_SetUserData(g_parser, &data_004_2[i]); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - XML_ParserReset(g_parser, NULL); - } -} -END_TEST - -/* Test the recursive parse interacts with a not standalone handler */ -static int XMLCALL -external_entity_not_standalone(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text1 = "<!ELEMENT doc EMPTY>\n" - "<!ENTITY % e1 SYSTEM 'bar'>\n" - "%e1;\n"; - const char *text2 = "<!ATTLIST doc a1 CDATA 'value'>"; - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(publicId); - if (systemId == NULL) - return XML_STATUS_OK; - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - if (! xcstrcmp(systemId, XCS("foo"))) { - XML_SetNotStandaloneHandler(ext_parser, reject_not_standalone_handler); - if (_XML_Parse_SINGLE_BYTES(ext_parser, text1, (int)strlen(text1), XML_TRUE) - != XML_STATUS_ERROR) - fail("Expected not standalone rejection"); - if (XML_GetErrorCode(ext_parser) != XML_ERROR_NOT_STANDALONE) - xml_failure(ext_parser); - XML_SetNotStandaloneHandler(ext_parser, NULL); - XML_ParserFree(ext_parser); - return XML_STATUS_ERROR; - } else if (! xcstrcmp(systemId, XCS("bar"))) { - if (_XML_Parse_SINGLE_BYTES(ext_parser, text2, (int)strlen(text2), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(ext_parser); - } - - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_ext_entity_not_standalone) { - const char *text = "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc></doc>"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_not_standalone); - expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, - "Standalone rejection not caught"); -} -END_TEST - -static int XMLCALL -external_entity_value_aborter(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text1 = "<!ELEMENT doc EMPTY>\n" - "<!ENTITY % e1 SYSTEM '004-2.ent'>\n" - "<!ENTITY % e2 '%e1;'>\n" - "%e1;\n"; - const char *text2 = "<?xml version='1.0' encoding='utf-8'?>"; - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(publicId); - if (systemId == NULL) - return XML_STATUS_OK; - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - if (! xcstrcmp(systemId, XCS("004-1.ent"))) { - if (_XML_Parse_SINGLE_BYTES(ext_parser, text1, (int)strlen(text1), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(ext_parser); - } - if (! xcstrcmp(systemId, XCS("004-2.ent"))) { - XML_SetXmlDeclHandler(ext_parser, entity_suspending_xdecl_handler); - XML_SetUserData(ext_parser, ext_parser); - if (_XML_Parse_SINGLE_BYTES(ext_parser, text2, (int)strlen(text2), XML_TRUE) - != XML_STATUS_ERROR) - fail("Aborted parse not faulted"); - if (XML_GetErrorCode(ext_parser) != XML_ERROR_ABORTED) - xml_failure(ext_parser); - } - - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_ext_entity_value_abort) { - const char *text = "<!DOCTYPE doc SYSTEM '004-1.ent'>\n" - "<doc></doc>\n"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_value_aborter); - resumable = XML_FALSE; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -START_TEST(test_bad_public_doctype) { - const char *text = "<?xml version='1.0' encoding='utf-8'?>\n" - "<!DOCTYPE doc PUBLIC '{BadName}' 'test'>\n" - "<doc></doc>"; - - /* Setting a handler provokes a particular code path */ - XML_SetDoctypeDeclHandler(g_parser, dummy_start_doctype_handler, - dummy_end_doctype_handler); - expect_failure(text, XML_ERROR_PUBLICID, "Bad Public ID not failed"); -} -END_TEST - -/* Test based on ibm/valid/P32/ibm32v04.xml */ -START_TEST(test_attribute_enum_value) { - const char *text = "<?xml version='1.0' standalone='no'?>\n" - "<!DOCTYPE animal SYSTEM 'test.dtd'>\n" - "<animal>This is a \n <a/> \n\nyellow tiger</animal>"; - ExtTest dtd_data - = {"<!ELEMENT animal (#PCDATA|a)*>\n" - "<!ELEMENT a EMPTY>\n" - "<!ATTLIST animal xml:space (default|preserve) 'preserve'>", - NULL, NULL}; - const XML_Char *expected = XCS("This is a \n \n\nyellow tiger"); - - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); - XML_SetUserData(g_parser, &dtd_data); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - /* An attribute list handler provokes a different code path */ - XML_SetAttlistDeclHandler(g_parser, dummy_attlist_decl_handler); - run_ext_character_check(text, &dtd_data, expected); -} -END_TEST - -/* Slightly bizarrely, the library seems to silently ignore entity - * definitions for predefined entities, even when they are wrong. The - * language of the XML 1.0 spec is somewhat unhelpful as to what ought - * to happen, so this is currently treated as acceptable. - */ -START_TEST(test_predefined_entity_redefinition) { - const char *text = "<!DOCTYPE doc [\n" - "<!ENTITY apos 'foo'>\n" - "]>\n" - "<doc>'</doc>"; - run_character_check(text, XCS("'")); -} -END_TEST - -/* Test that the parser stops processing the DTD after an unresolved - * parameter entity is encountered. - */ -START_TEST(test_dtd_stop_processing) { - const char *text = "<!DOCTYPE doc [\n" - "%foo;\n" - "<!ENTITY bar 'bas'>\n" - "]><doc/>"; - - XML_SetEntityDeclHandler(g_parser, dummy_entity_decl_handler); - dummy_handler_flags = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - if (dummy_handler_flags != 0) - fail("DTD processing still going after undefined PE"); -} -END_TEST - -/* Test public notations with no system ID */ -START_TEST(test_public_notation_no_sysid) { - const char *text = "<!DOCTYPE doc [\n" - "<!NOTATION note PUBLIC 'foo'>\n" - "<!ELEMENT doc EMPTY>\n" - "]>\n<doc/>"; - - dummy_handler_flags = 0; - XML_SetNotationDeclHandler(g_parser, dummy_notation_decl_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - if (dummy_handler_flags != DUMMY_NOTATION_DECL_HANDLER_FLAG) - fail("Notation declaration handler not called"); -} -END_TEST - -static void XMLCALL -record_element_start_handler(void *userData, const XML_Char *name, - const XML_Char **atts) { - UNUSED_P(atts); - CharData_AppendXMLChars((CharData *)userData, name, (int)xcstrlen(name)); -} - -START_TEST(test_nested_groups) { - const char *text - = "<!DOCTYPE doc [\n" - "<!ELEMENT doc " - /* Sixteen elements per line */ - "(e,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?," - "(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?" - "))))))))))))))))))))))))))))))))>\n" - "<!ELEMENT e EMPTY>" - "]>\n" - "<doc><e/></doc>"; - CharData storage; - - CharData_Init(&storage); - XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); - XML_SetStartElementHandler(g_parser, record_element_start_handler); - XML_SetUserData(g_parser, &storage); - dummy_handler_flags = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, XCS("doce")); - if (dummy_handler_flags != DUMMY_ELEMENT_DECL_HANDLER_FLAG) - fail("Element handler not fired"); -} -END_TEST - -START_TEST(test_group_choice) { - const char *text = "<!DOCTYPE doc [\n" - "<!ELEMENT doc (a|b|c)+>\n" - "<!ELEMENT a EMPTY>\n" - "<!ELEMENT b (#PCDATA)>\n" - "<!ELEMENT c ANY>\n" - "]>\n" - "<doc>\n" - "<a/>\n" - "<b attr='foo'>This is a foo</b>\n" - "<c></c>\n" - "</doc>\n"; - - XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); - dummy_handler_flags = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - if (dummy_handler_flags != DUMMY_ELEMENT_DECL_HANDLER_FLAG) - fail("Element handler flag not raised"); -} -END_TEST - -static int XMLCALL -external_entity_public(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text1 = (const char *)XML_GetUserData(parser); - const char *text2 = "<!ATTLIST doc a CDATA 'value'>"; - const char *text = NULL; - XML_Parser ext_parser; - int parse_res; - - UNUSED_P(base); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - return XML_STATUS_ERROR; - if (systemId != NULL && ! xcstrcmp(systemId, XCS("http://example.org/"))) { - text = text1; - } else if (publicId != NULL && ! xcstrcmp(publicId, XCS("foo"))) { - text = text2; - } else - fail("Unexpected parameters to external entity parser"); - assert(text != NULL); - parse_res - = _XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE); - XML_ParserFree(ext_parser); - return parse_res; -} - -START_TEST(test_standalone_parameter_entity) { - const char *text = "<?xml version='1.0' standalone='yes'?>\n" - "<!DOCTYPE doc SYSTEM 'http://example.org/' [\n" - "<!ENTITY % entity '<!ELEMENT doc (#PCDATA)>'>\n" - "%entity;\n" - "]>\n" - "<doc></doc>"; - char dtd_data[] = "<!ENTITY % e1 'foo'>\n"; - - XML_SetUserData(g_parser, dtd_data); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_public); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test skipping of parameter entity in an external DTD */ -/* Derived from ibm/invalid/P69/ibm69i01.xml */ -START_TEST(test_skipped_parameter_entity) { - const char *text = "<?xml version='1.0'?>\n" - "<!DOCTYPE root SYSTEM 'http://example.org/dtd.ent' [\n" - "<!ELEMENT root (#PCDATA|a)* >\n" - "]>\n" - "<root></root>"; - ExtTest dtd_data = {"%pe2;", NULL, NULL}; - - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); - XML_SetUserData(g_parser, &dtd_data); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetSkippedEntityHandler(g_parser, dummy_skip_handler); - dummy_handler_flags = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - if (dummy_handler_flags != DUMMY_SKIP_HANDLER_FLAG) - fail("Skip handler not executed"); -} -END_TEST - -/* Test recursive parameter entity definition rejected in external DTD */ -START_TEST(test_recursive_external_parameter_entity) { - const char *text = "<?xml version='1.0'?>\n" - "<!DOCTYPE root SYSTEM 'http://example.org/dtd.ent' [\n" - "<!ELEMENT root (#PCDATA|a)* >\n" - "]>\n" - "<root></root>"; - ExtFaults dtd_data = {"<!ENTITY % pe2 '%pe2;'>\n%pe2;", - "Recursive external parameter entity not faulted", NULL, - XML_ERROR_RECURSIVE_ENTITY_REF}; - - XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter); - XML_SetUserData(g_parser, &dtd_data); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, - "Recursive external parameter not spotted"); -} -END_TEST - -/* Test undefined parameter entity in external entity handler */ -static int XMLCALL -external_entity_devaluer(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text = "<!ELEMENT doc EMPTY>\n" - "<!ENTITY % e1 SYSTEM 'bar'>\n" - "%e1;\n"; - XML_Parser ext_parser; - intptr_t clear_handler = (intptr_t)XML_GetUserData(parser); - - UNUSED_P(base); - UNUSED_P(publicId); - if (systemId == NULL || ! xcstrcmp(systemId, XCS("bar"))) - return XML_STATUS_OK; - if (xcstrcmp(systemId, XCS("foo"))) - fail("Unexpected system ID"); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could note create external entity parser"); - if (clear_handler) - XML_SetExternalEntityRefHandler(ext_parser, NULL); - if (_XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(ext_parser); - - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_undefined_ext_entity_in_external_dtd) { - const char *text = "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc></doc>\n"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_devaluer); - XML_SetUserData(g_parser, (void *)(intptr_t)XML_FALSE); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - - /* Now repeat without the external entity ref handler invoking - * another copy of itself. - */ - XML_ParserReset(g_parser, NULL); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_devaluer); - XML_SetUserData(g_parser, (void *)(intptr_t)XML_TRUE); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -static void XMLCALL -aborting_xdecl_handler(void *userData, const XML_Char *version, - const XML_Char *encoding, int standalone) { - UNUSED_P(userData); - UNUSED_P(version); - UNUSED_P(encoding); - UNUSED_P(standalone); - XML_StopParser(g_parser, resumable); - XML_SetXmlDeclHandler(g_parser, NULL); -} - -/* Test suspending the parse on receiving an XML declaration works */ -START_TEST(test_suspend_xdecl) { - const char *text = long_character_data_text; - - XML_SetXmlDeclHandler(g_parser, aborting_xdecl_handler); - resumable = XML_TRUE; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_SUSPENDED) - xml_failure(g_parser); - if (XML_GetErrorCode(g_parser) != XML_ERROR_NONE) - xml_failure(g_parser); - /* Attempt to start a new parse while suspended */ - if (XML_Parse(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - fail("Attempt to parse while suspended not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_SUSPENDED) - fail("Suspended parse not faulted with correct error"); -} -END_TEST - -/* Test aborting the parse in an epilog works */ -static void XMLCALL -selective_aborting_default_handler(void *userData, const XML_Char *s, int len) { - const XML_Char *match = (const XML_Char *)userData; - - if (match == NULL - || (xcstrlen(match) == (unsigned)len && ! xcstrncmp(match, s, len))) { - XML_StopParser(g_parser, resumable); - XML_SetDefaultHandler(g_parser, NULL); - } -} - -START_TEST(test_abort_epilog) { - const char *text = "<doc></doc>\n\r\n"; - XML_Char match[] = XCS("\r"); - - XML_SetDefaultHandler(g_parser, selective_aborting_default_handler); - XML_SetUserData(g_parser, match); - resumable = XML_FALSE; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - fail("Abort not triggered"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_ABORTED) - xml_failure(g_parser); -} -END_TEST - -/* Test a different code path for abort in the epilog */ -START_TEST(test_abort_epilog_2) { - const char *text = "<doc></doc>\n"; - XML_Char match[] = XCS("\n"); - - XML_SetDefaultHandler(g_parser, selective_aborting_default_handler); - XML_SetUserData(g_parser, match); - resumable = XML_FALSE; - expect_failure(text, XML_ERROR_ABORTED, "Abort not triggered"); -} -END_TEST - -/* Test suspension from the epilog */ -START_TEST(test_suspend_epilog) { - const char *text = "<doc></doc>\n"; - XML_Char match[] = XCS("\n"); - - XML_SetDefaultHandler(g_parser, selective_aborting_default_handler); - XML_SetUserData(g_parser, match); - resumable = XML_TRUE; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_SUSPENDED) - xml_failure(g_parser); -} -END_TEST - -static void XMLCALL -suspending_end_handler(void *userData, const XML_Char *s) { - UNUSED_P(s); - XML_StopParser((XML_Parser)userData, 1); -} - -START_TEST(test_suspend_in_sole_empty_tag) { - const char *text = "<doc/>"; - enum XML_Status rc; - - XML_SetEndElementHandler(g_parser, suspending_end_handler); - XML_SetUserData(g_parser, g_parser); - rc = _XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE); - if (rc == XML_STATUS_ERROR) - xml_failure(g_parser); - else if (rc != XML_STATUS_SUSPENDED) - fail("Suspend not triggered"); - rc = XML_ResumeParser(g_parser); - if (rc == XML_STATUS_ERROR) - xml_failure(g_parser); - else if (rc != XML_STATUS_OK) - fail("Resume failed"); -} -END_TEST - -START_TEST(test_unfinished_epilog) { - const char *text = "<doc></doc><"; - - expect_failure(text, XML_ERROR_UNCLOSED_TOKEN, - "Incomplete epilog entry not faulted"); -} -END_TEST - -START_TEST(test_partial_char_in_epilog) { - const char *text = "<doc></doc>\xe2\x82"; - - /* First check that no fault is raised if the parse is not finished */ - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - /* Now check that it is faulted once we finish */ - if (XML_ParseBuffer(g_parser, 0, XML_TRUE) != XML_STATUS_ERROR) - fail("Partial character in epilog not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_PARTIAL_CHAR) - xml_failure(g_parser); -} -END_TEST - -START_TEST(test_hash_collision) { - /* For full coverage of the lookup routine, we need to ensure a - * hash collision even though we can only tell that we have one - * through breakpoint debugging or coverage statistics. The - * following will cause a hash collision on machines with a 64-bit - * long type; others will have to experiment. The full coverage - * tests invoked from qa.sh usually provide a hash collision, but - * not always. This is an attempt to provide insurance. - */ -#define COLLIDING_HASH_SALT (unsigned long)_SIP_ULL(0xffffffffU, 0xff99fc90U) - const char *text - = "<doc>\n" - "<a1/><a2/><a3/><a4/><a5/><a6/><a7/><a8/>\n" - "<b1></b1><b2 attr='foo'>This is a foo</b2><b3></b3><b4></b4>\n" - "<b5></b5><b6></b6><b7></b7><b8></b8>\n" - "<c1/><c2/><c3/><c4/><c5/><c6/><c7/><c8/>\n" - "<d1/><d2/><d3/><d4/><d5/><d6/><d7/>\n" - "<d8>This triggers the table growth and collides with b2</d8>\n" - "</doc>\n"; - - XML_SetHashSalt(g_parser, COLLIDING_HASH_SALT); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST -#undef COLLIDING_HASH_SALT - -/* Test resuming a parse suspended in entity substitution */ -static void XMLCALL -start_element_suspender(void *userData, const XML_Char *name, - const XML_Char **atts) { - UNUSED_P(userData); - UNUSED_P(atts); - if (! xcstrcmp(name, XCS("suspend"))) - XML_StopParser(g_parser, XML_TRUE); - if (! xcstrcmp(name, XCS("abort"))) - XML_StopParser(g_parser, XML_FALSE); -} - -START_TEST(test_suspend_resume_internal_entity) { - const char *text - = "<!DOCTYPE doc [\n" - "<!ENTITY foo '<suspend>Hi<suspend>Ho</suspend></suspend>'>\n" - "]>\n" - "<doc>&foo;</doc>\n"; - const XML_Char *expected1 = XCS("Hi"); - const XML_Char *expected2 = XCS("HiHo"); - CharData storage; - - CharData_Init(&storage); - XML_SetStartElementHandler(g_parser, start_element_suspender); - XML_SetCharacterDataHandler(g_parser, accumulate_characters); - XML_SetUserData(g_parser, &storage); - if (XML_Parse(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_SUSPENDED) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, XCS("")); - if (XML_ResumeParser(g_parser) != XML_STATUS_SUSPENDED) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected1); - if (XML_ResumeParser(g_parser) != XML_STATUS_OK) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected2); -} -END_TEST - -/* Test syntax error is caught at parse resumption */ -START_TEST(test_resume_entity_with_syntax_error) { - const char *text = "<!DOCTYPE doc [\n" - "<!ENTITY foo '<suspend>Hi</wombat>'>\n" - "]>\n" - "<doc>&foo;</doc>\n"; - - XML_SetStartElementHandler(g_parser, start_element_suspender); - if (XML_Parse(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_SUSPENDED) - xml_failure(g_parser); - if (XML_ResumeParser(g_parser) != XML_STATUS_ERROR) - fail("Syntax error in entity not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_TAG_MISMATCH) - xml_failure(g_parser); -} -END_TEST - -/* Test suspending and resuming in a parameter entity substitution */ -static void XMLCALL -element_decl_suspender(void *userData, const XML_Char *name, - XML_Content *model) { - UNUSED_P(userData); - UNUSED_P(name); - XML_StopParser(g_parser, XML_TRUE); - XML_FreeContentModel(g_parser, model); -} - -START_TEST(test_suspend_resume_parameter_entity) { - const char *text = "<!DOCTYPE doc [\n" - "<!ENTITY % foo '<!ELEMENT doc (#PCDATA)*>'>\n" - "%foo;\n" - "]>\n" - "<doc>Hello, world</doc>"; - const XML_Char *expected = XCS("Hello, world"); - CharData storage; - - CharData_Init(&storage); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetElementDeclHandler(g_parser, element_decl_suspender); - XML_SetCharacterDataHandler(g_parser, accumulate_characters); - XML_SetUserData(g_parser, &storage); - if (XML_Parse(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_SUSPENDED) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, XCS("")); - if (XML_ResumeParser(g_parser) != XML_STATUS_OK) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Test attempting to use parser after an error is faulted */ -START_TEST(test_restart_on_error) { - const char *text = "<$doc><doc></doc>"; - - if (XML_Parse(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - fail("Invalid tag name not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_INVALID_TOKEN) - xml_failure(g_parser); - if (XML_Parse(g_parser, NULL, 0, XML_TRUE) != XML_STATUS_ERROR) - fail("Restarting invalid parse not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_INVALID_TOKEN) - xml_failure(g_parser); -} -END_TEST - -/* Test that angle brackets in an attribute default value are faulted */ -START_TEST(test_reject_lt_in_attribute_value) { - const char *text = "<!DOCTYPE doc [<!ATTLIST doc a CDATA '<bar>'>]>\n" - "<doc></doc>"; - - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "Bad attribute default not faulted"); -} -END_TEST - -START_TEST(test_reject_unfinished_param_in_att_value) { - const char *text = "<!DOCTYPE doc [<!ATTLIST doc a CDATA '&foo'>]>\n" - "<doc></doc>"; - - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "Bad attribute default not faulted"); -} -END_TEST - -START_TEST(test_trailing_cr_in_att_value) { - const char *text = "<doc a='value\r'/>"; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST +#include "common.h" -/* Try parsing a general entity within a parameter entity in a - * standalone internal DTD. Covers a corner case in the parser. - */ -START_TEST(test_standalone_internal_entity) { - const char *text = "<?xml version='1.0' standalone='yes' ?>\n" - "<!DOCTYPE doc [\n" - " <!ELEMENT doc (#PCDATA)>\n" - " <!ENTITY % pe '<!ATTLIST doc att2 CDATA \"≥\">'>\n" - " <!ENTITY ge 'AttDefaultValue'>\n" - " %pe;\n" - "]>\n" - "<doc att2='any'/>"; +#include "basic_tests.h" +#include "ns_tests.h" +#include "misc_tests.h" +#include "alloc_tests.h" +#include "nsalloc_tests.h" +#include "acc_tests.h" - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test that a reference to an unknown external entity is skipped */ -START_TEST(test_skipped_external_entity) { - const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/'>\n" - "<doc></doc>\n"; - ExtTest test_data = {"<!ELEMENT doc EMPTY>\n" - "<!ENTITY % e2 '%e1;'>\n", - NULL, NULL}; - - XML_SetUserData(g_parser, &test_data); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test a different form of unknown external entity */ -typedef struct ext_hdlr_data { - const char *parse_text; - XML_ExternalEntityRefHandler handler; -} ExtHdlrData; - -static int XMLCALL -external_entity_oneshot_loader(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - ExtHdlrData *test_data = (ExtHdlrData *)XML_GetUserData(parser); - XML_Parser ext_parser; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser."); - /* Use the requested entity parser for further externals */ - XML_SetExternalEntityRefHandler(ext_parser, test_data->handler); - if (_XML_Parse_SINGLE_BYTES(ext_parser, test_data->parse_text, - (int)strlen(test_data->parse_text), XML_TRUE) - == XML_STATUS_ERROR) { - xml_failure(ext_parser); - } - - XML_ParserFree(ext_parser); - return XML_STATUS_OK; -} - -START_TEST(test_skipped_null_loaded_ext_entity) { - const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/one.ent'>\n" - "<doc />"; - ExtHdlrData test_data - = {"<!ENTITY % pe1 SYSTEM 'http://example.org/two.ent'>\n" - "<!ENTITY % pe2 '%pe1;'>\n" - "%pe2;\n", - external_entity_null_loader}; - - XML_SetUserData(g_parser, &test_data); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_oneshot_loader); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -START_TEST(test_skipped_unloaded_ext_entity) { - const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/one.ent'>\n" - "<doc />"; - ExtHdlrData test_data - = {"<!ENTITY % pe1 SYSTEM 'http://example.org/two.ent'>\n" - "<!ENTITY % pe2 '%pe1;'>\n" - "%pe2;\n", - NULL}; - - XML_SetUserData(g_parser, &test_data); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_oneshot_loader); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test that a parameter entity value ending with a carriage return - * has it translated internally into a newline. - */ -START_TEST(test_param_entity_with_trailing_cr) { -#define PARAM_ENTITY_NAME "pe" -#define PARAM_ENTITY_CORE_VALUE "<!ATTLIST doc att CDATA \"default\">" - const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/'>\n" - "<doc/>"; - ExtTest test_data - = {"<!ENTITY % " PARAM_ENTITY_NAME " '" PARAM_ENTITY_CORE_VALUE "\r'>\n" - "%" PARAM_ENTITY_NAME ";\n", - NULL, NULL}; - - XML_SetUserData(g_parser, &test_data); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader); - XML_SetEntityDeclHandler(g_parser, param_entity_match_handler); - entity_name_to_match = XCS(PARAM_ENTITY_NAME); - entity_value_to_match = XCS(PARAM_ENTITY_CORE_VALUE) XCS("\n"); - entity_match_flag = ENTITY_MATCH_NOT_FOUND; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - if (entity_match_flag == ENTITY_MATCH_FAIL) - fail("Parameter entity CR->NEWLINE conversion failed"); - else if (entity_match_flag == ENTITY_MATCH_NOT_FOUND) - fail("Parameter entity not parsed"); -} -#undef PARAM_ENTITY_NAME -#undef PARAM_ENTITY_CORE_VALUE -END_TEST - -START_TEST(test_invalid_character_entity) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY entity '�'>\n" - "]>\n" - "<doc>&entity;</doc>"; - - expect_failure(text, XML_ERROR_BAD_CHAR_REF, - "Out of range character reference not faulted"); -} -END_TEST - -START_TEST(test_invalid_character_entity_2) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY entity '&#xg0;'>\n" - "]>\n" - "<doc>&entity;</doc>"; - - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "Out of range character reference not faulted"); -} -END_TEST - -START_TEST(test_invalid_character_entity_3) { - const char text[] = - /* <!DOCTYPE doc [\n */ - "\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0d\0o\0c\0 \0[\0\n" - /* U+0E04 = KHO KHWAI - * U+0E08 = CHO CHAN */ - /* <!ENTITY entity '&\u0e04\u0e08;'>\n */ - "\0<\0!\0E\0N\0T\0I\0T\0Y\0 \0e\0n\0t\0i\0t\0y\0 " - "\0'\0&\x0e\x04\x0e\x08\0;\0'\0>\0\n" - /* ]>\n */ - "\0]\0>\0\n" - /* <doc>&entity;</doc> */ - "\0<\0d\0o\0c\0>\0&\0e\0n\0t\0i\0t\0y\0;\0<\0/\0d\0o\0c\0>"; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - != XML_STATUS_ERROR) - fail("Invalid start of entity name not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_UNDEFINED_ENTITY) - xml_failure(g_parser); -} -END_TEST - -START_TEST(test_invalid_character_entity_4) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY entity '�'>\n" /* = � */ - "]>\n" - "<doc>&entity;</doc>"; - - expect_failure(text, XML_ERROR_BAD_CHAR_REF, - "Out of range character reference not faulted"); -} -END_TEST - -/* Test that processing instructions are picked up by a default handler */ -START_TEST(test_pi_handled_in_default) { - const char *text = "<?test processing instruction?>\n<doc/>"; - const XML_Char *expected = XCS("<?test processing instruction?>\n<doc/>"); - CharData storage; - - CharData_Init(&storage); - XML_SetDefaultHandler(g_parser, accumulate_characters); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Test that comments are picked up by a default handler */ -START_TEST(test_comment_handled_in_default) { - const char *text = "<!-- This is a comment -->\n<doc/>"; - const XML_Char *expected = XCS("<!-- This is a comment -->\n<doc/>"); - CharData storage; - - CharData_Init(&storage); - XML_SetDefaultHandler(g_parser, accumulate_characters); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Test PIs that look almost but not quite like XML declarations */ -static void XMLCALL -accumulate_pi_characters(void *userData, const XML_Char *target, - const XML_Char *data) { - CharData *storage = (CharData *)userData; - - CharData_AppendXMLChars(storage, target, -1); - CharData_AppendXMLChars(storage, XCS(": "), 2); - CharData_AppendXMLChars(storage, data, -1); - CharData_AppendXMLChars(storage, XCS("\n"), 1); -} - -START_TEST(test_pi_yml) { - const char *text = "<?yml something like data?><doc/>"; - const XML_Char *expected = XCS("yml: something like data\n"); - CharData storage; - - CharData_Init(&storage); - XML_SetProcessingInstructionHandler(g_parser, accumulate_pi_characters); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_pi_xnl) { - const char *text = "<?xnl nothing like data?><doc/>"; - const XML_Char *expected = XCS("xnl: nothing like data\n"); - CharData storage; - - CharData_Init(&storage); - XML_SetProcessingInstructionHandler(g_parser, accumulate_pi_characters); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_pi_xmm) { - const char *text = "<?xmm everything like data?><doc/>"; - const XML_Char *expected = XCS("xmm: everything like data\n"); - CharData storage; - - CharData_Init(&storage); - XML_SetProcessingInstructionHandler(g_parser, accumulate_pi_characters); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_utf16_pi) { - const char text[] = - /* <?{KHO KHWAI}{CHO CHAN}?> - * where {KHO KHWAI} = U+0E04 - * and {CHO CHAN} = U+0E08 - */ - "<\0?\0\x04\x0e\x08\x0e?\0>\0" - /* <q/> */ - "<\0q\0/\0>\0"; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x0e04\x0e08: \n"); -#else - const XML_Char *expected = XCS("\xe0\xb8\x84\xe0\xb8\x88: \n"); -#endif - CharData storage; - - CharData_Init(&storage); - XML_SetProcessingInstructionHandler(g_parser, accumulate_pi_characters); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_utf16_be_pi) { - const char text[] = - /* <?{KHO KHWAI}{CHO CHAN}?> - * where {KHO KHWAI} = U+0E04 - * and {CHO CHAN} = U+0E08 - */ - "\0<\0?\x0e\x04\x0e\x08\0?\0>" - /* <q/> */ - "\0<\0q\0/\0>"; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x0e04\x0e08: \n"); -#else - const XML_Char *expected = XCS("\xe0\xb8\x84\xe0\xb8\x88: \n"); -#endif - CharData storage; - - CharData_Init(&storage); - XML_SetProcessingInstructionHandler(g_parser, accumulate_pi_characters); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Test that comments can be picked up and translated */ -static void XMLCALL -accumulate_comment(void *userData, const XML_Char *data) { - CharData *storage = (CharData *)userData; - - CharData_AppendXMLChars(storage, data, -1); -} - -START_TEST(test_utf16_be_comment) { - const char text[] = - /* <!-- Comment A --> */ - "\0<\0!\0-\0-\0 \0C\0o\0m\0m\0e\0n\0t\0 \0A\0 \0-\0-\0>\0\n" - /* <doc/> */ - "\0<\0d\0o\0c\0/\0>"; - const XML_Char *expected = XCS(" Comment A "); - CharData storage; - - CharData_Init(&storage); - XML_SetCommentHandler(g_parser, accumulate_comment); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_utf16_le_comment) { - const char text[] = - /* <!-- Comment B --> */ - "<\0!\0-\0-\0 \0C\0o\0m\0m\0e\0n\0t\0 \0B\0 \0-\0-\0>\0\n\0" - /* <doc/> */ - "<\0d\0o\0c\0/\0>\0"; - const XML_Char *expected = XCS(" Comment B "); - CharData storage; - - CharData_Init(&storage); - XML_SetCommentHandler(g_parser, accumulate_comment); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Test that the unknown encoding handler with map entries that expect - * conversion but no conversion function is faulted - */ -static int XMLCALL -failing_converter(void *data, const char *s) { - UNUSED_P(data); - UNUSED_P(s); - /* Always claim to have failed */ - return -1; -} - -static int XMLCALL -prefix_converter(void *data, const char *s) { - UNUSED_P(data); - /* If the first byte is 0xff, raise an error */ - if (s[0] == (char)-1) - return -1; - /* Just add the low bits of the first byte to the second */ - return (s[1] + (s[0] & 0x7f)) & 0x01ff; -} - -static int XMLCALL -MiscEncodingHandler(void *data, const XML_Char *encoding, XML_Encoding *info) { - int i; - int high_map = -2; /* Assume a 2-byte sequence */ - - if (! xcstrcmp(encoding, XCS("invalid-9")) - || ! xcstrcmp(encoding, XCS("ascii-like")) - || ! xcstrcmp(encoding, XCS("invalid-len")) - || ! xcstrcmp(encoding, XCS("invalid-a")) - || ! xcstrcmp(encoding, XCS("invalid-surrogate")) - || ! xcstrcmp(encoding, XCS("invalid-high"))) - high_map = -1; - - for (i = 0; i < 128; ++i) - info->map[i] = i; - for (; i < 256; ++i) - info->map[i] = high_map; - - /* If required, put an invalid value in the ASCII entries */ - if (! xcstrcmp(encoding, XCS("invalid-9"))) - info->map[9] = 5; - /* If required, have a top-bit set character starts a 5-byte sequence */ - if (! xcstrcmp(encoding, XCS("invalid-len"))) - info->map[0x81] = -5; - /* If required, make a top-bit set character a valid ASCII character */ - if (! xcstrcmp(encoding, XCS("invalid-a"))) - info->map[0x82] = 'a'; - /* If required, give a top-bit set character a forbidden value, - * what would otherwise be the first of a surrogate pair. - */ - if (! xcstrcmp(encoding, XCS("invalid-surrogate"))) - info->map[0x83] = 0xd801; - /* If required, give a top-bit set character too high a value */ - if (! xcstrcmp(encoding, XCS("invalid-high"))) - info->map[0x84] = 0x010101; - - info->data = data; - info->release = NULL; - if (! xcstrcmp(encoding, XCS("failing-conv"))) - info->convert = failing_converter; - else if (! xcstrcmp(encoding, XCS("prefix-conv"))) - info->convert = prefix_converter; - else - info->convert = NULL; - return XML_STATUS_OK; -} - -START_TEST(test_missing_encoding_conversion_fn) { - const char *text = "<?xml version='1.0' encoding='no-conv'?>\n" - "<doc>\x81</doc>"; - - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - /* MiscEncodingHandler sets up an encoding with every top-bit-set - * character introducing a two-byte sequence. For this, it - * requires a convert function. The above function call doesn't - * pass one through, so when BadEncodingHandler actually gets - * called it should supply an invalid encoding. - */ - expect_failure(text, XML_ERROR_UNKNOWN_ENCODING, - "Encoding with missing convert() not faulted"); -} -END_TEST - -START_TEST(test_failing_encoding_conversion_fn) { - const char *text = "<?xml version='1.0' encoding='failing-conv'?>\n" - "<doc>\x81</doc>"; - - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - /* BadEncodingHandler sets up an encoding with every top-bit-set - * character introducing a two-byte sequence. For this, it - * requires a convert function. The above function call passes - * one that insists all possible sequences are invalid anyway. - */ - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "Encoding with failing convert() not faulted"); -} -END_TEST - -/* Test unknown encoding conversions */ -START_TEST(test_unknown_encoding_success) { - const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n" - /* Equivalent to <eoc>Hello, world</eoc> */ - "<\x81\x64\x80oc>Hello, world</\x81\x64\x80oc>"; - - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - run_character_check(text, XCS("Hello, world")); -} -END_TEST - -/* Test bad name character in unknown encoding */ -START_TEST(test_unknown_encoding_bad_name) { - const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n" - "<\xff\x64oc>Hello, world</\xff\x64oc>"; - - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "Bad name start in unknown encoding not faulted"); -} -END_TEST - -/* Test bad mid-name character in unknown encoding */ -START_TEST(test_unknown_encoding_bad_name_2) { - const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n" - "<d\xffoc>Hello, world</d\xffoc>"; - - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "Bad name in unknown encoding not faulted"); -} -END_TEST - -/* Test element name that is long enough to fill the conversion buffer - * in an unknown encoding, finishing with an encoded character. - */ -START_TEST(test_unknown_encoding_long_name_1) { - const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n" - "<abcdefghabcdefghabcdefghijkl\x80m\x80n\x80o\x80p>" - "Hi" - "</abcdefghabcdefghabcdefghijkl\x80m\x80n\x80o\x80p>"; - const XML_Char *expected = XCS("abcdefghabcdefghabcdefghijklmnop"); - CharData storage; - - CharData_Init(&storage); - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - XML_SetStartElementHandler(g_parser, record_element_start_handler); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Test element name that is long enough to fill the conversion buffer - * in an unknown encoding, finishing with an simple character. - */ -START_TEST(test_unknown_encoding_long_name_2) { - const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n" - "<abcdefghabcdefghabcdefghijklmnop>" - "Hi" - "</abcdefghabcdefghabcdefghijklmnop>"; - const XML_Char *expected = XCS("abcdefghabcdefghabcdefghijklmnop"); - CharData storage; - - CharData_Init(&storage); - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - XML_SetStartElementHandler(g_parser, record_element_start_handler); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_invalid_unknown_encoding) { - const char *text = "<?xml version='1.0' encoding='invalid-9'?>\n" - "<doc>Hello world</doc>"; - - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - expect_failure(text, XML_ERROR_UNKNOWN_ENCODING, - "Invalid unknown encoding not faulted"); -} -END_TEST - -START_TEST(test_unknown_ascii_encoding_ok) { - const char *text = "<?xml version='1.0' encoding='ascii-like'?>\n" - "<doc>Hello, world</doc>"; - - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - run_character_check(text, XCS("Hello, world")); -} -END_TEST - -START_TEST(test_unknown_ascii_encoding_fail) { - const char *text = "<?xml version='1.0' encoding='ascii-like'?>\n" - "<doc>Hello, \x80 world</doc>"; - - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "Invalid character not faulted"); -} -END_TEST - -START_TEST(test_unknown_encoding_invalid_length) { - const char *text = "<?xml version='1.0' encoding='invalid-len'?>\n" - "<doc>Hello, world</doc>"; - - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - expect_failure(text, XML_ERROR_UNKNOWN_ENCODING, - "Invalid unknown encoding not faulted"); -} -END_TEST - -START_TEST(test_unknown_encoding_invalid_topbit) { - const char *text = "<?xml version='1.0' encoding='invalid-a'?>\n" - "<doc>Hello, world</doc>"; - - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - expect_failure(text, XML_ERROR_UNKNOWN_ENCODING, - "Invalid unknown encoding not faulted"); -} -END_TEST - -START_TEST(test_unknown_encoding_invalid_surrogate) { - const char *text = "<?xml version='1.0' encoding='invalid-surrogate'?>\n" - "<doc>Hello, \x82 world</doc>"; - - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "Invalid unknown encoding not faulted"); -} -END_TEST - -START_TEST(test_unknown_encoding_invalid_high) { - const char *text = "<?xml version='1.0' encoding='invalid-high'?>\n" - "<doc>Hello, world</doc>"; - - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - expect_failure(text, XML_ERROR_UNKNOWN_ENCODING, - "Invalid unknown encoding not faulted"); -} -END_TEST - -START_TEST(test_unknown_encoding_invalid_attr_value) { - const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n" - "<doc attr='\xff\x30'/>"; - - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "Invalid attribute valid not faulted"); -} -END_TEST - -/* Test an external entity parser set to use latin-1 detects UTF-16 - * BOMs correctly. - */ -enum ee_parse_flags { EE_PARSE_NONE = 0x00, EE_PARSE_FULL_BUFFER = 0x01 }; - -typedef struct ExtTest2 { - const char *parse_text; - int parse_len; - const XML_Char *encoding; - CharData *storage; - enum ee_parse_flags flags; -} ExtTest2; - -static int XMLCALL -external_entity_loader2(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - ExtTest2 *test_data = (ExtTest2 *)XML_GetUserData(parser); - XML_Parser extparser; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - extparser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (extparser == NULL) - fail("Coulr not create external entity parser"); - if (test_data->encoding != NULL) { - if (! XML_SetEncoding(extparser, test_data->encoding)) - fail("XML_SetEncoding() ignored for external entity"); - } - if (test_data->flags & EE_PARSE_FULL_BUFFER) { - if (XML_Parse(extparser, test_data->parse_text, test_data->parse_len, - XML_TRUE) - == XML_STATUS_ERROR) { - xml_failure(extparser); - } - } else if (_XML_Parse_SINGLE_BYTES(extparser, test_data->parse_text, - test_data->parse_len, XML_TRUE) - == XML_STATUS_ERROR) { - xml_failure(extparser); - } - - XML_ParserFree(extparser); - return XML_STATUS_OK; -} - -/* Test that UTF-16 BOM does not select UTF-16 given explicit encoding */ -static void XMLCALL -ext2_accumulate_characters(void *userData, const XML_Char *s, int len) { - ExtTest2 *test_data = (ExtTest2 *)userData; - accumulate_characters(test_data->storage, s, len); -} - -START_TEST(test_ext_entity_latin1_utf16le_bom) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - ExtTest2 test_data - = {/* If UTF-16, 0xfeff is the BOM and 0x204c is black left bullet */ - /* If Latin-1, 0xff = Y-diaeresis, 0xfe = lowercase thorn, - * 0x4c = L and 0x20 is a space - */ - "\xff\xfe\x4c\x20", 4, XCS("iso-8859-1"), NULL, EE_PARSE_NONE}; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x00ff\x00feL "); -#else - /* In UTF-8, y-diaeresis is 0xc3 0xbf, lowercase thorn is 0xc3 0xbe */ - const XML_Char *expected = XCS("\xc3\xbf\xc3\xbeL "); -#endif - CharData storage; - - CharData_Init(&storage); - test_data.storage = &storage; - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); - XML_SetUserData(g_parser, &test_data); - XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_ext_entity_latin1_utf16be_bom) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - ExtTest2 test_data - = {/* If UTF-16, 0xfeff is the BOM and 0x204c is black left bullet */ - /* If Latin-1, 0xff = Y-diaeresis, 0xfe = lowercase thorn, - * 0x4c = L and 0x20 is a space - */ - "\xfe\xff\x20\x4c", 4, XCS("iso-8859-1"), NULL, EE_PARSE_NONE}; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x00fe\x00ff L"); -#else - /* In UTF-8, y-diaeresis is 0xc3 0xbf, lowercase thorn is 0xc3 0xbe */ - const XML_Char *expected = XCS("\xc3\xbe\xc3\xbf L"); -#endif - CharData storage; - - CharData_Init(&storage); - test_data.storage = &storage; - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); - XML_SetUserData(g_parser, &test_data); - XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Parsing the full buffer rather than a byte at a time makes a - * difference to the encoding scanning code, so repeat the above tests - * without breaking them down by byte. - */ -START_TEST(test_ext_entity_latin1_utf16le_bom2) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - ExtTest2 test_data - = {/* If UTF-16, 0xfeff is the BOM and 0x204c is black left bullet */ - /* If Latin-1, 0xff = Y-diaeresis, 0xfe = lowercase thorn, - * 0x4c = L and 0x20 is a space - */ - "\xff\xfe\x4c\x20", 4, XCS("iso-8859-1"), NULL, EE_PARSE_FULL_BUFFER}; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x00ff\x00feL "); -#else - /* In UTF-8, y-diaeresis is 0xc3 0xbf, lowercase thorn is 0xc3 0xbe */ - const XML_Char *expected = XCS("\xc3\xbf\xc3\xbeL "); -#endif - CharData storage; - - CharData_Init(&storage); - test_data.storage = &storage; - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); - XML_SetUserData(g_parser, &test_data); - XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); - if (XML_Parse(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_ext_entity_latin1_utf16be_bom2) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - ExtTest2 test_data - = {/* If UTF-16, 0xfeff is the BOM and 0x204c is black left bullet */ - /* If Latin-1, 0xff = Y-diaeresis, 0xfe = lowercase thorn, - * 0x4c = L and 0x20 is a space - */ - "\xfe\xff\x20\x4c", 4, XCS("iso-8859-1"), NULL, EE_PARSE_FULL_BUFFER}; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x00fe\x00ff L"); -#else - /* In UTF-8, y-diaeresis is 0xc3 0xbf, lowercase thorn is 0xc3 0xbe */ - const XML_Char *expected = "\xc3\xbe\xc3\xbf L"; -#endif - CharData storage; - - CharData_Init(&storage); - test_data.storage = &storage; - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); - XML_SetUserData(g_parser, &test_data); - XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); - if (XML_Parse(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Test little-endian UTF-16 given an explicit big-endian encoding */ -START_TEST(test_ext_entity_utf16_be) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - ExtTest2 test_data - = {"<\0e\0/\0>\0", 8, XCS("utf-16be"), NULL, EE_PARSE_NONE}; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x3c00\x6500\x2f00\x3e00"); -#else - const XML_Char *expected = XCS("\xe3\xb0\x80" /* U+3C00 */ - "\xe6\x94\x80" /* U+6500 */ - "\xe2\xbc\x80" /* U+2F00 */ - "\xe3\xb8\x80"); /* U+3E00 */ -#endif - CharData storage; - - CharData_Init(&storage); - test_data.storage = &storage; - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); - XML_SetUserData(g_parser, &test_data); - XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Test big-endian UTF-16 given an explicit little-endian encoding */ -START_TEST(test_ext_entity_utf16_le) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - ExtTest2 test_data - = {"\0<\0e\0/\0>", 8, XCS("utf-16le"), NULL, EE_PARSE_NONE}; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x3c00\x6500\x2f00\x3e00"); -#else - const XML_Char *expected = XCS("\xe3\xb0\x80" /* U+3C00 */ - "\xe6\x94\x80" /* U+6500 */ - "\xe2\xbc\x80" /* U+2F00 */ - "\xe3\xb8\x80"); /* U+3E00 */ -#endif - CharData storage; - - CharData_Init(&storage); - test_data.storage = &storage; - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); - XML_SetUserData(g_parser, &test_data); - XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Test little-endian UTF-16 given no explicit encoding. - * The existing default encoding (UTF-8) is assumed to hold without a - * BOM to contradict it, so the entity value will in fact provoke an - * error because 0x00 is not a valid XML character. We parse the - * whole buffer in one go rather than feeding it in byte by byte to - * exercise different code paths in the initial scanning routines. - */ -typedef struct ExtFaults2 { - const char *parse_text; - int parse_len; - const char *fail_text; - const XML_Char *encoding; - enum XML_Error error; -} ExtFaults2; - -static int XMLCALL -external_entity_faulter2(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - ExtFaults2 *test_data = (ExtFaults2 *)XML_GetUserData(parser); - XML_Parser extparser; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - extparser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (extparser == NULL) - fail("Could not create external entity parser"); - if (test_data->encoding != NULL) { - if (! XML_SetEncoding(extparser, test_data->encoding)) - fail("XML_SetEncoding() ignored for external entity"); - } - if (XML_Parse(extparser, test_data->parse_text, test_data->parse_len, - XML_TRUE) - != XML_STATUS_ERROR) - fail(test_data->fail_text); - if (XML_GetErrorCode(extparser) != test_data->error) - xml_failure(extparser); - - XML_ParserFree(extparser); - return XML_STATUS_ERROR; -} - -START_TEST(test_ext_entity_utf16_unknown) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - ExtFaults2 test_data - = {"a\0b\0c\0", 6, "Invalid character in entity not faulted", NULL, - XML_ERROR_INVALID_TOKEN}; - - XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter2); - XML_SetUserData(g_parser, &test_data); - expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, - "Invalid character should not have been accepted"); -} -END_TEST - -/* Test not-quite-UTF-8 BOM (0xEF 0xBB 0xBF) */ -START_TEST(test_ext_entity_utf8_non_bom) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - ExtTest2 test_data - = {"\xef\xbb\x80", /* Arabic letter DAD medial form, U+FEC0 */ - 3, NULL, NULL, EE_PARSE_NONE}; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\xfec0"); -#else - const XML_Char *expected = XCS("\xef\xbb\x80"); -#endif - CharData storage; - - CharData_Init(&storage); - test_data.storage = &storage; - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); - XML_SetUserData(g_parser, &test_data); - XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Test that UTF-8 in a CDATA section is correctly passed through */ -START_TEST(test_utf8_in_cdata_section) { - const char *text = "<doc><![CDATA[one \xc3\xa9 two]]></doc>"; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("one \x00e9 two"); -#else - const XML_Char *expected = XCS("one \xc3\xa9 two"); -#endif - - run_character_check(text, expected); -} -END_TEST - -/* Test that little-endian UTF-16 in a CDATA section is handled */ -START_TEST(test_utf8_in_cdata_section_2) { - const char *text = "<doc><![CDATA[\xc3\xa9]\xc3\xa9two]]></doc>"; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x00e9]\x00e9two"); -#else - const XML_Char *expected = XCS("\xc3\xa9]\xc3\xa9two"); -#endif - - run_character_check(text, expected); -} -END_TEST - -/* Test trailing spaces in elements are accepted */ -static void XMLCALL -record_element_end_handler(void *userData, const XML_Char *name) { - CharData *storage = (CharData *)userData; - - CharData_AppendXMLChars(storage, XCS("/"), 1); - CharData_AppendXMLChars(storage, name, -1); -} - -START_TEST(test_trailing_spaces_in_elements) { - const char *text = "<doc >Hi</doc >"; - const XML_Char *expected = XCS("doc/doc"); - CharData storage; - - CharData_Init(&storage); - XML_SetElementHandler(g_parser, record_element_start_handler, - record_element_end_handler); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_utf16_attribute) { - const char text[] = - /* <d {KHO KHWAI}{CHO CHAN}='a'/> - * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8 - * and {CHO CHAN} = U+0E08 = 0xe0 0xb8 0x88 in UTF-8 - */ - "<\0d\0 \0\x04\x0e\x08\x0e=\0'\0a\0'\0/\0>\0"; - const XML_Char *expected = XCS("a"); - CharData storage; - - CharData_Init(&storage); - XML_SetStartElementHandler(g_parser, accumulate_attribute); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_utf16_second_attr) { - /* <d a='1' {KHO KHWAI}{CHO CHAN}='2'/> - * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8 - * and {CHO CHAN} = U+0E08 = 0xe0 0xb8 0x88 in UTF-8 - */ - const char text[] = "<\0d\0 \0a\0=\0'\0\x31\0'\0 \0" - "\x04\x0e\x08\x0e=\0'\0\x32\0'\0/\0>\0"; - const XML_Char *expected = XCS("1"); - CharData storage; - - CharData_Init(&storage); - XML_SetStartElementHandler(g_parser, accumulate_attribute); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_attr_after_solidus) { - const char *text = "<doc attr1='a' / attr2='b'>"; - - expect_failure(text, XML_ERROR_INVALID_TOKEN, "Misplaced / not faulted"); -} -END_TEST - -static void XMLCALL -accumulate_entity_decl(void *userData, const XML_Char *entityName, - int is_parameter_entity, const XML_Char *value, - int value_length, const XML_Char *base, - const XML_Char *systemId, const XML_Char *publicId, - const XML_Char *notationName) { - CharData *storage = (CharData *)userData; - - UNUSED_P(is_parameter_entity); - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - UNUSED_P(notationName); - CharData_AppendXMLChars(storage, entityName, -1); - CharData_AppendXMLChars(storage, XCS("="), 1); - CharData_AppendXMLChars(storage, value, value_length); - CharData_AppendXMLChars(storage, XCS("\n"), 1); -} - -START_TEST(test_utf16_pe) { - /* <!DOCTYPE doc [ - * <!ENTITY % {KHO KHWAI}{CHO CHAN} '<!ELEMENT doc (#PCDATA)>'> - * %{KHO KHWAI}{CHO CHAN}; - * ]> - * <doc></doc> - * - * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8 - * and {CHO CHAN} = U+0E08 = 0xe0 0xb8 0x88 in UTF-8 - */ - const char text[] = "\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0d\0o\0c\0 \0[\0\n" - "\0<\0!\0E\0N\0T\0I\0T\0Y\0 \0%\0 \x0e\x04\x0e\x08\0 " - "\0'\0<\0!\0E\0L\0E\0M\0E\0N\0T\0 " - "\0d\0o\0c\0 \0(\0#\0P\0C\0D\0A\0T\0A\0)\0>\0'\0>\0\n" - "\0%\x0e\x04\x0e\x08\0;\0\n" - "\0]\0>\0\n" - "\0<\0d\0o\0c\0>\0<\0/\0d\0o\0c\0>"; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x0e04\x0e08=<!ELEMENT doc (#PCDATA)>\n"); -#else - const XML_Char *expected - = XCS("\xe0\xb8\x84\xe0\xb8\x88=<!ELEMENT doc (#PCDATA)>\n"); -#endif - CharData storage; - - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetEntityDeclHandler(g_parser, accumulate_entity_decl); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Test that duff attribute description keywords are rejected */ -START_TEST(test_bad_attr_desc_keyword) { - const char *text = "<!DOCTYPE doc [\n" - " <!ATTLIST doc attr CDATA #!IMPLIED>\n" - "]>\n" - "<doc />"; - - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "Bad keyword !IMPLIED not faulted"); -} -END_TEST - -/* Test that an invalid attribute description keyword consisting of - * UTF-16 characters with their top bytes non-zero are correctly - * faulted - */ -START_TEST(test_bad_attr_desc_keyword_utf16) { - /* <!DOCTYPE d [ - * <!ATTLIST d a CDATA #{KHO KHWAI}{CHO CHAN}> - * ]><d/> - * - * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8 - * and {CHO CHAN} = U+0E08 = 0xe0 0xb8 0x88 in UTF-8 - */ - const char text[] - = "\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0d\0 \0[\0\n" - "\0<\0!\0A\0T\0T\0L\0I\0S\0T\0 \0d\0 \0a\0 \0C\0D\0A\0T\0A\0 " - "\0#\x0e\x04\x0e\x08\0>\0\n" - "\0]\0>\0<\0d\0/\0>"; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - != XML_STATUS_ERROR) - fail("Invalid UTF16 attribute keyword not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_SYNTAX) - xml_failure(g_parser); -} -END_TEST - -/* Test that invalid syntax in a <!DOCTYPE> is rejected. Do this - * using prefix-encoding (see above) to trigger specific code paths - */ -START_TEST(test_bad_doctype) { - const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n" - "<!DOCTYPE doc [ \x80\x44 ]><doc/>"; - - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - expect_failure(text, XML_ERROR_SYNTAX, - "Invalid bytes in DOCTYPE not faulted"); -} -END_TEST - -START_TEST(test_bad_doctype_utf16) { - const char text[] = - /* <!DOCTYPE doc [ \x06f2 ]><doc/> - * - * U+06F2 = EXTENDED ARABIC-INDIC DIGIT TWO, a valid number - * (name character) but not a valid letter (name start character) - */ - "\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0d\0o\0c\0 \0[\0 " - "\x06\xf2" - "\0 \0]\0>\0<\0d\0o\0c\0/\0>"; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - != XML_STATUS_ERROR) - fail("Invalid bytes in DOCTYPE not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_SYNTAX) - xml_failure(g_parser); -} -END_TEST - -START_TEST(test_bad_doctype_plus) { - const char *text = "<!DOCTYPE 1+ [ <!ENTITY foo 'bar'> ]>\n" - "<1+>&foo;</1+>"; - - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "'+' in document name not faulted"); -} -END_TEST - -START_TEST(test_bad_doctype_star) { - const char *text = "<!DOCTYPE 1* [ <!ENTITY foo 'bar'> ]>\n" - "<1*>&foo;</1*>"; - - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "'*' in document name not faulted"); -} -END_TEST - -START_TEST(test_bad_doctype_query) { - const char *text = "<!DOCTYPE 1? [ <!ENTITY foo 'bar'> ]>\n" - "<1?>&foo;</1?>"; - - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "'?' in document name not faulted"); -} -END_TEST - -START_TEST(test_unknown_encoding_bad_ignore) { - const char *text = "<?xml version='1.0' encoding='prefix-conv'?>" - "<!DOCTYPE doc SYSTEM 'foo'>" - "<doc><e>&entity;</e></doc>"; - ExtFaults fault = {"<![IGNORE[<!ELEMENT \xffG (#PCDATA)*>]]>", - "Invalid character not faulted", XCS("prefix-conv"), - XML_ERROR_INVALID_TOKEN}; - - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter); - XML_SetUserData(g_parser, &fault); - expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, - "Bad IGNORE section with unknown encoding not failed"); -} -END_TEST - -START_TEST(test_entity_in_utf16_be_attr) { - const char text[] = - /* <e a='ä ä'></e> */ - "\0<\0e\0 \0a\0=\0'\0&\0#\0\x32\0\x32\0\x38\0;\0 " - "\0&\0#\0x\0\x30\0\x30\0E\0\x34\0;\0'\0>\0<\0/\0e\0>"; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x00e4 \x00e4"); -#else - const XML_Char *expected = XCS("\xc3\xa4 \xc3\xa4"); -#endif - CharData storage; - - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetStartElementHandler(g_parser, accumulate_attribute); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_entity_in_utf16_le_attr) { - const char text[] = - /* <e a='ä ä'></e> */ - "<\0e\0 \0a\0=\0'\0&\0#\0\x32\0\x32\0\x38\0;\0 \0" - "&\0#\0x\0\x30\0\x30\0E\0\x34\0;\0'\0>\0<\0/\0e\0>\0"; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("\x00e4 \x00e4"); -#else - const XML_Char *expected = XCS("\xc3\xa4 \xc3\xa4"); -#endif - CharData storage; - - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetStartElementHandler(g_parser, accumulate_attribute); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_entity_public_utf16_be) { - const char text[] = - /* <!DOCTYPE d [ */ - "\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0d\0 \0[\0\n" - /* <!ENTITY % e PUBLIC 'foo' 'bar.ent'> */ - "\0<\0!\0E\0N\0T\0I\0T\0Y\0 \0%\0 \0e\0 \0P\0U\0B\0L\0I\0C\0 " - "\0'\0f\0o\0o\0'\0 \0'\0b\0a\0r\0.\0e\0n\0t\0'\0>\0\n" - /* %e; */ - "\0%\0e\0;\0\n" - /* ]> */ - "\0]\0>\0\n" - /* <d>&j;</d> */ - "\0<\0d\0>\0&\0j\0;\0<\0/\0d\0>"; - ExtTest2 test_data = {/* <!ENTITY j 'baz'> */ - "\0<\0!\0E\0N\0T\0I\0T\0Y\0 \0j\0 \0'\0b\0a\0z\0'\0>", - 34, NULL, NULL, EE_PARSE_NONE}; - const XML_Char *expected = XCS("baz"); - CharData storage; - - CharData_Init(&storage); - test_data.storage = &storage; - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); - XML_SetUserData(g_parser, &test_data); - XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_entity_public_utf16_le) { - const char text[] = - /* <!DOCTYPE d [ */ - "<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0d\0 \0[\0\n\0" - /* <!ENTITY % e PUBLIC 'foo' 'bar.ent'> */ - "<\0!\0E\0N\0T\0I\0T\0Y\0 \0%\0 \0e\0 \0P\0U\0B\0L\0I\0C\0 \0" - "'\0f\0o\0o\0'\0 \0'\0b\0a\0r\0.\0e\0n\0t\0'\0>\0\n\0" - /* %e; */ - "%\0e\0;\0\n\0" - /* ]> */ - "]\0>\0\n\0" - /* <d>&j;</d> */ - "<\0d\0>\0&\0j\0;\0<\0/\0d\0>\0"; - ExtTest2 test_data = {/* <!ENTITY j 'baz'> */ - "<\0!\0E\0N\0T\0I\0T\0Y\0 \0j\0 \0'\0b\0a\0z\0'\0>\0", - 34, NULL, NULL, EE_PARSE_NONE}; - const XML_Char *expected = XCS("baz"); - CharData storage; - - CharData_Init(&storage); - test_data.storage = &storage; - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_loader2); - XML_SetUserData(g_parser, &test_data); - XML_SetCharacterDataHandler(g_parser, ext2_accumulate_characters); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -/* Test that a doctype with neither an internal nor external subset is - * faulted - */ -START_TEST(test_short_doctype) { - const char *text = "<!DOCTYPE doc></doc>"; - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "DOCTYPE without subset not rejected"); -} -END_TEST - -START_TEST(test_short_doctype_2) { - const char *text = "<!DOCTYPE doc PUBLIC></doc>"; - expect_failure(text, XML_ERROR_SYNTAX, - "DOCTYPE without Public ID not rejected"); -} -END_TEST - -START_TEST(test_short_doctype_3) { - const char *text = "<!DOCTYPE doc SYSTEM></doc>"; - expect_failure(text, XML_ERROR_SYNTAX, - "DOCTYPE without System ID not rejected"); -} -END_TEST - -START_TEST(test_long_doctype) { - const char *text = "<!DOCTYPE doc PUBLIC 'foo' 'bar' 'baz'></doc>"; - expect_failure(text, XML_ERROR_SYNTAX, "DOCTYPE with extra ID not rejected"); -} -END_TEST - -START_TEST(test_bad_entity) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY foo PUBLIC>\n" - "]>\n" - "<doc/>"; - expect_failure(text, XML_ERROR_SYNTAX, - "ENTITY without Public ID is not rejected"); -} -END_TEST - -/* Test unquoted value is faulted */ -START_TEST(test_bad_entity_2) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY % foo bar>\n" - "]>\n" - "<doc/>"; - expect_failure(text, XML_ERROR_SYNTAX, - "ENTITY without Public ID is not rejected"); -} -END_TEST - -START_TEST(test_bad_entity_3) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY % foo PUBLIC>\n" - "]>\n" - "<doc/>"; - expect_failure(text, XML_ERROR_SYNTAX, - "Parameter ENTITY without Public ID is not rejected"); -} -END_TEST - -START_TEST(test_bad_entity_4) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY % foo SYSTEM>\n" - "]>\n" - "<doc/>"; - expect_failure(text, XML_ERROR_SYNTAX, - "Parameter ENTITY without Public ID is not rejected"); -} -END_TEST - -START_TEST(test_bad_notation) { - const char *text = "<!DOCTYPE doc [\n" - " <!NOTATION n SYSTEM>\n" - "]>\n" - "<doc/>"; - expect_failure(text, XML_ERROR_SYNTAX, - "Notation without System ID is not rejected"); -} -END_TEST - -/* Test for issue #11, wrongly suppressed default handler */ -typedef struct default_check { - const XML_Char *expected; - const int expectedLen; - XML_Bool seen; -} DefaultCheck; - -static void XMLCALL -checking_default_handler(void *userData, const XML_Char *s, int len) { - DefaultCheck *data = (DefaultCheck *)userData; - int i; - - for (i = 0; data[i].expected != NULL; i++) { - if (data[i].expectedLen == len - && ! memcmp(data[i].expected, s, len * sizeof(XML_Char))) { - data[i].seen = XML_TRUE; - break; - } - } -} - -START_TEST(test_default_doctype_handler) { - const char *text = "<!DOCTYPE doc PUBLIC 'pubname' 'test.dtd' [\n" - " <!ENTITY foo 'bar'>\n" - "]>\n" - "<doc>&foo;</doc>"; - DefaultCheck test_data[] = {{XCS("'pubname'"), 9, XML_FALSE}, - {XCS("'test.dtd'"), 10, XML_FALSE}, - {NULL, 0, XML_FALSE}}; - int i; - - XML_SetUserData(g_parser, &test_data); - XML_SetDefaultHandler(g_parser, checking_default_handler); - XML_SetEntityDeclHandler(g_parser, dummy_entity_decl_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - for (i = 0; test_data[i].expected != NULL; i++) - if (! test_data[i].seen) - fail("Default handler not run for public !DOCTYPE"); -} -END_TEST - -START_TEST(test_empty_element_abort) { - const char *text = "<abort/>"; - - XML_SetStartElementHandler(g_parser, start_element_suspender); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - fail("Expected to error on abort"); -} -END_TEST - -/* - * Namespaces tests. - */ - -static void -namespace_setup(void) { - g_parser = XML_ParserCreateNS(NULL, XCS(' ')); - if (g_parser == NULL) - fail("Parser not created."); -} - -static void -namespace_teardown(void) { - basic_teardown(); -} - -/* Check that an element name and attribute name match the expected values. - The expected values are passed as an array reference of string pointers - provided as the userData argument; the first is the expected - element name, and the second is the expected attribute name. -*/ -static int triplet_start_flag = XML_FALSE; -static int triplet_end_flag = XML_FALSE; - -static void XMLCALL -triplet_start_checker(void *userData, const XML_Char *name, - const XML_Char **atts) { - XML_Char **elemstr = (XML_Char **)userData; - char buffer[1024]; - if (xcstrcmp(elemstr[0], name) != 0) { - sprintf(buffer, "unexpected start string: '%" XML_FMT_STR "'", name); - fail(buffer); - } - if (xcstrcmp(elemstr[1], atts[0]) != 0) { - sprintf(buffer, "unexpected attribute string: '%" XML_FMT_STR "'", atts[0]); - fail(buffer); - } - triplet_start_flag = XML_TRUE; -} - -/* Check that the element name passed to the end-element handler matches - the expected value. The expected value is passed as the first element - in an array of strings passed as the userData argument. -*/ -static void XMLCALL -triplet_end_checker(void *userData, const XML_Char *name) { - XML_Char **elemstr = (XML_Char **)userData; - if (xcstrcmp(elemstr[0], name) != 0) { - char buffer[1024]; - sprintf(buffer, "unexpected end string: '%" XML_FMT_STR "'", name); - fail(buffer); - } - triplet_end_flag = XML_TRUE; -} - -START_TEST(test_return_ns_triplet) { - const char *text = "<foo:e xmlns:foo='http://example.org/' bar:a='12'\n" - " xmlns:bar='http://example.org/'>"; - const char *epilog = "</foo:e>"; - const XML_Char *elemstr[] - = {XCS("http://example.org/ e foo"), XCS("http://example.org/ a bar")}; - XML_SetReturnNSTriplet(g_parser, XML_TRUE); - XML_SetUserData(g_parser, (void *)elemstr); - XML_SetElementHandler(g_parser, triplet_start_checker, triplet_end_checker); - XML_SetNamespaceDeclHandler(g_parser, dummy_start_namespace_decl_handler, - dummy_end_namespace_decl_handler); - triplet_start_flag = XML_FALSE; - triplet_end_flag = XML_FALSE; - dummy_handler_flags = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - if (! triplet_start_flag) - fail("triplet_start_checker not invoked"); - /* Check that unsetting "return triplets" fails while still parsing */ - XML_SetReturnNSTriplet(g_parser, XML_FALSE); - if (_XML_Parse_SINGLE_BYTES(g_parser, epilog, (int)strlen(epilog), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - if (! triplet_end_flag) - fail("triplet_end_checker not invoked"); - if (dummy_handler_flags - != (DUMMY_START_NS_DECL_HANDLER_FLAG | DUMMY_END_NS_DECL_HANDLER_FLAG)) - fail("Namespace handlers not called"); -} -END_TEST - -static void XMLCALL -overwrite_start_checker(void *userData, const XML_Char *name, - const XML_Char **atts) { - CharData *storage = (CharData *)userData; - CharData_AppendXMLChars(storage, XCS("start "), 6); - CharData_AppendXMLChars(storage, name, -1); - while (*atts != NULL) { - CharData_AppendXMLChars(storage, XCS("\nattribute "), 11); - CharData_AppendXMLChars(storage, *atts, -1); - atts += 2; - } - CharData_AppendXMLChars(storage, XCS("\n"), 1); -} - -static void XMLCALL -overwrite_end_checker(void *userData, const XML_Char *name) { - CharData *storage = (CharData *)userData; - CharData_AppendXMLChars(storage, XCS("end "), 4); - CharData_AppendXMLChars(storage, name, -1); - CharData_AppendXMLChars(storage, XCS("\n"), 1); -} - -static void -run_ns_tagname_overwrite_test(const char *text, const XML_Char *result) { - CharData storage; - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetElementHandler(g_parser, overwrite_start_checker, - overwrite_end_checker); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, result); -} - -/* Regression test for SF bug #566334. */ -START_TEST(test_ns_tagname_overwrite) { - const char *text = "<n:e xmlns:n='http://example.org/'>\n" - " <n:f n:attr='foo'/>\n" - " <n:g n:attr2='bar'/>\n" - "</n:e>"; - const XML_Char *result = XCS("start http://example.org/ e\n") - XCS("start http://example.org/ f\n") - XCS("attribute http://example.org/ attr\n") - XCS("end http://example.org/ f\n") - XCS("start http://example.org/ g\n") - XCS("attribute http://example.org/ attr2\n") - XCS("end http://example.org/ g\n") - XCS("end http://example.org/ e\n"); - run_ns_tagname_overwrite_test(text, result); -} -END_TEST - -/* Regression test for SF bug #566334. */ -START_TEST(test_ns_tagname_overwrite_triplet) { - const char *text = "<n:e xmlns:n='http://example.org/'>\n" - " <n:f n:attr='foo'/>\n" - " <n:g n:attr2='bar'/>\n" - "</n:e>"; - const XML_Char *result = XCS("start http://example.org/ e n\n") - XCS("start http://example.org/ f n\n") - XCS("attribute http://example.org/ attr n\n") - XCS("end http://example.org/ f n\n") - XCS("start http://example.org/ g n\n") - XCS("attribute http://example.org/ attr2 n\n") - XCS("end http://example.org/ g n\n") - XCS("end http://example.org/ e n\n"); - XML_SetReturnNSTriplet(g_parser, XML_TRUE); - run_ns_tagname_overwrite_test(text, result); -} -END_TEST - -/* Regression test for SF bug #620343. */ -static void XMLCALL -start_element_fail(void *userData, const XML_Char *name, - const XML_Char **atts) { - UNUSED_P(userData); - UNUSED_P(name); - UNUSED_P(atts); - - /* We should never get here. */ - fail("should never reach start_element_fail()"); -} - -static void XMLCALL -start_ns_clearing_start_element(void *userData, const XML_Char *prefix, - const XML_Char *uri) { - UNUSED_P(prefix); - UNUSED_P(uri); - XML_SetStartElementHandler((XML_Parser)userData, NULL); -} - -START_TEST(test_start_ns_clears_start_element) { - /* This needs to use separate start/end tags; using the empty tag - syntax doesn't cause the problematic path through Expat to be - taken. - */ - const char *text = "<e xmlns='http://example.org/'></e>"; - - XML_SetStartElementHandler(g_parser, start_element_fail); - XML_SetStartNamespaceDeclHandler(g_parser, start_ns_clearing_start_element); - XML_SetEndNamespaceDeclHandler(g_parser, dummy_end_namespace_decl_handler); - XML_UseParserAsHandlerArg(g_parser); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Regression test for SF bug #616863. */ -static int XMLCALL -external_entity_handler(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - intptr_t callno = 1 + (intptr_t)XML_GetUserData(parser); - const char *text; - XML_Parser p2; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - if (callno == 1) - text = ("<!ELEMENT doc (e+)>\n" - "<!ATTLIST doc xmlns CDATA #IMPLIED>\n" - "<!ELEMENT e EMPTY>\n"); - else - text = ("<?xml version='1.0' encoding='us-ascii'?>" - "<e/>"); - - XML_SetUserData(parser, (void *)callno); - p2 = XML_ExternalEntityParserCreate(parser, context, NULL); - if (_XML_Parse_SINGLE_BYTES(p2, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) { - xml_failure(p2); - return XML_STATUS_ERROR; - } - XML_ParserFree(p2); - return XML_STATUS_OK; -} - -START_TEST(test_default_ns_from_ext_subset_and_ext_ge) { - const char *text = "<?xml version='1.0'?>\n" - "<!DOCTYPE doc SYSTEM 'http://example.org/doc.dtd' [\n" - " <!ENTITY en SYSTEM 'http://example.org/entity.ent'>\n" - "]>\n" - "<doc xmlns='http://example.org/ns1'>\n" - "&en;\n" - "</doc>"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_handler); - /* We actually need to set this handler to tickle this bug. */ - XML_SetStartElementHandler(g_parser, dummy_start_element); - XML_SetUserData(g_parser, NULL); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Regression test #1 for SF bug #673791. */ -START_TEST(test_ns_prefix_with_empty_uri_1) { - const char *text = "<doc xmlns:prefix='http://example.org/'>\n" - " <e xmlns:prefix=''/>\n" - "</doc>"; - - expect_failure(text, XML_ERROR_UNDECLARING_PREFIX, - "Did not report re-setting namespace" - " URI with prefix to ''."); -} -END_TEST - -/* Regression test #2 for SF bug #673791. */ -START_TEST(test_ns_prefix_with_empty_uri_2) { - const char *text = "<?xml version='1.0'?>\n" - "<docelem xmlns:pre=''/>"; - - expect_failure(text, XML_ERROR_UNDECLARING_PREFIX, - "Did not report setting namespace URI with prefix to ''."); -} -END_TEST - -/* Regression test #3 for SF bug #673791. */ -START_TEST(test_ns_prefix_with_empty_uri_3) { - const char *text = "<!DOCTYPE doc [\n" - " <!ELEMENT doc EMPTY>\n" - " <!ATTLIST doc\n" - " xmlns:prefix CDATA ''>\n" - "]>\n" - "<doc/>"; - - expect_failure(text, XML_ERROR_UNDECLARING_PREFIX, - "Didn't report attr default setting NS w/ prefix to ''."); -} -END_TEST - -/* Regression test #4 for SF bug #673791. */ -START_TEST(test_ns_prefix_with_empty_uri_4) { - const char *text = "<!DOCTYPE doc [\n" - " <!ELEMENT prefix:doc EMPTY>\n" - " <!ATTLIST prefix:doc\n" - " xmlns:prefix CDATA 'http://example.org/'>\n" - "]>\n" - "<prefix:doc/>"; - /* Packaged info expected by the end element handler; - the weird structuring lets us re-use the triplet_end_checker() - function also used for another test. */ - const XML_Char *elemstr[] = {XCS("http://example.org/ doc prefix")}; - XML_SetReturnNSTriplet(g_parser, XML_TRUE); - XML_SetUserData(g_parser, (void *)elemstr); - XML_SetEndElementHandler(g_parser, triplet_end_checker); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test with non-xmlns prefix */ -START_TEST(test_ns_unbound_prefix) { - const char *text = "<!DOCTYPE doc [\n" - " <!ELEMENT prefix:doc EMPTY>\n" - " <!ATTLIST prefix:doc\n" - " notxmlns:prefix CDATA 'http://example.org/'>\n" - "]>\n" - "<prefix:doc/>"; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - fail("Unbound prefix incorrectly passed"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_UNBOUND_PREFIX) - xml_failure(g_parser); -} -END_TEST - -START_TEST(test_ns_default_with_empty_uri) { - const char *text = "<doc xmlns='http://example.org/'>\n" - " <e xmlns=''/>\n" - "</doc>"; - /* Add some handlers to exercise extra code paths */ - XML_SetStartNamespaceDeclHandler(g_parser, - dummy_start_namespace_decl_handler); - XML_SetEndNamespaceDeclHandler(g_parser, dummy_end_namespace_decl_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Regression test for SF bug #692964: two prefixes for one namespace. */ -START_TEST(test_ns_duplicate_attrs_diff_prefixes) { - const char *text = "<doc xmlns:a='http://example.org/a'\n" - " xmlns:b='http://example.org/a'\n" - " a:a='v' b:a='v' />"; - expect_failure(text, XML_ERROR_DUPLICATE_ATTRIBUTE, - "did not report multiple attributes with same URI+name"); -} -END_TEST - -START_TEST(test_ns_duplicate_hashes) { - /* The hash of an attribute is calculated as the hash of its URI - * concatenated with a space followed by its name (after the - * colon). We wish to generate attributes with the same hash - * value modulo the attribute table size so that we can check that - * the attribute hash table works correctly. The attribute hash - * table size will be the smallest power of two greater than the - * number of attributes, but at least eight. There is - * unfortunately no programmatic way of getting the hash or the - * table size at user level, but the test code coverage percentage - * will drop if the hashes cease to point to the same row. - * - * The cunning plan is to have few enough attributes to have a - * reliable table size of 8, and have the single letter attribute - * names be 8 characters apart, producing a hash which will be the - * same modulo 8. - */ - const char *text = "<doc xmlns:a='http://example.org/a'\n" - " a:a='v' a:i='w' />"; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Regression test for SF bug #695401: unbound prefix. */ -START_TEST(test_ns_unbound_prefix_on_attribute) { - const char *text = "<doc a:attr=''/>"; - expect_failure(text, XML_ERROR_UNBOUND_PREFIX, - "did not report unbound prefix on attribute"); -} -END_TEST - -/* Regression test for SF bug #695401: unbound prefix. */ -START_TEST(test_ns_unbound_prefix_on_element) { - const char *text = "<a:doc/>"; - expect_failure(text, XML_ERROR_UNBOUND_PREFIX, - "did not report unbound prefix on element"); -} -END_TEST - -/* Test that the parsing status is correctly reset by XML_ParserReset(). - * We usE test_return_ns_triplet() for our example parse to improve - * coverage of tidying up code executed. - */ -START_TEST(test_ns_parser_reset) { - XML_ParsingStatus status; - - XML_GetParsingStatus(g_parser, &status); - if (status.parsing != XML_INITIALIZED) - fail("parsing status doesn't start INITIALIZED"); - test_return_ns_triplet(); - XML_GetParsingStatus(g_parser, &status); - if (status.parsing != XML_FINISHED) - fail("parsing status doesn't end FINISHED"); - XML_ParserReset(g_parser, NULL); - XML_GetParsingStatus(g_parser, &status); - if (status.parsing != XML_INITIALIZED) - fail("parsing status doesn't reset to INITIALIZED"); -} -END_TEST - -/* Test that long element names with namespaces are handled correctly */ -START_TEST(test_ns_long_element) { - const char *text - = "<foo:thisisalongenoughelementnametotriggerareallocation\n" - " xmlns:foo='http://example.org/' bar:a='12'\n" - " xmlns:bar='http://example.org/'>" - "</foo:thisisalongenoughelementnametotriggerareallocation>"; - const XML_Char *elemstr[] - = {XCS("http://example.org/") - XCS(" thisisalongenoughelementnametotriggerareallocation foo"), - XCS("http://example.org/ a bar")}; - - XML_SetReturnNSTriplet(g_parser, XML_TRUE); - XML_SetUserData(g_parser, (void *)elemstr); - XML_SetElementHandler(g_parser, triplet_start_checker, triplet_end_checker); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test mixed population of prefixed and unprefixed attributes */ -START_TEST(test_ns_mixed_prefix_atts) { - const char *text = "<e a='12' bar:b='13'\n" - " xmlns:bar='http://example.org/'>" - "</e>"; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test having a long namespaced element name inside a short one. - * This exercises some internal buffer reallocation that is shared - * across elements with the same namespace URI. - */ -START_TEST(test_ns_extend_uri_buffer) { - const char *text = "<foo:e xmlns:foo='http://example.org/'>" - " <foo:thisisalongenoughnametotriggerallocationaction" - " foo:a='12' />" - "</foo:e>"; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test that xmlns is correctly rejected as an attribute in the xmlns - * namespace, but not in other namespaces - */ -START_TEST(test_ns_reserved_attributes) { - const char *text1 - = "<foo:e xmlns:foo='http://example.org/' xmlns:xmlns='12' />"; - const char *text2 - = "<foo:e xmlns:foo='http://example.org/' foo:xmlns='12' />"; - expect_failure(text1, XML_ERROR_RESERVED_PREFIX_XMLNS, - "xmlns not rejected as an attribute"); - XML_ParserReset(g_parser, NULL); - if (_XML_Parse_SINGLE_BYTES(g_parser, text2, (int)strlen(text2), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test more reserved attributes */ -START_TEST(test_ns_reserved_attributes_2) { - const char *text1 = "<foo:e xmlns:foo='http://example.org/'" - " xmlns:xml='http://example.org/' />"; - const char *text2 - = "<foo:e xmlns:foo='http://www.w3.org/XML/1998/namespace' />"; - const char *text3 = "<foo:e xmlns:foo='http://www.w3.org/2000/xmlns/' />"; - - expect_failure(text1, XML_ERROR_RESERVED_PREFIX_XML, - "xml not rejected as an attribute"); - XML_ParserReset(g_parser, NULL); - expect_failure(text2, XML_ERROR_RESERVED_NAMESPACE_URI, - "Use of w3.org URL not faulted"); - XML_ParserReset(g_parser, NULL); - expect_failure(text3, XML_ERROR_RESERVED_NAMESPACE_URI, - "Use of w3.org xmlns URL not faulted"); -} -END_TEST - -/* Test string pool handling of namespace names of 2048 characters */ -/* Exercises a particular string pool growth path */ -START_TEST(test_ns_extremely_long_prefix) { - /* C99 compilers are only required to support 4095-character - * strings, so the following needs to be split in two to be safe - * for all compilers. - */ - const char *text1 - = "<doc " - /* 64 character on each line */ - /* ...gives a total length of 2048 */ - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - ":a='12'"; - const char *text2 - = " xmlns:" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "='foo'\n>" - "</doc>"; - - if (_XML_Parse_SINGLE_BYTES(g_parser, text1, (int)strlen(text1), XML_FALSE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - if (_XML_Parse_SINGLE_BYTES(g_parser, text2, (int)strlen(text2), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -/* Test unknown encoding handlers in namespace setup */ -START_TEST(test_ns_unknown_encoding_success) { - const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n" - "<foo:e xmlns:foo='http://example.org/'>Hi</foo:e>"; - - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - run_character_check(text, XCS("Hi")); -} -END_TEST - -/* Test that too many colons are rejected */ -START_TEST(test_ns_double_colon) { - const char *text = "<foo:e xmlns:foo='http://example.org/' foo:a:b='bar' />"; - const enum XML_Status status - = _XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE); -#ifdef XML_NS - if ((status == XML_STATUS_OK) - || (XML_GetErrorCode(g_parser) != XML_ERROR_INVALID_TOKEN)) { - fail("Double colon in attribute name not faulted" - " (despite active namespace support)"); - } -#else - if (status != XML_STATUS_OK) { - fail("Double colon in attribute name faulted" - " (despite inactive namespace support"); - } -#endif -} -END_TEST - -START_TEST(test_ns_double_colon_element) { - const char *text = "<foo:bar:e xmlns:foo='http://example.org/' />"; - const enum XML_Status status - = _XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE); -#ifdef XML_NS - if ((status == XML_STATUS_OK) - || (XML_GetErrorCode(g_parser) != XML_ERROR_INVALID_TOKEN)) { - fail("Double colon in element name not faulted" - " (despite active namespace support)"); - } -#else - if (status != XML_STATUS_OK) { - fail("Double colon in element name faulted" - " (despite inactive namespace support"); - } -#endif -} -END_TEST - -/* Test that non-name characters after a colon are rejected */ -START_TEST(test_ns_bad_attr_leafname) { - const char *text = "<foo:e xmlns:foo='http://example.org/' foo:?ar='baz' />"; - - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "Invalid character in leafname not faulted"); -} -END_TEST - -START_TEST(test_ns_bad_element_leafname) { - const char *text = "<foo:?oc xmlns:foo='http://example.org/' />"; - - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "Invalid character in element leafname not faulted"); -} -END_TEST - -/* Test high-byte-set UTF-16 characters are valid in a leafname */ -START_TEST(test_ns_utf16_leafname) { - const char text[] = - /* <n:e xmlns:n='URI' n:{KHO KHWAI}='a' /> - * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8 - */ - "<\0n\0:\0e\0 \0x\0m\0l\0n\0s\0:\0n\0=\0'\0U\0R\0I\0'\0 \0" - "n\0:\0\x04\x0e=\0'\0a\0'\0 \0/\0>\0"; - const XML_Char *expected = XCS("a"); - CharData storage; - - CharData_Init(&storage); - XML_SetStartElementHandler(g_parser, accumulate_attribute); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_ns_utf16_element_leafname) { - const char text[] = - /* <n:{KHO KHWAI} xmlns:n='URI'/> - * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8 - */ - "\0<\0n\0:\x0e\x04\0 \0x\0m\0l\0n\0s\0:\0n\0=\0'\0U\0R\0I\0'\0/\0>"; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("URI \x0e04"); -#else - const XML_Char *expected = XCS("URI \xe0\xb8\x84"); -#endif - CharData storage; - - CharData_Init(&storage); - XML_SetStartElementHandler(g_parser, start_element_event_handler); - XML_SetUserData(g_parser, &storage); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_ns_utf16_doctype) { - const char text[] = - /* <!DOCTYPE foo:{KHO KHWAI} [ <!ENTITY bar 'baz'> ]>\n - * where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8 - */ - "\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0f\0o\0o\0:\x0e\x04\0 " - "\0[\0 \0<\0!\0E\0N\0T\0I\0T\0Y\0 \0b\0a\0r\0 \0'\0b\0a\0z\0'\0>\0 " - "\0]\0>\0\n" - /* <foo:{KHO KHWAI} xmlns:foo='URI'>&bar;</foo:{KHO KHWAI}> */ - "\0<\0f\0o\0o\0:\x0e\x04\0 " - "\0x\0m\0l\0n\0s\0:\0f\0o\0o\0=\0'\0U\0R\0I\0'\0>" - "\0&\0b\0a\0r\0;" - "\0<\0/\0f\0o\0o\0:\x0e\x04\0>"; -#ifdef XML_UNICODE - const XML_Char *expected = XCS("URI \x0e04"); -#else - const XML_Char *expected = XCS("URI \xe0\xb8\x84"); -#endif - CharData storage; - - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetStartElementHandler(g_parser, start_element_event_handler); - XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -START_TEST(test_ns_invalid_doctype) { - const char *text = "<!DOCTYPE foo:!bad [ <!ENTITY bar 'baz' ]>\n" - "<foo:!bad>&bar;</foo:!bad>"; - - expect_failure(text, XML_ERROR_INVALID_TOKEN, - "Invalid character in document local name not faulted"); -} -END_TEST - -START_TEST(test_ns_double_colon_doctype) { - const char *text = "<!DOCTYPE foo:a:doc [ <!ENTITY bar 'baz' ]>\n" - "<foo:a:doc>&bar;</foo:a:doc>"; - - expect_failure(text, XML_ERROR_SYNTAX, - "Double colon in document name not faulted"); -} -END_TEST - -/* Control variable; the number of times duff_allocator() will successfully - * allocate */ -#define ALLOC_ALWAYS_SUCCEED (-1) -#define REALLOC_ALWAYS_SUCCEED (-1) - -static intptr_t allocation_count = ALLOC_ALWAYS_SUCCEED; -static intptr_t reallocation_count = REALLOC_ALWAYS_SUCCEED; - -/* Crocked allocator for allocation failure tests */ -static void * -duff_allocator(size_t size) { - if (allocation_count == 0) - return NULL; - if (allocation_count != ALLOC_ALWAYS_SUCCEED) - allocation_count--; - return malloc(size); -} - -/* Crocked reallocator for allocation failure tests */ -static void * -duff_reallocator(void *ptr, size_t size) { - if (reallocation_count == 0) - return NULL; - if (reallocation_count != REALLOC_ALWAYS_SUCCEED) - reallocation_count--; - return realloc(ptr, size); -} - -/* Test that a failure to allocate the parser structure fails gracefully */ -START_TEST(test_misc_alloc_create_parser) { - XML_Memory_Handling_Suite memsuite = {duff_allocator, realloc, free}; - unsigned int i; - const unsigned int max_alloc_count = 10; - - /* Something this simple shouldn't need more than 10 allocations */ - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - g_parser = XML_ParserCreate_MM(NULL, &memsuite, NULL); - if (g_parser != NULL) - break; - } - if (i == 0) - fail("Parser unexpectedly ignored failing allocator"); - else if (i == max_alloc_count) - fail("Parser not created with max allocation count"); -} -END_TEST - -/* Test memory allocation failures for a parser with an encoding */ -START_TEST(test_misc_alloc_create_parser_with_encoding) { - XML_Memory_Handling_Suite memsuite = {duff_allocator, realloc, free}; - unsigned int i; - const unsigned int max_alloc_count = 10; - - /* Try several levels of allocation */ - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - g_parser = XML_ParserCreate_MM(XCS("us-ascii"), &memsuite, NULL); - if (g_parser != NULL) - break; - } - if (i == 0) - fail("Parser ignored failing allocator"); - else if (i == max_alloc_count) - fail("Parser not created with max allocation count"); -} -END_TEST - -/* Test that freeing a NULL parser doesn't cause an explosion. - * (Not actually tested anywhere else) - */ -START_TEST(test_misc_null_parser) { - XML_ParserFree(NULL); -} -END_TEST - -/* Test that XML_ErrorString rejects out-of-range codes */ -START_TEST(test_misc_error_string) { - if (XML_ErrorString((enum XML_Error) - 1) != NULL) - fail("Negative error code not rejected"); - if (XML_ErrorString((enum XML_Error)100) != NULL) - fail("Large error code not rejected"); -} -END_TEST - -/* Test the version information is consistent */ - -/* Since we are working in XML_LChars (potentially 16-bits), we - * can't use the standard C library functions for character - * manipulation and have to roll our own. - */ -static int -parse_version(const XML_LChar *version_text, - XML_Expat_Version *version_struct) { - if (! version_text) - return XML_FALSE; - - while (*version_text != 0x00) { - if (*version_text >= ASCII_0 && *version_text <= ASCII_9) - break; - version_text++; - } - if (*version_text == 0x00) - return XML_FALSE; - - /* version_struct->major = strtoul(version_text, 10, &version_text) */ - version_struct->major = 0; - while (*version_text >= ASCII_0 && *version_text <= ASCII_9) { - version_struct->major - = 10 * version_struct->major + (*version_text++ - ASCII_0); - } - if (*version_text++ != ASCII_PERIOD) - return XML_FALSE; - - /* Now for the minor version number */ - version_struct->minor = 0; - while (*version_text >= ASCII_0 && *version_text <= ASCII_9) { - version_struct->minor - = 10 * version_struct->minor + (*version_text++ - ASCII_0); - } - if (*version_text++ != ASCII_PERIOD) - return XML_FALSE; - - /* Finally the micro version number */ - version_struct->micro = 0; - while (*version_text >= ASCII_0 && *version_text <= ASCII_9) { - version_struct->micro - = 10 * version_struct->micro + (*version_text++ - ASCII_0); - } - if (*version_text != 0x00) - return XML_FALSE; - return XML_TRUE; -} - -static int -versions_equal(const XML_Expat_Version *first, - const XML_Expat_Version *second) { - return (first->major == second->major && first->minor == second->minor - && first->micro == second->micro); -} - -START_TEST(test_misc_version) { - XML_Expat_Version read_version = XML_ExpatVersionInfo(); - /* Silence compiler warning with the following assignment */ - XML_Expat_Version parsed_version = {0, 0, 0}; - const XML_LChar *version_text = XML_ExpatVersion(); - - if (version_text == NULL) - fail("Could not obtain version text"); - assert(version_text != NULL); - if (! parse_version(version_text, &parsed_version)) - fail("Unable to parse version text"); - if (! versions_equal(&read_version, &parsed_version)) - fail("Version mismatch"); - -#if ! defined(XML_UNICODE) || defined(XML_UNICODE_WCHAR_T) - if (xcstrcmp(version_text, XCS("expat_2.2.10"))) /* needs bump on releases */ - fail("XML_*_VERSION in expat.h out of sync?\n"); -#else - /* If we have XML_UNICODE defined but not XML_UNICODE_WCHAR_T - * then XML_LChar is defined as char, for some reason. - */ - if (strcmp(version_text, "expat_2.2.5")) /* needs bump on releases */ - fail("XML_*_VERSION in expat.h out of sync?\n"); -#endif /* ! defined(XML_UNICODE) || defined(XML_UNICODE_WCHAR_T) */ -} -END_TEST - -/* Test feature information */ -START_TEST(test_misc_features) { - const XML_Feature *features = XML_GetFeatureList(); - - /* Prevent problems with double-freeing parsers */ - g_parser = NULL; - if (features == NULL) { - fail("Failed to get feature information"); - } else { - /* Loop through the features checking what we can */ - while (features->feature != XML_FEATURE_END) { - switch (features->feature) { - case XML_FEATURE_SIZEOF_XML_CHAR: - if (features->value != sizeof(XML_Char)) - fail("Incorrect size of XML_Char"); - break; - case XML_FEATURE_SIZEOF_XML_LCHAR: - if (features->value != sizeof(XML_LChar)) - fail("Incorrect size of XML_LChar"); - break; - default: - break; - } - features++; - } - } -} -END_TEST - -/* Regression test for GitHub Issue #17: memory leak parsing attribute - * values with mixed bound and unbound namespaces. - */ -START_TEST(test_misc_attribute_leak) { - const char *text = "<D xmlns:L=\"D\" l:a='' L:a=''/>"; - XML_Memory_Handling_Suite memsuite - = {tracking_malloc, tracking_realloc, tracking_free}; - - g_parser = XML_ParserCreate_MM(XCS("UTF-8"), &memsuite, XCS("\n")); - expect_failure(text, XML_ERROR_UNBOUND_PREFIX, "Unbound prefixes not found"); - XML_ParserFree(g_parser); - /* Prevent the teardown trying to double free */ - g_parser = NULL; - - if (! tracking_report()) - fail("Memory leak found"); -} -END_TEST - -/* Test parser created for UTF-16LE is successful */ -START_TEST(test_misc_utf16le) { - const char text[] = - /* <?xml version='1.0'?><q>Hi</q> */ - "<\0?\0x\0m\0l\0 \0" - "v\0e\0r\0s\0i\0o\0n\0=\0'\0\x31\0.\0\x30\0'\0?\0>\0" - "<\0q\0>\0H\0i\0<\0/\0q\0>\0"; - const XML_Char *expected = XCS("Hi"); - CharData storage; - - g_parser = XML_ParserCreate(XCS("UTF-16LE")); - if (g_parser == NULL) - fail("Parser not created"); - - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetCharacterDataHandler(g_parser, accumulate_characters); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - CharData_CheckXMLChars(&storage, expected); -} -END_TEST - -typedef struct { - XML_Parser parser; - int deep; -} DataIssue240; - -static void -start_element_issue_240(void *userData, const XML_Char *name, - const XML_Char **atts) { - DataIssue240 *mydata = (DataIssue240 *)userData; - UNUSED_P(name); - UNUSED_P(atts); - mydata->deep++; -} - -static void -end_element_issue_240(void *userData, const XML_Char *name) { - DataIssue240 *mydata = (DataIssue240 *)userData; - - UNUSED_P(name); - mydata->deep--; - if (mydata->deep == 0) { - XML_StopParser(mydata->parser, 0); - } -} - -START_TEST(test_misc_stop_during_end_handler_issue_240_1) { - XML_Parser parser; - DataIssue240 *mydata; - enum XML_Status result; - const char *const doc1 = "<doc><e1/><e><foo/></e></doc>"; - - parser = XML_ParserCreate(NULL); - XML_SetElementHandler(parser, start_element_issue_240, end_element_issue_240); - mydata = (DataIssue240 *)malloc(sizeof(DataIssue240)); - mydata->parser = parser; - mydata->deep = 0; - XML_SetUserData(parser, mydata); - - result = XML_Parse(parser, doc1, (int)strlen(doc1), 1); - XML_ParserFree(parser); - free(mydata); - if (result != XML_STATUS_ERROR) - fail("Stopping the parser did not work as expected"); -} -END_TEST - -START_TEST(test_misc_stop_during_end_handler_issue_240_2) { - XML_Parser parser; - DataIssue240 *mydata; - enum XML_Status result; - const char *const doc2 = "<doc><elem/></doc>"; - - parser = XML_ParserCreate(NULL); - XML_SetElementHandler(parser, start_element_issue_240, end_element_issue_240); - mydata = (DataIssue240 *)malloc(sizeof(DataIssue240)); - mydata->parser = parser; - mydata->deep = 0; - XML_SetUserData(parser, mydata); - - result = XML_Parse(parser, doc2, (int)strlen(doc2), 1); - XML_ParserFree(parser); - free(mydata); - if (result != XML_STATUS_ERROR) - fail("Stopping the parser did not work as expected"); -} -END_TEST - -START_TEST(test_misc_deny_internal_entity_closing_doctype_issue_317) { - const char *const inputOne = "<!DOCTYPE d [\n" - "<!ENTITY % e ']><d/>'>\n" - "\n" - "%e;"; - const char *const inputTwo = "<!DOCTYPE d [\n" - "<!ENTITY % e1 ']><d/>'><!ENTITY % e2 '&e1;'>\n" - "\n" - "%e2;"; - const char *const inputThree = "<!DOCTYPE d [\n" - "<!ENTITY % e ']><d'>\n" - "\n" - "%e;"; - const char *const inputIssue317 = "<!DOCTYPE doc [\n" - "<!ENTITY % foo ']>\n" - "<doc>Hell<oc (#PCDATA)*>'>\n" - "%foo;\n" - "]>\n" - "<doc>Hello, world</dVc>"; - - const char *const inputs[] = {inputOne, inputTwo, inputThree, inputIssue317}; - size_t inputIndex = 0; - - for (; inputIndex < sizeof(inputs) / sizeof(inputs[0]); inputIndex++) { - XML_Parser parser; - enum XML_Status parseResult; - int setParamEntityResult; - XML_Size lineNumber; - XML_Size columnNumber; - const char *const input = inputs[inputIndex]; - - parser = XML_ParserCreate(NULL); - setParamEntityResult - = XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - if (setParamEntityResult != 1) - fail("Failed to set XML_PARAM_ENTITY_PARSING_ALWAYS."); - - parseResult = XML_Parse(parser, input, (int)strlen(input), 0); - if (parseResult != XML_STATUS_ERROR) { - parseResult = XML_Parse(parser, "", 0, 1); - if (parseResult != XML_STATUS_ERROR) { - fail("Parsing was expected to fail but succeeded."); - } - } - - if (XML_GetErrorCode(parser) != XML_ERROR_INVALID_TOKEN) - fail("Error code does not match XML_ERROR_INVALID_TOKEN"); - - lineNumber = XML_GetCurrentLineNumber(parser); - if (lineNumber != 4) - fail("XML_GetCurrentLineNumber does not work as expected."); - - columnNumber = XML_GetCurrentColumnNumber(parser); - if (columnNumber != 0) - fail("XML_GetCurrentColumnNumber does not work as expected."); - - XML_ParserFree(parser); - } -} -END_TEST - -static void -alloc_setup(void) { - XML_Memory_Handling_Suite memsuite = {duff_allocator, duff_reallocator, free}; - - /* Ensure the parser creation will go through */ - allocation_count = ALLOC_ALWAYS_SUCCEED; - reallocation_count = REALLOC_ALWAYS_SUCCEED; - g_parser = XML_ParserCreate_MM(NULL, &memsuite, NULL); - if (g_parser == NULL) - fail("Parser not created"); -} - -static void -alloc_teardown(void) { - basic_teardown(); -} - -/* Test the effects of allocation failures on xml declaration processing */ -START_TEST(test_alloc_parse_xdecl) { - const char *text = "<?xml version='1.0' encoding='utf-8'?>\n" - "<doc>Hello, world</doc>"; - int i; - const int max_alloc_count = 15; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetXmlDeclHandler(g_parser, dummy_xdecl_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* Resetting the parser is insufficient, because some memory - * allocations are cached within the parser. Instead we use - * the teardown and setup routines to ensure that we have the - * right sort of parser back in our hands. - */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed with max allocations"); -} -END_TEST - -/* As above, but with an encoding big enough to cause storing the - * version information to expand the string pool being used. - */ -static int XMLCALL -long_encoding_handler(void *userData, const XML_Char *encoding, - XML_Encoding *info) { - int i; - - UNUSED_P(userData); - UNUSED_P(encoding); - for (i = 0; i < 256; i++) - info->map[i] = i; - info->data = NULL; - info->convert = NULL; - info->release = NULL; - return XML_STATUS_OK; -} - -START_TEST(test_alloc_parse_xdecl_2) { - const char *text - = "<?xml version='1.0' encoding='" - /* Each line is 64 characters */ - "ThisIsAStupidlyLongEncodingNameIntendedToTriggerPoolGrowth123456" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMN" - "'?>" - "<doc>Hello, world</doc>"; - int i; - const int max_alloc_count = 20; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetXmlDeclHandler(g_parser, dummy_xdecl_handler); - XML_SetUnknownEncodingHandler(g_parser, long_encoding_handler, NULL); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed with max allocations"); -} -END_TEST - -/* Test the effects of allocation failures on a straightforward parse */ -START_TEST(test_alloc_parse_pi) { - const char *text = "<?xml version='1.0' encoding='utf-8'?>\n" - "<?pi unknown?>\n" - "<doc>" - "Hello, world" - "</doc>"; - int i; - const int max_alloc_count = 15; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetProcessingInstructionHandler(g_parser, dummy_pi_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed with max allocations"); -} -END_TEST - -START_TEST(test_alloc_parse_pi_2) { - const char *text = "<?xml version='1.0' encoding='utf-8'?>\n" - "<doc>" - "Hello, world" - "<?pi unknown?>\n" - "</doc>"; - int i; - const int max_alloc_count = 15; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetProcessingInstructionHandler(g_parser, dummy_pi_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed with max allocations"); -} -END_TEST - -START_TEST(test_alloc_parse_pi_3) { - const char *text - = "<?" - /* 64 characters per line */ - "This processing instruction should be long enough to ensure that" - "it triggers the growth of an internal string pool when the " - "allocator fails at a cruicial moment FGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "Q?><doc/>"; - int i; - const int max_alloc_count = 20; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetProcessingInstructionHandler(g_parser, dummy_pi_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed with max allocations"); -} -END_TEST - -START_TEST(test_alloc_parse_comment) { - const char *text = "<?xml version='1.0' encoding='utf-8'?>\n" - "<!-- Test parsing this comment -->" - "<doc>Hi</doc>"; - int i; - const int max_alloc_count = 15; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetCommentHandler(g_parser, dummy_comment_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed with max allocations"); -} -END_TEST - -START_TEST(test_alloc_parse_comment_2) { - const char *text = "<?xml version='1.0' encoding='utf-8'?>\n" - "<doc>" - "Hello, world" - "<!-- Parse this comment too -->" - "</doc>"; - int i; - const int max_alloc_count = 15; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetCommentHandler(g_parser, dummy_comment_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed with max allocations"); -} -END_TEST - -static int XMLCALL -external_entity_duff_loader(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - XML_Parser new_parser; - unsigned int i; - const unsigned int max_alloc_count = 10; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - /* Try a few different allocation levels */ - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - new_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (new_parser != NULL) { - XML_ParserFree(new_parser); - break; - } - } - if (i == 0) - fail("External parser creation ignored failing allocator"); - else if (i == max_alloc_count) - fail("Extern parser not created with max allocation count"); - - /* Make sure other random allocation doesn't now fail */ - allocation_count = ALLOC_ALWAYS_SUCCEED; - - /* Make sure the failure code path is executed too */ - return XML_STATUS_ERROR; -} - -/* Test that external parser creation running out of memory is - * correctly reported. Based on the external entity test cases. - */ -START_TEST(test_alloc_create_external_parser) { - const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc>&entity;</doc>"; - char foo_text[] = "<!ELEMENT doc (#PCDATA)*>"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetUserData(g_parser, foo_text); - XML_SetExternalEntityRefHandler(g_parser, external_entity_duff_loader); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) { - fail("External parser allocator returned success incorrectly"); - } -} -END_TEST - -/* More external parser memory allocation testing */ -START_TEST(test_alloc_run_external_parser) { - const char *text = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<!DOCTYPE doc SYSTEM 'foo'>\n" - "<doc>&entity;</doc>"; - char foo_text[] = "<!ELEMENT doc (#PCDATA)*>"; - unsigned int i; - const unsigned int max_alloc_count = 15; - - for (i = 0; i < max_alloc_count; i++) { - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetUserData(g_parser, foo_text); - XML_SetExternalEntityRefHandler(g_parser, external_entity_null_loader); - allocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parsing ignored failing allocator"); - else if (i == max_alloc_count) - fail("Parsing failed with allocation count 10"); -} -END_TEST - -static int XMLCALL -external_entity_dbl_handler(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - intptr_t callno = (intptr_t)XML_GetUserData(parser); - const char *text; - XML_Parser new_parser; - int i; - const int max_alloc_count = 20; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - if (callno == 0) { - /* First time through, check how many calls to malloc occur */ - text = ("<!ELEMENT doc (e+)>\n" - "<!ATTLIST doc xmlns CDATA #IMPLIED>\n" - "<!ELEMENT e EMPTY>\n"); - allocation_count = 10000; - new_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (new_parser == NULL) { - fail("Unable to allocate first external parser"); - return XML_STATUS_ERROR; - } - /* Stash the number of calls in the user data */ - XML_SetUserData(parser, (void *)(intptr_t)(10000 - allocation_count)); - } else { - text = ("<?xml version='1.0' encoding='us-ascii'?>" - "<e/>"); - /* Try at varying levels to exercise more code paths */ - for (i = 0; i < max_alloc_count; i++) { - allocation_count = callno + i; - new_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (new_parser != NULL) - break; - } - if (i == 0) { - fail("Second external parser unexpectedly created"); - XML_ParserFree(new_parser); - return XML_STATUS_ERROR; - } else if (i == max_alloc_count) { - fail("Second external parser not created"); - return XML_STATUS_ERROR; - } - } - - allocation_count = ALLOC_ALWAYS_SUCCEED; - if (_XML_Parse_SINGLE_BYTES(new_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) { - xml_failure(new_parser); - return XML_STATUS_ERROR; - } - XML_ParserFree(new_parser); - return XML_STATUS_OK; -} - -/* Test that running out of memory in dtdCopy is correctly reported. - * Based on test_default_ns_from_ext_subset_and_ext_ge() - */ -START_TEST(test_alloc_dtd_copy_default_atts) { - const char *text = "<?xml version='1.0'?>\n" - "<!DOCTYPE doc SYSTEM 'http://example.org/doc.dtd' [\n" - " <!ENTITY en SYSTEM 'http://example.org/entity.ent'>\n" - "]>\n" - "<doc xmlns='http://example.org/ns1'>\n" - "&en;\n" - "</doc>"; - - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_dbl_handler); - XML_SetUserData(g_parser, NULL); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); -} -END_TEST - -static int XMLCALL -external_entity_dbl_handler_2(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - intptr_t callno = (intptr_t)XML_GetUserData(parser); - const char *text; - XML_Parser new_parser; - enum XML_Status rv; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - if (callno == 0) { - /* Try different allocation levels for whole exercise */ - text = ("<!ELEMENT doc (e+)>\n" - "<!ATTLIST doc xmlns CDATA #IMPLIED>\n" - "<!ELEMENT e EMPTY>\n"); - XML_SetUserData(parser, (void *)(intptr_t)1); - new_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (new_parser == NULL) - return XML_STATUS_ERROR; - rv = _XML_Parse_SINGLE_BYTES(new_parser, text, (int)strlen(text), XML_TRUE); - } else { - /* Just run through once */ - text = ("<?xml version='1.0' encoding='us-ascii'?>" - "<e/>"); - new_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (new_parser == NULL) - return XML_STATUS_ERROR; - rv = _XML_Parse_SINGLE_BYTES(new_parser, text, (int)strlen(text), XML_TRUE); - } - XML_ParserFree(new_parser); - if (rv == XML_STATUS_ERROR) - return XML_STATUS_ERROR; - return XML_STATUS_OK; -} - -/* Test more external entity allocation failure paths */ -START_TEST(test_alloc_external_entity) { - const char *text = "<?xml version='1.0'?>\n" - "<!DOCTYPE doc SYSTEM 'http://example.org/doc.dtd' [\n" - " <!ENTITY en SYSTEM 'http://example.org/entity.ent'>\n" - "]>\n" - "<doc xmlns='http://example.org/ns1'>\n" - "&en;\n" - "</doc>"; - int i; - const int alloc_test_max_repeats = 50; - - for (i = 0; i < alloc_test_max_repeats; i++) { - allocation_count = -1; - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_dbl_handler_2); - XML_SetUserData(g_parser, NULL); - allocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_OK) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - allocation_count = -1; - if (i == 0) - fail("External entity parsed despite duff allocator"); - if (i == alloc_test_max_repeats) - fail("External entity not parsed at max allocation count"); -} -END_TEST - -/* Test more allocation failure paths */ -static int XMLCALL -external_entity_alloc_set_encoding(XML_Parser parser, const XML_Char *context, - const XML_Char *base, - const XML_Char *systemId, - const XML_Char *publicId) { - /* As for external_entity_loader() */ - const char *text = "<?xml encoding='iso-8859-3'?>" - "\xC3\xA9"; - XML_Parser ext_parser; - enum XML_Status status; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - return XML_STATUS_ERROR; - if (! XML_SetEncoding(ext_parser, XCS("utf-8"))) { - XML_ParserFree(ext_parser); - return XML_STATUS_ERROR; - } - status - = _XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE); - XML_ParserFree(ext_parser); - if (status == XML_STATUS_ERROR) - return XML_STATUS_ERROR; - return XML_STATUS_OK; -} - -START_TEST(test_alloc_ext_entity_set_encoding) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - int i; - const int max_allocation_count = 30; - - for (i = 0; i < max_allocation_count; i++) { - XML_SetExternalEntityRefHandler(g_parser, - external_entity_alloc_set_encoding); - allocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_OK) - break; - allocation_count = -1; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Encoding check succeeded despite failing allocator"); - if (i == max_allocation_count) - fail("Encoding failed at max allocation count"); -} -END_TEST - -static int XMLCALL -unknown_released_encoding_handler(void *data, const XML_Char *encoding, - XML_Encoding *info) { - UNUSED_P(data); - if (! xcstrcmp(encoding, XCS("unsupported-encoding"))) { - int i; - - for (i = 0; i < 256; i++) - info->map[i] = i; - info->data = NULL; - info->convert = NULL; - info->release = dummy_release; - return XML_STATUS_OK; - } - return XML_STATUS_ERROR; -} - -/* Test the effects of allocation failure in internal entities. - * Based on test_unknown_encoding_internal_entity - */ -START_TEST(test_alloc_internal_entity) { - const char *text = "<?xml version='1.0' encoding='unsupported-encoding'?>\n" - "<!DOCTYPE test [<!ENTITY foo 'bar'>]>\n" - "<test a='&foo;'/>"; - unsigned int i; - const unsigned int max_alloc_count = 20; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetUnknownEncodingHandler(g_parser, unknown_released_encoding_handler, - NULL); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Internal entity worked despite failing allocations"); - else if (i == max_alloc_count) - fail("Internal entity failed at max allocation count"); -} -END_TEST - -/* Test the robustness against allocation failure of element handling - * Based on test_dtd_default_handling(). - */ -START_TEST(test_alloc_dtd_default_handling) { - const char *text = "<!DOCTYPE doc [\n" - "<!ENTITY e SYSTEM 'http://example.org/e'>\n" - "<!NOTATION n SYSTEM 'http://example.org/n'>\n" - "<!ENTITY e1 SYSTEM 'http://example.org/e' NDATA n>\n" - "<!ELEMENT doc (#PCDATA)>\n" - "<!ATTLIST doc a CDATA #IMPLIED>\n" - "<?pi in dtd?>\n" - "<!--comment in dtd-->\n" - "]>\n" - "<doc><![CDATA[text in doc]]></doc>"; - const XML_Char *expected = XCS("\n\n\n\n\n\n\n\n\n<doc>text in doc</doc>"); - CharData storage; - int i; - const int max_alloc_count = 25; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - dummy_handler_flags = 0; - XML_SetDefaultHandler(g_parser, accumulate_characters); - XML_SetDoctypeDeclHandler(g_parser, dummy_start_doctype_handler, - dummy_end_doctype_handler); - XML_SetEntityDeclHandler(g_parser, dummy_entity_decl_handler); - XML_SetNotationDeclHandler(g_parser, dummy_notation_decl_handler); - XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); - XML_SetAttlistDeclHandler(g_parser, dummy_attlist_decl_handler); - XML_SetProcessingInstructionHandler(g_parser, dummy_pi_handler); - XML_SetCommentHandler(g_parser, dummy_comment_handler); - XML_SetCdataSectionHandler(g_parser, dummy_start_cdata_handler, - dummy_end_cdata_handler); - XML_SetUnparsedEntityDeclHandler(g_parser, - dummy_unparsed_entity_decl_handler); - CharData_Init(&storage); - XML_SetUserData(g_parser, &storage); - XML_SetCharacterDataHandler(g_parser, accumulate_characters); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Default DTD parsed despite allocation failures"); - if (i == max_alloc_count) - fail("Default DTD not parsed with maximum alloc count"); - CharData_CheckXMLChars(&storage, expected); - if (dummy_handler_flags - != (DUMMY_START_DOCTYPE_HANDLER_FLAG | DUMMY_END_DOCTYPE_HANDLER_FLAG - | DUMMY_ENTITY_DECL_HANDLER_FLAG | DUMMY_NOTATION_DECL_HANDLER_FLAG - | DUMMY_ELEMENT_DECL_HANDLER_FLAG | DUMMY_ATTLIST_DECL_HANDLER_FLAG - | DUMMY_COMMENT_HANDLER_FLAG | DUMMY_PI_HANDLER_FLAG - | DUMMY_START_CDATA_HANDLER_FLAG | DUMMY_END_CDATA_HANDLER_FLAG - | DUMMY_UNPARSED_ENTITY_DECL_HANDLER_FLAG)) - fail("Not all handlers were called"); -} -END_TEST - -/* Test robustness of XML_SetEncoding() with a failing allocator */ -START_TEST(test_alloc_explicit_encoding) { - int i; - const int max_alloc_count = 5; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - if (XML_SetEncoding(g_parser, XCS("us-ascii")) == XML_STATUS_OK) - break; - } - if (i == 0) - fail("Encoding set despite failing allocator"); - else if (i == max_alloc_count) - fail("Encoding not set at max allocation count"); -} -END_TEST - -/* Test robustness of XML_SetBase against a failing allocator */ -START_TEST(test_alloc_set_base) { - const XML_Char *new_base = XCS("/local/file/name.xml"); - int i; - const int max_alloc_count = 5; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - if (XML_SetBase(g_parser, new_base) == XML_STATUS_OK) - break; - } - if (i == 0) - fail("Base set despite failing allocator"); - else if (i == max_alloc_count) - fail("Base not set with max allocation count"); -} -END_TEST - -/* Test buffer extension in the face of a duff reallocator */ -START_TEST(test_alloc_realloc_buffer) { - const char *text = get_buffer_test_text; - void *buffer; - int i; - const int max_realloc_count = 10; - - /* Get a smallish buffer */ - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - buffer = XML_GetBuffer(g_parser, 1536); - if (buffer == NULL) - fail("1.5K buffer reallocation failed"); - assert(buffer != NULL); - memcpy(buffer, text, strlen(text)); - if (XML_ParseBuffer(g_parser, (int)strlen(text), XML_FALSE) - == XML_STATUS_OK) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - reallocation_count = -1; - if (i == 0) - fail("Parse succeeded with no reallocation"); - else if (i == max_realloc_count) - fail("Parse failed with max reallocation count"); -} -END_TEST - -/* Same test for external entity parsers */ -static int XMLCALL -external_entity_reallocator(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text = get_buffer_test_text; - XML_Parser ext_parser; - void *buffer; - enum XML_Status status; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - fail("Could not create external entity parser"); - - reallocation_count = (intptr_t)XML_GetUserData(parser); - buffer = XML_GetBuffer(ext_parser, 1536); - if (buffer == NULL) - fail("Buffer allocation failed"); - assert(buffer != NULL); - memcpy(buffer, text, strlen(text)); - status = XML_ParseBuffer(ext_parser, (int)strlen(text), XML_FALSE); - reallocation_count = -1; - XML_ParserFree(ext_parser); - return (status == XML_STATUS_OK) ? XML_STATUS_OK : XML_STATUS_ERROR; -} - -START_TEST(test_alloc_ext_entity_realloc_buffer) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY en SYSTEM 'http://example.org/dummy.ent'>\n" - "]>\n" - "<doc>&en;</doc>"; - int i; - const int max_realloc_count = 10; - - for (i = 0; i < max_realloc_count; i++) { - XML_SetExternalEntityRefHandler(g_parser, external_entity_reallocator); - XML_SetUserData(g_parser, (void *)(intptr_t)i); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - == XML_STATUS_OK) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Succeeded with no reallocations"); - if (i == max_realloc_count) - fail("Failed with max reallocations"); -} -END_TEST - -/* Test elements with many attributes are handled correctly */ -START_TEST(test_alloc_realloc_many_attributes) { - const char *text = "<!DOCTYPE doc [\n" - "<!ATTLIST doc za CDATA 'default'>\n" - "<!ATTLIST doc zb CDATA 'def2'>\n" - "<!ATTLIST doc zc CDATA 'def3'>\n" - "]>\n" - "<doc a='1'" - " b='2'" - " c='3'" - " d='4'" - " e='5'" - " f='6'" - " g='7'" - " h='8'" - " i='9'" - " j='10'" - " k='11'" - " l='12'" - " m='13'" - " n='14'" - " p='15'" - " q='16'" - " r='17'" - " s='18'>" - "</doc>"; - int i; - const int max_realloc_count = 10; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite no reallocations"); - if (i == max_realloc_count) - fail("Parse failed at max reallocations"); -} -END_TEST - -/* Test handling of a public entity with failing allocator */ -START_TEST(test_alloc_public_entity_value) { - const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/'>\n" - "<doc></doc>\n"; - char dtd_text[] - = "<!ELEMENT doc EMPTY>\n" - "<!ENTITY % e1 PUBLIC 'foo' 'bar.ent'>\n" - "<!ENTITY % " - /* Each line is 64 characters */ - "ThisIsAStupidlyLongParameterNameIntendedToTriggerPoolGrowth12345" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - " '%e1;'>\n" - "%e1;\n"; - int i; - const int max_alloc_count = 50; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - dummy_handler_flags = 0; - XML_SetUserData(g_parser, dtd_text); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_public); - /* Provoke a particular code path */ - XML_SetEntityDeclHandler(g_parser, dummy_entity_decl_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing allocation"); - if (i == max_alloc_count) - fail("Parsing failed at max allocation count"); - if (dummy_handler_flags != DUMMY_ENTITY_DECL_HANDLER_FLAG) - fail("Entity declaration handler not called"); -} -END_TEST - -START_TEST(test_alloc_realloc_subst_public_entity_value) { - const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/'>\n" - "<doc></doc>\n"; - char dtd_text[] - = "<!ELEMENT doc EMPTY>\n" - "<!ENTITY % " - /* Each line is 64 characters */ - "ThisIsAStupidlyLongParameterNameIntendedToTriggerPoolGrowth12345" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - " PUBLIC 'foo' 'bar.ent'>\n" - "%ThisIsAStupidlyLongParameterNameIntendedToTriggerPoolGrowth12345" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP;"; - int i; - const int max_realloc_count = 10; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - XML_SetUserData(g_parser, dtd_text); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_public); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing reallocation"); - if (i == max_realloc_count) - fail("Parsing failed at max reallocation count"); -} -END_TEST - -START_TEST(test_alloc_parse_public_doctype) { - const char *text - = "<?xml version='1.0' encoding='utf-8'?>\n" - "<!DOCTYPE doc PUBLIC '" - /* 64 characters per line */ - "http://example.com/a/long/enough/name/to/trigger/pool/growth/zz/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "' 'test'>\n" - "<doc></doc>"; - int i; - const int max_alloc_count = 25; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - dummy_handler_flags = 0; - XML_SetDoctypeDeclHandler(g_parser, dummy_start_doctype_decl_handler, - dummy_end_doctype_decl_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed at maximum allocation count"); - if (dummy_handler_flags - != (DUMMY_START_DOCTYPE_DECL_HANDLER_FLAG - | DUMMY_END_DOCTYPE_DECL_HANDLER_FLAG)) - fail("Doctype handler functions not called"); -} -END_TEST - -START_TEST(test_alloc_parse_public_doctype_long_name) { - const char *text - = "<?xml version='1.0' encoding='utf-8'?>\n" - "<!DOCTYPE doc PUBLIC 'http://example.com/foo' '" - /* 64 characters per line */ - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "'>\n" - "<doc></doc>"; - int i; - const int max_alloc_count = 25; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetDoctypeDeclHandler(g_parser, dummy_start_doctype_decl_handler, - dummy_end_doctype_decl_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed at maximum allocation count"); -} -END_TEST - -static int XMLCALL -external_entity_alloc(XML_Parser parser, const XML_Char *context, - const XML_Char *base, const XML_Char *systemId, - const XML_Char *publicId) { - const char *text = (const char *)XML_GetUserData(parser); - XML_Parser ext_parser; - int parse_res; - - UNUSED_P(base); - UNUSED_P(systemId); - UNUSED_P(publicId); - ext_parser = XML_ExternalEntityParserCreate(parser, context, NULL); - if (ext_parser == NULL) - return XML_STATUS_ERROR; - parse_res - = _XML_Parse_SINGLE_BYTES(ext_parser, text, (int)strlen(text), XML_TRUE); - XML_ParserFree(ext_parser); - return parse_res; -} - -/* Test foreign DTD handling */ -START_TEST(test_alloc_set_foreign_dtd) { - const char *text1 = "<?xml version='1.0' encoding='us-ascii'?>\n" - "<doc>&entity;</doc>"; - char text2[] = "<!ELEMENT doc (#PCDATA)*>"; - int i; - const int max_alloc_count = 25; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetUserData(g_parser, &text2); - XML_SetExternalEntityRefHandler(g_parser, external_entity_alloc); - if (XML_UseForeignDTD(g_parser, XML_TRUE) != XML_ERROR_NONE) - fail("Could not set foreign DTD"); - if (_XML_Parse_SINGLE_BYTES(g_parser, text1, (int)strlen(text1), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed at maximum allocation count"); -} -END_TEST - -/* Test based on ibm/valid/P32/ibm32v04.xml */ -START_TEST(test_alloc_attribute_enum_value) { - const char *text = "<?xml version='1.0' standalone='no'?>\n" - "<!DOCTYPE animal SYSTEM 'test.dtd'>\n" - "<animal>This is a \n <a/> \n\nyellow tiger</animal>"; - char dtd_text[] = "<!ELEMENT animal (#PCDATA|a)*>\n" - "<!ELEMENT a EMPTY>\n" - "<!ATTLIST animal xml:space (default|preserve) 'preserve'>"; - int i; - const int max_alloc_count = 30; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetExternalEntityRefHandler(g_parser, external_entity_alloc); - XML_SetUserData(g_parser, dtd_text); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - /* An attribute list handler provokes a different code path */ - XML_SetAttlistDeclHandler(g_parser, dummy_attlist_decl_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed at maximum allocation count"); -} -END_TEST - -/* Test attribute enums sufficient to overflow the string pool */ -START_TEST(test_alloc_realloc_attribute_enum_value) { - const char *text = "<?xml version='1.0' standalone='no'?>\n" - "<!DOCTYPE animal SYSTEM 'test.dtd'>\n" - "<animal>This is a yellow tiger</animal>"; - /* We wish to define a collection of attribute enums that will - * cause the string pool storing them to have to expand. This - * means more than 1024 bytes, including the parentheses and - * separator bars. - */ - char dtd_text[] - = "<!ELEMENT animal (#PCDATA)*>\n" - "<!ATTLIST animal thing " - "(default" - /* Each line is 64 characters */ - "|ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|BBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|CBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|DBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|EBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|FBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|GBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|HBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|IBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|JBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|KBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|LBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|MBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|NBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|OBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|PBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO)" - " 'default'>"; - int i; - const int max_realloc_count = 10; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - XML_SetExternalEntityRefHandler(g_parser, external_entity_alloc); - XML_SetUserData(g_parser, dtd_text); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - /* An attribute list handler provokes a different code path */ - XML_SetAttlistDeclHandler(g_parser, dummy_attlist_decl_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing reallocator"); - if (i == max_realloc_count) - fail("Parse failed at maximum reallocation count"); -} -END_TEST - -/* Test attribute enums in a #IMPLIED attribute forcing pool growth */ -START_TEST(test_alloc_realloc_implied_attribute) { - /* Forcing this particular code path is a balancing act. The - * addition of the closing parenthesis and terminal NUL must be - * what pushes the string of enums over the 1024-byte limit, - * otherwise a different code path will pick up the realloc. - */ - const char *text - = "<!DOCTYPE doc [\n" - "<!ELEMENT doc EMPTY>\n" - "<!ATTLIST doc a " - /* Each line is 64 characters */ - "(ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|BBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|CBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|DBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|EBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|FBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|GBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|HBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|IBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|JBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|KBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|LBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|MBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|NBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|OBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|PBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMN)" - " #IMPLIED>\n" - "]><doc/>"; - int i; - const int max_realloc_count = 10; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - XML_SetAttlistDeclHandler(g_parser, dummy_attlist_decl_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing reallocator"); - if (i == max_realloc_count) - fail("Parse failed at maximum reallocation count"); -} -END_TEST - -/* Test attribute enums in a defaulted attribute forcing pool growth */ -START_TEST(test_alloc_realloc_default_attribute) { - /* Forcing this particular code path is a balancing act. The - * addition of the closing parenthesis and terminal NUL must be - * what pushes the string of enums over the 1024-byte limit, - * otherwise a different code path will pick up the realloc. - */ - const char *text - = "<!DOCTYPE doc [\n" - "<!ELEMENT doc EMPTY>\n" - "<!ATTLIST doc a " - /* Each line is 64 characters */ - "(ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|BBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|CBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|DBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|EBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|FBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|GBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|HBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|IBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|JBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|KBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|LBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|MBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|NBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|OBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO" - "|PBCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMN)" - " 'ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNO'" - ">\n]><doc/>"; - int i; - const int max_realloc_count = 10; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - XML_SetAttlistDeclHandler(g_parser, dummy_attlist_decl_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing reallocator"); - if (i == max_realloc_count) - fail("Parse failed at maximum reallocation count"); -} -END_TEST - -/* Test long notation name with dodgy allocator */ -START_TEST(test_alloc_notation) { - const char *text - = "<!DOCTYPE doc [\n" - "<!NOTATION " - /* Each line is 64 characters */ - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - " SYSTEM 'http://example.org/n'>\n" - "<!ENTITY e SYSTEM 'http://example.org/e' NDATA " - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - ">\n" - "<!ELEMENT doc EMPTY>\n" - "]>\n<doc/>"; - int i; - const int max_alloc_count = 20; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - dummy_handler_flags = 0; - XML_SetNotationDeclHandler(g_parser, dummy_notation_decl_handler); - XML_SetEntityDeclHandler(g_parser, dummy_entity_decl_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite allocation failures"); - if (i == max_alloc_count) - fail("Parse failed at maximum allocation count"); - if (dummy_handler_flags - != (DUMMY_ENTITY_DECL_HANDLER_FLAG | DUMMY_NOTATION_DECL_HANDLER_FLAG)) - fail("Entity declaration handler not called"); -} -END_TEST - -/* Test public notation with dodgy allocator */ -START_TEST(test_alloc_public_notation) { - const char *text - = "<!DOCTYPE doc [\n" - "<!NOTATION note PUBLIC '" - /* 64 characters per line */ - "http://example.com/a/long/enough/name/to/trigger/pool/growth/zz/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "' 'foo'>\n" - "<!ENTITY e SYSTEM 'http://example.com/e' NDATA note>\n" - "<!ELEMENT doc EMPTY>\n" - "]>\n<doc/>"; - int i; - const int max_alloc_count = 20; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - dummy_handler_flags = 0; - XML_SetNotationDeclHandler(g_parser, dummy_notation_decl_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite allocation failures"); - if (i == max_alloc_count) - fail("Parse failed at maximum allocation count"); - if (dummy_handler_flags != DUMMY_NOTATION_DECL_HANDLER_FLAG) - fail("Notation handler not called"); -} -END_TEST - -/* Test public notation with dodgy allocator */ -START_TEST(test_alloc_system_notation) { - const char *text - = "<!DOCTYPE doc [\n" - "<!NOTATION note SYSTEM '" - /* 64 characters per line */ - "http://example.com/a/long/enough/name/to/trigger/pool/growth/zz/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "'>\n" - "<!ENTITY e SYSTEM 'http://example.com/e' NDATA note>\n" - "<!ELEMENT doc EMPTY>\n" - "]>\n<doc/>"; - int i; - const int max_alloc_count = 20; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - dummy_handler_flags = 0; - XML_SetNotationDeclHandler(g_parser, dummy_notation_decl_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite allocation failures"); - if (i == max_alloc_count) - fail("Parse failed at maximum allocation count"); - if (dummy_handler_flags != DUMMY_NOTATION_DECL_HANDLER_FLAG) - fail("Notation handler not called"); -} -END_TEST - -START_TEST(test_alloc_nested_groups) { - const char *text - = "<!DOCTYPE doc [\n" - "<!ELEMENT doc " - /* Sixteen elements per line */ - "(e,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?," - "(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?" - "))))))))))))))))))))))))))))))))>\n" - "<!ELEMENT e EMPTY>" - "]>\n" - "<doc><e/></doc>"; - CharData storage; - int i; - const int max_alloc_count = 20; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - CharData_Init(&storage); - XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); - XML_SetStartElementHandler(g_parser, record_element_start_handler); - XML_SetUserData(g_parser, &storage); - dummy_handler_flags = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - - if (i == 0) - fail("Parse succeeded despite failing reallocator"); - if (i == max_alloc_count) - fail("Parse failed at maximum reallocation count"); - CharData_CheckXMLChars(&storage, XCS("doce")); - if (dummy_handler_flags != DUMMY_ELEMENT_DECL_HANDLER_FLAG) - fail("Element handler not fired"); -} -END_TEST - -START_TEST(test_alloc_realloc_nested_groups) { - const char *text - = "<!DOCTYPE doc [\n" - "<!ELEMENT doc " - /* Sixteen elements per line */ - "(e,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?," - "(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?,(e?" - "))))))))))))))))))))))))))))))))>\n" - "<!ELEMENT e EMPTY>" - "]>\n" - "<doc><e/></doc>"; - CharData storage; - int i; - const int max_realloc_count = 10; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - CharData_Init(&storage); - XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); - XML_SetStartElementHandler(g_parser, record_element_start_handler); - XML_SetUserData(g_parser, &storage); - dummy_handler_flags = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - - if (i == 0) - fail("Parse succeeded despite failing reallocator"); - if (i == max_realloc_count) - fail("Parse failed at maximum reallocation count"); - CharData_CheckXMLChars(&storage, XCS("doce")); - if (dummy_handler_flags != DUMMY_ELEMENT_DECL_HANDLER_FLAG) - fail("Element handler not fired"); -} -END_TEST - -START_TEST(test_alloc_large_group) { - const char *text = "<!DOCTYPE doc [\n" - "<!ELEMENT doc (" - "a1|a2|a3|a4|a5|a6|a7|a8|" - "b1|b2|b3|b4|b5|b6|b7|b8|" - "c1|c2|c3|c4|c5|c6|c7|c8|" - "d1|d2|d3|d4|d5|d6|d7|d8|" - "e1" - ")+>\n" - "]>\n" - "<doc>\n" - "<a1/>\n" - "</doc>\n"; - int i; - const int max_alloc_count = 50; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); - dummy_handler_flags = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed at maximum allocation count"); - if (dummy_handler_flags != DUMMY_ELEMENT_DECL_HANDLER_FLAG) - fail("Element handler flag not raised"); -} -END_TEST - -START_TEST(test_alloc_realloc_group_choice) { - const char *text = "<!DOCTYPE doc [\n" - "<!ELEMENT doc (" - "a1|a2|a3|a4|a5|a6|a7|a8|" - "b1|b2|b3|b4|b5|b6|b7|b8|" - "c1|c2|c3|c4|c5|c6|c7|c8|" - "d1|d2|d3|d4|d5|d6|d7|d8|" - "e1" - ")+>\n" - "]>\n" - "<doc>\n" - "<a1/>\n" - "<b2 attr='foo'>This is a foo</b2>\n" - "<c3></c3>\n" - "</doc>\n"; - int i; - const int max_realloc_count = 10; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - XML_SetElementDeclHandler(g_parser, dummy_element_decl_handler); - dummy_handler_flags = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing reallocator"); - if (i == max_realloc_count) - fail("Parse failed at maximum reallocation count"); - if (dummy_handler_flags != DUMMY_ELEMENT_DECL_HANDLER_FLAG) - fail("Element handler flag not raised"); -} -END_TEST - -START_TEST(test_alloc_pi_in_epilog) { - const char *text = "<doc></doc>\n" - "<?pi in epilog?>"; - int i; - const int max_alloc_count = 15; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetProcessingInstructionHandler(g_parser, dummy_pi_handler); - dummy_handler_flags = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse completed despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed at maximum allocation count"); - if (dummy_handler_flags != DUMMY_PI_HANDLER_FLAG) - fail("Processing instruction handler not invoked"); -} -END_TEST - -START_TEST(test_alloc_comment_in_epilog) { - const char *text = "<doc></doc>\n" - "<!-- comment in epilog -->"; - int i; - const int max_alloc_count = 15; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetCommentHandler(g_parser, dummy_comment_handler); - dummy_handler_flags = 0; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse completed despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed at maximum allocation count"); - if (dummy_handler_flags != DUMMY_COMMENT_HANDLER_FLAG) - fail("Processing instruction handler not invoked"); -} -END_TEST - -START_TEST(test_alloc_realloc_long_attribute_value) { - const char *text - = "<!DOCTYPE doc [<!ENTITY foo '" - /* Each line is 64 characters */ - "This entity will be substituted as an attribute value, and is " - "calculated to be exactly long enough that the terminating NUL " - "that the library adds internally will trigger the string pool to" - "grow. GHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "'>]>\n" - "<doc a='&foo;'></doc>"; - int i; - const int max_realloc_count = 10; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing reallocator"); - if (i == max_realloc_count) - fail("Parse failed at maximum reallocation count"); -} -END_TEST - -START_TEST(test_alloc_attribute_whitespace) { - const char *text = "<doc a=' '></doc>"; - int i; - const int max_alloc_count = 15; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed at maximum allocation count"); -} -END_TEST - -START_TEST(test_alloc_attribute_predefined_entity) { - const char *text = "<doc a='&'></doc>"; - int i; - const int max_alloc_count = 15; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed at maximum allocation count"); -} -END_TEST - -/* Test that a character reference at the end of a suitably long - * default value for an attribute can trigger pool growth, and recovers - * if the allocator fails on it. - */ -START_TEST(test_alloc_long_attr_default_with_char_ref) { - const char *text - = "<!DOCTYPE doc [<!ATTLIST doc a CDATA '" - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHI" - "1'>]>\n" - "<doc/>"; - int i; - const int max_alloc_count = 20; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed at maximum allocation count"); -} -END_TEST - -/* Test that a long character reference substitution triggers a pool - * expansion correctly for an attribute value. - */ -START_TEST(test_alloc_long_attr_value) { - const char *text - = "<!DOCTYPE test [<!ENTITY foo '\n" - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "'>]>\n" - "<test a='&foo;'/>"; - int i; - const int max_alloc_count = 25; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing allocator"); - if (i == max_alloc_count) - fail("Parse failed at maximum allocation count"); -} -END_TEST - -/* Test that an error in a nested parameter entity substitution is - * handled correctly. It seems unlikely that the code path being - * exercised can be reached purely by carefully crafted XML, but an - * allocation error in the right place will definitely do it. - */ -START_TEST(test_alloc_nested_entities) { - const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/one.ent'>\n" - "<doc />"; - ExtFaults test_data - = {"<!ENTITY % pe1 '" - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "'>\n" - "<!ENTITY % pe2 '%pe1;'>\n" - "%pe2;", - "Memory Fail not faulted", NULL, XML_ERROR_NO_MEMORY}; - - /* Causes an allocation error in a nested storeEntityValue() */ - allocation_count = 12; - XML_SetUserData(g_parser, &test_data); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_faulter); - expect_failure(text, XML_ERROR_EXTERNAL_ENTITY_HANDLING, - "Entity allocation failure not noted"); -} -END_TEST - -START_TEST(test_alloc_realloc_param_entity_newline) { - const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/'>\n" - "<doc/>"; - char dtd_text[] - = "<!ENTITY % pe '<!ATTLIST doc att CDATA \"" - /* 64 characters per line */ - "This default value is carefully crafted so that the carriage " - "return right at the end of the entity string causes an internal " - "string pool to have to grow. This allows us to test the alloc " - "failure path from that point. OPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDE" - "\">\n'>" - "%pe;\n"; - int i; - const int max_realloc_count = 5; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - XML_SetUserData(g_parser, dtd_text); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_alloc); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing reallocator"); - if (i == max_realloc_count) - fail("Parse failed at maximum reallocation count"); -} -END_TEST - -START_TEST(test_alloc_realloc_ce_extends_pe) { - const char *text = "<!DOCTYPE doc SYSTEM 'http://example.org/'>\n" - "<doc/>"; - char dtd_text[] - = "<!ENTITY % pe '<!ATTLIST doc att CDATA \"" - /* 64 characters per line */ - "This default value is carefully crafted so that the character " - "entity at the end causes an internal string pool to have to " - "grow. This allows us to test the allocation failure path from " - "that point onwards. EFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGQ" - "\">\n'>" - "%pe;\n"; - int i; - const int max_realloc_count = 5; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - XML_SetUserData(g_parser, dtd_text); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_alloc); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parse succeeded despite failing reallocator"); - if (i == max_realloc_count) - fail("Parse failed at maximum reallocation count"); -} -END_TEST - -START_TEST(test_alloc_realloc_attributes) { - const char *text = "<!DOCTYPE doc [\n" - " <!ATTLIST doc\n" - " a1 (a|b|c) 'a'\n" - " a2 (foo|bar) #IMPLIED\n" - " a3 NMTOKEN #IMPLIED\n" - " a4 NMTOKENS #IMPLIED\n" - " a5 ID #IMPLIED\n" - " a6 IDREF #IMPLIED\n" - " a7 IDREFS #IMPLIED\n" - " a8 ENTITY #IMPLIED\n" - " a9 ENTITIES #IMPLIED\n" - " a10 CDATA #IMPLIED\n" - " >]>\n" - "<doc>wombat</doc>\n"; - int i; - const int max_realloc_count = 5; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - - if (i == 0) - fail("Parse succeeded despite failing reallocator"); - if (i == max_realloc_count) - fail("Parse failed at maximum reallocation count"); -} -END_TEST - -START_TEST(test_alloc_long_doc_name) { - const char *text = - /* 64 characters per line */ - "<LongRootElementNameThatWillCauseTheNextAllocationToExpandTheStr" - "ingPoolForTheDTDQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - " a='1'/>"; - int i; - const int max_alloc_count = 20; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing reallocations"); - else if (i == max_alloc_count) - fail("Parsing failed even at max reallocation count"); -} -END_TEST - -START_TEST(test_alloc_long_base) { - const char *text = "<!DOCTYPE doc [\n" - " <!ENTITY e SYSTEM 'foo'>\n" - "]>\n" - "<doc>&e;</doc>"; - char entity_text[] = "Hello world"; - const XML_Char *base = - /* 64 characters per line */ - /* clang-format off */ - XCS("LongBaseURI/that/will/overflow/an/internal/buffer/and/cause/it/t") - XCS("o/have/to/grow/PQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/"); - /* clang-format on */ - int i; - const int max_alloc_count = 25; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetUserData(g_parser, entity_text); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_alloc); - if (XML_SetBase(g_parser, base) == XML_STATUS_ERROR) { - XML_ParserReset(g_parser, NULL); - continue; - } - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing allocations"); - else if (i == max_alloc_count) - fail("Parsing failed even at max allocation count"); -} -END_TEST - -START_TEST(test_alloc_long_public_id) { - const char *text - = "<!DOCTYPE doc [\n" - " <!ENTITY e PUBLIC '" - /* 64 characters per line */ - "LongPublicIDThatShouldResultInAnInternalStringPoolGrowingAtASpec" - "ificMomentKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "' 'bar'>\n" - "]>\n" - "<doc>&e;</doc>"; - char entity_text[] = "Hello world"; - int i; - const int max_alloc_count = 40; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetUserData(g_parser, entity_text); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_alloc); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing allocations"); - else if (i == max_alloc_count) - fail("Parsing failed even at max allocation count"); -} -END_TEST - -START_TEST(test_alloc_long_entity_value) { - const char *text - = "<!DOCTYPE doc [\n" - " <!ENTITY e1 '" - /* 64 characters per line */ - "Long entity value that should provoke a string pool to grow whil" - "e setting up to parse the external entity below. xyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "'>\n" - " <!ENTITY e2 SYSTEM 'bar'>\n" - "]>\n" - "<doc>&e2;</doc>"; - char entity_text[] = "Hello world"; - int i; - const int max_alloc_count = 40; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetUserData(g_parser, entity_text); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_alloc); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing allocations"); - else if (i == max_alloc_count) - fail("Parsing failed even at max allocation count"); -} -END_TEST - -START_TEST(test_alloc_long_notation) { - const char *text - = "<!DOCTYPE doc [\n" - " <!NOTATION note SYSTEM '" - /* 64 characters per line */ - "ALongNotationNameThatShouldProvokeStringPoolGrowthWhileCallingAn" - "ExternalEntityParserUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "'>\n" - " <!ENTITY e1 SYSTEM 'foo' NDATA " - /* 64 characters per line */ - "ALongNotationNameThatShouldProvokeStringPoolGrowthWhileCallingAn" - "ExternalEntityParserUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" - ">\n" - " <!ENTITY e2 SYSTEM 'bar'>\n" - "]>\n" - "<doc>&e2;</doc>"; - ExtOption options[] - = {{XCS("foo"), "Entity Foo"}, {XCS("bar"), "Entity Bar"}, {NULL, NULL}}; - int i; - const int max_alloc_count = 40; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetUserData(g_parser, options); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_optioner); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - - /* See comment in test_alloc_parse_xdecl() */ - alloc_teardown(); - alloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing allocations"); - else if (i == max_alloc_count) - fail("Parsing failed even at max allocation count"); -} -END_TEST - -static void -nsalloc_setup(void) { - XML_Memory_Handling_Suite memsuite = {duff_allocator, duff_reallocator, free}; - XML_Char ns_sep[2] = {' ', '\0'}; - - /* Ensure the parser creation will go through */ - allocation_count = ALLOC_ALWAYS_SUCCEED; - reallocation_count = REALLOC_ALWAYS_SUCCEED; - g_parser = XML_ParserCreate_MM(NULL, &memsuite, ns_sep); - if (g_parser == NULL) - fail("Parser not created"); -} - -static void -nsalloc_teardown(void) { - basic_teardown(); -} - -/* Test the effects of allocation failure in simple namespace parsing. - * Based on test_ns_default_with_empty_uri() - */ -START_TEST(test_nsalloc_xmlns) { - const char *text = "<doc xmlns='http://example.org/'>\n" - " <e xmlns=''/>\n" - "</doc>"; - unsigned int i; - const unsigned int max_alloc_count = 30; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - /* Exercise more code paths with a default handler */ - XML_SetDefaultHandler(g_parser, dummy_default_handler); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* Resetting the parser is insufficient, because some memory - * allocations are cached within the parser. Instead we use - * the teardown and setup routines to ensure that we have the - * right sort of parser back in our hands. - */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing allocations"); - else if (i == max_alloc_count) - fail("Parsing failed even at maximum allocation count"); -} -END_TEST - -/* Test XML_ParseBuffer interface with namespace and a dicky allocator */ -START_TEST(test_nsalloc_parse_buffer) { - const char *text = "<doc>Hello</doc>"; - void *buffer; - - /* Try a parse before the start of the world */ - /* (Exercises new code path) */ - allocation_count = 0; - if (XML_ParseBuffer(g_parser, 0, XML_FALSE) != XML_STATUS_ERROR) - fail("Pre-init XML_ParseBuffer not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_NO_MEMORY) - fail("Pre-init XML_ParseBuffer faulted for wrong reason"); - - /* Now with actual memory allocation */ - allocation_count = ALLOC_ALWAYS_SUCCEED; - if (XML_ParseBuffer(g_parser, 0, XML_FALSE) != XML_STATUS_OK) - xml_failure(g_parser); - - /* Check that resuming an unsuspended parser is faulted */ - if (XML_ResumeParser(g_parser) != XML_STATUS_ERROR) - fail("Resuming unsuspended parser not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_NOT_SUSPENDED) - xml_failure(g_parser); - - /* Get the parser into suspended state */ - XML_SetCharacterDataHandler(g_parser, clearing_aborting_character_handler); - resumable = XML_TRUE; - buffer = XML_GetBuffer(g_parser, (int)strlen(text)); - if (buffer == NULL) - fail("Could not acquire parse buffer"); - assert(buffer != NULL); - memcpy(buffer, text, strlen(text)); - if (XML_ParseBuffer(g_parser, (int)strlen(text), XML_TRUE) - != XML_STATUS_SUSPENDED) - xml_failure(g_parser); - if (XML_GetErrorCode(g_parser) != XML_ERROR_NONE) - xml_failure(g_parser); - if (XML_ParseBuffer(g_parser, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - fail("Suspended XML_ParseBuffer not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_SUSPENDED) - xml_failure(g_parser); - if (XML_GetBuffer(g_parser, (int)strlen(text)) != NULL) - fail("Suspended XML_GetBuffer not faulted"); - - /* Get it going again and complete the world */ - XML_SetCharacterDataHandler(g_parser, NULL); - if (XML_ResumeParser(g_parser) != XML_STATUS_OK) - xml_failure(g_parser); - if (XML_ParseBuffer(g_parser, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - fail("Post-finishing XML_ParseBuffer not faulted"); - if (XML_GetErrorCode(g_parser) != XML_ERROR_FINISHED) - xml_failure(g_parser); - if (XML_GetBuffer(g_parser, (int)strlen(text)) != NULL) - fail("Post-finishing XML_GetBuffer not faulted"); -} -END_TEST - -/* Check handling of long prefix names (pool growth) */ -START_TEST(test_nsalloc_long_prefix) { - const char *text - = "<" - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - ":foo xmlns:" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "='http://example.org/'>" - "</" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - ":foo>"; - int i; - const int max_alloc_count = 40; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing allocations"); - else if (i == max_alloc_count) - fail("Parsing failed even at max allocation count"); -} -END_TEST - -/* Check handling of long uri names (pool growth) */ -START_TEST(test_nsalloc_long_uri) { - const char *text - = "<foo:e xmlns:foo='http://example.org/" - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "' bar:a='12'\n" - "xmlns:bar='http://example.org/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789A/" - "'>" - "</foo:e>"; - int i; - const int max_alloc_count = 40; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing allocations"); - else if (i == max_alloc_count) - fail("Parsing failed even at max allocation count"); -} -END_TEST - -/* Test handling of long attribute names with prefixes */ -START_TEST(test_nsalloc_long_attr) { - const char *text - = "<foo:e xmlns:foo='http://example.org/' bar:" - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "='12'\n" - "xmlns:bar='http://example.org/'>" - "</foo:e>"; - int i; - const int max_alloc_count = 40; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing allocations"); - else if (i == max_alloc_count) - fail("Parsing failed even at max allocation count"); -} -END_TEST - -/* Test handling of an attribute name with a long namespace prefix */ -START_TEST(test_nsalloc_long_attr_prefix) { - const char *text - = "<foo:e xmlns:foo='http://example.org/' " - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - ":a='12'\n" - "xmlns:" - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "='http://example.org/'>" - "</foo:e>"; - const XML_Char *elemstr[] = { - /* clang-format off */ - XCS("http://example.org/ e foo"), - XCS("http://example.org/ a ") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") - XCS("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ") - /* clang-format on */ - }; - int i; - const int max_alloc_count = 40; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetReturnNSTriplet(g_parser, XML_TRUE); - XML_SetUserData(g_parser, (void *)elemstr); - XML_SetElementHandler(g_parser, triplet_start_checker, triplet_end_checker); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing allocations"); - else if (i == max_alloc_count) - fail("Parsing failed even at max allocation count"); -} -END_TEST - -/* Test attribute handling in the face of a dodgy reallocator */ -START_TEST(test_nsalloc_realloc_attributes) { - const char *text = "<foo:e xmlns:foo='http://example.org/' bar:a='12'\n" - " xmlns:bar='http://example.org/'>" - "</foo:e>"; - int i; - const int max_realloc_count = 10; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing reallocations"); - else if (i == max_realloc_count) - fail("Parsing failed at max reallocation count"); -} -END_TEST - -/* Test long element names with namespaces under a failing allocator */ -START_TEST(test_nsalloc_long_element) { - const char *text - = "<foo:thisisalongenoughelementnametotriggerareallocation\n" - " xmlns:foo='http://example.org/' bar:a='12'\n" - " xmlns:bar='http://example.org/'>" - "</foo:thisisalongenoughelementnametotriggerareallocation>"; - const XML_Char *elemstr[] - = {XCS("http://example.org/") - XCS(" thisisalongenoughelementnametotriggerareallocation foo"), - XCS("http://example.org/ a bar")}; - int i; - const int max_alloc_count = 30; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetReturnNSTriplet(g_parser, XML_TRUE); - XML_SetUserData(g_parser, (void *)elemstr); - XML_SetElementHandler(g_parser, triplet_start_checker, triplet_end_checker); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing reallocations"); - else if (i == max_alloc_count) - fail("Parsing failed at max reallocation count"); -} -END_TEST - -/* Test the effects of reallocation failure when reassigning a - * binding. - * - * XML_ParserReset does not free the BINDING structures used by a - * parser, but instead adds them to an internal free list to be reused - * as necessary. Likewise the URI buffers allocated for the binding - * aren't freed, but kept attached to their existing binding. If the - * new binding has a longer URI, it will need reallocation. This test - * provokes that reallocation, and tests the control path if it fails. - */ -START_TEST(test_nsalloc_realloc_binding_uri) { - const char *first = "<doc xmlns='http://example.org/'>\n" - " <e xmlns='' />\n" - "</doc>"; - const char *second - = "<doc xmlns='http://example.org/long/enough/URI/to/reallocate/'>\n" - " <e xmlns='' />\n" - "</doc>"; - unsigned i; - const unsigned max_realloc_count = 10; - - /* First, do a full parse that will leave bindings around */ - if (_XML_Parse_SINGLE_BYTES(g_parser, first, (int)strlen(first), XML_TRUE) - == XML_STATUS_ERROR) - xml_failure(g_parser); - - /* Now repeat with a longer URI and a duff reallocator */ - for (i = 0; i < max_realloc_count; i++) { - XML_ParserReset(g_parser, NULL); - reallocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, second, (int)strlen(second), XML_TRUE) - != XML_STATUS_ERROR) - break; - } - if (i == 0) - fail("Parsing worked despite failing reallocation"); - else if (i == max_realloc_count) - fail("Parsing failed at max reallocation count"); -} -END_TEST - -/* Check handling of long prefix names (pool growth) */ -START_TEST(test_nsalloc_realloc_long_prefix) { - const char *text - = "<" - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - ":foo xmlns:" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "='http://example.org/'>" - "</" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - ":foo>"; - int i; - const int max_realloc_count = 12; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing reallocations"); - else if (i == max_realloc_count) - fail("Parsing failed even at max reallocation count"); -} -END_TEST - -/* Check handling of even long prefix names (different code path) */ -START_TEST(test_nsalloc_realloc_longer_prefix) { - const char *text - = "<" - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "Q:foo xmlns:" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "Q='http://example.org/'>" - "</" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "Q:foo>"; - int i; - const int max_realloc_count = 12; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing reallocations"); - else if (i == max_realloc_count) - fail("Parsing failed even at max reallocation count"); -} -END_TEST - -START_TEST(test_nsalloc_long_namespace) { - const char *text1 - = "<" - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - ":e xmlns:" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "='http://example.org/'>\n"; - const char *text2 - = "<" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - ":f " - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - ":attr='foo'/>\n" - "</" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - ":e>"; - int i; - const int max_alloc_count = 40; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text1, (int)strlen(text1), XML_FALSE) - != XML_STATUS_ERROR - && _XML_Parse_SINGLE_BYTES(g_parser, text2, (int)strlen(text2), - XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing allocations"); - else if (i == max_alloc_count) - fail("Parsing failed even at max allocation count"); -} -END_TEST - -/* Using a slightly shorter namespace name provokes allocations in - * slightly different places in the code. - */ -START_TEST(test_nsalloc_less_long_namespace) { - const char *text - = "<" - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678" - ":e xmlns:" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678" - "='http://example.org/'>\n" - "<" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678" - ":f " - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678" - ":att='foo'/>\n" - "</" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AZ" - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012345678" - ":e>"; - int i; - const int max_alloc_count = 40; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing allocations"); - else if (i == max_alloc_count) - fail("Parsing failed even at max allocation count"); -} -END_TEST - -START_TEST(test_nsalloc_long_context) { - const char *text - = "<!DOCTYPE doc SYSTEM 'foo' [\n" - " <!ATTLIST doc baz ID #REQUIRED>\n" - " <!ENTITY en SYSTEM 'bar'>\n" - "]>\n" - "<doc xmlns='http://example.org/" - /* 64 characters per line */ - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKL" - "' baz='2'>\n" - "&en;" - "</doc>"; - ExtOption options[] = { - {XCS("foo"), "<!ELEMENT e EMPTY>"}, {XCS("bar"), "<e/>"}, {NULL, NULL}}; - int i; - const int max_alloc_count = 70; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetUserData(g_parser, options); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_optioner); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing allocations"); - else if (i == max_alloc_count) - fail("Parsing failed even at max allocation count"); -} -END_TEST - -/* This function is void; it will throw a fail() on error, so if it - * returns normally it must have succeeded. - */ -static void -context_realloc_test(const char *text) { - ExtOption options[] = { - {XCS("foo"), "<!ELEMENT e EMPTY>"}, {XCS("bar"), "<e/>"}, {NULL, NULL}}; - int i; - const int max_realloc_count = 6; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - XML_SetUserData(g_parser, options); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_optioner); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing reallocations"); - else if (i == max_realloc_count) - fail("Parsing failed even at max reallocation count"); -} - -START_TEST(test_nsalloc_realloc_long_context) { - const char *text - = "<!DOCTYPE doc SYSTEM 'foo' [\n" - " <!ENTITY en SYSTEM 'bar'>\n" - "]>\n" - "<doc xmlns='http://example.org/" - /* 64 characters per line */ - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKL" - "'>\n" - "&en;" - "</doc>"; - - context_realloc_test(text); -} -END_TEST - -START_TEST(test_nsalloc_realloc_long_context_2) { - const char *text - = "<!DOCTYPE doc SYSTEM 'foo' [\n" - " <!ENTITY en SYSTEM 'bar'>\n" - "]>\n" - "<doc xmlns='http://example.org/" - /* 64 characters per line */ - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJK" - "'>\n" - "&en;" - "</doc>"; - - context_realloc_test(text); -} -END_TEST - -START_TEST(test_nsalloc_realloc_long_context_3) { - const char *text - = "<!DOCTYPE doc SYSTEM 'foo' [\n" - " <!ENTITY en SYSTEM 'bar'>\n" - "]>\n" - "<doc xmlns='http://example.org/" - /* 64 characters per line */ - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGH" - "'>\n" - "&en;" - "</doc>"; - - context_realloc_test(text); -} -END_TEST - -START_TEST(test_nsalloc_realloc_long_context_4) { - const char *text - = "<!DOCTYPE doc SYSTEM 'foo' [\n" - " <!ENTITY en SYSTEM 'bar'>\n" - "]>\n" - "<doc xmlns='http://example.org/" - /* 64 characters per line */ - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO" - "'>\n" - "&en;" - "</doc>"; - - context_realloc_test(text); -} -END_TEST - -START_TEST(test_nsalloc_realloc_long_context_5) { - const char *text - = "<!DOCTYPE doc SYSTEM 'foo' [\n" - " <!ENTITY en SYSTEM 'bar'>\n" - "]>\n" - "<doc xmlns='http://example.org/" - /* 64 characters per line */ - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABC" - "'>\n" - "&en;" - "</doc>"; - - context_realloc_test(text); -} -END_TEST - -START_TEST(test_nsalloc_realloc_long_context_6) { - const char *text - = "<!DOCTYPE doc SYSTEM 'foo' [\n" - " <!ENTITY en SYSTEM 'bar'>\n" - "]>\n" - "<doc xmlns='http://example.org/" - /* 64 characters per line */ - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNOP" - "'>\n" - "&en;" - "</doc>"; - - context_realloc_test(text); -} -END_TEST - -START_TEST(test_nsalloc_realloc_long_context_7) { - const char *text - = "<!DOCTYPE doc SYSTEM 'foo' [\n" - " <!ENTITY en SYSTEM 'bar'>\n" - "]>\n" - "<doc xmlns='http://example.org/" - /* 64 characters per line */ - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLM" - "'>\n" - "&en;" - "</doc>"; - - context_realloc_test(text); -} -END_TEST - -START_TEST(test_nsalloc_realloc_long_ge_name) { - const char *text - = "<!DOCTYPE doc SYSTEM 'foo' [\n" - " <!ENTITY " - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - " SYSTEM 'bar'>\n" - "]>\n" - "<doc xmlns='http://example.org/baz'>\n" - "&" - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - ";" - "</doc>"; - ExtOption options[] = { - {XCS("foo"), "<!ELEMENT el EMPTY>"}, {XCS("bar"), "<el/>"}, {NULL, NULL}}; - int i; - const int max_realloc_count = 10; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - XML_SetUserData(g_parser, options); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_optioner); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing reallocations"); - else if (i == max_realloc_count) - fail("Parsing failed even at max reallocation count"); -} -END_TEST - -/* Test that when a namespace is passed through the context mechanism - * to an external entity parser, the parsers handle reallocation - * failures correctly. The prefix is exactly the right length to - * provoke particular uncommon code paths. - */ -START_TEST(test_nsalloc_realloc_long_context_in_dtd) { - const char *text1 - = "<!DOCTYPE " - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - ":doc [\n" - " <!ENTITY First SYSTEM 'foo/First'>\n" - "]>\n" - "<" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - ":doc xmlns:" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "='foo/Second'>&First;"; - const char *text2 - = "</" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - ":doc>"; - ExtOption options[] = {{XCS("foo/First"), "Hello world"}, {NULL, NULL}}; - int i; - const int max_realloc_count = 20; - - for (i = 0; i < max_realloc_count; i++) { - reallocation_count = i; - XML_SetUserData(g_parser, options); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_optioner); - if (_XML_Parse_SINGLE_BYTES(g_parser, text1, (int)strlen(text1), XML_FALSE) - != XML_STATUS_ERROR - && _XML_Parse_SINGLE_BYTES(g_parser, text2, (int)strlen(text2), - XML_TRUE) - != XML_STATUS_ERROR) - break; - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing reallocations"); - else if (i == max_realloc_count) - fail("Parsing failed even at max reallocation count"); -} -END_TEST - -START_TEST(test_nsalloc_long_default_in_ext) { - const char *text - = "<!DOCTYPE doc [\n" - " <!ATTLIST e a1 CDATA '" - /* 64 characters per line */ - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP" - "'>\n" - " <!ENTITY x SYSTEM 'foo'>\n" - "]>\n" - "<doc>&x;</doc>"; - ExtOption options[] = {{XCS("foo"), "<e/>"}, {NULL, NULL}}; - int i; - const int max_alloc_count = 50; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetUserData(g_parser, options); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_optioner); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing allocations"); - else if (i == max_alloc_count) - fail("Parsing failed even at max allocation count"); -} -END_TEST - -START_TEST(test_nsalloc_long_systemid_in_ext) { - const char *text - = "<!DOCTYPE doc SYSTEM 'foo' [\n" - " <!ENTITY en SYSTEM '" - /* 64 characters per line */ - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/" - "'>\n" - "]>\n" - "<doc>&en;</doc>"; - ExtOption options[] = { - {XCS("foo"), "<!ELEMENT e EMPTY>"}, - {/* clang-format off */ - XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") - XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") - XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") - XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") - XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") - XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") - XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") - XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") - XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") - XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") - XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") - XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") - XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") - XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") - XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/") - XCS("ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/ABCDEFGHIJKLMNO/"), - /* clang-format on */ - "<e/>"}, - {NULL, NULL}}; - int i; - const int max_alloc_count = 55; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetUserData(g_parser, options); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_optioner); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Parsing worked despite failing allocations"); - else if (i == max_alloc_count) - fail("Parsing failed even at max allocation count"); -} -END_TEST - -/* Test the effects of allocation failure on parsing an element in a - * namespace. Based on test_nsalloc_long_context. - */ -START_TEST(test_nsalloc_prefixed_element) { - const char *text = "<!DOCTYPE pfx:element SYSTEM 'foo' [\n" - " <!ATTLIST pfx:element baz ID #REQUIRED>\n" - " <!ENTITY en SYSTEM 'bar'>\n" - "]>\n" - "<pfx:element xmlns:pfx='http://example.org/' baz='2'>\n" - "&en;" - "</pfx:element>"; - ExtOption options[] = { - {XCS("foo"), "<!ELEMENT e EMPTY>"}, {XCS("bar"), "<e/>"}, {NULL, NULL}}; - int i; - const int max_alloc_count = 70; - - for (i = 0; i < max_alloc_count; i++) { - allocation_count = i; - XML_SetUserData(g_parser, options); - XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS); - XML_SetExternalEntityRefHandler(g_parser, external_entity_optioner); - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) - != XML_STATUS_ERROR) - break; - - /* See comment in test_nsalloc_xmlns() */ - nsalloc_teardown(); - nsalloc_setup(); - } - if (i == 0) - fail("Success despite failing allocator"); - else if (i == max_alloc_count) - fail("Failed even at full allocation count"); -} -END_TEST +XML_Parser g_parser = NULL; static Suite * make_suite(void) { Suite *s = suite_create("basic"); - TCase *tc_basic = tcase_create("basic tests"); - TCase *tc_namespace = tcase_create("XML namespaces"); - TCase *tc_misc = tcase_create("miscellaneous tests"); - TCase *tc_alloc = tcase_create("allocation tests"); - TCase *tc_nsalloc = tcase_create("namespace allocation tests"); - suite_add_tcase(s, tc_basic); - tcase_add_checked_fixture(tc_basic, basic_setup, basic_teardown); - tcase_add_test(tc_basic, test_nul_byte); - tcase_add_test(tc_basic, test_u0000_char); - tcase_add_test(tc_basic, test_siphash_self); - tcase_add_test(tc_basic, test_siphash_spec); - tcase_add_test(tc_basic, test_bom_utf8); - tcase_add_test(tc_basic, test_bom_utf16_be); - tcase_add_test(tc_basic, test_bom_utf16_le); - tcase_add_test(tc_basic, test_nobom_utf16_le); - tcase_add_test(tc_basic, test_illegal_utf8); - tcase_add_test(tc_basic, test_utf8_auto_align); - tcase_add_test(tc_basic, test_utf16); - tcase_add_test(tc_basic, test_utf16_le_epilog_newline); - tcase_add_test(tc_basic, test_not_utf16); - tcase_add_test(tc_basic, test_bad_encoding); - tcase_add_test(tc_basic, test_latin1_umlauts); - tcase_add_test(tc_basic, test_long_utf8_character); - tcase_add_test(tc_basic, test_long_latin1_attribute); - tcase_add_test(tc_basic, test_long_ascii_attribute); - /* Regression test for SF bug #491986. */ - tcase_add_test(tc_basic, test_danish_latin1); - /* Regression test for SF bug #514281. */ - tcase_add_test(tc_basic, test_french_charref_hexidecimal); - tcase_add_test(tc_basic, test_french_charref_decimal); - tcase_add_test(tc_basic, test_french_latin1); - tcase_add_test(tc_basic, test_french_utf8); - tcase_add_test(tc_basic, test_utf8_false_rejection); - tcase_add_test(tc_basic, test_line_number_after_parse); - tcase_add_test(tc_basic, test_column_number_after_parse); - tcase_add_test(tc_basic, test_line_and_column_numbers_inside_handlers); - tcase_add_test(tc_basic, test_line_number_after_error); - tcase_add_test(tc_basic, test_column_number_after_error); - tcase_add_test(tc_basic, test_really_long_lines); - tcase_add_test(tc_basic, test_really_long_encoded_lines); - tcase_add_test(tc_basic, test_end_element_events); - tcase_add_test(tc_basic, test_attr_whitespace_normalization); - tcase_add_test(tc_basic, test_xmldecl_misplaced); - tcase_add_test(tc_basic, test_xmldecl_invalid); - tcase_add_test(tc_basic, test_xmldecl_missing_attr); - tcase_add_test(tc_basic, test_xmldecl_missing_value); - tcase_add_test(tc_basic, test_unknown_encoding_internal_entity); - tcase_add_test(tc_basic, test_unrecognised_encoding_internal_entity); - tcase_add_test(tc_basic, test_wfc_undeclared_entity_unread_external_subset); - tcase_add_test(tc_basic, test_wfc_undeclared_entity_no_external_subset); - tcase_add_test(tc_basic, test_wfc_undeclared_entity_standalone); - tcase_add_test(tc_basic, test_wfc_undeclared_entity_with_external_subset); - tcase_add_test(tc_basic, test_not_standalone_handler_reject); - tcase_add_test(tc_basic, test_not_standalone_handler_accept); - tcase_add_test(tc_basic, - test_wfc_undeclared_entity_with_external_subset_standalone); - tcase_add_test(tc_basic, test_entity_with_external_subset_unless_standalone); - tcase_add_test(tc_basic, test_wfc_no_recursive_entity_refs); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_set_encoding); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_no_handler); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_set_bom); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_bad_encoding); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_bad_encoding_2); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_invalid_parse); - tcase_add_test__ifdef_xml_dtd(tc_basic, - test_ext_entity_invalid_suspended_parse); - tcase_add_test(tc_basic, test_dtd_default_handling); - tcase_add_test(tc_basic, test_dtd_attr_handling); - tcase_add_test(tc_basic, test_empty_ns_without_namespaces); - tcase_add_test(tc_basic, test_ns_in_attribute_default_without_namespaces); - tcase_add_test(tc_basic, test_stop_parser_between_char_data_calls); - tcase_add_test(tc_basic, test_suspend_parser_between_char_data_calls); - tcase_add_test(tc_basic, test_repeated_stop_parser_between_char_data_calls); - tcase_add_test(tc_basic, test_good_cdata_ascii); - tcase_add_test(tc_basic, test_good_cdata_utf16); - tcase_add_test(tc_basic, test_good_cdata_utf16_le); - tcase_add_test(tc_basic, test_long_cdata_utf16); -#ifndef XML_MIN_SIZE /* FIXME workaround -DXML_MIN_SIZE + ASan (issue #332) */ - tcase_add_test(tc_basic, test_multichar_cdata_utf16); + make_basic_test_case(s); + make_namespace_test_case(s); + make_miscellaneous_test_case(s); + make_alloc_test_case(s); + make_nsalloc_test_case(s); +#if XML_GE == 1 + make_accounting_test_case(s); #endif - tcase_add_test(tc_basic, test_utf16_bad_surrogate_pair); - tcase_add_test(tc_basic, test_bad_cdata); -#ifndef XML_MIN_SIZE /* FIXME workaround -DXML_MIN_SIZE + ASan (issue #332) */ - tcase_add_test(tc_basic, test_bad_cdata_utf16); -#endif - tcase_add_test(tc_basic, test_stop_parser_between_cdata_calls); - tcase_add_test(tc_basic, test_suspend_parser_between_cdata_calls); - tcase_add_test(tc_basic, test_memory_allocation); - tcase_add_test(tc_basic, test_default_current); - tcase_add_test(tc_basic, test_dtd_elements); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_set_foreign_dtd); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_foreign_dtd_not_standalone); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_invalid_foreign_dtd); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_foreign_dtd_with_doctype); - tcase_add_test__ifdef_xml_dtd(tc_basic, - test_foreign_dtd_without_external_subset); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_empty_foreign_dtd); - tcase_add_test(tc_basic, test_set_base); - tcase_add_test(tc_basic, test_attributes); - tcase_add_test(tc_basic, test_reset_in_entity); - tcase_add_test(tc_basic, test_resume_invalid_parse); - tcase_add_test(tc_basic, test_resume_resuspended); - tcase_add_test(tc_basic, test_cdata_default); - tcase_add_test(tc_basic, test_subordinate_reset); - tcase_add_test(tc_basic, test_subordinate_suspend); - tcase_add_test(tc_basic, test_subordinate_xdecl_suspend); - tcase_add_test(tc_basic, test_subordinate_xdecl_abort); - tcase_add_test(tc_basic, test_explicit_encoding); - tcase_add_test(tc_basic, test_trailing_cr); - tcase_add_test(tc_basic, test_ext_entity_trailing_cr); - tcase_add_test(tc_basic, test_trailing_rsqb); - tcase_add_test(tc_basic, test_ext_entity_trailing_rsqb); - tcase_add_test(tc_basic, test_ext_entity_good_cdata); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_user_parameters); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_ref_parameter); - tcase_add_test(tc_basic, test_empty_parse); - tcase_add_test(tc_basic, test_get_buffer_1); - tcase_add_test(tc_basic, test_get_buffer_2); - tcase_add_test(tc_basic, test_byte_info_at_end); - tcase_add_test(tc_basic, test_byte_info_at_error); - tcase_add_test(tc_basic, test_byte_info_at_cdata); - tcase_add_test(tc_basic, test_predefined_entities); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_invalid_tag_in_dtd); - tcase_add_test(tc_basic, test_not_predefined_entities); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_ignore_section); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_ignore_section_utf16); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_ignore_section_utf16_be); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_bad_ignore_section); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_external_entity_values); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_not_standalone); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_ext_entity_value_abort); - tcase_add_test(tc_basic, test_bad_public_doctype); - tcase_add_test(tc_basic, test_attribute_enum_value); - tcase_add_test(tc_basic, test_predefined_entity_redefinition); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_dtd_stop_processing); - tcase_add_test(tc_basic, test_public_notation_no_sysid); - tcase_add_test(tc_basic, test_nested_groups); - tcase_add_test(tc_basic, test_group_choice); - tcase_add_test(tc_basic, test_standalone_parameter_entity); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_skipped_parameter_entity); - tcase_add_test__ifdef_xml_dtd(tc_basic, - test_recursive_external_parameter_entity); - tcase_add_test(tc_basic, test_undefined_ext_entity_in_external_dtd); - tcase_add_test(tc_basic, test_suspend_xdecl); - tcase_add_test(tc_basic, test_abort_epilog); - tcase_add_test(tc_basic, test_abort_epilog_2); - tcase_add_test(tc_basic, test_suspend_epilog); - tcase_add_test(tc_basic, test_suspend_in_sole_empty_tag); - tcase_add_test(tc_basic, test_unfinished_epilog); - tcase_add_test(tc_basic, test_partial_char_in_epilog); - tcase_add_test(tc_basic, test_hash_collision); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_suspend_resume_internal_entity); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_resume_entity_with_syntax_error); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_suspend_resume_parameter_entity); - tcase_add_test(tc_basic, test_restart_on_error); - tcase_add_test(tc_basic, test_reject_lt_in_attribute_value); - tcase_add_test(tc_basic, test_reject_unfinished_param_in_att_value); - tcase_add_test(tc_basic, test_trailing_cr_in_att_value); - tcase_add_test(tc_basic, test_standalone_internal_entity); - tcase_add_test(tc_basic, test_skipped_external_entity); - tcase_add_test(tc_basic, test_skipped_null_loaded_ext_entity); - tcase_add_test(tc_basic, test_skipped_unloaded_ext_entity); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_param_entity_with_trailing_cr); - tcase_add_test(tc_basic, test_invalid_character_entity); - tcase_add_test(tc_basic, test_invalid_character_entity_2); - tcase_add_test(tc_basic, test_invalid_character_entity_3); - tcase_add_test(tc_basic, test_invalid_character_entity_4); - tcase_add_test(tc_basic, test_pi_handled_in_default); - tcase_add_test(tc_basic, test_comment_handled_in_default); - tcase_add_test(tc_basic, test_pi_yml); - tcase_add_test(tc_basic, test_pi_xnl); - tcase_add_test(tc_basic, test_pi_xmm); - tcase_add_test(tc_basic, test_utf16_pi); - tcase_add_test(tc_basic, test_utf16_be_pi); - tcase_add_test(tc_basic, test_utf16_be_comment); - tcase_add_test(tc_basic, test_utf16_le_comment); - tcase_add_test(tc_basic, test_missing_encoding_conversion_fn); - tcase_add_test(tc_basic, test_failing_encoding_conversion_fn); - tcase_add_test(tc_basic, test_unknown_encoding_success); - tcase_add_test(tc_basic, test_unknown_encoding_bad_name); - tcase_add_test(tc_basic, test_unknown_encoding_bad_name_2); - tcase_add_test(tc_basic, test_unknown_encoding_long_name_1); - tcase_add_test(tc_basic, test_unknown_encoding_long_name_2); - tcase_add_test(tc_basic, test_invalid_unknown_encoding); - tcase_add_test(tc_basic, test_unknown_ascii_encoding_ok); - tcase_add_test(tc_basic, test_unknown_ascii_encoding_fail); - tcase_add_test(tc_basic, test_unknown_encoding_invalid_length); - tcase_add_test(tc_basic, test_unknown_encoding_invalid_topbit); - tcase_add_test(tc_basic, test_unknown_encoding_invalid_surrogate); - tcase_add_test(tc_basic, test_unknown_encoding_invalid_high); - tcase_add_test(tc_basic, test_unknown_encoding_invalid_attr_value); - tcase_add_test(tc_basic, test_ext_entity_latin1_utf16le_bom); - tcase_add_test(tc_basic, test_ext_entity_latin1_utf16be_bom); - tcase_add_test(tc_basic, test_ext_entity_latin1_utf16le_bom2); - tcase_add_test(tc_basic, test_ext_entity_latin1_utf16be_bom2); - tcase_add_test(tc_basic, test_ext_entity_utf16_be); - tcase_add_test(tc_basic, test_ext_entity_utf16_le); - tcase_add_test(tc_basic, test_ext_entity_utf16_unknown); - tcase_add_test(tc_basic, test_ext_entity_utf8_non_bom); - tcase_add_test(tc_basic, test_utf8_in_cdata_section); - tcase_add_test(tc_basic, test_utf8_in_cdata_section_2); - tcase_add_test(tc_basic, test_trailing_spaces_in_elements); - tcase_add_test(tc_basic, test_utf16_attribute); - tcase_add_test(tc_basic, test_utf16_second_attr); - tcase_add_test(tc_basic, test_attr_after_solidus); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_utf16_pe); - tcase_add_test(tc_basic, test_bad_attr_desc_keyword); - tcase_add_test(tc_basic, test_bad_attr_desc_keyword_utf16); - tcase_add_test(tc_basic, test_bad_doctype); - tcase_add_test(tc_basic, test_bad_doctype_utf16); - tcase_add_test(tc_basic, test_bad_doctype_plus); - tcase_add_test(tc_basic, test_bad_doctype_star); - tcase_add_test(tc_basic, test_bad_doctype_query); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_unknown_encoding_bad_ignore); - tcase_add_test(tc_basic, test_entity_in_utf16_be_attr); - tcase_add_test(tc_basic, test_entity_in_utf16_le_attr); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_entity_public_utf16_be); - tcase_add_test__ifdef_xml_dtd(tc_basic, test_entity_public_utf16_le); - tcase_add_test(tc_basic, test_short_doctype); - tcase_add_test(tc_basic, test_short_doctype_2); - tcase_add_test(tc_basic, test_short_doctype_3); - tcase_add_test(tc_basic, test_long_doctype); - tcase_add_test(tc_basic, test_bad_entity); - tcase_add_test(tc_basic, test_bad_entity_2); - tcase_add_test(tc_basic, test_bad_entity_3); - tcase_add_test(tc_basic, test_bad_entity_4); - tcase_add_test(tc_basic, test_bad_notation); - tcase_add_test(tc_basic, test_default_doctype_handler); - tcase_add_test(tc_basic, test_empty_element_abort); - - suite_add_tcase(s, tc_namespace); - tcase_add_checked_fixture(tc_namespace, namespace_setup, namespace_teardown); - tcase_add_test(tc_namespace, test_return_ns_triplet); - tcase_add_test(tc_namespace, test_ns_tagname_overwrite); - tcase_add_test(tc_namespace, test_ns_tagname_overwrite_triplet); - tcase_add_test(tc_namespace, test_start_ns_clears_start_element); - tcase_add_test__ifdef_xml_dtd(tc_namespace, - test_default_ns_from_ext_subset_and_ext_ge); - tcase_add_test(tc_namespace, test_ns_prefix_with_empty_uri_1); - tcase_add_test(tc_namespace, test_ns_prefix_with_empty_uri_2); - tcase_add_test(tc_namespace, test_ns_prefix_with_empty_uri_3); - tcase_add_test(tc_namespace, test_ns_prefix_with_empty_uri_4); - tcase_add_test(tc_namespace, test_ns_unbound_prefix); - tcase_add_test(tc_namespace, test_ns_default_with_empty_uri); - tcase_add_test(tc_namespace, test_ns_duplicate_attrs_diff_prefixes); - tcase_add_test(tc_namespace, test_ns_duplicate_hashes); - tcase_add_test(tc_namespace, test_ns_unbound_prefix_on_attribute); - tcase_add_test(tc_namespace, test_ns_unbound_prefix_on_element); - tcase_add_test(tc_namespace, test_ns_parser_reset); - tcase_add_test(tc_namespace, test_ns_long_element); - tcase_add_test(tc_namespace, test_ns_mixed_prefix_atts); - tcase_add_test(tc_namespace, test_ns_extend_uri_buffer); - tcase_add_test(tc_namespace, test_ns_reserved_attributes); - tcase_add_test(tc_namespace, test_ns_reserved_attributes_2); - tcase_add_test(tc_namespace, test_ns_extremely_long_prefix); - tcase_add_test(tc_namespace, test_ns_unknown_encoding_success); - tcase_add_test(tc_namespace, test_ns_double_colon); - tcase_add_test(tc_namespace, test_ns_double_colon_element); - tcase_add_test(tc_namespace, test_ns_bad_attr_leafname); - tcase_add_test(tc_namespace, test_ns_bad_element_leafname); - tcase_add_test(tc_namespace, test_ns_utf16_leafname); - tcase_add_test(tc_namespace, test_ns_utf16_element_leafname); - tcase_add_test(tc_namespace, test_ns_utf16_doctype); - tcase_add_test(tc_namespace, test_ns_invalid_doctype); - tcase_add_test(tc_namespace, test_ns_double_colon_doctype); - - suite_add_tcase(s, tc_misc); - tcase_add_checked_fixture(tc_misc, NULL, basic_teardown); - tcase_add_test(tc_misc, test_misc_alloc_create_parser); - tcase_add_test(tc_misc, test_misc_alloc_create_parser_with_encoding); - tcase_add_test(tc_misc, test_misc_null_parser); - tcase_add_test(tc_misc, test_misc_error_string); - tcase_add_test(tc_misc, test_misc_version); - tcase_add_test(tc_misc, test_misc_features); - tcase_add_test(tc_misc, test_misc_attribute_leak); - tcase_add_test(tc_misc, test_misc_utf16le); - tcase_add_test(tc_misc, test_misc_stop_during_end_handler_issue_240_1); - tcase_add_test(tc_misc, test_misc_stop_during_end_handler_issue_240_2); - tcase_add_test__ifdef_xml_dtd( - tc_misc, test_misc_deny_internal_entity_closing_doctype_issue_317); - - suite_add_tcase(s, tc_alloc); - tcase_add_checked_fixture(tc_alloc, alloc_setup, alloc_teardown); - tcase_add_test(tc_alloc, test_alloc_parse_xdecl); - tcase_add_test(tc_alloc, test_alloc_parse_xdecl_2); - tcase_add_test(tc_alloc, test_alloc_parse_pi); - tcase_add_test(tc_alloc, test_alloc_parse_pi_2); - tcase_add_test(tc_alloc, test_alloc_parse_pi_3); - tcase_add_test(tc_alloc, test_alloc_parse_comment); - tcase_add_test(tc_alloc, test_alloc_parse_comment_2); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_create_external_parser); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_run_external_parser); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_dtd_copy_default_atts); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_external_entity); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_ext_entity_set_encoding); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_internal_entity); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_dtd_default_handling); - tcase_add_test(tc_alloc, test_alloc_explicit_encoding); - tcase_add_test(tc_alloc, test_alloc_set_base); - tcase_add_test(tc_alloc, test_alloc_realloc_buffer); - tcase_add_test(tc_alloc, test_alloc_ext_entity_realloc_buffer); - tcase_add_test(tc_alloc, test_alloc_realloc_many_attributes); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_public_entity_value); - tcase_add_test__ifdef_xml_dtd(tc_alloc, - test_alloc_realloc_subst_public_entity_value); - tcase_add_test(tc_alloc, test_alloc_parse_public_doctype); - tcase_add_test(tc_alloc, test_alloc_parse_public_doctype_long_name); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_set_foreign_dtd); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_attribute_enum_value); - tcase_add_test__ifdef_xml_dtd(tc_alloc, - test_alloc_realloc_attribute_enum_value); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_realloc_implied_attribute); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_realloc_default_attribute); - tcase_add_test(tc_alloc, test_alloc_notation); - tcase_add_test(tc_alloc, test_alloc_public_notation); - tcase_add_test(tc_alloc, test_alloc_system_notation); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_nested_groups); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_realloc_nested_groups); - tcase_add_test(tc_alloc, test_alloc_large_group); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_realloc_group_choice); - tcase_add_test(tc_alloc, test_alloc_pi_in_epilog); - tcase_add_test(tc_alloc, test_alloc_comment_in_epilog); - tcase_add_test__ifdef_xml_dtd(tc_alloc, - test_alloc_realloc_long_attribute_value); - tcase_add_test(tc_alloc, test_alloc_attribute_whitespace); - tcase_add_test(tc_alloc, test_alloc_attribute_predefined_entity); - tcase_add_test(tc_alloc, test_alloc_long_attr_default_with_char_ref); - tcase_add_test(tc_alloc, test_alloc_long_attr_value); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_nested_entities); - tcase_add_test__ifdef_xml_dtd(tc_alloc, - test_alloc_realloc_param_entity_newline); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_realloc_ce_extends_pe); - tcase_add_test__ifdef_xml_dtd(tc_alloc, test_alloc_realloc_attributes); - tcase_add_test(tc_alloc, test_alloc_long_doc_name); - tcase_add_test(tc_alloc, test_alloc_long_base); - tcase_add_test(tc_alloc, test_alloc_long_public_id); - tcase_add_test(tc_alloc, test_alloc_long_entity_value); - tcase_add_test(tc_alloc, test_alloc_long_notation); - - suite_add_tcase(s, tc_nsalloc); - tcase_add_checked_fixture(tc_nsalloc, nsalloc_setup, nsalloc_teardown); - tcase_add_test(tc_nsalloc, test_nsalloc_xmlns); - tcase_add_test(tc_nsalloc, test_nsalloc_parse_buffer); - tcase_add_test(tc_nsalloc, test_nsalloc_long_prefix); - tcase_add_test(tc_nsalloc, test_nsalloc_long_uri); - tcase_add_test(tc_nsalloc, test_nsalloc_long_attr); - tcase_add_test(tc_nsalloc, test_nsalloc_long_attr_prefix); - tcase_add_test(tc_nsalloc, test_nsalloc_realloc_attributes); - tcase_add_test(tc_nsalloc, test_nsalloc_long_element); - tcase_add_test(tc_nsalloc, test_nsalloc_realloc_binding_uri); - tcase_add_test(tc_nsalloc, test_nsalloc_realloc_long_prefix); - tcase_add_test(tc_nsalloc, test_nsalloc_realloc_longer_prefix); - tcase_add_test(tc_nsalloc, test_nsalloc_long_namespace); - tcase_add_test(tc_nsalloc, test_nsalloc_less_long_namespace); - tcase_add_test(tc_nsalloc, test_nsalloc_long_context); - tcase_add_test(tc_nsalloc, test_nsalloc_realloc_long_context); - tcase_add_test(tc_nsalloc, test_nsalloc_realloc_long_context_2); - tcase_add_test(tc_nsalloc, test_nsalloc_realloc_long_context_3); - tcase_add_test(tc_nsalloc, test_nsalloc_realloc_long_context_4); - tcase_add_test(tc_nsalloc, test_nsalloc_realloc_long_context_5); - tcase_add_test(tc_nsalloc, test_nsalloc_realloc_long_context_6); - tcase_add_test(tc_nsalloc, test_nsalloc_realloc_long_context_7); - tcase_add_test(tc_nsalloc, test_nsalloc_realloc_long_ge_name); - tcase_add_test(tc_nsalloc, test_nsalloc_realloc_long_context_in_dtd); - tcase_add_test(tc_nsalloc, test_nsalloc_long_default_in_ext); - tcase_add_test(tc_nsalloc, test_nsalloc_long_systemid_in_ext); - tcase_add_test(tc_nsalloc, test_nsalloc_prefixed_element); return s; } @@ -11613,9 +84,6 @@ main(int argc, char *argv[]) { Suite *s = make_suite(); SRunner *sr = srunner_create(s); - /* run the tests for internal helper functions */ - testhelper_is_whitespace_normalized(); - for (i = 1; i < argc; ++i) { char *opt = argv[i]; if (strcmp(opt, "-v") == 0 || strcmp(opt, "--verbose") == 0) @@ -11629,7 +97,18 @@ main(int argc, char *argv[]) { } if (verbosity != CK_SILENT) printf("Expat version: %" XML_FMT_STR "\n", XML_ExpatVersion()); - srunner_run_all(sr, verbosity); + + for (g_chunkSize = 0; g_chunkSize <= 5; g_chunkSize++) { + for (int enabled = 0; enabled <= 1; ++enabled) { + char context[100]; + g_reparseDeferralEnabledDefault = enabled; + snprintf(context, sizeof(context), "chunksize=%d deferral=%d", + g_chunkSize, enabled); + context[sizeof(context) - 1] = '\0'; + srunner_run_all(sr, context, verbosity); + } + } + srunner_summarize(sr, verbosity); nf = srunner_ntests_failed(sr); srunner_free(sr); diff --git a/3rdparty/expat/tests/runtestspp.cpp b/3rdparty/expat/tests/runtests_cxx.cpp index fd3ceaa97a3..396714560a0 100644 --- a/3rdparty/expat/tests/runtestspp.cpp +++ b/3rdparty/expat/tests/runtests_cxx.cpp @@ -9,8 +9,8 @@ \___/_/\_\ .__/ \__,_|\__| |_| XML parser - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/tests/structdata.c b/3rdparty/expat/tests/structdata.c index e81b7b18460..e311f1fae3a 100644 --- a/3rdparty/expat/tests/structdata.c +++ b/3rdparty/expat/tests/structdata.c @@ -6,8 +6,9 @@ \___/_/\_\ .__/ \__,_|\__| |_| XML parser - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2022 Sean McBride <sean@rogue-research.com> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -30,10 +31,12 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifdef HAVE_EXPAT_CONFIG_H -# include "expat_config.h" +#if defined(NDEBUG) +# undef NDEBUG /* because test suite relies on assert(...) at the moment */ #endif +#include "expat_config.h" + #include <assert.h> #include <stdlib.h> #include <stdio.h> @@ -58,7 +61,7 @@ static XML_Char * xmlstrdup(const XML_Char *s) { size_t byte_count = (xcstrlen(s) + 1) * sizeof(XML_Char); - XML_Char *dup = malloc(byte_count); + XML_Char *const dup = (XML_Char *)malloc(byte_count); assert(dup != NULL); memcpy(dup, s, byte_count); @@ -81,13 +84,13 @@ StructData_AddItem(StructData *storage, const XML_Char *s, int data0, int data1, assert(storage != NULL); assert(s != NULL); if (storage->count == storage->max_count) { - StructDataEntry *new; + StructDataEntry *new_entries; storage->max_count += STRUCT_EXTENSION_COUNT; - new = realloc(storage->entries, - storage->max_count * sizeof(StructDataEntry)); - assert(new != NULL); - storage->entries = new; + new_entries = (StructDataEntry *)realloc( + storage->entries, storage->max_count * sizeof(StructDataEntry)); + assert(new_entries != NULL); + storage->entries = new_entries; } entry = &storage->entries[storage->count]; @@ -105,17 +108,17 @@ void StructData_CheckItems(StructData *storage, const StructDataEntry *expected, int count) { char buffer[1024]; - int i; assert(storage != NULL); assert(expected != NULL); if (count != storage->count) { - sprintf(buffer, "wrong number of entries: got %d, expected %d", - storage->count, count); + snprintf(buffer, sizeof(buffer), + "wrong number of entries: got %d, expected %d", storage->count, + count); StructData_Dispose(storage); fail(buffer); } else { - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { const StructDataEntry *got = &storage->entries[i]; const StructDataEntry *want = &expected[i]; @@ -128,11 +131,11 @@ StructData_CheckItems(StructData *storage, const StructDataEntry *expected, } else { if (got->data0 != want->data0 || got->data1 != want->data1 || got->data2 != want->data2) { - sprintf(buffer, - "struct '%" XML_FMT_STR - "' expected (%d,%d,%d), got (%d,%d,%d)", - got->str, want->data0, want->data1, want->data2, got->data0, - got->data1, got->data2); + snprintf(buffer, sizeof(buffer), + "struct '%" XML_FMT_STR + "' expected (%d,%d,%d), got (%d,%d,%d)", + got->str, want->data0, want->data1, want->data2, got->data0, + got->data1, got->data2); StructData_Dispose(storage); fail(buffer); } diff --git a/3rdparty/expat/tests/structdata.h b/3rdparty/expat/tests/structdata.h index 870ffaf2af0..09881b175f7 100644 --- a/3rdparty/expat/tests/structdata.h +++ b/3rdparty/expat/tests/structdata.h @@ -7,8 +7,7 @@ \___/_/\_\ .__/ \__,_|\__| |_| XML parser - Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/tests/structdata_cxx.cpp b/3rdparty/expat/tests/structdata_cxx.cpp new file mode 100644 index 00000000000..43448f63405 --- /dev/null +++ b/3rdparty/expat/tests/structdata_cxx.cpp @@ -0,0 +1,32 @@ +/* C++ compilation harness for the test suite. + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org> + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "structdata.c" diff --git a/3rdparty/expat/tests/udiffer.py b/3rdparty/expat/tests/udiffer.py index 6fb91be7e3d..2b58a4c3486 100755 --- a/3rdparty/expat/tests/udiffer.py +++ b/3rdparty/expat/tests/udiffer.py @@ -6,7 +6,8 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2017 Expat development team +# Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> +# Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/tests/xmltest.sh b/3rdparty/expat/tests/xmltest.sh index 9b500351143..dc409d01e45 100755 --- a/3rdparty/expat/tests/xmltest.sh +++ b/3rdparty/expat/tests/xmltest.sh @@ -1,24 +1,55 @@ #! /usr/bin/env bash - -# EXPAT TEST SCRIPT FOR W3C XML TEST SUITE - +# EXPAT TEST SCRIPT FOR W3C XML TEST SUITE +# # This script can be used to exercise Expat against the # w3c.org xml test suite, available from # http://www.w3.org/XML/Test/xmlts20020606.zip. - +# # To run this script, first set XMLWF below so that xmlwf can be # found, then set the output directory with OUTPUT. - +# # The script lists all test cases where Expat shows a discrepancy # from the expected result. Test cases where only the canonical # output differs are prefixed with "Output differs:", and a diff file # is generated in the appropriate subdirectory under $OUTPUT. - +# # If there are output files provided, the script will use # output from xmlwf and compare the desired output against it. # However, one has to take into account that the canonical output # produced by xmlwf conforms to an older definition of canonical XML # and does not generate notation declarations. +# +# __ __ _ +# ___\ \/ /_ __ __ _| |_ +# / _ \\ /| '_ \ / _` | __| +# | __// \| |_) | (_| | |_ +# \___/_/\_\ .__/ \__,_|\__| +# |_| XML parser +# +# Copyright (c) 2002-2004 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> +# Copyright (c) 2002 Karl Waclawek <karl@waclawek.net> +# Copyright (c) 2008-2019 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> +# Licensed under the MIT license: +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to permit +# persons to whom the Software is furnished to do so, subject to the +# following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +# USE OR OTHER DEALINGS IN THE SOFTWARE. shopt -s nullglob diff --git a/3rdparty/expat/win32/README.txt b/3rdparty/expat/win32/README.txt index d1069cdd2f0..7a8a0df6a2a 100644 --- a/3rdparty/expat/win32/README.txt +++ b/3rdparty/expat/win32/README.txt @@ -5,13 +5,13 @@ Expat can be built on Windows in two ways: * Cygwin: This follows the Unix build procedures. -* MS Visual Studio 2008, 2010, 2013, 2015 and 2017: +* MS Visual Studio 2019 and 2022: Use CMake to generate a solution file for Visual Studio, then use msbuild to compile. For example: md build cd build - cmake -G"Visual Studio 15 2017" -DCMAKE_BUILD_TYPE=RelWithDebInfo .. + cmake -G"Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=RelWithDebInfo .. msbuild /m expat.sln * All MS C/C++ compilers: diff --git a/3rdparty/expat/win32/build_expat_iss.bat b/3rdparty/expat/win32/build_expat_iss.bat index 4e31c17dfc3..aea73489bca 100644 --- a/3rdparty/expat/win32/build_expat_iss.bat +++ b/3rdparty/expat/win32/build_expat_iss.bat @@ -7,7 +7,7 @@ REM | __// \| |_) | (_| | |_ REM \___/_/\_\ .__/ \__,_|\__| REM |_| XML parser REM -REM Copyright (C) 2019 Expat development team +REM Copyright (c) 2019-2024 Sebastian Pipping <sebastian@pipping.org> REM Licensed under the MIT license: REM REM Permission is hereby granted, free of charge, to any person obtaining @@ -29,7 +29,7 @@ REM DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR REM OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE REM USE OR OTHER DEALINGS IN THE SOFTWARE. -SET GENERATOR=Visual Studio 15 2017 +SET GENERATOR=Visual Studio 16 2019 REM Read by msbuild! SET CONFIGURATION=RelWithDebInfo @@ -43,7 +43,7 @@ MD %BINDIR% || EXIT /b 1 MD build_shared_char || EXIT /b 1 CD build_shared_char || EXIT /b 1 - cmake -G"%GENERATOR%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DEXPAT_MSVC_STATIC_CRT=ON -DEXPAT_BUILD_EXAMPLES=OFF -DEXPAT_BUILD_TESTS=OFF -DEXPAT_BUILD_TOOLS=OFF .. || EXIT /b 1 + cmake -A Win32 -G"%GENERATOR%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DEXPAT_WARNINGS_AS_ERRORS=ON -DEXPAT_MSVC_STATIC_CRT=ON -DEXPAT_BUILD_EXAMPLES=OFF -DEXPAT_BUILD_TESTS=OFF -DEXPAT_BUILD_TOOLS=OFF .. || EXIT /b 1 msbuild /m expat.sln || EXIT /b 1 DIR %CONFIGURATION% || EXIT /b 1 CD .. || EXIT /b 1 @@ -53,7 +53,7 @@ COPY build_shared_char\%CONFIGURATION%\libexpat.lib %BINDIR%\ || EXIT /b 1 MD build_static_char || EXIT /b 1 CD build_static_char || EXIT /b 1 - cmake -G"%GENERATOR%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DEXPAT_MSVC_STATIC_CRT=ON -DEXPAT_BUILD_EXAMPLES=OFF -DEXPAT_BUILD_TESTS=OFF -DEXPAT_SHARED_LIBS=OFF .. || EXIT /b 1 + cmake -A Win32 -G"%GENERATOR%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DEXPAT_WARNINGS_AS_ERRORS=ON -DEXPAT_MSVC_STATIC_CRT=ON -DEXPAT_BUILD_EXAMPLES=OFF -DEXPAT_BUILD_TESTS=OFF -DEXPAT_SHARED_LIBS=OFF .. || EXIT /b 1 msbuild /m expat.sln || EXIT /b 1 DIR %CONFIGURATION% || EXIT /b 1 CD .. || EXIT /b 1 @@ -63,7 +63,7 @@ COPY build_static_char\xmlwf\%CONFIGURATION%\xmlwf.exe %BINDIR%\ || EXIT /b 1 MD build_shared_wchar_t || EXIT /b 1 CD build_shared_wchar_t || EXIT /b 1 - cmake -G"%GENERATOR%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DEXPAT_MSVC_STATIC_CRT=ON -DEXPAT_BUILD_EXAMPLES=OFF -DEXPAT_BUILD_TESTS=OFF -DEXPAT_BUILD_TOOLS=OFF -DEXPAT_CHAR_TYPE=wchar_t .. || EXIT /b 1 + cmake -A Win32 -G"%GENERATOR%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DEXPAT_WARNINGS_AS_ERRORS=ON -DEXPAT_MSVC_STATIC_CRT=ON -DEXPAT_BUILD_EXAMPLES=OFF -DEXPAT_BUILD_TESTS=OFF -DEXPAT_BUILD_TOOLS=OFF -DEXPAT_CHAR_TYPE=wchar_t .. || EXIT /b 1 msbuild /m expat.sln || EXIT /b 1 DIR %CONFIGURATION% || EXIT /b 1 CD .. || EXIT /b 1 @@ -73,7 +73,7 @@ COPY build_shared_wchar_t\%CONFIGURATION%\libexpatw.lib %BINDIR%\ || EXIT /b 1 MD build_static_wchar_t || EXIT /b 1 CD build_static_wchar_t || EXIT /b 1 - cmake -G"%GENERATOR%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DEXPAT_MSVC_STATIC_CRT=ON -DEXPAT_BUILD_EXAMPLES=OFF -DEXPAT_BUILD_TESTS=OFF -DEXPAT_BUILD_TOOLS=OFF -DEXPAT_SHARED_LIBS=OFF -DEXPAT_CHAR_TYPE=wchar_t .. || EXIT /b 1 + cmake -A Win32 -G"%GENERATOR%" -DCMAKE_BUILD_TYPE=%CONFIGURATION% -DEXPAT_WARNINGS_AS_ERRORS=ON -DEXPAT_MSVC_STATIC_CRT=ON -DEXPAT_BUILD_EXAMPLES=OFF -DEXPAT_BUILD_TESTS=OFF -DEXPAT_BUILD_TOOLS=OFF -DEXPAT_SHARED_LIBS=OFF -DEXPAT_CHAR_TYPE=wchar_t .. || EXIT /b 1 msbuild /m expat.sln || EXIT /b 1 DIR %CONFIGURATION% || EXIT /b 1 CD .. || EXIT /b 1 diff --git a/3rdparty/expat/win32/expat.iss b/3rdparty/expat/win32/expat.iss index ef95f175857..09aa7e533ce 100644 --- a/3rdparty/expat/win32/expat.iss +++ b/3rdparty/expat/win32/expat.iss @@ -1,21 +1,55 @@ ; Basic setup script for the Inno Setup installer builder. For more ; information on the free installer builder, see www.jrsoftware.org. ; -; This script was contributed by Tim Peters. +; This script was originally contributed by Tim Peters. ; It was designed for Inno Setup 2.0.19 but works with later versions as well. +; +; __ __ _ +; ___\ \/ /_ __ __ _| |_ +; / _ \\ /| '_ \ / _` | __| +; | __// \| |_) | (_| | |_ +; \___/_/\_\ .__/ \__,_|\__| +; |_| XML parser +; +; Copyright (c) 2001 Tim Peters <tim.peters@gmail.com> +; Copyright (c) 2001-2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> +; Copyright (c) 2006-2017 Karl Waclawek <karl@waclawek.net> +; Copyright (c) 2007-2024 Sebastian Pipping <sebastian@pipping.org> +; Copyright (c) 2022 Johnny Jazeix <jazeix@gmail.com> +; Copyright (c) 2024 Dag-Erling Smørgrav <des@des.dev> +; Licensed under the MIT license: +; +; Permission is hereby granted, free of charge, to any person obtaining +; a copy of this software and associated documentation files (the +; "Software"), to deal in the Software without restriction, including +; without limitation the rights to use, copy, modify, merge, publish, +; distribute, sublicense, and/or sell copies of the Software, and to permit +; persons to whom the Software is furnished to do so, subject to the +; following conditions: +; +; The above copyright notice and this permission notice shall be included +; in all copies or substantial portions of the Software. +; +; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +; NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +; DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +; OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +; USE OR OTHER DEALINGS IN THE SOFTWARE. -#define expatVer "2.2.10" +#define expatVer "2.6.4" [Setup] AppName=Expat AppId=expat AppVersion={#expatVer} AppVerName=Expat {#expatVer} -AppCopyright=Copyright © 1998-2017 Thai Open Source Software Center, Clark Cooper, and the Expat maintainers +AppCopyright=Copyright © 1997-2022 Thai Open Source Software Center, Clark Cooper, and the Expat maintainers AppPublisher=The Expat Developers -AppPublisherURL=http://www.libexpat.org/ -AppSupportURL=http://www.libexpat.org/ -AppUpdatesURL=http://www.libexpat.org/ +AppPublisherURL=https://libexpat.github.io/ +AppSupportURL=https://libexpat.github.io/ +AppUpdatesURL=https://libexpat.github.io/ UninstallDisplayName=Expat XML Parser {#expatVer} VersionInfoVersion={#expatVer} OutputBaseFilename=expat-win32bin-{#expatVer} @@ -41,24 +75,29 @@ Flags: ignoreversion; Source: COPYING; DestDir: "{app}"; De Flags: ignoreversion; Source: README.md; DestDir: "{app}"; DestName: README.txt Flags: ignoreversion; Source: doc\*.html; DestDir: "{app}\Doc" Flags: ignoreversion; Source: doc\*.css; DestDir: "{app}\Doc" -Flags: ignoreversion; Source: doc\*.png; DestDir: "{app}\Doc" +Flags: ignoreversion; Source: doc\*.xml; DestDir: "{app}\Doc" Flags: ignoreversion; Source: win32\bin\Release\*.dll; DestDir: "{app}\Bin" Flags: ignoreversion; Source: win32\bin\Release\*.lib; DestDir: "{app}\Bin" +Flags: ignoreversion; Source: win32\version.rc.cmake; DestDir: "{app}\Source\win32" Flags: ignoreversion; Source: win32\README.txt; DestDir: "{app}\Source" +Flags: ignoreversion; Source: AUTHORS; DestDir: "{app}\Source" Flags: ignoreversion; Source: Changes; DestDir: "{app}\Source" Flags: ignoreversion; Source: CMake.README; DestDir: "{app}\Source" Flags: ignoreversion; Source: CMakeLists.txt; DestDir: "{app}\Source" Flags: ignoreversion; Source: ConfigureChecks.cmake; DestDir: "{app}\Source" +Flags: ignoreversion; Source: expat.pc.cmake; DestDir: "{app}\Source" Flags: ignoreversion; Source: expat_config.h.cmake; DestDir: "{app}\Source" +Flags: ignoreversion; Source: run.sh.in; DestDir: "{app}\Source" Flags: ignoreversion; Source: cmake\expat-config.cmake.in; DestDir: "{app}\Source\cmake" +Flags: ignoreversion; Source: fuzz\*.c; DestDir: "{app}\Source\fuzz" Flags: ignoreversion; Source: lib\*.c; DestDir: "{app}\Source\lib" Flags: ignoreversion; Source: lib\*.h; DestDir: "{app}\Source\lib" -Flags: ignoreversion; Source: lib\*.def; DestDir: "{app}\Source\lib" +Flags: ignoreversion; Source: lib\*.def.cmake; DestDir: "{app}\Source\lib" Flags: ignoreversion; Source: examples\*.c; DestDir: "{app}\Source\examples" Flags: ignoreversion; Source: tests\*.c; DestDir: "{app}\Source\tests" Flags: ignoreversion; Source: tests\*.cpp; DestDir: "{app}\Source\tests" Flags: ignoreversion; Source: tests\*.h; DestDir: "{app}\Source\tests" -Flags: ignoreversion; Source: tests\README.txt; DestDir: "{app}\Source\tests" +Flags: ignoreversion; Source: tests\README.md; DestDir: "{app}\Source\tests" Flags: ignoreversion; Source: tests\benchmark\*.c; DestDir: "{app}\Source\tests\benchmark" Flags: ignoreversion; Source: tests\benchmark\README.txt; DestDir: "{app}\Source\tests\benchmark" Flags: ignoreversion; Source: xmlwf\*.c*; DestDir: "{app}\Source\xmlwf" diff --git a/3rdparty/expat/win32/version.rc.cmake b/3rdparty/expat/win32/version.rc.cmake new file mode 100644 index 00000000000..4b883f37aaf --- /dev/null +++ b/3rdparty/expat/win32/version.rc.cmake @@ -0,0 +1,17 @@ +1 VERSIONINFO +FILEVERSION VER_FILEVERSION +PRODUCTVERSION VER_FILEVERSION +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + BEGIN + VALUE "FileVersion", "${PROJECT_VERSION}.0" + VALUE "ProductVersion", "${PROJECT_VERSION}.0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409, 1252 + END +END diff --git a/3rdparty/expat/xmlwf/Makefile.am b/3rdparty/expat/xmlwf/Makefile.am index f35ade7a77a..c7eebd1eeec 100644 --- a/3rdparty/expat/xmlwf/Makefile.am +++ b/3rdparty/expat/xmlwf/Makefile.am @@ -6,7 +6,7 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2017 Expat development team +# Copyright (c) 2017-2021 Sebastian Pipping <sebastian@pipping.org> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -38,7 +38,7 @@ xmlwf_SOURCES = \ @FILEMAP@.c xmlwf_CPPFLAGS = @AM_CPPFLAGS@ -I$(srcdir)/../lib -xmlwf_LDFLAGS = @AM_LDFLAGS@ +xmlwf_LDFLAGS = @AM_LDFLAGS@ @LIBM@ if MINGW if UNICODE diff --git a/3rdparty/expat/xmlwf/Makefile.in b/3rdparty/expat/xmlwf/Makefile.in index 531475ab243..480fd3e0410 100644 --- a/3rdparty/expat/xmlwf/Makefile.in +++ b/3rdparty/expat/xmlwf/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.16.2 from Makefile.am. +# Makefile.in generated by automake 1.16.5 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2020 Free Software Foundation, Inc. +# Copyright (C) 1994-2021 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -22,7 +22,7 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2017 Expat development team +# Copyright (c) 2017-2021 Sebastian Pipping <sebastian@pipping.org> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -134,6 +134,8 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/libtool.m4 \ $(top_srcdir)/conftools/ax-append-compile-flags.m4 \ $(top_srcdir)/conftools/ax-append-link-flags.m4 \ $(top_srcdir)/conftools/expatcfg-compiler-supports-visibility.m4 \ + $(top_srcdir)/conftools/ax-cxx-compile-stdcxx.m4 \ + $(top_srcdir)/conftools/ax-cxx-compile-stdcxx-11.m4 \ $(top_srcdir)/configure.ac am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) @@ -216,8 +218,6 @@ am__define_uniq_tagged_files = \ unique=`for i in $$list; do \ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ done | $(am__uniquify_input)` -ETAGS = etags -CTAGS = ctags am__DIST_COMMON = $(srcdir)/Makefile.in \ $(top_srcdir)/conftools/depcomp DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -237,8 +237,10 @@ AWK = @AWK@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ -CPP = @CPP@ +CMAKE_SHARED_LIBRARY_PREFIX = @CMAKE_SHARED_LIBRARY_PREFIX@ CPPFLAGS = @CPPFLAGS@ +CSCOPE = @CSCOPE@ +CTAGS = @CTAGS@ CXX = @CXX@ CXXCPP = @CXXCPP@ CXXDEPMODE = @CXXDEPMODE@ @@ -254,10 +256,20 @@ ECHO_C = @ECHO_C@ ECHO_N = @ECHO_N@ ECHO_T = @ECHO_T@ EGREP = @EGREP@ +ETAGS = @ETAGS@ EXEEXT = @EXEEXT@ +EXPAT_ATTR_INFO = @EXPAT_ATTR_INFO@ +EXPAT_CHAR_TYPE = @EXPAT_CHAR_TYPE@ +EXPAT_CONTEXT_BYTES = @EXPAT_CONTEXT_BYTES@ +EXPAT_DTD = @EXPAT_DTD@ +EXPAT_LARGE_SIZE = @EXPAT_LARGE_SIZE@ +EXPAT_MIN_SIZE = @EXPAT_MIN_SIZE@ +EXPAT_NS = @EXPAT_NS@ FGREP = @FGREP@ +FILECMD = @FILECMD@ FILEMAP = @FILEMAP@ GREP = @GREP@ +HAVE_CXX11 = @HAVE_CXX11@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -267,6 +279,8 @@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBAGE = @LIBAGE@ LIBCURRENT = @LIBCURRENT@ +LIBDIR_BASENAME = @LIBDIR_BASENAME@ +LIBM = @LIBM@ LIBOBJS = @LIBOBJS@ LIBREVISION = @LIBREVISION@ LIBS = @LIBS@ @@ -275,6 +289,7 @@ LIPO = @LIPO@ LN_S = @LN_S@ LTLIBOBJS = @LTLIBOBJS@ LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAINT = @MAINT@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ @@ -296,9 +311,12 @@ RANLIB = @RANLIB@ SED = @SED@ SET_MAKE = @SET_MAKE@ SHELL = @SHELL@ +SIZEOF_VOID_P = @SIZEOF_VOID_P@ +SO_MAJOR = @SO_MAJOR@ +SO_MINOR = @SO_MINOR@ +SO_PATCH = @SO_PATCH@ STRIP = @STRIP@ VERSION = @VERSION@ -_EXPAT_OUTPUT_NAME = @_EXPAT_OUTPUT_NAME@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ @@ -361,7 +379,7 @@ xmlwf_SOURCES = \ @FILEMAP@.c xmlwf_CPPFLAGS = @AM_CPPFLAGS@ -I$(srcdir)/../lib $(am__append_1) -xmlwf_LDFLAGS = @AM_LDFLAGS@ $(am__append_2) +xmlwf_LDFLAGS = @AM_LDFLAGS@ @LIBM@ $(am__append_2) EXTRA_DIST = \ codepage.h \ ct.c \ @@ -378,7 +396,7 @@ all: all-am .SUFFIXES: .SUFFIXES: .c .lo .o .obj -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ *$$dep*) \ @@ -402,9 +420,9 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(top_srcdir)/configure: $(am__configure_deps) +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): $(am__aclocal_m4_deps) +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): install-binPROGRAMS: $(bin_PROGRAMS) @@ -612,7 +630,6 @@ cscopelist-am: $(am__tagged_files) distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - distdir: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) distdir-am diff --git a/3rdparty/expat/xmlwf/codepage.c b/3rdparty/expat/xmlwf/codepage.c index 44d2035811d..8e0b5d199cd 100644 --- a/3rdparty/expat/xmlwf/codepage.c +++ b/3rdparty/expat/xmlwf/codepage.c @@ -7,7 +7,11 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2005-2006 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2019 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/xmlwf/codepage.h b/3rdparty/expat/xmlwf/codepage.h index 1b75d58365f..75ddbce4a45 100644 --- a/3rdparty/expat/xmlwf/codepage.h +++ b/3rdparty/expat/xmlwf/codepage.h @@ -7,7 +7,9 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2016-2017 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/xmlwf/ct.c b/3rdparty/expat/xmlwf/ct.c index dcf92bab568..d4c0e7a0a95 100644 --- a/3rdparty/expat/xmlwf/ct.c +++ b/3rdparty/expat/xmlwf/ct.c @@ -7,7 +7,8 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2016-2017 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/xmlwf/filemap.h b/3rdparty/expat/xmlwf/filemap.h index ef66114422f..5e0c70fa99b 100644 --- a/3rdparty/expat/xmlwf/filemap.h +++ b/3rdparty/expat/xmlwf/filemap.h @@ -7,7 +7,9 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2016-2017 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/xmlwf/readfilemap.c b/3rdparty/expat/xmlwf/readfilemap.c index d5b84f995ad..2cb53feef8d 100644 --- a/3rdparty/expat/xmlwf/readfilemap.c +++ b/3rdparty/expat/xmlwf/readfilemap.c @@ -7,7 +7,13 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2001-2004 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2002-2009 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2017 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2017 Franek Korta <fkorta@gmail.com> + Copyright (c) 2022 Sean McBride <sean@rogue-research.com> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -45,14 +51,14 @@ #if defined(_MSC_VER) # include <io.h> /* https://msdn.microsoft.com/en-us/library/wyssk1bs(v=vs.100).aspx */ -# define _EXPAT_read _read -# define _EXPAT_read_count_t int -# define _EXPAT_read_req_t unsigned int +# define EXPAT_read _read +# define EXPAT_read_count_t int +# define EXPAT_read_req_t unsigned int #else /* POSIX */ /* http://pubs.opengroup.org/onlinepubs/009695399/functions/read.html */ -# define _EXPAT_read read -# define _EXPAT_read_count_t ssize_t -# define _EXPAT_read_req_t size_t +# define EXPAT_read read +# define EXPAT_read_count_t ssize_t +# define EXPAT_read_req_t size_t #endif #ifndef S_ISREG @@ -62,7 +68,7 @@ # ifndef S_IFMT # define S_IFMT _S_IFMT # endif -# define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) +# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) #endif /* not S_ISREG */ #ifndef O_BINARY @@ -82,7 +88,7 @@ filemap(const tchar *name, void *arg) { size_t nbytes; int fd; - _EXPAT_read_count_t n; + EXPAT_read_count_t n; struct stat sb; void *p; @@ -120,14 +126,14 @@ filemap(const tchar *name, close(fd); return 0; } - n = _EXPAT_read(fd, p, (_EXPAT_read_req_t)nbytes); + n = EXPAT_read(fd, p, (EXPAT_read_req_t)nbytes); if (n < 0) { tperror(name); free(p); close(fd); return 0; } - if (n != (_EXPAT_read_count_t)nbytes) { + if (n != (EXPAT_read_count_t)nbytes) { ftprintf(stderr, T("%s: read unexpected number of bytes\n"), name); free(p); close(fd); diff --git a/3rdparty/expat/xmlwf/unixfilemap.c b/3rdparty/expat/xmlwf/unixfilemap.c index 0d0dc0424dc..d0ce9cc60a8 100644 --- a/3rdparty/expat/xmlwf/unixfilemap.c +++ b/3rdparty/expat/xmlwf/unixfilemap.c @@ -7,7 +7,11 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2001-2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2006 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2017 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/xmlwf/win32filemap.c b/3rdparty/expat/xmlwf/win32filemap.c index 0c9b7ecc5ff..a2db8eafc43 100644 --- a/3rdparty/expat/xmlwf/win32filemap.c +++ b/3rdparty/expat/xmlwf/win32filemap.c @@ -7,7 +7,10 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2022 Martin Ettl <ettl.martin78@googlemail.com> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -105,7 +108,7 @@ filemap(const TCHAR *name, static void win32perror(const TCHAR *s) { - LPVOID buf; + LPVOID buf = NULL; if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buf, 0, diff --git a/3rdparty/expat/xmlwf/xmlfile.c b/3rdparty/expat/xmlwf/xmlfile.c index e3d22c574c5..cd2533e0257 100644 --- a/3rdparty/expat/xmlwf/xmlfile.c +++ b/3rdparty/expat/xmlwf/xmlfile.c @@ -7,7 +7,15 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2004-2006 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2021 Donghee Na <donghee.na@python.org> + Copyright (c) 2024 Hanno Böck <hanno@gentoo.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -30,6 +38,8 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "expat_config.h" + #include <stdio.h> #include <stdlib.h> #include <stddef.h> @@ -38,9 +48,7 @@ #ifdef _WIN32 # include "winconfig.h" -#elif defined(HAVE_EXPAT_CONFIG_H) -# include <expat_config.h> -#endif /* ndef _WIN32 */ +#endif #include "expat.h" #include "internal.h" /* for UNUSED_P only */ @@ -64,11 +72,7 @@ # endif #endif -#ifdef _DEBUG -# define READ_SIZE 16 -#else -# define READ_SIZE (1024 * 8) -#endif +int g_read_size_bytes = 1024 * 8; typedef struct { XML_Parser parser; @@ -88,7 +92,8 @@ reportError(XML_Parser parser, const XML_Char *filename) { filename, XML_GetErrorLineNumber(parser), XML_GetErrorColumnNumber(parser), message); else - ftprintf(stderr, T("%s: (unknown message %d)\n"), filename, code); + ftprintf(stderr, T("%s: (unknown message %u)\n"), filename, + (unsigned int)code); } /* This implementation will give problems on files larger than INT_MAX. */ @@ -188,7 +193,7 @@ processStream(const XML_Char *filename, XML_Parser parser) { } for (;;) { int nread; - char *buf = (char *)XML_GetBuffer(parser, READ_SIZE); + char *buf = (char *)XML_GetBuffer(parser, g_read_size_bytes); if (! buf) { if (filename != NULL) close(fd); @@ -196,7 +201,7 @@ processStream(const XML_Char *filename, XML_Parser parser) { filename != NULL ? filename : T("xmlwf")); return 0; } - nread = read(fd, buf, READ_SIZE); + nread = read(fd, buf, g_read_size_bytes); if (nread < 0) { tperror(filename != NULL ? filename : T("STDIN")); if (filename != NULL) diff --git a/3rdparty/expat/xmlwf/xmlfile.h b/3rdparty/expat/xmlwf/xmlfile.h index 6e5d5b49eb7..579201ccf49 100644 --- a/3rdparty/expat/xmlwf/xmlfile.h +++ b/3rdparty/expat/xmlwf/xmlfile.h @@ -7,7 +7,10 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2005 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -39,5 +42,7 @@ # define XML_FMT_INT_MOD "l" #endif +extern int g_read_size_bytes; + extern int XML_ProcessFile(XML_Parser parser, const XML_Char *filename, unsigned flags); diff --git a/3rdparty/expat/xmlwf/xmlmime.c b/3rdparty/expat/xmlwf/xmlmime.c index 39160d7198c..883e293dac4 100644 --- a/3rdparty/expat/xmlwf/xmlmime.c +++ b/3rdparty/expat/xmlwf/xmlmime.c @@ -7,7 +7,9 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2016-2018 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/xmlwf/xmlmime.h b/3rdparty/expat/xmlwf/xmlmime.h index 0471286234a..591a8847760 100644 --- a/3rdparty/expat/xmlwf/xmlmime.h +++ b/3rdparty/expat/xmlwf/xmlmime.h @@ -7,7 +7,8 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2016-2017 Sebastian Pipping <sebastian@pipping.org> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining diff --git a/3rdparty/expat/xmlwf/xmltchar.h b/3rdparty/expat/xmlwf/xmltchar.h index d7e7b411b44..30283d086dd 100644 --- a/3rdparty/expat/xmlwf/xmltchar.h +++ b/3rdparty/expat/xmlwf/xmltchar.h @@ -7,7 +7,8 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2016-2021 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -54,6 +55,8 @@ # define tmain wmain # define tremove _wremove # define tchar wchar_t +# define tcstof wcstof +# define tcstoull wcstoull #else /* not XML_UNICODE */ # define T(x) x # define ftprintf fprintf @@ -71,4 +74,6 @@ # define tmain main # define tremove remove # define tchar char +# define tcstof strtof +# define tcstoull strtoull #endif /* not XML_UNICODE */ diff --git a/3rdparty/expat/xmlwf/xmlwf.c b/3rdparty/expat/xmlwf/xmlwf.c index 5121fa1028e..2bcd4627f7f 100644 --- a/3rdparty/expat/xmlwf/xmlwf.c +++ b/3rdparty/expat/xmlwf/xmlwf.c @@ -7,7 +7,18 @@ |_| XML parser Copyright (c) 1997-2000 Thai Open Source Software Center Ltd - Copyright (c) 2000-2017 Expat development team + Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> + Copyright (c) 2001-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> + Copyright (c) 2004-2009 Karl Waclawek <karl@waclawek.net> + Copyright (c) 2005-2007 Steven Solie <steven@solie.ca> + Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org> + Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> + Copyright (c) 2019 David Loffredo <loffredo@steptools.com> + Copyright (c) 2020 Joe Orton <jorton@redhat.com> + Copyright (c) 2020 Kleber Tarcísio <klebertarcisio@yahoo.com.br> + Copyright (c) 2021 Tim Bray <tbray@textuality.com> + Copyright (c) 2022 Martin Ettl <ettl.martin78@googlemail.com> + Copyright (c) 2022 Sean McBride <sean@rogue-research.com> Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -30,11 +41,15 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "expat_config.h" + #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <stddef.h> #include <string.h> +#include <math.h> /* for isnan */ +#include <errno.h> #include "expat.h" #include "codepage.h" @@ -50,6 +65,14 @@ # include <wchar.h> #endif +enum ExitCode { + XMLWF_EXIT_SUCCESS = 0, + XMLWF_EXIT_INTERNAL_ERROR = 1, + XMLWF_EXIT_NOT_WELLFORMED = 2, + XMLWF_EXIT_OUTPUT_ERROR = 3, + XMLWF_EXIT_USAGE_ERROR = 4, +}; + /* Structures for handler user data */ typedef struct NotationList { struct NotationList *next; @@ -156,7 +179,7 @@ is equivalent to lexicographically comparing based on the character number. */ static int attcmp(const void *att1, const void *att2) { - return tcscmp(*(const XML_Char **)att1, *(const XML_Char **)att2); + return tcscmp(*(const XML_Char *const *)att1, *(const XML_Char *const *)att2); } static void XMLCALL @@ -193,10 +216,10 @@ endElement(void *userData, const XML_Char *name) { static int nsattcmp(const void *p1, const void *p2) { - const XML_Char *att1 = *(const XML_Char **)p1; - const XML_Char *att2 = *(const XML_Char **)p2; + const XML_Char *att1 = *(const XML_Char *const *)p1; + const XML_Char *att2 = *(const XML_Char *const *)p2; int sep1 = (tcsrchr(att1, NSSEP) != 0); - int sep2 = (tcsrchr(att1, NSSEP) != 0); + int sep2 = (tcsrchr(att2, NSSEP) != 0); if (sep1 != sep2) return sep1 - sep2; return tcscmp(att1, att2); @@ -322,6 +345,13 @@ freeNotations(XmlwfUserData *data) { data->notationListHead = NULL; } +static void +cleanupUserData(XmlwfUserData *userData) { + free((void *)userData->currentDoctypeName); + userData->currentDoctypeName = NULL; + freeNotations(userData); +} + static int xcscmp(const XML_Char *xs, const XML_Char *xt) { while (*xs != 0 && *xt != 0) { @@ -341,8 +371,8 @@ xcscmp(const XML_Char *xs, const XML_Char *xt) { static int notationCmp(const void *a, const void *b) { - const NotationList *const n1 = *(NotationList **)a; - const NotationList *const n2 = *(NotationList **)b; + const NotationList *const n1 = *(const NotationList *const *)a; + const NotationList *const n2 = *(const NotationList *const *)b; return xcscmp(n1->notationName, n2->notationName); } @@ -842,47 +872,71 @@ showVersion(XML_Char *prog) { } } +#if defined(__GNUC__) +__attribute__((noreturn)) +#endif static void usage(const XML_Char *prog, int rc) { ftprintf( stderr, /* Generated with: * $ xmlwf/xmlwf_helpgen.sh + * To update, change xmlwf/xmlwf_helpgen.py, then paste the output of + * xmlwf/xmlwf_helpgen.sh in here. */ /* clang-format off */ - T("usage: %s [-s] [-n] [-p] [-x] [-e ENCODING] [-w] [-r] [-d DIRECTORY]\n") - T(" [-c | -m | -t] [-N]\n") - T(" [FILE [FILE ...]]\n") + T("usage:\n") + T(" %s [OPTIONS] [FILE ...]\n") + T(" %s -h|--help\n") + T(" %s -v|--version\n") T("\n") T("xmlwf - Determines if an XML document is well-formed\n") T("\n") T("positional arguments:\n") - T(" FILE file to process (default: STDIN)\n") + T(" FILE file to process (default: STDIN)\n") T("\n") T("input control arguments:\n") - T(" -s print an error if the document is not [s]tandalone\n") - T(" -n enable [n]amespace processing\n") - T(" -p enable processing external DTDs and [p]arameter entities\n") - T(" -x enable processing of e[x]ternal entities\n") - T(" -e ENCODING override any in-document [e]ncoding declaration\n") - T(" -w enable support for [W]indows code pages\n") - T(" -r disable memory-mapping and use normal file [r]ead IO calls instead\n") + T(" -s print an error if the document is not [s]tandalone\n") + T(" -n enable [n]amespace processing\n") + T(" -p enable processing of external DTDs and [p]arameter entities\n") + T(" -x enable processing of e[x]ternal entities\n") + T(" -e ENCODING override any in-document [e]ncoding declaration\n") + T(" -w enable support for [W]indows code pages\n") + T(" -r disable memory-mapping and use [r]ead calls instead\n") + T(" -g BYTES buffer size to request per call pair to XML_[G]etBuffer and read (default: 8 KiB)\n") + T(" -k when processing multiple files, [k]eep processing after first file with error\n") T("\n") T("output control arguments:\n") - T(" -d DIRECTORY output [d]estination directory\n") - T(" -c write a [c]opy of input XML, not canonical XML\n") - T(" -m write [m]eta XML, not canonical XML\n") - T(" -t write no XML output for [t]iming of plain parsing\n") - T(" -N enable adding doctype and [n]otation declarations\n") + T(" -d DIRECTORY output [d]estination directory\n") + T(" -c write a [c]opy of input XML, not canonical XML\n") + T(" -m write [m]eta XML, not canonical XML\n") + T(" -t write no XML output for [t]iming of plain parsing\n") + T(" -N enable adding doctype and [n]otation declarations\n") + T("\n") + T("billion laughs attack protection:\n") + T(" NOTE: If you ever need to increase these values for non-attack payload, please file a bug report.\n") + T("\n") + T(" -a FACTOR set maximum tolerated [a]mplification factor (default: 100.0)\n") + T(" -b BYTES set number of output [b]ytes needed to activate (default: 8 MiB)\n") + T("\n") + T("reparse deferral:\n") + T(" -q disable reparse deferral, and allow [q]uadratic parse runtime with large tokens\n") T("\n") T("info arguments:\n") - T(" -h show this [h]elp message and exit\n") - T(" -v show program's [v]ersion number and exit\n") + T(" -h, --help show this [h]elp message and exit\n") + T(" -v, --version show program's [v]ersion number and exit\n") + T("\n") + T("exit status:\n") + T(" 0 the input files are well-formed and the output (if requested) was written successfully\n") + T(" 1 could not allocate data structures, signals a serious problem with execution environment\n") + T(" 2 one or more input files were not well-formed\n") + T(" 3 could not create an output file\n") + T(" 4 command-line argument error\n") T("\n") T("xmlwf of libexpat is software libre, licensed under the MIT license.\n") - T("Please report bugs at https://github.com/libexpat/libexpat/issues. Thank you!\n") + T("Please report bugs at https://github.com/libexpat/libexpat/issues -- thank you!\n") , /* clang-format on */ - prog); + prog, prog, prog); exit(rc); } @@ -891,6 +945,21 @@ usage(const XML_Char *prog, int rc) { int wmain(int argc, XML_Char **argv); #endif +#define XMLWF_SHIFT_ARG_INTO(constCharStarTarget, argc, argv, i, j) \ + { \ + if (argv[i][j + 1] == T('\0')) { \ + if (++i == argc) { \ + usage(argv[0], XMLWF_EXIT_USAGE_ERROR); \ + /* usage called exit(..), never gets here */ \ + } \ + constCharStarTarget = argv[i]; \ + } else { \ + constCharStarTarget = argv[i] + j + 1; \ + } \ + i++; \ + j = 0; \ + } + int tmain(int argc, XML_Char **argv) { int i, j; @@ -902,6 +971,15 @@ tmain(int argc, XML_Char **argv) { int useNamespaces = 0; int requireStandalone = 0; int requiresNotations = 0; + int continueOnError = 0; + + float attackMaximumAmplification = -1.0f; /* signaling "not set" */ + unsigned long long attackThresholdBytes = 0; + XML_Bool attackThresholdGiven = XML_FALSE; + + XML_Bool disableDeferral = XML_FALSE; + + int exitCode = XMLWF_EXIT_SUCCESS; enum XML_ParamEntityParsing paramEntityParsing = XML_PARAM_ENTITY_PARSING_NEVER; int useStdin = 0; @@ -917,9 +995,17 @@ tmain(int argc, XML_Char **argv) { if (j == 0) { if (argv[i][0] != T('-')) break; - if (argv[i][1] == T('-') && argv[i][2] == T('\0')) { - i++; - break; + if (argv[i][1] == T('-')) { + if (argv[i][2] == T('\0')) { + i++; + break; + } else if (tcscmp(argv[i] + 2, T("help")) == 0) { + usage(argv[0], XMLWF_EXIT_SUCCESS); + // usage called exit(..), never gets here + } else if (tcscmp(argv[i] + 2, T("version")) == 0) { + showVersion(argv[0]); + return XMLWF_EXIT_SUCCESS; + } } j++; } @@ -965,31 +1051,91 @@ tmain(int argc, XML_Char **argv) { j++; break; case T('d'): - if (argv[i][j + 1] == T('\0')) { - if (++i == argc) - usage(argv[0], 2); - outputDir = argv[i]; - } else - outputDir = argv[i] + j + 1; - i++; - j = 0; + XMLWF_SHIFT_ARG_INTO(outputDir, argc, argv, i, j); break; case T('e'): - if (argv[i][j + 1] == T('\0')) { - if (++i == argc) - usage(argv[0], 2); - encoding = argv[i]; - } else - encoding = argv[i] + j + 1; - i++; - j = 0; + XMLWF_SHIFT_ARG_INTO(encoding, argc, argv, i, j); break; case T('h'): - usage(argv[0], 0); - return 0; + usage(argv[0], XMLWF_EXIT_SUCCESS); + // usage called exit(..), never gets here case T('v'): showVersion(argv[0]); - return 0; + return XMLWF_EXIT_SUCCESS; + case T('g'): { + const XML_Char *valueText = NULL; + XMLWF_SHIFT_ARG_INTO(valueText, argc, argv, i, j); + + errno = 0; + XML_Char *afterValueText = (XML_Char *)valueText; + const long long read_size_bytes_candidate + = tcstoull(valueText, &afterValueText, 10); + if ((errno != 0) || (afterValueText[0] != T('\0')) + || (read_size_bytes_candidate < 1) + || (read_size_bytes_candidate > (INT_MAX / 2 + 1))) { + // This prevents tperror(..) from reporting misleading "[..]: Success" + errno = ERANGE; + tperror(T("invalid buffer size") T( + " (needs an integer from 1 to INT_MAX/2+1 i.e. 1,073,741,824 on most platforms)")); + exit(XMLWF_EXIT_USAGE_ERROR); + } + g_read_size_bytes = (int)read_size_bytes_candidate; + break; + } + case T('k'): + continueOnError = 1; + j++; + break; + case T('a'): { + const XML_Char *valueText = NULL; + XMLWF_SHIFT_ARG_INTO(valueText, argc, argv, i, j); + + errno = 0; + XML_Char *afterValueText = NULL; + attackMaximumAmplification = tcstof(valueText, &afterValueText); + if ((errno != 0) || (afterValueText[0] != T('\0')) + || isnan(attackMaximumAmplification) + || (attackMaximumAmplification < 1.0f)) { + // This prevents tperror(..) from reporting misleading "[..]: Success" + errno = ERANGE; + tperror(T("invalid amplification limit") T( + " (needs a floating point number greater or equal than 1.0)")); + exit(XMLWF_EXIT_USAGE_ERROR); + } +#if XML_GE == 0 + ftprintf(stderr, + T("Warning: Given amplification limit ignored") + T(", xmlwf has been compiled without DTD/GE support.\n")); +#endif + break; + } + case T('b'): { + const XML_Char *valueText = NULL; + XMLWF_SHIFT_ARG_INTO(valueText, argc, argv, i, j); + + errno = 0; + XML_Char *afterValueText = (XML_Char *)valueText; + attackThresholdBytes = tcstoull(valueText, &afterValueText, 10); + if ((errno != 0) || (afterValueText[0] != T('\0'))) { + // This prevents tperror(..) from reporting misleading "[..]: Success" + errno = ERANGE; + tperror(T("invalid ignore threshold") + T(" (needs an integer from 0 to 2^64-1)")); + exit(XMLWF_EXIT_USAGE_ERROR); + } + attackThresholdGiven = XML_TRUE; +#if XML_GE == 0 + ftprintf(stderr, + T("Warning: Given attack threshold ignored") + T(", xmlwf has been compiled without DTD/GE support.\n")); +#endif + break; + } + case T('q'): { + disableDeferral = XML_TRUE; + j++; + break; + } case T('\0'): if (j > 1) { i++; @@ -998,7 +1144,8 @@ tmain(int argc, XML_Char **argv) { } /* fall through */ default: - usage(argv[0], 2); + usage(argv[0], XMLWF_EXIT_USAGE_ERROR); + // usage called exit(..), never gets here } } if (i == argc) { @@ -1017,7 +1164,32 @@ tmain(int argc, XML_Char **argv) { if (! parser) { tperror(T("Could not instantiate parser")); - exit(1); + exit(XMLWF_EXIT_INTERNAL_ERROR); + } + + if (attackMaximumAmplification != -1.0f) { +#if XML_GE == 1 + XML_SetBillionLaughsAttackProtectionMaximumAmplification( + parser, attackMaximumAmplification); +#endif + } + if (attackThresholdGiven) { +#if XML_GE == 1 + XML_SetBillionLaughsAttackProtectionActivationThreshold( + parser, attackThresholdBytes); +#else + (void)attackThresholdBytes; // silence -Wunused-but-set-variable +#endif + } + + if (disableDeferral) { + const XML_Bool success = XML_SetReparseDeferralEnabled(parser, XML_FALSE); + if (! success) { + // This prevents tperror(..) from reporting misleading "[..]: Success" + errno = EINVAL; + tperror(T("Failed to disable reparse deferral")); + exit(XMLWF_EXIT_INTERNAL_ERROR); + } } if (requireStandalone) @@ -1053,7 +1225,7 @@ tmain(int argc, XML_Char **argv) { * sizeof(XML_Char)); if (! outName) { tperror(T("Could not allocate memory")); - exit(1); + exit(XMLWF_EXIT_INTERNAL_ERROR); } tcscpy(outName, outputDir); tcscat(outName, delim); @@ -1061,7 +1233,14 @@ tmain(int argc, XML_Char **argv) { userData.fp = tfopen(outName, T("wb")); if (! userData.fp) { tperror(outName); - exit(3); + exitCode = XMLWF_EXIT_OUTPUT_ERROR; + free(outName); + XML_ParserFree(parser); + if (continueOnError) { + continue; + } else { + break; + } } setvbuf(userData.fp, NULL, _IOFBF, 16384); #ifdef XML_UNICODE @@ -1123,8 +1302,12 @@ tmain(int argc, XML_Char **argv) { } XML_ParserFree(parser); if (! result) { - exit(2); + exitCode = XMLWF_EXIT_NOT_WELLFORMED; + cleanupUserData(&userData); + if (! continueOnError) { + break; + } } } - return 0; + return exitCode; } diff --git a/3rdparty/expat/xmlwf/xmlwf_helpgen.py b/3rdparty/expat/xmlwf/xmlwf_helpgen.py index 939286e5c2c..3d32f5d148b 100755 --- a/3rdparty/expat/xmlwf/xmlwf_helpgen.py +++ b/3rdparty/expat/xmlwf/xmlwf_helpgen.py @@ -6,7 +6,8 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2019 Expat development team +# Copyright (c) 2019-2023 Sebastian Pipping <sebastian@pipping.org> +# Copyright (c) 2021 Tim Bray <tbray@textuality.com> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -31,11 +32,25 @@ import argparse epilog = """ +exit status: + 0 the input files are well-formed and the output (if requested) was written successfully + 1 could not allocate data structures, signals a serious problem with execution environment + 2 one or more input files were not well-formed + 3 could not create an output file + 4 command-line argument error + xmlwf of libexpat is software libre, licensed under the MIT license. -Please report bugs at https://github.com/libexpat/libexpat/issues. Thank you! +Please report bugs at https://github.com/libexpat/libexpat/issues -- thank you! +""" + +usage = """ + %(prog)s [OPTIONS] [FILE ...] + %(prog)s -h|--help + %(prog)s -v|--version """ parser = argparse.ArgumentParser(prog='xmlwf', add_help=False, + usage=usage, description='xmlwf - Determines if an XML document is well-formed', formatter_class=argparse.RawTextHelpFormatter, epilog=epilog) @@ -43,11 +58,13 @@ parser = argparse.ArgumentParser(prog='xmlwf', add_help=False, input_related = parser.add_argument_group('input control arguments') input_related.add_argument('-s', action='store_true', help='print an error if the document is not [s]tandalone') input_related.add_argument('-n', action='store_true', help='enable [n]amespace processing') -input_related.add_argument('-p', action='store_true', help='enable processing external DTDs and [p]arameter entities') +input_related.add_argument('-p', action='store_true', help='enable processing of external DTDs and [p]arameter entities') input_related.add_argument('-x', action='store_true', help='enable processing of e[x]ternal entities') input_related.add_argument('-e', action='store', metavar='ENCODING', help='override any in-document [e]ncoding declaration') input_related.add_argument('-w', action='store_true', help='enable support for [W]indows code pages') -input_related.add_argument('-r', action='store_true', help='disable memory-mapping and use normal file [r]ead IO calls instead') +input_related.add_argument('-r', action='store_true', help='disable memory-mapping and use [r]ead calls instead') +input_related.add_argument('-g', metavar='BYTES', help='buffer size to request per call pair to XML_[G]etBuffer and read (default: 8 KiB)') +input_related.add_argument('-k', action='store_true', help='when processing multiple files, [k]eep processing after first file with error') output_related = parser.add_argument_group('output control arguments') output_related.add_argument('-d', action='store', metavar='DIRECTORY', help='output [d]estination directory') @@ -57,12 +74,24 @@ output_mode.add_argument('-m', action='store_true', help='write [m]eta XML, not output_mode.add_argument('-t', action='store_true', help='write no XML output for [t]iming of plain parsing') output_related.add_argument('-N', action='store_true', help='enable adding doctype and [n]otation declarations') +billion_laughs = parser.add_argument_group('billion laughs attack protection', + description='NOTE: ' + 'If you ever need to increase these values ' + 'for non-attack payload, please file a bug report.') +billion_laughs.add_argument('-a', metavar='FACTOR', + help='set maximum tolerated [a]mplification factor (default: 100.0)') +billion_laughs.add_argument('-b', metavar='BYTES', help='set number of output [b]ytes needed to activate (default: 8 MiB)') + +reparse_deferral = parser.add_argument_group('reparse deferral') +reparse_deferral.add_argument('-q', metavar='FACTOR', + help='disable reparse deferral, and allow [q]uadratic parse runtime with large tokens') + parser.add_argument('files', metavar='FILE', nargs='*', help='file to process (default: STDIN)') info = parser.add_argument_group('info arguments') info = info.add_mutually_exclusive_group() -info.add_argument('-h', action='store_true', help='show this [h]elp message and exit') -info.add_argument('-v', action='store_true', help='show program\'s [v]ersion number and exit') +info.add_argument('-h', '--help', action='store_true', help='show this [h]elp message and exit') +info.add_argument('-v', '--version', action='store_true', help='show program\'s [v]ersion number and exit') if __name__ == '__main__': diff --git a/3rdparty/expat/xmlwf/xmlwf_helpgen.sh b/3rdparty/expat/xmlwf/xmlwf_helpgen.sh index 6b0fbf929a0..864e47086d1 100755 --- a/3rdparty/expat/xmlwf/xmlwf_helpgen.sh +++ b/3rdparty/expat/xmlwf/xmlwf_helpgen.sh @@ -6,7 +6,7 @@ # \___/_/\_\ .__/ \__,_|\__| # |_| XML parser # -# Copyright (c) 2019 Expat development team +# Copyright (c) 2019-2021 Sebastian Pipping <sebastian@pipping.org> # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -29,7 +29,8 @@ # USE OR OTHER DEALINGS IN THE SOFTWARE. ./xmlwf/xmlwf_helpgen.py | sed \ - -e 's,usage: xmlwf,usage: %s,' \ + -e 's,usage: ,usage:,' \ + -e 's, xmlwf, %s,' \ -e 's, \[-h | -v\],,' \ -e 's,^, T(",' \ -e 's,$,\\n"),' |