1
0
mirror of https://github.com/GNOME/libxml2.git synced 2025-10-16 23:26:56 +08:00
Commit Graph

5362 Commits

Author SHA1 Message Date
David Kilzer
300e19932f Add fuzzing asserts to xmlSetTreeDoc()
* tree.c:
(xmlSetTreeDoc):
- When xmlSetTreeDoc() has to change documents, the calling code
  probably has a bug, so assert when those conditions are hit.
  This is a follow-up to commit 4bc3ebf3.
2022-05-25 10:04:59 -07:00
David Kilzer
4bc3ebf3ea Fix ownership of xmlNodePtr & xmlAttrPtr fields in xmlSetTreeDoc()
When changing `doc` on an xmlNodePtr or xmlAttrPtr, certain
fields must either be a free-standing string, or they must be
owned by `doc->dict`.

The code to make this change was simply missing, so the crash
happened when an xmlAttrPtr was being torn down after `doc`
changed from non-NULL to NULL, but the `name` field was not
copied.  This is scenario 1 below.

The xmlNodePtr->name and xmlNodePtr->content fields are also
fixed at the same time.  Note that xmlNodePtr->content is never
added to the dictionary, so NULL is used instead of `newDict` to
force a free-standing copy.

This change covers all cases of dictionary changes:
1. Owned by old dictionary -> NULL new dictionary
   - Create free-standing copy of string.
2. Owned by old dictionary -> Non-NULL new dictionary
   - Get string from new dictionary pool.
3. Not owned by old dictionary -> Non-NULL new dictionary
   - No action necessary (already a free-standing string).
4. Not owned by old dictionary -> NULL new dictionary
   - No action necessary (already a free-standing string).

* tree.c:
(_copyStringForNewDictIfNeeded): Add.
(xmlSetTreeDoc):
- Update xmlNodePtr->name, xmlNodePtr->content and
  xmlAttrPtr->name when changing the document, if needed.

Found by OSS-Fuzz Issue 45132.
2022-05-25 16:55:26 +00:00
Nick Wellnhofer
0aa8652e59 Use xmlNewDocText in xmlXIncludeCopyRange
Otherwise, the initial node of the copy could be a text node with a
NULL document. This results in the NULL document being propagated to
copies of other nodes, losing information about the dictionary in which
node data is stored, and freeing a dict-allocated string.

See discussion in !175.
2022-05-20 14:54:49 +02:00
Nick Wellnhofer
351dbdfe8b Disable network in API tests
Avoids hangs when trying to make network connections.
2022-05-20 14:53:33 +02:00
David Kilzer
c50196c13d Fix use-after-free bugs when calling xmlTextReaderClose() before xmlFreeTextReader() on post-validating parser
When creating an xmlTextReaderPtr using xmlReaderForMemory(),
there are two optional API functions that can be used:
- xmlTextReaderClose() may be called prior to calling
  xmlFreeTextReader() to free parsing resources and close the
  xmlTextReaderPtr without freeing it.
- xmlTextReaderCurrentDoc() may be called to return an
  xmlDocPtr that's owned by the caller, and must be free using
  xmlFreeDoc() after calling xmlFreeTextReader().

The use-after-free issues occur when calling
xmlTextReaderClose() before xmlFreeTextReader(), with different
issues occurring depending on whether xmlTextReaderCurrentDoc()
is also called.

* xmlreader.c:
(xmlFreeTextReader):
- Move code to xmlTextReaderClose(), remove duplicate code, and
  call xmlTextReaderClose() if it hasn't been called yet.
(xmlTextReaderClose):
- Move call to xmlFreeNode(reader->faketext) from
  xmlFreeTextReader() to fix a use-after-free bug when calling
  xmlTextReaderClose() before xmlFreeTextReader(), but not when
  using xmlTextReaderCurrentDoc().  The bug was introduced in
  2002 by commit beb70bd39.  In 2009 commit f4653dcd8 fixed the
  use-after-free that occurred every time xmlFreeTextReader()
  was called, but not the case where xmlTextReaderClose() was
  called first.
- Move post-parsing validation code from xmlFreeTextReader() to
  fix a second use-after-free when calling xmlTextReaderClose()
  before xmlFreeTextReader().  This regressed in v2.9.10 with
  commit 57a3af56f.
2022-05-18 08:32:18 -07:00
David Kilzer
054e46b097 Restore behavior of htmlDocContentDumpFormatOutput()
Patch by J Pascoe of Apple.

* HTMLtree.c:
(htmlDocContentDumpFormatOutput):
- Prior to commit b79ab6e6d9, xmlDoc.type was set to
  XML_HTML_DOCUMENT_NODE before dumping the HTML output, then
  restored before returning.
2022-05-14 08:56:47 -07:00
Joey Arhar
e08d8c37f5 Add xptr_locs flag to win32/configure.js
The xptr_locs flag was added in commit 67070107 but no flag was added to
win32/configure.js, leading a compile error I had on windows where the
@WITH_XPTR_LOCS@ macro was not replaced properly on windows.
2022-05-06 10:21:29 -07:00
Mehltretter Karl
c1632fbd0a fix typo in comment 2022-05-06 10:58:58 +02:00
Mehltretter Karl
e9270ef0d4 fix Schematron spelling 2022-05-06 10:44:03 +02:00
Nick Wellnhofer
6c283d83ec [CVE-2022-29824] Fix integer overflows in xmlBuf and xmlBuffer
In several places, the code handling string buffers didn't check for
integer overflow or used wrong types for buffer sizes. This could
result in out-of-bounds writes or other memory errors when working on
large, multi-gigabyte buffers.

Thanks to Felix Wilhelm for the report.
2022-05-02 14:11:07 +02:00
Nick Wellnhofer
433b318668 Define LFS macros before including system headers
xmlstring.h includes stdarg.h, so it must be included after defining
macros like _FILE_OFFSET_BITS.
2022-04-27 17:31:57 +02:00
Nick Wellnhofer
145170125a Fix parsing of subtracted regex character classes
Fixes #370.
2022-04-23 19:22:42 +02:00
Nick Wellnhofer
d9e1198c61 Redirect examples test output to /dev/null
Regressed in commit c61e1273.
2022-04-23 18:42:35 +02:00
Nick Wellnhofer
d314046f89 Don't try to copy children of entity references
This would result in an error, aborting the whole copy operation.
Regressed in commit 7618a3b1.

Fixes #371.
2022-04-23 17:45:35 +02:00
Nick Wellnhofer
0c0f2a57c7 Port genUnicode.py to Python 3 2022-04-23 17:45:35 +02:00
Mike Gilbert
b31e07dbf4 testapi: remove leading slash from "/missing.xml"
Fixes an error when running tests in a sandbox on Gentoo Linux.

Bug: https://bugs.gentoo.org/839804
2022-04-22 20:14:05 -04:00
Nick Wellnhofer
65b01647bf Build Autotools CI tests out of source tree (VPATH) 2022-04-21 06:59:02 +02:00
Nick Wellnhofer
ad098030ad Add --with-minimum build to CI tests 2022-04-21 06:59:02 +02:00
Nick Wellnhofer
c61e12739f Fix warnings when testing --with-minimum build
There's no simple way to make the doc/examples tests handle different
configurations. But these tests aren't especially valuable, so remove
the result file checks.
2022-04-21 06:58:14 +02:00
Nick Wellnhofer
4612ce3031 Implement xpath1() XPointer scheme
See https://www.w3.org/2005/04/xpointer-schemes/
2022-04-21 04:26:52 +02:00
Nick Wellnhofer
670701075b Add configuration flag for XPointer locations support
Add a new configuration flag that controls whether the outdated support
for XPointer locations (ranges and points) is enabled.

    --with-xptr-locs          # Autotools
    LIBXML2_WITH_XPTR_LOCS    # CMake

The latest spec for what it essentially an XPath extension seems to be
this working draft from 2002:

    https://www.w3.org/TR/xptr-xpointer/

The xpointer() scheme is listed as "being reviewed" in the XPointer
registry since at least 2006. libxml2 seems to be the only modern
software that tries to implement this spec, but the code has many bugs
and quality issues.

The flag defaults to "off" and support for this extensions has to be
requested explicitly. The relevant API functions are deprecated.
2022-04-21 02:41:58 +02:00
Nick Wellnhofer
9a0be0dc4d Regenerate api.xml and testapi.c 2022-04-21 01:58:59 +02:00
Nick Wellnhofer
343fc1421c Port gentest.py to Python 3 2022-04-21 00:54:03 +02:00
Nick Wellnhofer
02709d0f67 Remove remaining definitions of STDC_HEADERS
Sync with Autotools build.
2022-04-20 19:18:17 +02:00
Nick Wellnhofer
270eb712bf cmake: Run all tests when threads are disabled 2022-04-20 14:28:38 +02:00
Nick Wellnhofer
18bcced9d7 cmake: Fix build with thread support
Move configure_file(config.h) below pthreads check.

Fix regression caused by commit f5659a1.
2022-04-20 13:36:02 +02:00
Nick Wellnhofer
dbc23ed301 Also build CI tests with -Werror 2022-04-13 17:02:50 +02:00
Nick Wellnhofer
7204dbb0ad Don't mix declarations and code in runtest.c 2022-04-13 16:51:49 +02:00
Nick Wellnhofer
776b00284d cmake: Disable FTP and legacy modules by default
Sync with Autotools build.
2022-04-13 16:47:54 +02:00
Nick Wellnhofer
e13c808124 Run CI tests with FTP and legacy modules
These modules are disabled by default. Enable them when testing.
2022-04-13 16:45:57 +02:00
Nick Wellnhofer
cacf65556c Fix compiler warnings in Python code
Add more deprecated functions to avoid compiler warnings when building
the Python bindings.
2022-04-13 16:43:15 +02:00
Nick Wellnhofer
f5659a122d cmake: Fix build without thread support
Only check for pthread.h if threads are enabled.

Fixes #367.
2022-04-13 14:30:54 +02:00
David Kilzer
44e9118c02 Prevent integer-overflow in htmlSkipBlankChars() and xmlSkipBlankChars()
* HTMLparser.c:
(htmlSkipBlankChars):
* parser.c:
(xmlSkipBlankChars):
- Cap the return value at INT_MAX.
- The commit range that OSS-Fuzz listed for the fix didn't make
  any changes to xmlSkipBlankChars(), so it seems like this
  issue may still exist.

Found by OSS-Fuzz Issue 44803.
2022-04-11 18:09:37 +00:00
David Kilzer
a15f2abef1 Use UPDATE_COMPAT() consistently in buf.c
* buf.c:
(xmlBufCreate):
(xmlBufCreateSize):
(xmlBufDetach):
(xmlBufCreateStatic):
(xmlBufFromBuffer):
2022-04-10 12:55:52 +00:00
Nick Wellnhofer
41afa89fc9 Fix short-lived regression in xmlStaticCopyNode
Commit 7618a3b1 didn't account for coalesced text nodes.

I think it would be better if xmlStaticCopyNode didn't try to coalesce
text nodes at all. This code path can only be triggered if some other
code doesn't coalesce text nodes properly. In this case, OSS-Fuzz found
such behavior in xinclude.c.
2022-04-10 14:17:31 +02:00
Nick Wellnhofer
a5724a3b4a cmake: Install documentation in CMAKE_INSTALL_DOCDIR
Sync with recent Autotools change.
2022-04-08 15:47:45 +02:00
Daniel E
4d98f6f9c5 cmake: Remove more unnecessary files installed in docs dir
Sync with commit 9576654162
Don't install man pages in docs directory, these are already installed
in the correct path and while at it sort list
2022-04-08 12:11:39 +00:00
David Kilzer
21561e833a Mark more static data as const
Similar to 8f5710379, mark more static data structures with
`const` keyword.

Also fix placement of `const` in encoding.c.

Original patch by Sarah Wilkin.
2022-04-07 12:01:23 -07:00
David Kilzer
b7e8e4c7f7 Fix leak of xmlElementContent
* valid.c:
(xmlCopyDocElementContent):
- Set `tmp->parent` properly to fix a leak that occurs in
  xmlFreeDocElementContent().
- Appears to be a regresion from cee2b3a5f1.

Found by OSS-Fuzz Issue 44509.
2022-04-07 12:02:02 +00:00
Nick Wellnhofer
94ac5e61f3 CMakeLists.txt: Fix LIBXML_VERSION_NUMBER
Also fix LIBXML_VERSION and remove LIBXML_VERSION_STRING.

Fixes #365.
2022-04-07 02:09:48 +02:00
David Seifert
a62b31f43f Use portable python shebangs
* In conda or Gentoo Prefix, we don't want to use the system python and
  instead rely on PATH lookup.
2022-04-06 19:57:30 +02:00
Daniel E
f2987a295f cmake: Remove non needed files in docs dir
Don't install files that are used to generate the documentation
2022-04-04 12:04:21 +00:00
Nick Wellnhofer
e59aa6cab4 Move doc/examples tests to new test suite 2022-04-04 05:57:07 +02:00
Nick Wellnhofer
3f74e42bae Simplify 'make check' targets 2022-04-04 05:41:51 +02:00
Christopher Degawa
f60e219325 configure: move XML_PRIVATE_LIBS after WIN32_EXTRA_LIBADD is set
currently the pkg-config file lacks -lws2_32 because WIN32_EXTRA_LIBADD
isn't set by the time XML_PRIVATE_LIBS is set

Signed-off-by: Christopher Degawa <ccom@randomderp.com>
2022-04-04 02:40:16 +00:00
Nick Wellnhofer
48f191e7d7 Fix schemas and relaxng tests
Run all tests in runtest.c with warnings. This is required to match the
schema validation output from xmllint and doesn't seem to cause any
problems.

Fix the .xml file pattern.

Check parser errors. Print xmllint message if Relax-NG schema can't be
parsed.
2022-04-04 04:28:15 +02:00
Nick Wellnhofer
4de7f2acfe Remove unused result files 2022-04-04 04:28:15 +02:00
Nick Wellnhofer
5ce893c0c4 Move regexp tests to runtest 2022-04-04 04:28:15 +02:00
Nick Wellnhofer
f1c32b4c78 Allow missing result files in runtest
Treat missing files as empty.
2022-04-04 04:28:15 +02:00
Nick Wellnhofer
95c7f315ab Move SVG tests to runtest.c
Also update the test results for the first time since 2000.
2022-04-04 04:18:07 +02:00