1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-24 13:33:01 +03:00
Commit Graph

605 Commits

Author SHA1 Message Date
Nick Wellnhofer
09905670f4 tree: Don't free linked DOM namespaces in error case 2024-03-15 19:54:27 +01:00
Nick Wellnhofer
27f07f1002 tree: Report malloc failure in xmlDOMWrapCloneNode
Also don't store text content in dictionaries.
2024-03-15 19:54:26 +01:00
Nick Wellnhofer
8d04f0eea0 tree: Refactor text node updates 2024-03-15 19:54:26 +01:00
Nick Wellnhofer
4ccd3eb80f tree: Refactor node insertion
Also fixes a text coalescing bug.
2024-03-15 19:54:26 +01:00
Nick Wellnhofer
9f049afa6d tree: Refactor element creation and parsing of attribute values
Replace xmlStringGetNodeList and xmlStringLenGetNodeList with
xmlNodeParseContentInternal which also updates an optional parent
node.

Don't look up entities a second time via xmlNewReference.
2024-03-15 19:54:26 +01:00
Nick Wellnhofer
9991fae4f4 tree: Simplify xmlNodeGetContent, xmlBufGetNodeContent
Factor out xmlBufGetEntityRefContent and xmlBufGetChildContent.

Also allow entity declarations.

Optimize single text children.

Ignore missing or recursive entities silently.

Prefer xmlNodeGetContent over xmlNodeListGetString.

Check for entity cycles in xmlBufGetNodeContent.

Use children pointer of entity reference nodes if available to look up
entities.
2024-03-15 19:47:08 +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
e3342f731c tree: Work on documentation 2024-03-15 19:47:08 +01:00
Nick Wellnhofer
8677f54703 malloc-fail: Fix erroneous report in xmlNodeGetBaseSafe 2024-03-15 19:47:08 +01:00
Nick Wellnhofer
9b3750c660 malloc-fail: Avoid use-after-free in xmlAddChild
Returning NULL doesn't signal that the node was freed.
2024-03-15 19:47:08 +01:00
Nick Wellnhofer
702f2e463c malloc-fail: Fix memory leak in xmlNewNodeEatName 2024-03-15 19:47:08 +01:00
Nick Wellnhofer
b043d9590e tree: Check return value of xmlNodeAddContent 2024-03-15 19:47:07 +01:00
Nick Wellnhofer
18ebdacf80 tree: Fix error return in xmlGetPropNodeValueInternal 2024-03-15 19:47:07 +01:00
Nick Wellnhofer
e4e9096164 tree: Prefer xmlGetPropNodeInternal over xmlHasNsProp
xmlHasNsProp can cause unreported malloc failures when looking up
default attributes. Switch to xmlGetPropNodeInternal when moving
attributes. We don't care about default attributes in this case.
2024-03-15 19:47:07 +01:00
Nick Wellnhofer
7d9ffd40e1 tree: Report malloc failure in xmlAddNextSibling 2024-03-15 19:47:07 +01:00
Nick Wellnhofer
bc7ab5a2e6 tree: Rewrite xmlSetTreeDoc
Report malloc failures.

Fix when called directly on attribute node.

Clear 'content' and 'last' and look up new entity for entity reference
nodes.
2024-03-15 19:47:07 +01:00
Nick Wellnhofer
2ba690a78f tree: Remove more unused node types 2024-03-15 19:47:07 +01:00
Nick Wellnhofer
fc9a2ca0f3 tree: Report more malloc failures 2024-03-15 19:47:07 +01:00
Nick Wellnhofer
536aa2cd3e tree: Fix adding ids in xmlNewPropInternal
Don't try to add ids to NULL document.

Report malloc failure from xmlIsID.
2024-03-15 19:47:07 +01:00
Nick Wellnhofer
d0d6174e81 valid: Rework xmlAddID 2024-03-15 19:47:07 +01:00
Nick Wellnhofer
d57c57ed2f tree: Improve argument check in xmlTextConcat 2024-03-15 19:47:07 +01:00
Nick Wellnhofer
16c2955733 tree: Remove unused node types 2024-03-15 19:47:07 +01:00
Nick Wellnhofer
f960c60d18 tree: Make namespace comparison more consistent
The API allows NULL namespace URIs, so we should match them
consistently. Simply use xmlStrEqual which already takes NULL strings
into account.
2024-03-15 19:47:07 +01:00
Nick Wellnhofer
d1cc6f7df2 tree: Don't allow NULL name in xmlSetNsProp 2024-03-15 19:47:07 +01:00
Nick Wellnhofer
2840e33c5e tree: Allocate XML namespace statically 2024-03-15 19:47:07 +01:00
Nick Wellnhofer
696faeb474 tree: Rework xmlNodeListGetString
Use string buffer to avoid quadratic complexity.

Handle entities with xmlBufGetNodeContent.

Report malloc failures.
2024-03-15 19:47:07 +01:00
Nick Wellnhofer
4196454818 tree: Rework xmlTextMerge
Return NULL on error. Check for malloc failure. Check that nodes are
distinct.
2024-03-15 19:47:07 +01:00
Nick Wellnhofer
a3713f78e3 tree: Rework xmlNodeSetName
Disallow xmlNodeSetName on DTD nodes. DTD nodes don't store the name in
a dictionary. Calling xmlNodeSetName with a DTD node could result in an
invalid free.

This function doesn't report errors but we can make sure that name
isn't set to NULL.
2024-03-15 19:47:07 +01:00
Nick Wellnhofer
77c713501b tree: Simplify xmlAddChild with text parent 2024-03-15 19:47:07 +01:00
Nick Wellnhofer
7e46242568 tree: Don't allow misuse of xmlAddChild
xmlAddChild assumes that the child is unlinked. If the child is already
linked, return an error instead of corrupting the tree.
2024-03-15 19:47:07 +01:00
Nick Wellnhofer
2c214a508d tree: Fix xmlAddPropSibling with duplicate attributes
Look up existing attribute before unlinking new attribute. This makes
it easier for the fuzzer to detect which attribute will de deleted if
there are multiple attributes with the same name.
2024-03-15 19:47:06 +01:00
Nick Wellnhofer
2e7650830d tree: Fix indentation in xmlAddPropSibling 2024-03-15 19:47:06 +01:00
Nick Wellnhofer
16c0374a7d tree: Fix xmlAddSibling with last sibling
If the node to be added was already at the correct position, the tree
could be corrupted.
2024-03-15 19:47:06 +01:00
Nick Wellnhofer
74ca2f5952 tree: Move type check in xmlAddChild
Avoid aborting halfway after changing parent pointer if node types
don't match when adding attributes.
2024-03-15 19:47:06 +01:00
Nick Wellnhofer
29db988165 tree: Fix xmlDocSetRootElement with multiple top-level elements
Fix xmlDocSetRootElement when setting the original root if multiple
top-level elements are present.
2024-03-15 19:47:06 +01:00
Nick Wellnhofer
4b698dbaec tree: Only allow elements in xmlDocSetRootElement 2024-03-15 19:47:06 +01:00
Nick Wellnhofer
d5f5060246 tree: Disallow setting content of entity reference nodes
The content of entity reference nodes points to the entity declaration
and isn't freed. Changing the content would result in a memory leak.
2024-03-15 19:47:06 +01:00
Nick Wellnhofer
77f2012ca7 tree: Rework xmlReconciliateNs 2024-03-15 19:47:06 +01:00
Nick Wellnhofer
af66a6b59b tree: Unlink DTD in xmlStaticCopyNodeList
Avoid tree corruption when copying within a document.
2024-03-15 19:47:06 +01:00
Nick Wellnhofer
bb22cfb900 tree: Unlink DTD in xmlFreeNodeList
Avoid dangling next/prev pointers.
2024-03-15 19:47:06 +01:00
Nick Wellnhofer
a581f65194 tree: Check for integer overflow in xmlStringGetNodeList
This function is called with unvalidated strings from functions like
xmlNewDocProp, xmlNewDocNode or xmlNodeSetContent, so we have to check
for integer overflow after all.
2024-02-21 12:12:30 +01:00
Nick Wellnhofer
6aae176798 tree: Fix error condition in xmlNodeListGetString
Don't return NULL in case of undeclared entities.
2024-02-01 15:18:26 +01:00
Nick Wellnhofer
d025cfbb4b parser: Always copy content from entity to target.
Make sure that references from IDs are updated.

Note that if there are IDs with the same value in a document, the last
one will now be returned. IDs should be unique, but maybe this should be
addressed.
2023-12-29 01:22:11 +01:00
Nick Wellnhofer
c49572e57d malloc-fail: Fix erroneous report in xmlStringGetNodeList
The parser can produce invalid attribute content in recovery mode.
Unless this is fixed, xmlStringGetNodeList should ignore such errors
silently.
2023-12-23 15:10:15 +01:00
Nick Wellnhofer
0ea47327c2 malloc-fail: Fix memory leak in xmlNodeGetBaseSafe
Short-lived regression.
2023-12-13 14:58:53 +01:00
Nick Wellnhofer
5c06f4e384 malloc-fail: Fix erroneous reports in xmlNodeListGetString
Short-lived regression.
2023-12-12 15:19:07 +01:00
Nick Wellnhofer
aca16fb3d4 tree: Report malloc failures
Fix many places where malloc failures aren't reported.

Make some API function return an error code. Changing the return type
from void to int is technically an ABI break but should be safe on most
platforms.

- xmlNodeSetContent
- xmlNodeSetContentLen
- xmlNodeAddContent
- xmlNodeAddContentLen
- xmlNodeSetBase

Introduce new API functions that return a separate error code if a
memory allocation fails.

- xmlNodeGetAttrValue
- xmlNodeGetBaseSafe
- xmlGetNsListSafe

Introduce private functions xmlTreeEnsureXMLDecl and xmlSplitQName4.

Don't report low-level errors to the global error handler.

Fix tree

Introduce xmlGetNsListSafe

Fix tree
2023-12-11 22:13:05 +01:00
Nick Wellnhofer
502971cc23 tree: Another fix related to #538
Should fix #639.
2023-12-01 19:44:37 +01:00
Nick Wellnhofer
8707838e69 tree: Fix #583 again
Only set doc->intSubset after successful copy to avoid dangling pointers
in error case.
2023-11-28 13:45:49 +01:00
Nick Wellnhofer
de3f70146d tree: Fix regression when copying DTDs
This reverts commit d39f78069d.

Fixes #634.
2023-11-28 13:30:56 +01:00