libxml2: update to 2.13.6

arm-master
pedro 1 week ago
parent 9ee7fd21c2
commit 211006a663

@ -267,7 +267,7 @@ sub fixDyn
fixDynDep("nginx", "libpcre2-8.so.0.13.0");
fixDynDep("nginx", "libpcre2-posix.so.3.0.5");
fixDynDep("nginx", "libwolfssl.so.42.2.0");
fixDynDep("php-cgi", "libxml2.so.2.13.5");
fixDynDep("php-cgi", "libxml2.so.2.13.6");
fixDynDep("php-cgi", "libpng16.so.16.46.0");
fixDynDep("php-cgi", "libiconv.so.2.7.0");
fixDynDep("php-cgi", "libsqlite3.so.0.8.6");
@ -278,7 +278,7 @@ sub fixDyn
fixDynDep("php-cgi", "libpcre2-8.so.0.13.0");
fixDynDep("php-cgi", "libpcre2-posix.so.3.0.5");
fixDynDep("php-cgi", "libzip.so.5.5");
fixDynDep("php-cli", "libxml2.so.2.13.5");
fixDynDep("php-cli", "libxml2.so.2.13.6");
fixDynDep("php-cli", "libpng16.so.16.46.0");
fixDynDep("php-cli", "libiconv.so.2.7.0");
fixDynDep("php-cli", "libsqlite3.so.0.8.6");
@ -289,7 +289,7 @@ sub fixDyn
fixDynDep("php-cli", "libpcre2-8.so.0.13.0");
fixDynDep("php-cli", "libpcre2-posix.so.3.0.5");
fixDynDep("php-cli", "libzip.so.5.5");
fixDynDep("php-fpm", "libxml2.so.2.13.5");
fixDynDep("php-fpm", "libxml2.so.2.13.6");
fixDynDep("php-fpm", "libpng16.so.16.46.0");
fixDynDep("php-fpm", "libiconv.so.2.7.0");
fixDynDep("php-fpm", "libsqlite3.so.0.8.6");
@ -692,7 +692,7 @@ genSO("${root}/usr/lib/libcurl.so.4.8.0", "${router}/libcurl/lib/.libs/libcurl.a
genSO("${root}/usr/lib/libevent-2.1.so.7", "${router}/libevent/.libs/libevent.a", "${stripshared}");
genSO("${root}/usr/lib/libiconv.so.2.7.0", "${router}/libiconv/lib/.libs/libiconv.a", "${stripshared}");
genSO("${root}/usr/lib/libpng16.so.16.46.0", "${router}/libpng/staged/usr/lib/libpng16.a", "${stripshared}", "-L${router}/zlib");
genSO("${root}/usr/lib/libxml2.so.2.13.5", "${router}/libxml2/staged/usr/lib/libxml2.a", "${stripshared}", "-L${router}/zlib");
genSO("${root}/usr/lib/libxml2.so.2.13.6", "${router}/libxml2/staged/usr/lib/libxml2.a", "${stripshared}", "-L${router}/zlib");
genSO("${root}/usr/lib/libpcre.so.1.2.13", "${router}/pcre/.libs/libpcre.a", "${stripshared}");
genSO("${root}/usr/lib/libpcre2-8.so.0.13.0", "${router}/pcre2/staged/usr/lib/libpcre2-8.a", "${stripshared}");
#genSO("${root}/usr/lib/libpcre2-posix.so.3.0.5", "${router}/pcre2/staged/usr/lib/libpcre2-posix.a", "${stripshared}"); # (deleted)

@ -2464,9 +2464,9 @@ libxml2: libxml2/static/Makefile libxml2/build/Makefile
@$(MAKE) -C libxml2/build DESTDIR=$(TOP)/libxml2/staged install
libxml2-install:
install -D libxml2/staged/usr/lib/libxml2.so.2.13.5 $(INSTALLDIR)/libxml2/usr/lib/libxml2.so.2.13.5
$(STRIP) $(INSTALLDIR)/libxml2/usr/lib/libxml2.so.2.13.5
cd $(INSTALLDIR)/libxml2/usr/lib && ln -sf libxml2.so.2.13.5 libxml2.so.2 && ln -sf libxml2.so.2.13.5 libxml2.so
install -D libxml2/staged/usr/lib/libxml2.so.2.13.6 $(INSTALLDIR)/libxml2/usr/lib/libxml2.so.2.13.6
$(STRIP) $(INSTALLDIR)/libxml2/usr/lib/libxml2.so.2.13.6
cd $(INSTALLDIR)/libxml2/usr/lib && ln -sf libxml2.so.2.13.6 libxml2.so.2 && ln -sf libxml2.so.2.13.6 libxml2.so
libxml2-clean:
@rm -rf libxml2/static

@ -1,3 +1,9 @@
include:
- component: "gitlab.gnome.org/GNOME/citemplates/release-service@master"
inputs:
dist-job-name: "dist"
tarball-artifact-path: "libxml2-dist/libxml2-2.13.6.tar.xz"
.test:
image: registry.gitlab.gnome.org/gnome/libxml2
variables:
@ -286,6 +292,14 @@ cmake:linux:gcc:shared:
CC: gcc
SUFFIX: linux-gcc-shared
dist:
image: registry.gitlab.gnome.org/gnome/libxml2
script:
- sh .gitlab-ci/dist.sh
artifacts:
paths:
- libxml2-dist/*.tar.xz
pages:
script:
- mkdir -p public

@ -0,0 +1,11 @@
#!/bin/sh
set -e
mkdir -p libxml2-dist
cd libxml2-dist
sh ../autogen.sh
make distcheck V=1 DISTCHECK_CONFIGURE_FLAGS='--with-legacy'
if [ -z "$CI_COMMIT_TAG" ]; then
mv libxml2-*.tar.xz libxml2-git-$CI_COMMIT_SHORT_SHA.tar.xz
fi

@ -149,7 +149,12 @@ if (NOT MSVC)
check_function_exists(stat HAVE_STAT)
check_include_files(stdint.h HAVE_STDINT_H)
check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
check_include_files(sys/random.h HAVE_SYS_RANDOM_H)
if (APPLE)
# In old macOS SDKs (ex: 10.15), sys/random.h fails to include header files it needs, so add them here.
check_include_files("Availability.h;stddef.h;sys/random.h" HAVE_SYS_RANDOM_H)
else()
check_include_files(sys/random.h HAVE_SYS_RANDOM_H)
endif()
check_include_files(sys/select.h HAVE_SYS_SELECT_H)
check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
check_include_files(sys/stat.h HAVE_SYS_STAT_H)
@ -549,7 +554,7 @@ if(LIBXML2_WITH_PYTHON)
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/libxml2.py.in "${LIBXML2CLASS_PY}")
configure_file(${CMAKE_CURRENT_BINARY_DIR}/libxml2.py.in libxml2.py COPYONLY)
add_library(
LibXml2Mod
LibXml2Mod SHARED
libxml2-py.c
libxml2-py.h
python/libxml.c
@ -611,7 +616,7 @@ install(
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY ExactVersion
COMPATIBILITY SameMajorVersion
)
install(

@ -1,19 +1,50 @@
NEWS file for libxml2
v2.13.6: Feb 18 2025
### Security
- [CVE-2025-24928] Fix stack-buffer-overflow in xmlSnprintfElements
- [CVE-2024-56171] Fix use-after-free after xmlSchemaItemListAdd
- pattern: Fix compilation of explicit child axis
### Regressions
- xmllint: Support compressed input from stdin
- uri: Fix handling of Windows drive letters
- reader: Fix return value of xmlTextReaderReadString again
- SAX2: Fix xmlSAX2ResolveEntity if systemId is NULL
### Portability
- dict: Handle ENOSYS from getentropy gracefully
- Fix compilation with uclibc (Dario Binacchi)
- python: Declare init func with PyMODINIT_FUNC
- tests: Fix sanitizer version check on old Apple clang
- cmake: Work around broken sys/random.h in old macOS SDKs
### Build
- autotools: Set AC_CONFIG_AUX_DIR
- cmake: Always build Python module as shared library
- cmake: add missing `Bcrypt` link on Windows (Saleem Abdulrasool)
- cmake: Fix compatibility in package version file
v2.13.5: Nov 12 2024
### Regressions
- xmlIO: Fix reading from non-regular files like pipes (Nick Wellnhofer)
- xmlreader: Fix return value of xmlTextReaderReadString (Nick Wellnhofer)
- parser: Fix loading of parameter entities in external DTDs (Nick Wellnhofer)
- parser: Fix downstream code that swaps DTDs (Nick Wellnhofer)
- parser: Fix detection of duplicate attributes (Nick Wellnhofer)
- string: Fix va_copy fallback (Nick Wellnhofer)
- xmlIO: Fix reading from non-regular files like pipes
- xmlreader: Fix return value of xmlTextReaderReadString
- parser: Fix loading of parameter entities in external DTDs
- parser: Fix downstream code that swaps DTDs
- parser: Fix detection of duplicate attributes
- string: Fix va_copy fallback
### Bug fixes
- xpath: Fix parsing of non-ASCII names (Nick Wellnhofer)
- xpath: Fix parsing of non-ASCII names
v2.13.4: Sep 18 2024

@ -404,42 +404,48 @@ xmlSAX2ResolveEntity(void *ctx, const xmlChar *publicId, const xmlChar *systemId
{
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
xmlParserInputPtr ret = NULL;
xmlChar *URI;
const xmlChar *base = NULL;
int res;
xmlChar *URI = NULL;
if (ctx == NULL) return(NULL);
if (ctxt->input != NULL)
base = BAD_CAST ctxt->input->filename;
/*
* We don't really need the 'directory' struct member, but some
* users set it manually to a base URI for memory streams.
*/
if (base == NULL)
base = BAD_CAST ctxt->directory;
if (systemId != NULL) {
const xmlChar *base = NULL;
int res;
if ((xmlStrlen(systemId) > XML_MAX_URI_LENGTH) ||
(xmlStrlen(base) > XML_MAX_URI_LENGTH)) {
xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT, "URI too long");
return(NULL);
}
res = xmlBuildURISafe(systemId, base, &URI);
if (URI == NULL) {
if (res < 0)
xmlSAX2ErrMemory(ctxt);
else
xmlWarnMsg(ctxt, XML_ERR_INVALID_URI,
"Can't resolve URI: %s\n", systemId);
return(NULL);
}
if (xmlStrlen(URI) > XML_MAX_URI_LENGTH) {
xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT, "URI too long");
} else {
ret = xmlLoadExternalEntity((const char *) URI,
(const char *) publicId, ctxt);
if (ctxt->input != NULL)
base = BAD_CAST ctxt->input->filename;
/*
* We don't really need the 'directory' struct member, but some
* users set it manually to a base URI for memory streams.
*/
if (base == NULL)
base = BAD_CAST ctxt->directory;
if ((xmlStrlen(systemId) > XML_MAX_URI_LENGTH) ||
(xmlStrlen(base) > XML_MAX_URI_LENGTH)) {
xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT, "URI too long");
return(NULL);
}
res = xmlBuildURISafe(systemId, base, &URI);
if (URI == NULL) {
if (res < 0)
xmlSAX2ErrMemory(ctxt);
else
xmlWarnMsg(ctxt, XML_ERR_INVALID_URI,
"Can't resolve URI: %s\n", systemId);
return(NULL);
}
if (xmlStrlen(URI) > XML_MAX_URI_LENGTH) {
xmlFatalErr(ctxt, XML_ERR_RESOURCE_LIMIT, "URI too long");
xmlFree(URI);
return(NULL);
}
}
ret = xmlLoadExternalEntity((const char *) URI,
(const char *) publicId, ctxt);
xmlFree(URI);
return(ret);
}

@ -3,12 +3,13 @@ AC_PREREQ([2.63])
m4_define([MAJOR_VERSION], 2)
m4_define([MINOR_VERSION], 13)
m4_define([MICRO_VERSION], 5)
m4_define([MICRO_VERSION], 6)
AC_INIT([libxml2],[MAJOR_VERSION.MINOR_VERSION.MICRO_VERSION])
AC_CONFIG_SRCDIR([entities.c])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_AUX_DIR([.])
AC_CANONICAL_HOST
LIBXML_MAJOR_VERSION=MAJOR_VERSION

@ -928,14 +928,15 @@ xmlDictQLookup(xmlDictPtr dict, const xmlChar *prefix, const xmlChar *name) {
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <bcrypt.h>
#elif defined(HAVE_GETENTROPY)
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_RANDOM_H
#include <sys/random.h>
#endif
#else
#if defined(HAVE_GETENTROPY)
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_SYS_RANDOM_H
#include <sys/random.h>
#endif
#endif
#include <time.h>
#endif
@ -965,9 +966,21 @@ xmlInitRandom(void) {
"error code %lu\n", GetLastError());
abort();
}
#elif defined(HAVE_GETENTROPY)
#else
int var;
#if defined(HAVE_GETENTROPY)
while (1) {
if (getentropy(globalRngState, sizeof(globalRngState)) == 0)
return;
/*
* This most likely means that libxml2 was compiled on
* a system supporting certain system calls and is running
* on a system that doesn't support these calls, as can
* be the case on Linux.
*/
if (errno == ENOSYS)
break;
if (errno != EINTR) {
@ -976,8 +989,7 @@ xmlInitRandom(void) {
abort();
}
}
#else
int var;
#endif
globalRngState[0] =
(unsigned) time(NULL) ^

@ -1264,7 +1264,7 @@ DECLARE_ISO_FUNCS(16)
#endif /* LIBXML_ISO8859X_ENABLED */
#ifdef LIBXML_ICONV_ENABLED
#define EMPTY_ICONV , (iconv_t) 0, (iconv_t) 0
#define EMPTY_ICONV , (iconv_t) -1, (iconv_t) -1
#else
#define EMPTY_ICONV
#endif
@ -1389,8 +1389,8 @@ xmlNewCharEncodingHandler(const char *name,
handler->name = up;
#ifdef LIBXML_ICONV_ENABLED
handler->iconv_in = NULL;
handler->iconv_out = NULL;
handler->iconv_in = (iconv_t) -1;
handler->iconv_out = (iconv_t) -1;
#endif
#ifdef LIBXML_ICU_ENABLED
handler->uconv_in = NULL;
@ -1641,6 +1641,10 @@ xmlCreateUconvHandler(const char *name, xmlCharEncodingHandler **out) {
}
enc->input = NULL;
enc->output = NULL;
#ifdef LIBXML_ICONV_ENABLED
enc->iconv_in = (iconv_t) -1;
enc->iconv_out = (iconv_t) -1;
#endif
enc->uconv_in = ucv_in;
enc->uconv_out = ucv_out;
@ -2200,7 +2204,7 @@ xmlEncInputChunk(xmlCharEncodingHandler *handler, unsigned char *out,
}
}
#ifdef LIBXML_ICONV_ENABLED
else if (handler->iconv_in != NULL) {
else if (handler->iconv_in != (iconv_t) -1) {
ret = xmlIconvWrapper(handler->iconv_in, out, outlen, in, inlen);
}
#endif /* LIBXML_ICONV_ENABLED */
@ -2260,7 +2264,7 @@ xmlEncOutputChunk(xmlCharEncodingHandler *handler, unsigned char *out,
}
}
#ifdef LIBXML_ICONV_ENABLED
else if (handler->iconv_out != NULL) {
else if (handler->iconv_out != (iconv_t) -1) {
ret = xmlIconvWrapper(handler->iconv_out, out, outlen, in, inlen);
}
#endif /* LIBXML_ICONV_ENABLED */
@ -2672,17 +2676,17 @@ xmlCharEncCloseFunc(xmlCharEncodingHandler *handler) {
* Iconv handlers can be used only once, free the whole block.
* and the associated icon resources.
*/
if ((handler->iconv_out != NULL) || (handler->iconv_in != NULL)) {
if ((handler->iconv_out != (iconv_t) -1) || (handler->iconv_in != (iconv_t) -1)) {
tofree = 1;
if (handler->iconv_out != NULL) {
if (handler->iconv_out != (iconv_t) -1) {
if (iconv_close(handler->iconv_out))
ret = -1;
handler->iconv_out = NULL;
handler->iconv_out = (iconv_t) -1;
}
if (handler->iconv_in != NULL) {
if (handler->iconv_in != (iconv_t) -1) {
if (iconv_close(handler->iconv_in))
ret = -1;
handler->iconv_in = NULL;
handler->iconv_in = (iconv_t) -1;
}
}
#endif /* LIBXML_ICONV_ENABLED */

@ -24,6 +24,9 @@ XML_HIDDEN xmlParserInputBufferPtr
xmlNewInputBufferMemory(const void *mem, size_t size, int flags,
xmlCharEncoding enc);
XML_HIDDEN int
xmlInputFromFd(xmlParserInputBufferPtr buf, int fd, int unzip);
#ifdef LIBXML_OUTPUT_ENABLED
XML_HIDDEN xmlOutputBufferPtr
xmlAllocOutputBufferInternal(xmlCharEncodingHandlerPtr encoder);

@ -90,6 +90,10 @@ xmlParserNsLookupSax(xmlParserCtxtPtr ctxt, const xmlChar *prefix);
#define XML_INPUT_BUF_STATIC (1u << 1)
#define XML_INPUT_BUF_ZERO_TERMINATED (1u << 2)
#define XML_INPUT_UNZIP (1u << 3)
/* Internal parser option */
#define XML_PARSE_UNZIP (1 << 24)
XML_HIDDEN xmlParserInputPtr
xmlNewInputURL(xmlParserCtxtPtr ctxt, const char *url, const char *publicId,

@ -55,7 +55,8 @@
#endif
#ifdef __clang__
#if __clang_major__ >= 12
#if (!defined(__apple_build_version__) && __clang_major__ >= 12) || \
(defined(__apple_build_version__) && __clang_major__ >= 13)
#define ATTRIBUTE_NO_SANITIZE_INTEGER \
ATTRIBUTE_NO_SANITIZE("unsigned-integer-overflow") \
ATTRIBUTE_NO_SANITIZE("unsigned-shift-base")

@ -157,7 +157,7 @@ if(NOT LIBXML2_SHARED)
endif()
if(WIN32)
list(APPEND LIBXML2_LIBRARIES ws2_32)
list(APPEND LIBXML2_LIBRARIES ws2_32;Bcrypt)
endif()
endif()

@ -113,8 +113,8 @@ if(UNIX)
endif()
if(WIN32)
list(APPEND LIBXML2_LIBRARIES ws2_32)
list(APPEND LIBXML2_INTERFACE_LINK_LIBRARIES "\$<LINK_ONLY:ws2_32>")
list(APPEND LIBXML2_LIBRARIES ws2_32;Bcrypt)
list(APPEND LIBXML2_INTERFACE_LINK_LIBRARIES "\$<LINK_ONLY:ws2_32>;\$<LINK_ONLY:Bcrypt>")
endif()
# whether libxml2 has dso support

@ -1,7 +1,7 @@
project(
'libxml2',
'c',
version: '2.13.5',
version: '2.13.6',
license: 'MIT',
default_options: ['buildtype=debug', 'warning_level=3'],
meson_version: '>= 0.61',

@ -13890,7 +13890,8 @@ xmlReadFile(const char *filename, const char *encoding, int options)
* should be removed at some point.
*/
if ((filename != NULL) && (filename[0] == '-') && (filename[1] == 0))
input = xmlNewInputFd(ctxt, filename, STDIN_FILENO, encoding, 0);
input = xmlNewInputFd(ctxt, filename, STDIN_FILENO, encoding,
XML_INPUT_UNZIP);
else
input = xmlNewInputURL(ctxt, filename, NULL, encoding, 0);
@ -14141,6 +14142,7 @@ xmlCtxtReadFd(xmlParserCtxtPtr ctxt, int fd,
const char *URL, const char *encoding, int options)
{
xmlParserInputPtr input;
int inputFlags;
if (ctxt == NULL)
return(NULL);
@ -14148,7 +14150,10 @@ xmlCtxtReadFd(xmlParserCtxtPtr ctxt, int fd,
xmlCtxtReset(ctxt);
xmlCtxtUseOptions(ctxt, options);
input = xmlNewInputFd(ctxt, URL, fd, encoding, 0);
inputFlags = 0;
if (options & XML_PARSE_UNZIP)
inputFlags |= XML_INPUT_UNZIP;
input = xmlNewInputFd(ctxt, URL, fd, encoding, inputFlags);
return(xmlCtxtParseDocument(ctxt, input));
}

@ -1715,18 +1715,23 @@ xmlNewInputString(xmlParserCtxtPtr ctxt, const char *url,
*/
xmlParserInputPtr
xmlNewInputFd(xmlParserCtxtPtr ctxt, const char *url,
int fd, const char *encoding, int flags ATTRIBUTE_UNUSED) {
int fd, const char *encoding, int flags) {
xmlParserInputBufferPtr buf;
if ((ctxt == NULL) || (fd < 0))
return(NULL);
buf = xmlParserInputBufferCreateFd(fd, XML_CHAR_ENCODING_NONE);
buf = xmlAllocParserInputBuffer(XML_CHAR_ENCODING_NONE);
if (buf == NULL) {
xmlCtxtErrMemory(ctxt);
return(NULL);
}
if (xmlInputFromFd(buf, fd, (flags & XML_INPUT_UNZIP) != 0) < 0) {
xmlFreeParserInputBuffer(buf);
return(NULL);
}
return(xmlNewInputInternal(ctxt, buf, url, encoding));
}

@ -1158,10 +1158,10 @@ xmlCompileStepPattern(xmlPatParserContextPtr ctxt) {
goto error;
}
} else {
PUSH(XML_OP_CHILD, token, URL);
PUSH(XML_OP_ELEM, token, URL);
}
} else
PUSH(XML_OP_CHILD, name, NULL);
PUSH(XML_OP_ELEM, name, NULL);
return;
} else if (xmlStrEqual(name, (const xmlChar *) "attribute")) {
XML_PAT_FREE_STRING(ctxt, name)

@ -30,7 +30,7 @@
#include "libxml2-py.h"
#if PY_MAJOR_VERSION >= 3
PyObject *PyInit_libxml2mod(void);
PyMODINIT_FUNC PyInit_libxml2mod(void);
#define PY_IMPORT_STRING_SIZE PyUnicode_FromStringAndSize
#define PY_IMPORT_STRING PyUnicode_FromString
@ -3671,7 +3671,7 @@ extern void initlibxsltmod(void);
#endif
#if PY_MAJOR_VERSION >= 3
PyObject *PyInit_libxml2mod(void)
PyMODINIT_FUNC PyInit_libxml2mod(void)
#else
void initlibxml2mod(void)
#endif

@ -1,3 +1,5 @@
#include "libxml.h"
#include <stdlib.h>
#include <string.h>
#include <libxml/parser.h>
@ -6,19 +8,6 @@
/**** dictionary tests ****/
#ifdef __clang__
#if __clang_major__ >= 12
#define ATTRIBUTE_NO_SANITIZE_INTEGER \
__attribute__ ((no_sanitize("unsigned-integer-overflow"))) \
__attribute__ ((no_sanitize("unsigned-shift-base")))
#else
#define ATTRIBUTE_NO_SANITIZE_INTEGER \
__attribute__ ((no_sanitize("unsigned-integer-overflow")))
#endif
#else
#define ATTRIBUTE_NO_SANITIZE_INTEGER
#endif
/* #define WITH_PRINT */
static const char *seeds1[] = {

@ -361,6 +361,76 @@ testReaderContent(void) {
return err;
}
static int
testReaderNode(xmlTextReader *reader) {
xmlChar *string;
int type;
int err = 0;
type = xmlTextReaderNodeType(reader);
string = xmlTextReaderReadString(reader);
if (type == XML_READER_TYPE_ELEMENT) {
xmlNodePtr node = xmlTextReaderCurrentNode(reader);
if ((node->children == NULL) != (string == NULL))
err = 1;
} else if (type == XML_READER_TYPE_TEXT ||
type == XML_READER_TYPE_CDATA ||
type == XML_READER_TYPE_WHITESPACE ||
type == XML_READER_TYPE_SIGNIFICANT_WHITESPACE) {
if (string == NULL)
err = 1;
} else {
if (string != NULL)
err = 1;
}
if (err)
fprintf(stderr, "xmlTextReaderReadString failed for %d\n", type);
xmlFree(string);
return err;
}
static int
testReader(void) {
xmlTextReader *reader;
const xmlChar *xml = BAD_CAST
"<d>\n"
" x<e a='v'>y</e><f>z</f>\n"
" <![CDATA[cdata]]>\n"
" <!-- comment -->\n"
" <?pi content?>\n"
" <empty/>\n"
"</d>";
int err = 0;
reader = xmlReaderForDoc(xml, NULL, NULL, 0);
while (xmlTextReaderRead(reader) > 0) {
if (testReaderNode(reader) > 0) {
err = 1;
break;
}
if (xmlTextReaderMoveToFirstAttribute(reader) > 0) {
do {
if (testReaderNode(reader) > 0) {
err = 1;
break;
}
} while (xmlTextReaderMoveToNextAttribute(reader) > 0);
xmlTextReaderMoveToElement(reader);
}
}
xmlFreeTextReader(reader);
return err;
}
#ifdef LIBXML_XINCLUDE_ENABLED
typedef struct {
char *message;
@ -613,6 +683,81 @@ testBuildRelativeUri(void) {
return err;
}
#if defined(_WIN32) || defined(__CYGWIN__)
static int
testWindowsUri(void) {
const char *url = "c:/a%20b/file.txt";
xmlURIPtr uri;
xmlChar *res;
int err = 0;
int i;
static const xmlRelativeUriTest tests[] = {
{
"c:/a%20b/file.txt",
"base.xml",
"c:/a b/file.txt"
}, {
"file:///c:/a%20b/file.txt",
"base.xml",
"file:///c:/a%20b/file.txt"
}, {
"Z:/a%20b/file.txt",
"http://example.com/",
"Z:/a b/file.txt"
}, {
"a%20b/b1/c1",
"C:/a/b2/c2",
"C:/a/b2/a b/b1/c1"
}, {
"a%20b/b1/c1",
"\\a\\b2\\c2",
"/a/b2/a b/b1/c1"
}, {
"a%20b/b1/c1",
"\\\\?\\a\\b2\\c2",
"//?/a/b2/a b/b1/c1"
}, {
"a%20b/b1/c1",
"\\\\\\\\server\\b2\\c2",
"//server/b2/a b/b1/c1"
}
};
uri = xmlParseURI(url);
if (uri == NULL) {
fprintf(stderr, "xmlParseURI failed\n");
err = 1;
} else {
if (uri->scheme != NULL) {
fprintf(stderr, "invalid scheme: %s\n", uri->scheme);
err = 1;
}
if (uri->path == NULL || strcmp(uri->path, "c:/a b/file.txt") != 0) {
fprintf(stderr, "invalid path: %s\n", uri->path);
err = 1;
}
xmlFreeURI(uri);
}
for (i = 0; (size_t) i < sizeof(tests) / sizeof(tests[0]); i++) {
const xmlRelativeUriTest *test = tests + i;
res = xmlBuildURI(BAD_CAST test->uri, BAD_CAST test->base);
if (res == NULL || !xmlStrEqual(res, BAD_CAST test->result)) {
fprintf(stderr, "xmlBuildURI failed uri=%s base=%s "
"result=%s expected=%s\n", test->uri, test->base,
res, test->result);
err = 1;
}
xmlFree(res);
}
return err;
}
#endif /* WIN32 */
int
main(void) {
int err = 0;
@ -638,6 +783,7 @@ main(void) {
#ifdef LIBXML_READER_ENABLED
err |= testReaderEncoding();
err |= testReaderContent();
err |= testReader();
#ifdef LIBXML_XINCLUDE_ENABLED
err |= testReaderXIncludeError();
#endif
@ -646,6 +792,9 @@ main(void) {
err |= testWriterClose();
#endif
err |= testBuildRelativeUri();
#if defined(_WIN32) || defined(__CYGWIN__)
err |= testWindowsUri();
#endif
return err;
}

@ -231,6 +231,15 @@ xmlParse3986Scheme(xmlURIPtr uri, const char **str) {
if (!ISA_ALPHA(cur))
return(1);
cur++;
#if defined(_WIN32) || defined(__CYGWIN__)
/*
* Don't treat Windows drive letters as scheme.
*/
if (*cur == ':')
return(1);
#endif
while (ISA_ALPHA(cur) || ISA_DIGIT(cur) ||
(*cur == '+') || (*cur == '-') || (*cur == '.')) cur++;
if (uri != NULL) {
@ -582,11 +591,21 @@ xmlParse3986Segment(xmlURIPtr uri, const char **str, char forbid, int empty)
const char *cur;
cur = *str;
if (!ISA_PCHAR(uri, cur)) {
if (!ISA_PCHAR(uri, cur) || (*cur == forbid)) {
if (empty)
return(0);
return(1);
}
NEXT(cur);
#if defined(_WIN32) || defined(__CYGWIN__)
/*
* Allow Windows drive letters.
*/
if ((forbid == ':') && (*cur == forbid))
NEXT(cur);
#endif
while (ISA_PCHAR(uri, cur) && (*cur != forbid))
NEXT(cur);
*str = cur;
@ -2064,6 +2083,23 @@ xmlBuildURISafe(const xmlChar *URI, const xmlChar *base, xmlChar **valPtr) {
return(xmlResolvePath(URI, base, valPtr));
}
#if defined(_WIN32) || defined(__CYGWIN__)
/*
* Resolve paths with a Windows drive letter as filesystem path
* even if base has a scheme.
*/
if ((ref != NULL) && (ref->path != NULL)) {
int c = ref->path[0];
if ((((c >= 'A') && (c <= 'Z')) ||
((c >= 'a') && (c <= 'z'))) &&
(ref->path[1] == ':')) {
xmlFreeURI(ref);
return(xmlResolvePath(URI, base, valPtr));
}
}
#endif
ret = xmlParseURISafe((const char *) base, &bas);
if (ret < 0)
goto done;

@ -5005,26 +5005,26 @@ xmlSnprintfElements(char *buf, int size, xmlNodePtr node, int glob) {
return;
}
switch (cur->type) {
case XML_ELEMENT_NODE:
case XML_ELEMENT_NODE: {
int qnameLen = xmlStrlen(cur->name);
if ((cur->ns != NULL) && (cur->ns->prefix != NULL))
qnameLen += xmlStrlen(cur->ns->prefix) + 1;
if (size - len < qnameLen + 10) {
if ((size - len > 4) && (buf[len - 1] != '.'))
strcat(buf, " ...");
return;
}
if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) {
if (size - len < xmlStrlen(cur->ns->prefix) + 10) {
if ((size - len > 4) && (buf[len - 1] != '.'))
strcat(buf, " ...");
return;
}
strcat(buf, (char *) cur->ns->prefix);
strcat(buf, ":");
}
if (size - len < xmlStrlen(cur->name) + 10) {
if ((size - len > 4) && (buf[len - 1] != '.'))
strcat(buf, " ...");
return;
}
if (cur->name != NULL)
strcat(buf, (char *) cur->name);
if (cur->next != NULL)
strcat(buf, " ");
break;
}
case XML_TEXT_NODE:
if (xmlIsBlankNode(cur))
break;

@ -1158,65 +1158,36 @@ xmlIODefaultMatch(const char *filename ATTRIBUTE_UNUSED) {
return(1);
}
/**
* xmlInputDefaultOpen:
* @buf: input buffer to be filled
* @filename: filename or URI
*
* Returns an xmlParserErrors code.
*/
static int
xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename) {
int ret;
int fd;
#ifdef LIBXML_FTP_ENABLED
if (xmlIOFTPMatch(filename)) {
buf->context = xmlIOFTPOpen(filename);
if (buf->context != NULL) {
buf->readcallback = xmlIOFTPRead;
buf->closecallback = xmlIOFTPClose;
return(XML_ERR_OK);
}
}
#endif /* LIBXML_FTP_ENABLED */
#ifdef LIBXML_HTTP_ENABLED
if (xmlIOHTTPMatch(filename)) {
buf->context = xmlIOHTTPOpen(filename);
if (buf->context != NULL) {
buf->readcallback = xmlIOHTTPRead;
buf->closecallback = xmlIOHTTPClose;
return(XML_ERR_OK);
}
}
#endif /* LIBXML_HTTP_ENABLED */
int
xmlInputFromFd(xmlParserInputBufferPtr buf, int fd, int unzip) {
int copy;
if (!xmlFileMatch(filename))
return(XML_IO_ENOENT);
(void) unzip;
#ifdef LIBXML_LZMA_ENABLED
{
if (unzip) {
xzFile xzStream;
off_t pos;
ret = xmlFdOpen(filename, 0, &fd);
if (ret != XML_ERR_OK)
return(ret);
pos = lseek(fd, 0, SEEK_CUR);
xzStream = __libxml2_xzdopen(filename, fd, "rb");
copy = dup(fd);
if (copy == -1)
return(xmlIOErr(0, "dup()"));
xzStream = __libxml2_xzdopen("?", copy, "rb");
if (xzStream == NULL) {
close(fd);
close(copy);
} else {
/*
* Non-regular files like pipes can't be reopened.
* If a file isn't seekable, we pipe uncompressed
* input through xzlib.
*/
if ((lseek(fd, 0, SEEK_CUR) < 0) ||
(__libxml2_xzcompressed(xzStream) > 0)) {
if ((__libxml2_xzcompressed(xzStream) > 0) ||
/* Try to rewind if not gzip compressed */
(pos < 0) ||
(lseek(fd, pos, SEEK_SET) < 0)) {
/*
* If a file isn't seekable, we pipe uncompressed
* input through xzlib.
*/
buf->context = xzStream;
buf->readcallback = xmlXzfileRead;
buf->closecallback = xmlXzfileClose;
@ -1231,25 +1202,29 @@ xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename) {
#endif /* LIBXML_LZMA_ENABLED */
#ifdef LIBXML_ZLIB_ENABLED
{
if (unzip) {
gzFile gzStream;
off_t pos;
ret = xmlFdOpen(filename, 0, &fd);
if (ret != XML_ERR_OK)
return(ret);
pos = lseek(fd, 0, SEEK_CUR);
copy = dup(fd);
if (copy == -1)
return(xmlIOErr(0, "dup()"));
gzStream = gzdopen(fd, "rb");
gzStream = gzdopen(copy, "rb");
if (gzStream == NULL) {
close(fd);
close(copy);
} else {
/*
* Non-regular files like pipes can't be reopened.
* If a file isn't seekable, we pipe uncompressed
* input through zlib.
*/
if ((lseek(fd, 0, SEEK_CUR) < 0) ||
(gzdirect(gzStream) == 0)) {
if ((gzdirect(gzStream) == 0) ||
/* Try to rewind if not gzip compressed */
(pos < 0) ||
(lseek(fd, pos, SEEK_SET) < 0)) {
/*
* If a file isn't seekable, we pipe uncompressed
* input through zlib.
*/
buf->context = gzStream;
buf->readcallback = xmlGzfileRead;
buf->closecallback = xmlGzfileClose;
@ -1263,16 +1238,67 @@ xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename) {
}
#endif /* LIBXML_ZLIB_ENABLED */
ret = xmlFdOpen(filename, 0, &fd);
if (ret != XML_ERR_OK)
return(ret);
copy = dup(fd);
if (copy == -1)
return(xmlIOErr(0, "dup()"));
buf->context = (void *) (ptrdiff_t) fd;
buf->context = (void *) (ptrdiff_t) copy;
buf->readcallback = xmlFdRead;
buf->closecallback = xmlFdClose;
return(XML_ERR_OK);
}
/**
* xmlInputDefaultOpen:
* @buf: input buffer to be filled
* @filename: filename or URI
*
* Returns an xmlParserErrors code.
*/
static int
xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename) {
int ret;
int fd;
#ifdef LIBXML_FTP_ENABLED
if (xmlIOFTPMatch(filename)) {
buf->context = xmlIOFTPOpen(filename);
if (buf->context != NULL) {
buf->readcallback = xmlIOFTPRead;
buf->closecallback = xmlIOFTPClose;
return(XML_ERR_OK);
}
}
#endif /* LIBXML_FTP_ENABLED */
#ifdef LIBXML_HTTP_ENABLED
if (xmlIOHTTPMatch(filename)) {
buf->context = xmlIOHTTPOpen(filename);
if (buf->context != NULL) {
buf->readcallback = xmlIOHTTPRead;
buf->closecallback = xmlIOHTTPClose;
return(XML_ERR_OK);
}
}
#endif /* LIBXML_HTTP_ENABLED */
if (!xmlFileMatch(filename))
return(XML_IO_ENOENT);
ret = xmlFdOpen(filename, 0, &fd);
if (ret != XML_ERR_OK)
return(ret);
ret = xmlInputFromFd(buf, fd, /* unzip */ 1);
close(fd);
return(ret);
}
#ifdef LIBXML_OUTPUT_ENABLED
/**
* xmlOutputDefaultOpen:

@ -95,6 +95,9 @@
#define STDIN_FILENO 0
#endif
/* Internal parser option */
#define XML_PARSE_UNZIP (1 << 24)
typedef enum {
XMLLINT_RETURN_OK = 0, /* No error */
XMLLINT_ERR_UNCLASS = 1, /* Unclassified */
@ -1648,7 +1651,8 @@ testSAX(const char *filename) {
xmlCtxtSetMaxAmplification(ctxt, maxAmpl);
if (strcmp(filename, "-") == 0)
xmlCtxtReadFd(ctxt, STDIN_FILENO, "-", NULL, options);
xmlCtxtReadFd(ctxt, STDIN_FILENO, "-", NULL,
options | XML_PARSE_UNZIP);
else
xmlCtxtReadFile(ctxt, filename, NULL, options);
@ -2333,7 +2337,8 @@ parseFile(const char *filename, xmlParserCtxtPtr rectxt) {
#endif
} else {
if (strcmp(filename, "-") == 0)
doc = xmlCtxtReadFd(ctxt, STDIN_FILENO, "-", NULL, options);
doc = xmlCtxtReadFd(ctxt, STDIN_FILENO, "-", NULL,
options | XML_PARSE_UNZIP);
else
doc = xmlCtxtReadFile(ctxt, filename, NULL, options);
}

@ -1730,8 +1730,9 @@ xmlTextReaderReadOuterXml(xmlTextReaderPtr reader)
*
* Reads the contents of an element or a text node as a string.
*
* Returns a string containing the contents of the Element or Text node,
* or NULL if the reader is positioned on any other type of node.
* Returns a string containing the contents of the non-empty Element or
* Text node (including CDATA sections), or NULL if the reader
* is positioned on any other type of node.
* The string must be deallocated by the caller.
*/
xmlChar *
@ -1754,11 +1755,8 @@ xmlTextReaderReadString(xmlTextReaderPtr reader)
(node->children == NULL))
return(NULL);
break;
case XML_ATTRIBUTE_NODE:
/* TODO */
break;
default:
break;
return(NULL);
}
buf = xmlBufCreateSize(30);

@ -23364,6 +23364,7 @@ xmlSchemaIDCFillNodeTables(xmlSchemaValidCtxtPtr vctxt,
}
if (xmlSchemaItemListAdd(bind->dupls, bind->nodeTable[j]) == -1)
goto internal_error;
dupls = (xmlSchemaPSVIIDCNodePtr *) bind->dupls->items;
/*
* Remove the duplicate entry from the IDC node-table.
*/
@ -23580,6 +23581,8 @@ xmlSchemaBubbleIDCNodeTables(xmlSchemaValidCtxtPtr vctxt)
goto internal_error;
}
xmlSchemaItemListAdd(parBind->dupls, parNode);
dupls = (xmlSchemaPSVIIDCNodePtr *)
parBind->dupls->items;
} else {
/*
* Add the node-table entry (node and key-sequence) of

Loading…
Cancel
Save