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

201 Commits

Author SHA1 Message Date
Nick Wellnhofer
e75e878e02 doc: Update and fix documentation 2024-05-20 14:23:39 +02:00
Nick Wellnhofer
577fb0e380 xinclude: Report malloc failure in xmlXIncludeMergeEntities 2024-04-27 16:31:01 +02:00
Nick Wellnhofer
087a346448 xinclude: Increase error count in xmlXIncludeErrMemory 2024-04-22 12:44:12 +02:00
Nick Wellnhofer
16ccb61dc1 xinclude: Don't try to fix base of non-elements
This would result in a spurious error.
2024-04-05 13:19:56 +02:00
Nick Wellnhofer
365976dbe0 xinclude: Don't use xmlHasNsProp
This function can malloc and doesn't report failures.

Another design mistake is that xmlUnsetNsProp requires an xmlNs
struct.
2024-03-30 17:17:21 +01:00
Nick Wellnhofer
f43197fca7 tree: Don't coalesce text nodes in xmlAdd{Prev,Next}Sibling
Commit 9e1c72da from 2001 introduced a bug where xmlAddPrevSibling and
xmlAddNextSibling would only try to merge text nodes with one of its
new siblings. Commit 4ccd3eb8 fixed this bug but unfortunately, lxml
and possibly other downstream code depend on text nodes not being
merged.

To avoid breaking downstream code while still having somewhat
consistent API behavior, it's probably best to make these functions
never coalesce text nodes.
2024-03-29 14:21:11 +01:00
Nick Wellnhofer
1ace0e8529 xinclude: Report malloc failure in xmlXIncludeAddNode 2024-03-24 12:28:22 +01:00
Nick Wellnhofer
0d04d79cd4 xinclude: Report malloc failures in xmlXIncludeIncludeNode 2024-03-22 12:26:28 +01:00
Nick Wellnhofer
3bdd0d7b30 xinclude: Set errNo in xmlXIncludeErrMemory 2024-03-18 14:13:15 +01:00
Nick Wellnhofer
12f0bb9478 parser: Synchronize more options 2024-01-05 20:39:40 +01:00
Nick Wellnhofer
0821efc8ee encoding: Check whether encoding handlers support input/output
The "HTML" encoding handler doesn't support input which could lead to a
wrong error report.
2024-01-02 19:48:23 +01:00
Nick Wellnhofer
e8fb3d639f parser: Convert some "internal errors" to meaningful codes 2024-01-02 19:48:23 +01:00
Nick Wellnhofer
2a2fbe1e5b xinclude: Only set xml:base if necessary 2023-12-28 16:47:45 +01:00
Nick Wellnhofer
8a685a3dfc xinclude: Allow empty nodesets
There's no reason to treat an empty nodeset as error.
2023-12-28 16:47:45 +01:00
Nick Wellnhofer
955c177f69 parser: Stop using 'directory' struct member
This was only used as a pointless fallback for URI resolution.
2023-12-25 23:38:40 +01:00
Nick Wellnhofer
6e3a2ac660 xinclude: Rework xml:base fixup
The xml:base fixup was broken in more complex cases.

Also avoid parsing and building the included URI multiple times.
2023-12-25 23:38:40 +01:00
Nick Wellnhofer
35a4bc50d0 xinclude: Report to xmlGenericError 2023-12-25 23:38:40 +01:00
Nick Wellnhofer
c8f1f4a280 doc: Improve documentation of error handlers 2023-12-21 17:36:17 +01:00
Nick Wellnhofer
0a658c0f0a io: Don't use "-" to read from stdin
To implement this feature on such a low level is a disaster waiting to
happen. Remove these checks from the IO code and move them to xmllint.

Note that the serialization API will still treat "-" as stdout.
2023-12-21 15:02:24 +01:00
Nick Wellnhofer
2829a21a95 xinclude: Improve error handling
Introduce xmlXIncludeSetErrorHandler allowing to set a structured error
handler for an XInclude context and forwarding errors from parser.

Remove arguments from memory error handlers.

Use xmlRaiseMemoryError.
2023-12-21 02:46:27 +01:00
Nick Wellnhofer
78eab7a130 xinclude: Report malloc failures
Fix many places where malloc failures aren't reported.

Introduce a new API function xmlXIncludeGetLastError.
2023-12-11 22:13:05 +01:00
Nick Wellnhofer
80a0580f23 xinclude: Expand comment about fuzz timeouts 2023-09-30 15:47:46 +02:00
Nick Wellnhofer
b9db3d7d02 parser: Simplify xmlStringCurrentChar
Start to move away from using this function.
2023-09-22 19:01:11 +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
4aa08c80b7 xinclude: Fix 'last' pointer in xmlXIncludeCopyNode
Also set the 'last' pointer for the root node.

Fixes https://gitlab.gnome.org/GNOME/libxslt/-/issues/93
2023-09-08 14:52:22 +02:00
Nick Wellnhofer
687a2b719e xinclude: Lower initial table size when fuzzing
We don't have test cases with many documents, so set the initial table
size to 1 when fuzzing, so there is a chance to detect reallocation
issues.
2023-05-11 13:27:52 +02:00
Nick Wellnhofer
c40cbf07a3 malloc-fail: Fix null deref after xmlXIncludeNewRef
See #344.
2023-05-11 13:27:52 +02:00
Nick Wellnhofer
105ce73da0 xinclude: Fix false positives in inclusion loop detection
xmlXIncludeRecurseDoc can realloc the cache.
2023-05-11 13:27:52 +02:00
Nick Wellnhofer
ec05f04d8b malloc-fail: Fix memory leak in xmlXIncludeLoadTxt
Found with libFuzzer, see #344.
2023-02-17 17:16:52 +01:00
Nick Wellnhofer
c02df68651 malloc-fail: Fix memory leak in xmlXIncludeLoadDoc
Found with libFuzzer, see #344.
2023-02-17 17:16:52 +01:00
Nick Wellnhofer
3b59fdf001 malloc-fail: Fix memory leak in xmlXIncludeAddNode
Found with libFuzzer, see #344.
2023-02-17 17:16:51 +01:00
Nick Wellnhofer
e20f4d7a65 xinclude: Fix quadratic behavior in xmlXIncludeLoadTxt
Also make text inclusions work with memory buffers, for example when
using a custom entity loader, and fix a memory leak in case of invalid
characters.

Fixes #483.
2023-02-14 12:25:07 +01:00
Nick Wellnhofer
a96312db51 xinclude: Avoid timeouts when fuzzing
Fix the check for maximum number of inclusions.
2023-02-13 11:29:26 +01:00
Nick Wellnhofer
be0ec005f3 xinclude: Abort immediately if max depth was exceeded
Avoids resource exhaustion if the maximum recursion depth was exceeded.

Note that the XInclude engine offers no protection against other
"billion laughs"-style amplification attacks as long as they stay below
the maximum depth.
2023-02-13 11:29:26 +01:00
Nick Wellnhofer
dc2dde1ab9 malloc-fail: Fix null deref in xmlXIncludeLoadTxt
Found with libFuzzer, see #344.
2023-02-13 11:19:55 +01:00
Nick Wellnhofer
a3749551e6 malloc-fail: Fix reallocation in xmlXIncludeNewRef
Avoid null deref.

Found with libFuzzer, see #344.
2023-02-13 11:19:55 +01:00
Nick Wellnhofer
5a19e21605 malloc-fail: Fix use-after-free in xmlXIncludeAddNode
Found with libFuzzer, see #344.
2022-11-02 16:13:27 +01:00
Nick Wellnhofer
b456e3bb42 xinclude: Always allow XPtr expressions in external documents 2022-10-31 16:49:36 +01:00
Nick Wellnhofer
f14529baf5 xinclude: Fix more memory leaks in xmlXIncludeLoadDoc 2022-10-30 14:12:55 +01:00
Nick Wellnhofer
eef0a7395c xinclude: Implement "streaming" mode
When using xmlreader, XPointer expressions in XIncludes simply cannot
work. Expressions can reference nodes which weren't parsed yet or which
were already deleted.

After fixing nested XIncludes, we reference includes which were parsed
previously. When streaming, these nodes could have been deleted, leading
to use-after-free errors.

Disallow XPointer expressions and truncate the include table in
streaming mode.
2022-10-30 14:12:55 +01:00
Nick Wellnhofer
7e078cc1fe xinclude: Clean up xmlXIncludeDoProcess
Only scan new includes in the second pass. Always reset the "replace"
flag.

This only matters if xmlXIncludeDoProcess is called multiple times on
the same document which currently only happens when called from
xmlreader.
2022-10-30 14:12:55 +01:00
Nick Wellnhofer
075cee9e9f xinclude: Fix memory leak when fuzzing
This only affects the fuzzing build mode.
2022-10-29 15:42:01 +02:00
Nick Wellnhofer
b59ff58728 xinclude: Fix memory leak in xmlXIncludeLoadDoc
Regressed in a recent commit.
2022-10-28 20:08:02 +02:00
Nick Wellnhofer
20e2fb4c1c xinclude: Avoid creation of subcontexts
Don't create subcontext in xmlXIncludeRecurseDoc. Save and restore 'doc'
and 'incTab' instead.

Make xmlXIncludeLoadFallback call xmlXIncludeCopyNode which seems safer
than xmlXIncludeDoProcess since the latter may modify the document.
This should also be more performant since we need to copy the whole
fallback subtree anyway. Also make sure to avoid replacements in
fallback elements in xmlXIncludeDoProcess.
2022-10-25 19:34:38 +02:00
Nick Wellnhofer
010b682fee xinclude: Rework XInclude cache
Use a single cache stored in the "root" context, avoiding cache misses
in some scenarios. Separate the cache from the "include" table. Rework
recursion check.
2022-10-23 18:55:10 +02:00
Nick Wellnhofer
3b68aa4753 xinclude: Remove unused 'doc' argument from xmlXIncludeDoProcess 2022-10-23 18:55:10 +02:00
Nick Wellnhofer
0b09f132f4 xinclude: Remove unused member 'url' from xmlXIncludeCtxt 2022-10-23 18:52:56 +02:00
Nick Wellnhofer
966f5ebd77 xinclude: Remove inefficient refcounting scheme
xinclude.c used to implement a refcounting mechanism for documents which
could result in documents being freed too early and reloaded. We really
should keep parsed and processed documents around for as long as
possible to avoid reprocessing.
2022-10-23 18:52:56 +02:00
Nick Wellnhofer
fe0194d56f xinlucde: Pass xmlXIncludeRefPtrs directly
Stop passing indices into the include table.
2022-10-23 18:52:56 +02:00