1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-12-25 23:21:26 +03:00
Commit Graph

4757 Commits

Author SHA1 Message Date
Nick Wellnhofer
44e7a0d5f7 Annotate functions with __attribute__((no_sanitize)) 2019-05-20 13:38:22 +02:00
Nick Wellnhofer
f9fce96313 Fix unsigned integer overflow
It's defined behavior but -fsanitize=unsigned-integer-overflow is
useful to discover bugs.
2019-05-20 13:38:22 +02:00
Nick Wellnhofer
dbc6b55b59 Fix warnings when compiling without reader or push parser 2019-05-16 21:06:56 +02:00
Nick Wellnhofer
407b393d80 Fix return value of xmlOutputBufferWrite
When using memory buffers, the total size of the buffer was added
again and again, potentially leading to an integer overflow.

Found by OSS-Fuzz.
2019-05-15 13:01:52 +02:00
David Warring
3c0d62b419 Fix parser termination from "Double hyphen within comment" error
The patch fixes the parser not halting immediately when the error
handler attempts to stop the parser.

Rather it was running on and continuing to reference the freed buffer
in the while loop termination test.

This is only a problem if xmlStopParser is called from an error
handler. Probably caused by commit 123234f2. Fixes #58.
2019-05-14 15:55:12 +02:00
Nick Wellnhofer
96125557b6 Remove unused member doc in xmlSaveCtxt 2019-05-10 12:30:03 +02:00
Nick Wellnhofer
14ed63b7d0 Limit recursion depth in xmlXPathCompOpEvalPredicate 2019-05-08 12:00:51 +02:00
Nick Wellnhofer
ad93f087d1 Remove -Wno-array-bounds
It's unsupported on GCC versions older than 4.3 and the false positives
seem to be fixed in newer versions.
2019-05-01 16:31:58 +02:00
Jérôme Duval
9948a9a355 timsort.h: support older GCCs
cherry-pick upstream pull request: __builtin_clzll isn't available on older GCCs
2019-05-01 16:31:05 +02:00
Nick Wellnhofer
346febc6ab Fix call stack overflow in xmlFreePattern
Since xmlFreePattern tried to free the next pattern recursively, its
behavior is identical to xmlFreePatternList. Make it call
xmlFreePatternList to avoid call stack overflows.

Found by OSS-Fuzz.
2019-04-25 11:37:37 +02:00
Nick Wellnhofer
f75256e7db Remove unreachable code in xmlXPathCountFunction
After the initial test, the condition

    (type == XPATH_NODESET) || (type == XPATH_XSLT_TREE)

always holds true.
2019-04-23 18:04:19 +02:00
Nick Wellnhofer
949eced484 Fix null deref in previous commit 2019-04-22 16:04:26 +02:00
Nick Wellnhofer
c2f4da1a93 Improve XPath predicate and filter evaluation
Consolidate code paths evaluating XPath predicates and filters.

Don't push context node on stack when evaluating predicates. I have no
idea why this was done. It seems completely useless and trying to pop
the context node from a corrupted stack has already caused security
issues.

Filter nodesets in-place and don't create node sets with NULL gaps which
allows to simplify merging a great deal. Simply move matched nodes
backward and create a compact node set.

Merge xmlXPathCompOpEvalPositionalPredicate into
xmlXPathCompOpEvalPredicate.
2019-04-22 14:48:46 +02:00
Nick Wellnhofer
012f8e9284 Limit recursion depth in xmlXPathOptimizeExpression 2019-04-20 17:01:19 +02:00
Nick Wellnhofer
93a1d22380 Fix memory leaks in xmlXPathParseNameComplex error paths
Found by OSS-Fuzz.
2019-04-16 13:37:47 +02:00
Nick Wellnhofer
fa3166c227 Disable hash randomization when fuzzing
Use the FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION macro proposed by
libFuzzer.
2019-04-12 12:06:34 +02:00
Nick Wellnhofer
2d97a97aa5 Optional recursion limit when parsing XPath expressions
Useful to avoid call stack overflows when fuzzing. Note that parsing a
parenthesized expression currently consumes more than 10 stack frames,
so this limit should be set rather low.
2019-04-11 15:35:57 +02:00
Nick Wellnhofer
64115ed62d Optional recursion limit when evaluating XPath expressions
Useful to avoid call stack overflows when fuzzing.
2019-04-11 15:35:57 +02:00
Nick Wellnhofer
5153c7bace Use break statements in xmlXPathCompOpEval
This prepares for the next commit.
2019-04-11 15:35:57 +02:00
Nick Wellnhofer
852c93a2dc Optional XPath operation limit
Optionally limit the maximum numbers of XPath operations when evaluating
an expression. Useful to avoid timeouts when fuzzing. The following
operations count towards the limit:

- XPath operations
- Location step iterations
- Union operations

Enabled by setting opLimit to a non-zero value. Note that it's the user's
responsibility to reset opCount. This allows to enforce the operation
limit across multiple reuses of an XPath context.
2019-04-11 15:35:57 +02:00
Nick Wellnhofer
91d576de8b Make configure.ac work with older pkg-config
Older versions of pkg.m4 require the action-if-not-found argument of
the PKG_CHECK_MODULES macro to be non-empty. Use a colon (null command)
instead of an empty string.

Fixes #50.
2019-04-09 13:16:50 +02:00
Nick Wellnhofer
0f51861154 Fix compilation with --with-minimum
Presence of xmlEncodeAttributeEntities doesn't depend on output module.

Fixes #52.
2019-04-08 14:04:44 +02:00
Nick Wellnhofer
b9bdb9dbfd Check for integer overflow in xmlXPtrEvalChildSeq
Found with libFuzzer and UBSan.
2019-03-29 13:03:17 +01:00
Nick Wellnhofer
236dd6ab2e Check XPath stack after calling functions
Check that there's exactly one return value on the stack after calling
XPath functions. Otherwise, functions that corrupt the stack without
signaling an error could lead to memory errors.

Found with libFuzzer and UBSan.
2019-03-29 13:03:03 +01:00
Nick Wellnhofer
c494a0ba67 Fix xmllint dump of XPath namespace nodes
Starting with commit da35eeae, xmllint uses the xmlNodeDump API to dump
XPath nodes. Make sure not to access node->doc which doesn't work with
namespace nodes.
2019-03-13 11:59:21 +01:00
Nick Wellnhofer
30a6533e01 Fix float casts in xmlXPathSubstringFunction
Rewrite conversion of double to int in xmlXPathSubstringFunction, adding
range checks to avoid undefined behavior. Make sure to add start and
length as floating-point numbers before converting to int. Fix a bug
when rounding negative start indices.

Remove unneeded calls to xmlXPathIs{Inf,NaN} and rely on IEEE math
instead. Avoid computing the string length. xmlUTF8Strsub works as
expected if the length of the requested substring exceeds the input.

Found with libFuzzer and UBSan.
2019-03-08 14:29:59 +01:00
Nick Wellnhofer
09797c139e Fix null deref in xmlregexp error path
Thanks to Shaobo He for the report.
2019-03-05 15:14:34 +01:00
Nick Wellnhofer
8161b463f5 Remove debug printf in xmlreader.c
Fixes #46.
2019-02-28 12:25:05 +01:00
Nick Wellnhofer
9a82ae30db Stop defining _REENTRANT on some Win32 platforms
The _REENTRANT macro was defined unconditionally on some Win32 builds
using the Microsoft C runtime. It shouldn't have an effect under MSVCRT
and was presumably only defined because of the LIBXML_THREAD_ENABLED
issue fixed with the previous commit.
2019-02-28 12:18:37 +01:00
Michael Haubenwallner
cf68fe3d50 Always define LIBXML_THREAD_ENABLED when enabled
When libxml2 is compiled with threads enabled, have the header file
define LIBXML_THREAD_ENABLED even if the subsequent application by
itself does not enable threads.  Otherwise, the application would see
the unthreaded API functions, but these are not exported (where it does
make a difference, like on Win32 based platforms).
2019-02-28 12:17:57 +01:00
Nick Wellnhofer
2c8dc7158a Fix null pointer dereference in xmlTextReaderReadOuterXml
Fix a regression caused by commit 39fbfb4f. If xmlTextReaderReadOuterXml
is called on a pristine xmlReader, the current node is NULL and must not
be dereferenced. Move the call to xmlTextReaderExpand to the start of
the function to make sure that we have a valid node.

Fixes #43.
2019-02-25 12:08:48 +01:00
Nick Wellnhofer
a7fe7ee459 Regenerate NEWS 2019-02-15 17:37:19 +01:00
Nick Wellnhofer
538d827cc0 Change git repo URL 2019-02-15 17:37:17 +01:00
Nick Wellnhofer
04fbfa3f19 Change bug tracker URL 2019-02-15 17:34:45 +01:00
Nick Wellnhofer
656df97d6d Remove outdated HTML file 2019-02-15 17:27:15 +01:00
Nick Wellnhofer
d3de757825 Fix nanohttp.c on MinGW
Commit e3890546 broke nanohttp.c on (old) MinGW. MinGW-w64 wasn't
affected.

Should fix #36. Thanks to Simon Sobisch for the report.
2019-01-15 12:33:48 +01:00
Nick Wellnhofer
b48226f78c Fix memory leaks in xmlParseStartTag2 error paths
Found by OSS-Fuzz.
2019-01-07 18:07:00 +01:00
Nick Wellnhofer
6b49db2cb2 Fix memory leak in xmlSAX2StartElement
Introduced by a recent commit. Only happens if max depth is exceeded
in SAX1 mode.

Found by OSS-Fuzz.
2019-01-07 18:07:00 +01:00
Nick Wellnhofer
26828cb3a1 Fix commit "Memory leak in xmlFreeID (xmlreader.c)"
The recent commit "Memory leak in xmlFreeID (xmlreader.c)" introduced
a double-free.
2019-01-07 18:07:00 +01:00
Nick Wellnhofer
619534ef2e Fix Windows compiler warning in testC14N.c 2019-01-06 14:32:28 +01:00
Nick Wellnhofer
57d4329bd7 Merge testThreadsWin32.c into testThreads.c
Apply the same cross-platform modifications as previously in runtest.c.
2019-01-06 14:32:28 +01:00
Nick Wellnhofer
7f40ed01f7 Fix Python bindings under Windows
- Correct linker flags for MinGW-w64
- Adjust PATH to find libxml2.dll when running tests
2019-01-06 14:32:28 +01:00
Nick Wellnhofer
e8fdf5df6e Fix unused function warning in testapi.c
Check whether all param and return types are known before generating
functions for param types. Otherwise, unused functions end up in
testapi.c.
2019-01-06 14:25:18 +01:00
Nick Wellnhofer
731b506409 Add some generated test files to .gitignore 2019-01-06 14:25:18 +01:00
Nick Wellnhofer
dcae579eca Remove unneeded function pointer casts 2019-01-06 14:25:18 +01:00
Nick Wellnhofer
19f0950d30 Fix -Wcast-function-type warnings (GCC 8)
Use xmlGenericError instead of fprintf as error handler. It also prints
to stderr by default.
2019-01-06 14:25:12 +01:00
Nick Wellnhofer
8919885ff9 Fix -Wformat-truncation warnings (GCC 8) 2019-01-06 14:24:59 +01:00
Nick Wellnhofer
157cd3aed7 Fix NULL pointer deref in xmlTextReaderValidateEntity
Found by OSS-Fuzz.
2019-01-06 14:05:36 +01:00
Nick Wellnhofer
57a3af56f4 Memory leak in xmlFreeTextReader
In error cases, there might still be elements in the vstate table.
Since vstateVPop in valid.c is private, we have to pop the elements
with xmlValidatePopElement. This inspects nodes of the document, so
the reader doc must be freed after the clearing the vstate table.

Found by OSS-Fuzz.
2019-01-06 14:05:36 +01:00
Nick Wellnhofer
efe8c093c4 Memory leak in xmlFreeID (xmlreader.c)
Fix a memory leak in xmlReader's private copy of xmlFreeID. Only
affects validation with NODICT.

Found by OSS-Fuzz.
2019-01-06 14:05:36 +01:00