1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-01-27 14:03:36 +03:00

573 Commits

Author SHA1 Message Date
Nick Wellnhofer
2a713a8091 tree: Document behavior if xmlSetTreeDoc fails 2024-03-29 12:57:20 +01:00
Nick Wellnhofer
f1e9c7bdf1 tree: Optimize xmlInsertNode
Relink the node directly without calling xmlUnlinkNodeInternal.
2024-03-29 12:57:20 +01:00
Nick Wellnhofer
ea0ee36546 tree: Align xmlAddChild with other node insertion functions
Make xmlAddChild unlink the child before insertion. Originally, linked
children would most likely cause tree corruption. The first fix
disallowed linked nodes, but there are cases where insertion of such
nodes could succeed.

Don't abort if the node is already a child of parent. In this case,
the node will be moved to the end of the child list.
2024-03-29 12:57:20 +01:00
Nick Wellnhofer
e5cdb23f10 tree: Introduce xmlUnlinkNodeInternal
xmlUnlinkNode also removes references to DTD nodes which shouldn't be
done when moving nodes within a document. Introduce a new function
xmlUnlinkNodeInternal which only unlinks a node from the tree.
Remove references to DTD nodes in xmlNodeSetDoc. Note that moving
element and attribute declarations to another document will still leave
references in the source document.
2024-03-29 12:56:56 +01:00
Nick Wellnhofer
23a81841d2 tree: Work on documentation 2024-03-25 20:51:14 +01:00
Nick Wellnhofer
ad9a5637f9 tree: Fix uninitialized value in xmlSearchNsSafe
Short-lived regression.
2024-03-22 19:37:12 +01:00
Nick Wellnhofer
7b316c1139 tree: Fix uninitialized value in xmlSearchNsByHrefSafe
Short-lived regression.
2024-03-22 12:15:23 +01:00
Nick Wellnhofer
3f05508a53 tree: Report malloc failures in attribute setters 2024-03-18 15:14:43 +01:00
Nick Wellnhofer
6a49bb777c tree: Introduce xmlSearchNsSafe
After the failed experiment with a static XML namespace, introduce
versions of xmlSearchNs that report malloc failures.

Optimize the no-document case by only adding the XML namespace
declaration if it wasn't found in an ancestor.
2024-03-17 21:07:46 +01:00
Nick Wellnhofer
047ea3ecb3 Revert "tree: Allocate XML namespace statically"
This reverts commit 2840e33c5e4b51589a0b96e8102638eeaea6df72.
2024-03-17 21:04:40 +01:00
Nick Wellnhofer
2469d5d065 tree: Tighten source doc check in xmlDOMWrapAdoptNode
sourceDoc must match even if node->doc is NULL.
2024-03-15 19:54:27 +01:00
Nick Wellnhofer
37556eb32a tree: Check destParent->doc in xmlDOMWrapCloneNode
The document must match destDoc to avoid tree corruption.
2024-03-15 19:54:27 +01:00
Nick Wellnhofer
7c48c01b1c tree: Switch to xmlNodeSetDoc in xmlDOMWrapAdoptNode
Report malloc failures.

Also fixes an issue where xmlDOMWrapAdoptAttr would descend into entity
references.
2024-03-15 19:54:27 +01:00
Nick Wellnhofer
be2c26fb67 tree: Fix tree iteration in xmlDOMWrapRemoveNode
We didn't descend into elements having attributes.
2024-03-15 19:54:27 +01:00
Nick Wellnhofer
4a90ce089c tree: Don't abort early if malloc fails in DOM functions
If malloc fails halfway through updating a subtree, we must process the
rest of the tree to avoid tree corruption.
2024-03-15 19:54:27 +01:00
Nick Wellnhofer
ad019ba102 tree: Fix reallocation in xmlDOMWrapNSNormAddNsMapItem2 2024-03-15 19:54:27 +01:00
Nick Wellnhofer
e321eba0c7 tree: Set parent->last early in xmlDOMWrapCloneNode
Avoids a corrupted tree in error case.
2024-03-15 19:54:27 +01:00
Nick Wellnhofer
84e6dc9e5b tree: Declare namespace on clone in xmlDOMWrapCloneNode
The new namespace must be declared on the cloned node, not the source
node.
2024-03-15 19:54:27 +01:00
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