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

541 Commits

Author SHA1 Message Date
Nick Wellnhofer
f307237e14 schemas: Use private copy of global NaN and Inf
Simplify symbol availability logic.
2024-06-16 18:47:12 +02:00
Nick Wellnhofer
669bd34993 xpointer: Remove support for XPointer locations
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.

If you configure --with-legacy, old symbols are retained for ABI
compatibility.
2024-06-12 18:20:01 +02:00
Nick Wellnhofer
e75e878e02 doc: Update and fix documentation 2024-05-20 14:23:39 +02:00
Nick Wellnhofer
8d215ac5cc xpath: Fix quadratic runtime accounting 2024-05-14 15:55:18 +02:00
Nick Wellnhofer
63ce5f9aed Make some globals const 2024-04-28 17:53:39 +02:00
Nick Wellnhofer
20b0bd9800 fuzz: Account for quadratic runtime in xmlXPathTranslateFunction
Avoid fuzzer timeouts caused by this known issue.
2024-04-09 18:00:13 +02:00
Nick Wellnhofer
047ea3ecb3 Revert "tree: Allocate XML namespace statically"
This reverts commit 2840e33c5e.
2024-03-17 21:04:40 +01:00
Nick Wellnhofer
05adfbf880 buf: Don't use default buffer size for small strings
Detaching strings from a buffer with a default size of 4096 can waste
a lot of memory.
2024-03-15 19:47:08 +01:00
Nick Wellnhofer
2840e33c5e tree: Allocate XML namespace statically 2024-03-15 19:47:07 +01:00
Nick Wellnhofer
2963a097b9 xpath: Report malloc failure in xmlXPathTranslateFunction 2024-02-05 15:35:54 +01:00
Nick Wellnhofer
37d474ff7e xpath: Fix return of empty node-set in xmlXPathNodeCollectAndTest
Don't return NULL node-sets. Ultimately, we should make sure that
obj->nodesetval is always non-NULL even for empty node-sets.

See #663.
2024-01-17 14:19:42 +01:00
Nick Wellnhofer
b8313b589f xpath: Rewrite substring-before and substring-after
Don't use buffers. Check malloc failures.
2023-12-28 16:47:45 +01:00
Nick Wellnhofer
c8f1f4a280 doc: Improve documentation of error handlers 2023-12-21 17:36:17 +01:00
Nick Wellnhofer
531d06add6 error: Stop printing some errors by default
Unfortunately, it's long-standing behavior for libxml2 to print all
reported errors to stderr by default. This default behavior is now
partially disabled. If no error handler is set, only parser and
validation errors are passed to a generic error handler or printed to
stderr. Other errors are still available via xmlGetLastError and can be
captured with a structured error handler.
2023-12-21 15:02:24 +01:00
Nick Wellnhofer
954b898494 xpath: Improve error handling
Introduce xmlXPathSetErrorHandler allowing to set a structured error
handler for an XPath context.

Remove arguments from memory error handlers.

Use xmlRaiseMemoryError.

Remove TODO, STRANGE and CHECK_CTXT macros.

Remove remaining uses of xmlGenericError.
2023-12-21 02:46:27 +01:00
Nick Wellnhofer
6fdc20ba36 xpath: Don't free nodes of XSLT result value trees
This feature hasn't been required for a long time and libxslt works
around by manually setting 'boolval' to 0.
2023-12-20 19:00:42 +01:00
Nick Wellnhofer
bcefef202e malloc-fail: Report malloc failure in xmlXPathNumberFunction 2023-12-20 14:40:27 +01:00
Nick Wellnhofer
6ae98ebc64 malloc-fail: Report malloc failure in xmlXPathTranslateFunction 2023-12-15 15:03:39 +01:00
Nick Wellnhofer
8583b9f1cd malloc-fail: Fix null deref in xmlXPathTranslateFunction
Short-lived regression.
2023-12-12 15:19:07 +01:00
Nick Wellnhofer
e632d9f02e xpath: Report malloc failures
Fix many places where malloc failures aren't reported.

Rework XPath object cache to store free objects in a linked list to
avoid allocating an additional array. Remove some unneeded object pools.
2023-12-11 22:13:05 +01:00
Nick Wellnhofer
8c084ebdc7 doc: Make apibuild.py happy 2023-09-21 22:57:33 +02:00
Nick Wellnhofer
9b5cce7a71 include: Remove more unnecessary includes 2023-09-21 01:50:53 +02:00
Nick Wellnhofer
699299cae3 globals: Stop including globals.h 2023-09-20 22:07:40 +02:00
Nick Wellnhofer
4e1c13ebfd debug: Remove debugging code
This is barely useful these days and only clutters the code base.
2023-09-19 17:35:09 +02:00
Nick Wellnhofer
6273df6c6d xpath: Ignore entity ref nodes when computing node hash
XPath queries only work reliably if entities are substituted.
Nevertheless, it's possible to query a document with entity reference
nodes. xmllint even deletes entities when the `--dropdtd` option is
passed, resulting in dangling pointers, so it's best to skip entity
reference nodes to avoid a use-after-free.

Fixes #550.
2023-05-30 12:30:27 +02:00
Nick Wellnhofer
01723fc68f xpath: Fix build without LIBXML_XPATH_ENABLED
Move static function declaration into XPATH block. Also move comparison
functions.

Fixes #537.
2023-05-08 23:15:30 +02:00
Nick Wellnhofer
b1319c902f malloc-fail: Check for malloc failures when creating XPath strings
Prevent null derefs.

Found by OSS-Fuzz, see #344.
2023-03-18 16:51:43 +01:00
Nick Wellnhofer
483793940c malloc-fail: Stop using XPath stack frames
There's too much code which assumes that if ctxt->value is non-null,
a value can be successfully popped off the stack. This assumption can
break with stack frames when malloc fails.

Instead of trying to fix all call sites, remove the stack frame logic.
It only offered very little protection against misbehaving extension
functions. We already check the stack size after a function call which
should be enough.

Found by OSS-Fuzz.
2023-03-13 17:11:27 +01:00
Nick Wellnhofer
bd6fa2c1d5 malloc-fail: Fix memory leak in xmlXPathRegisterNs
Found by OSS-Fuzz.
2023-03-09 22:33:19 +01:00
Nick Wellnhofer
282b75f110 malloc-fail: Fix memory leak in xmlXPathNameFunction
Found with libFuzzer, see #344.
2023-02-28 21:23:11 +01:00
Nick Wellnhofer
524654ed3c xpath: Fix harmless integer overflow in xmlXPathTranslateFunction 2023-02-27 17:18:11 +01:00
Nick Wellnhofer
8608b71fbc Revert "xpath: Fix popping of values in xmlXPathPopNodeset"
This reverts commit 47b0e0a620.
2023-02-27 17:18:11 +01:00
Nick Wellnhofer
bc9f372c10 malloc-fail: Fix memory leak in xmlXPathDistinctSorted
Found with libFuzzer, see #344.
2023-02-27 17:18:08 +01:00
Nick Wellnhofer
6f9604f0e3 malloc-fail: Fix memory leak in xmlXPathCacheNewNodeSet
Found with libFuzzer, see #344.
2023-02-27 17:18:06 +01:00
Nick Wellnhofer
44947afba0 malloc-fail: Fix null deref after xmlPointerListAddSize
Found with libFuzzer, see #344.
2023-02-27 17:17:50 +01:00
Nick Wellnhofer
70b21c9f2a malloc-fail: Fix null deref in xmlXPathCompiledEvalInternal
Found with libFuzzer, see #344.
2023-02-27 17:14:25 +01:00
Nick Wellnhofer
0f112d0289 malloc-fail: Fix use-after-free related to xmlXPathNodeSetFilter
Found with libFuzzer, see #344.
2023-02-26 13:25:01 +01:00
Nick Wellnhofer
a3e11b385c malloc-fail: Fix memory leak in xmlXPathEqualNodeSetFloat
Found with libFuzzer, see #344.
2023-02-26 13:24:55 +01:00
Nick Wellnhofer
b51478dc95 Revert "malloc-fail: Avoid use-after-free after unsuccessful valuePush"
This reverts commit 6a12be77c6.

There's too much code reading ctxt->value directly and making the wrong
assumptions.
2023-02-26 13:23:47 +01:00
Nick Wellnhofer
47b0e0a620 xpath: Fix popping of values in xmlXPathPopNodeset
After 6a12be77, valuePop can fail even if ctxt->value is non-NULL.

If it turns out that too much code relies on this assumption, a better
fix is needed.
2023-02-23 15:43:15 +01:00
Nick Wellnhofer
8d22e06588 malloc-fail: Fix memory leak after calling xmlXPathNodeSetMerge
Destroy the first argument in xmlXPathNodeSetMerge if the function
fails. This is somewhat dangerous but matches the expectations of users.

Found with libFuzzer, see #344.
2023-02-17 17:16:52 +01:00
Nick Wellnhofer
d31a0e8e75 malloc-fail: Fix memory leak after calling xmlXPathWrapString
Destroy the string in xmlXPathWrapString if the function fails. This is
somewhat dangerous but matches the expectations of users.

Found with libFuzzer, see #344.
2023-02-17 17:16:52 +01:00
Nick Wellnhofer
3dc645227e malloc-fail: Fix memory leak in xmlXPathEqualValuesCommon
Found with libFuzzer, see #344.
2023-02-17 17:16:52 +01:00
Nick Wellnhofer
691f7eb44d malloc-fail: Fix memory leak in xmlXPathCompareValues
Found with libFuzzer, see #344.
2023-02-17 17:16:51 +01:00
Nick Wellnhofer
ac746afd33 malloc-fail: Fix memory leak in xmlXPathTryStreamCompile
Found with libFuzzer, see #344.
2023-02-17 17:16:51 +01:00
Nick Wellnhofer
85bc313e79 malloc-fail: Fix memory leak after calling valuePush
Destroy the object in valuePush if the function fails. This is somewhat
dangerous but matches the expectations of users.

Found with libFuzzer, see #344.
2023-02-17 17:16:51 +01:00
Nick Wellnhofer
f5e1174933 malloc-fail: Fix memory leak after calling xmlXPathWrapNodeSet
Destroy the node set in xmlXPathWrapNodeSet if the function fails.
This is somewhat dangerous but matches the expectations of users.

Found with libFuzzer, see #344.
2023-02-17 17:16:51 +01:00
Nick Wellnhofer
15c9f43533 xpath: Only report the first error
Don't overwrite the original error code. Besides, subsequent error
reports are somewhat unreliable and not really useful.
2023-02-03 13:38:24 +01:00
Nick Wellnhofer
6a12be77c6 malloc-fail: Avoid use-after-free after unsuccessful valuePush
In xpath.c there's a lot of code like:

    valuePush(ctxt, xmlCacheNewX());
    ...
    valuePop(ctxt);

If xmlCacheNewX fails, no value will be pushed on the stack. If there's
no error check in between, valuePop will pop an unrelated value which
can lead to use-after-free errors.

Instead of trying to fix all call sites, we simply stop popping values
if an error was signaled. This requires to change the CHECK_TYPE macro
which is often used to determine whether a value can be safely popped.

Found with libFuzzer, see #344.
2023-02-03 12:40:15 +01:00
Nick Wellnhofer
7ec314efcd malloc-fail: Add error checks in xmlXPathEqualValuesCommon
Avoid null deref.

Found with libFuzzer, see #344.
2023-02-03 12:40:15 +01:00