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

586 Commits

Author SHA1 Message Date
Nick Wellnhofer
b8597f46df tree: Handle predefined entities in xmlBufGetEntityRefContent
It's possible to create references to predefined entities using the tree
API. This edge case was exposed by making predefined entities const in
commit 63ce5f9a.
2024-04-30 16:05:42 +02:00
Nick Wellnhofer
619e2808b5 tree: Don't call xmlNewCharRef in xmlNodeParseContent
xmlNewCharRef also tries to handle strings like '&name;' but in
xmlNodeParseContentInternal, we really want to use the possibly invalid
name without modification. Otherwise, content like '&"' could
create a reference to a predefined entity.
2024-04-30 15:53:08 +02:00
Nick Wellnhofer
5e80f4381b tree: Deprecate xmlRegisterNodeDefault
This rarely used feature should be phased out.
2024-04-28 19:30:40 +02:00
Nick Wellnhofer
88169bfda6 tree: Deprecate xmlSetCompressMode 2024-04-28 19:30:39 +02:00
Niels Dossche
6053f1ff54 Remove redundant size check
The condition size > UINT_MAX - 10 is already checked earlier, so the
check is always false.
2024-04-19 15:33:40 +02:00
Nick Wellnhofer
fbea03f3d0 tree: Remove another redundant check in xmlDOMWrapCloneNode
The node type was already checked earlier.
2024-04-19 15:22:30 +02:00
Niels Dossche
1a865567d4 Remove redundant NULL check on cur
This variable is already NULL checked in the previous if condition.
2024-04-19 15:14:15 +02:00
Niels Dossche
6fadd7980a Remove always-false check old == cur
This case is already checked at the start of the function.
There it returns NULL, which seems more correct.
2024-04-19 15:14:15 +02:00
Niels Dossche
2766520062 Remove redundant NULL check on cur
cur = node, and node cannot be NULL as it is checked at the start of the
function.
2024-04-19 15:12:56 +02:00
Nick Wellnhofer
a0341ac8e9 tree: Don't return empty localname in xmlSplitQName{2,3}
Match the behavior of xmlSplitQName and xmlSplitQName4.
2024-04-18 12:11:13 +02:00
Nick Wellnhofer
5c55332591 Revert "tree: Only allow elements in xmlDocSetRootElement"
This reverts commit 4b698dbaec.

lxml assumes that xmlDocSetRootElement works with non-elements.
2024-03-29 15:29:53 +01:00
Nick Wellnhofer
7c5daa3763 tree: Ignore namespace with NULL href in xmlSearchNs
Some users set href to NULL to unset a namespace without deleting it.

Also change the duplicate check in xmlNewNs which must agree with
xmlSearchNs.

Short-lived regression from f960c60d.
2024-03-29 15:28:47 +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
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 2840e33c5e.
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