1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-01-15 23:24:06 +03:00

485 Commits

Author SHA1 Message Date
Nick Wellnhofer
b6f1298ae7 warnings: Remove set-but-unused variables
Fixes compiler warnings with clang 15.
2022-10-25 19:34:38 +02:00
Nick Wellnhofer
27c8ba6054 xpath: Lower XPath recursion limit on Windows 2022-09-07 22:34:42 +02:00
Nick Wellnhofer
0d90125859 Fix Windows compiler warnings in python/types.c 2022-09-04 18:36:04 +02:00
Nick Wellnhofer
6843fc726f Remove or annotate char casts 2022-09-01 04:31:30 +02:00
Nick Wellnhofer
2cac626976 Don't use sizeof(xmlChar) or sizeof(char) 2022-09-01 03:35:19 +02:00
Nick Wellnhofer
ad338ca737 Remove explicit integer casts
Remove explicit integer casts as final operation

- in assignments
- when passing arguments
- when returning values

Remove casts

- to the same type
- from certain range-bound values

The main motivation is that these explicit casts don't change the result
of operations and only render UBSan's implicit-conversion checks
useless. Removing these casts allows UBSan to detect cases where
truncation or sign-changes occur unexpectedly.

Document some explicit casts as truncating and add a few missing ones.
2022-09-01 02:33:57 +02:00
Nick Wellnhofer
8016c8edcc Remove set-but-unused variable in xmlXPathScanName
Fix clang warning.
2022-08-26 15:12:21 +02:00
Nick Wellnhofer
0f568c0b73 Consolidate private header files
Private functions were previously declared

- in header files in the root directory
- in public headers guarded with IN_LIBXML
- in libxml.h
- redundantly in source files that used them.

Consolidate all private header files in include/private.
2022-08-26 02:11:56 +02:00
Nick Wellnhofer
677a42645e Make XPath depth check work with recursive invocations
EXSLT functions like dyn:map or dyn:evaluate invoke xmlXPathRunEval
recursively. Don't set depth to zero but keep and restore the original
value to avoid stack overflows when abusing these functions.
2022-07-28 21:36:10 +02:00
Sergey Kosukhin
c9925454fd Use NAN/INFINITY if available to init XPath NaN/Inf 2022-07-06 17:08:26 +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
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
Nick Wellnhofer
0e9776b070 Initialize XPath floating-point globals
Should fix #138.
2022-04-03 17:11:03 +02:00
jinsub ahn
74263eff5f fix: xmlXPathParserContext could be double-delete in OOM case. 2022-03-30 06:02:31 +00:00
Nick Wellnhofer
40483d0ce2 Deprecate module init and cleanup functions
These functions shouldn't be part of the public API. Most init
functions are only thread-safe when called from xmlInitParser. Global
variables should only be cleaned up by calling xmlCleanupParser.
2022-03-06 15:59:43 +01:00
Nick Wellnhofer
57b81c208c Normalize XPath strings in-place
Simplify the code and fix a potential memory leak.

Fixes #343.
2022-03-05 18:22:51 +01:00
Nick Wellnhofer
4a8c71eb7c Remove DOCBparser
This code has been broken and deprecated since version 2.6.0, released
in 2003. Because of a bug in commit 961b535c, DOCBparser.c was never
compiled since 2012. I couldn't find a Debian package using any of its
symbols, so it seems safe to remove this module.
2022-03-04 22:56:21 +01:00
Nick Wellnhofer
ebb1797030 Remove unneeded #includes 2022-03-04 22:11:49 +01:00
Nick Wellnhofer
776d15d383 Don't check for standard C89 headers
Don't check for

- ctype.h
- errno.h
- float.h
- limits.h
- math.h
- signal.h
- stdarg.h
- stdlib.h
- string.h
- time.h

Stop including non-standard headers

- malloc.h
- strings.h
2022-03-02 00:43:54 +01:00
Nick Wellnhofer
346c3a930c Remove elfgcchack.h
The same optimization can be enabled with -fno-semantic-interposition
since GCC 5. clang has always used this option by default.
2022-02-20 21:49:04 +01:00
Nick Wellnhofer
67953a9f11 Fix memory leak in xmlXPathCompNodeTest
Found by Coverity.
2022-01-16 15:30:02 +01:00
Nick Wellnhofer
3e1aad4fe5 Fix XPath recursion limit
Fix accounting of recursion depth when parsing XPath expressions.

This silly bug introduced in commit 804c5297 could lead to spurious
errors when parsing larger expressions or XSLT documents.

Should fix #264.
2021-06-02 17:39:41 +02:00
Nick Wellnhofer
868e49cffd Allow FP division by zero in xmlXPathInit 2021-03-16 10:36:04 +01:00
Nick Wellnhofer
d25460da14 Fix XPath NaN/Inf for older GCC versions
The DBL_MAX approach could lead to errors caused by excess precision.
Switch back to the division-by-zero approach with a work-around for
MSVC and use the extern globals instead of macro expressions.
2021-03-13 19:14:27 +01:00
Nick Wellnhofer
e6ec58ecf7 Fix null deref in XPointer expression error path
Make sure that the filter functions introduced with commit c2f4da1a
return node-sets without NULL pointers also in the error case.

Found by OSS-Fuzz.
2020-09-21 12:49:36 +02:00
Nick Wellnhofer
8b88503a27 Don't call xmlXPathInit directly
Call xmlInitParser which uses a lock to avoid race conditions.

Fixes #184.
2020-09-18 19:15:27 +02:00
Nick Wellnhofer
6f1470a5d6 Hardcode maximum XPath recursion depth
Always limit nested functions calls to 5000. This avoids call stack
overflows with deeply nested expressions.

The expression parser produces about 10 nested function calls when
parsing a subexpression in parentheses, so the effective nesting limit
is about 500 which should be more than enough.

Use a lower limit when fuzzing to account for increased memory usage
when using sanitizers.
2020-08-26 00:22:25 +02:00
Nick Wellnhofer
804c52978f Stop using maxParserDepth in xpath.c
Only use a single maxDepth value.
2020-08-17 03:39:51 +02:00
Nick Wellnhofer
beb7d71a8f Remove misleading comments in xpath.c
Fixes #169
2020-07-13 12:41:19 +02:00
Nick Wellnhofer
9f42f6baaa Don't follow next pointer on documents in xmlXPathRunStreamEval
RVTs from libxslt are document nodes which are linked using the 'next'
pointer. These pointers must never be used to navigate the document
tree. Otherwise, random content from other RVTs could be returned
when evaluating XPath expressions.

It's interesting that this seemingly long-standing bug wasn't
discovered earlier. This issue could also cause severe performance
degradation.

Fixes https://gitlab.gnome.org/GNOME/libxslt/-/issues/37
2020-06-24 15:33:38 +02:00
Nick Wellnhofer
487871b0e3 Fix undefined behavior in xmlXPathTryStreamCompile
&NULL[0] is undefined behavior.
2020-06-10 13:23:43 +02:00
Nick Wellnhofer
20c60886e4 Fix typos
Resolves #133.
2020-03-08 17:41:53 +01:00
Nick Wellnhofer
2c80fc9116 Fix more memory leaks in error paths of XPath parser
Found by OSS-Fuzz.
2019-12-02 11:30:30 +01:00
Nick Wellnhofer
d5f2f74d0f Fix memory leak in error path of XPath expr parser
Also propagate memory errors.

Found by OSS-Fuzz.
2019-11-11 11:27:40 +01:00
Nick Wellnhofer
bfc0f674cc Audit memory error handling in xpath.c
Memory allocation errors in the following functions a often ignored.
Add TODO comments.

- xmlXPathNodeSetCreate
- xmlXPathNodeSetAdd*
- xmlXPathNodeSetMerge*
- xmlXPathNodeSetDupNs

Note that the following functions currently lack a way to propagate
memory errors:

- xmlXPathCompareNodeSets
- xmlXPathEqualNodeSets
2019-10-20 14:39:46 +02:00
Nick Wellnhofer
429d4ecaae Propagate memory errors in valuePush
Currently, many memory allocation errors in xpath.c aren't propagated to
the parser/evaluation context and for the most part ignored. Most
XPath objects allocated via one of the New, Wrap or Copy functions end
up being pushed on the stack, so adding a check in valuePush handles
many cases without much effort.

Also simplify the code a little and make sure to return -1 in case of
error.
2019-10-20 14:38:05 +02:00
Nick Wellnhofer
390f05e703 Propagate memory errors in xmlXPathCompExprAdd
Make sure that memory errors in xmlXPathCompExprAdd are propagated to
the parser context. Hitting the step limit or running out of memory
without raising an error could also lead to an out-of-bounds read.

Also fixes a memory leak in xmlXPathErrMemory.

Found by OSS-Fuzz.
2019-10-20 14:13:05 +02:00
Jared Yanovich
2a350ee9b4 Large batch of typo fixes
Closes #109.
2019-09-30 18:04:38 +02:00
Nick Wellnhofer
6705f4d28e Remove executable bit from non-executable files 2019-09-16 15:48:59 +02:00
Jan Pokorný
5c0e48b883 Fix typo: xpath: simpli{ -> fi}ed
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-08-25 13:31:18 +02:00
zhouzhongyuan
59028ba08c Fix possible null dereference in xmlXPathIdFunction
If a certain memory allocation fails, xmlXPathIdFunction would
dereference a null pointer.

Closes #77.
2019-08-25 13:19:29 +02:00
Daniel Richard G
b17e3d1c2b Work around buggy ceil() function on AIX
AIX has a buggy ceil() function that does not handle negative-zero
correctly.

Closes #79.
2019-08-02 13:18:13 +02:00
Nick Wellnhofer
e79a903f3e Remove redundant code in xmlXPathCompRelationalExpr
Thanks to Anish K Kurian for the report. Closes #59.
2019-05-20 13:38:22 +02:00
Nick Wellnhofer
44e7a0d5f7 Annotate functions with __attribute__((no_sanitize)) 2019-05-20 13:38:22 +02:00
Nick Wellnhofer
14ed63b7d0 Limit recursion depth in xmlXPathCompOpEvalPredicate 2019-05-08 12:00:51 +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