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

6206 Commits

Author SHA1 Message Date
Nick Wellnhofer
f19a95108a parser: Report malloc failures
Fix many places where malloc failures aren't reported.

Make xmlErrMemory public. This is useful for custom external entity
loaders.

Introduce new API function xmlSwitchEncodingName.

Change the way how we store whether the the parser is stopped. This used
to be signaled by setting ctxt->instate to XML_PARSER_EOF which was
misdesigned and error-prone. Set ctxt->disableSAX to 2 instead and
introduce a macro PARSER_STOPPED. Also stop to remove parser inputs in
xmlHaltParser. This allows to remove many checks of ctxt->instate.

Introduce xmlErrParser to handle errors if a parser context is
available.
2023-12-11 22:13:05 +01:00
Nick Wellnhofer
0d97e43993 save: Report malloc failures
Fix places where malloc failures aren't report.

Introduce a new API function xmlSaveFinish which returns an error code.
2023-12-11 22:13:05 +01:00
Nick Wellnhofer
1a354d5b30 regexp: Report malloc failures
Fix places where malloc failures aren't reported.
2023-12-11 22:13:05 +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
f3455ecd52 error: Report malloc failures
Don't ignore malloc failures in xmlRaiseError and xmlCopyError.

Don't print filename if context has no input.

Introduce xmlVRaiseError taking a va_list.
2023-12-11 22:13:05 +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
e34a49b78e valid: Improve addition and deletion of IDs
Introduce a new API function xmlAddIDSafe that returns a separate error
code if a memory allocation fails.

Store a pointer to the ID struct in xmlAttr so attributes can be
freed without allocating memory. It's impossible to report malloc
failures in deallocation code.
2023-12-11 22:13:05 +01:00
Nick Wellnhofer
e1560990ec pattern: Report malloc failures
Fix places where malloc failures aren't reported.

Introduce a new API function xmlPatternCompileSafe that returns a
separate error code if a memory allocation fails.
2023-12-11 22:05:47 +01:00
Nick Wellnhofer
a1f7ecaef8 entities: Report malloc failures
Fix places where malloc failures aren't reported.

Introduce new API function xmlAddEntity that returns separate error
codes.

Don't invoke global error handler for low-level errors which should be
handled by higher layers.

Invalid redelcaration warnings will be fixed later.
2023-12-11 22:05:47 +01:00
Nick Wellnhofer
2e5d273beb string: Report malloc failures in xmlStrncat
Don't ignore malloc failures silently.
2023-12-11 22:05:47 +01:00
Nick Wellnhofer
c37a9051b0 buf: Stop invoking global error handler
Memory errors from low-level code should be handled by higher layers.
2023-12-11 22:05:47 +01:00
Nick Wellnhofer
f313848bd8 hash: Report malloc failures
Introduce new API functions that return a separate error code if a
memory allocation fails.

- xmlHashAdd
- xmlHashCopySafe
2023-12-11 22:05:47 +01:00
Nick Wellnhofer
bd5ad0308d encoding: Report malloc failures
Introduce new API functions that return a separate error code if a
memory allocation fails.

- xmlOpenCharEncodingHandler
- xmlLookupCharEncodingHandler

Fix a few places where malloc failures weren't reported.
2023-12-11 22:05:47 +01:00
Nick Wellnhofer
da996c8d0f uri: Report malloc failures
Fix many places where malloc failures weren't reported, for example
after calling xmlStrdup.

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

- xmlParseURISafe
- xmlBuildURISafe
- xmlBuildRelativeURISafe

Update the fuzzer to check whether malloc failures are reported.
2023-12-11 22:05:47 +01:00
Nick Wellnhofer
7d446e9736 parser: Fix namespaces redefined from default attributes
This regressed in commit e0dd330b.

Also fixes a long-standing issue where namespaces from default
attributes weren't added if they match an existing namespace.

Fixes #643.
2023-12-08 12:19:16 +01:00
Nick Wellnhofer
df0b540b3e include: Rename XML_EMPTY helper macro
Avoid name clash with downstream projects.
2023-12-07 14:59:47 +01:00
Nick Wellnhofer
a9738e311c include: Move declaration of xmlInitGlobals
Fix downstream build issues after reworking globals.h.
2023-12-07 14:59:40 +01:00
Nick Wellnhofer
52703ffdf1 include: Add missing includes 2023-12-07 12:31:16 +01:00
Nick Wellnhofer
9122ad0ce6 include: Move globals from xmlsave.h to parser.h
Fix downstream build issues after reworking globals.h.
2023-12-07 12:31:06 +01:00
Nick Wellnhofer
c011e7605d globals: Remove unused globals from thread storage
Setting these deprecated globals hasn't had an effect for a long time.
Make them constants. This reduces the size of per-thread storage from
~700 to ~250 bytes.
2023-12-06 20:07:54 +01:00
Nick Wellnhofer
be558647c1 autotools: Fix option description 2023-12-05 21:25:09 +01:00
Nick Wellnhofer
cf6e58d63c build: Disable compiler TLS by default
The global struct is quite large (~700 bytes on 64-bit systems which
will be allocated for each thread whether it uses libxml2 or not) and
already close to the total size limit on some platforms.

Disable compiler TLS by default.
2023-12-05 21:07:00 +01:00
Nick Wellnhofer
7f00273cf0 parser: Fix invalid free in xmlParseBalancedChunkMemoryRecover
Set the dictionary for newDoc in xmlParseBalancedChunkMemoryRecover.
This is a long-standing bug which was masked by

- xmlParseBalancedChunkMemoryRecover changing the document of the root
  node. This is a really bad idea, resulting in a mismatch between
  ctxt->myDoc and ctxt->node->doc.
- SAX2.c preferring ctxt->node->doc over ctxt->myDoc until commit
  a31e1b06.

Fixes #641.
2023-12-01 19:44:37 +01:00
Nick Wellnhofer
502971cc23 tree: Another fix related to #538
Should fix #639.
2023-12-01 19:44:37 +01:00
Nick Wellnhofer
4c17804050 globals: Disable TLS in static Windows builds
The cleanup callback would run after TLS was deallocated.
2023-12-01 17:19:55 +01:00
Nick Wellnhofer
c7629c9eb1 parser: Clarify documentation regarding xmlReadMemory buffer size
Fixes #638.
2023-11-30 16:52:34 +01:00
Nick Wellnhofer
e395946194 html: Reenable buggy detection of XML declarations
Switch to UTF-8 if a document starts with '<?xm' to match old behavior.
Also enable this check in the push parser.

Fixes #637.
2023-11-30 16:22:59 +01:00
Nick Wellnhofer
e2ce828c9b cmake: Update config.h.cmake.in
This should enable TLS and destructors.
2023-11-28 16:51:06 +01:00
Nick Wellnhofer
5cffba8381 Rework va_copy fallback
va_copy is a macro, so it can be detected without a feature test.
Fallback to __va_copy or memcpy.
2023-11-28 15:59:40 +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
Nick Wellnhofer
ec7f65069a tests: Fix tests --with-valid --without-xinclude
Fix a copy/paste error from commit 4eba9f9c.

Fixes #632.
2023-11-27 18:03:01 +01:00
Nick Wellnhofer
1c7f4c70fe nanohttp: Deprecate public API
The long-term plan is to remove the built-in HTTP client. There are
still a few downstream projects that use libxml2's client for other
purposes. These users should get deprecation warnings now.
2023-11-27 13:43:06 +01:00
Andre Klapper
de9af3e5a9 DOAP: Add download and issue tracker entries 2023-11-27 12:53:58 +01:00
Andre Klapper
75eb9327b4 DOAP: Replace defunct mailing list with Discourse support forum 2023-11-27 12:53:15 +01:00
Nick Wellnhofer
43b511fa71 parser: Make CRLF increment line number
Partial revert of cb927e85 fixing CRLFs not incrementing the line
number.

This requires to rework xmlParseQNameHashed. The original implementation
prompted the change to xmlCurrentChar which really shouldn't modify the
'cur' pointer as side effect. But the NEXTL macro relies on this
behavior.

Ultimately, we should reintroduce the change to xmlCurrentChar and fix
the NEXTL macro. This will lead to single CRs incrementing the line
number as well which seems more consistent.

Fixes #628.
2023-11-26 15:18:09 +01:00
Nick Wellnhofer
455c61d635 Remove VMS support
This was last updated 10 years ago and is most likely broken.
2023-11-23 15:59:41 +01:00
Nick Wellnhofer
7d6969d955 Remove Trio
Trio is a rather old cross-platform printf library which was bundled with
libxml2. It was needed for ancient pre-C99 systems without snprintf and
should be safe to remove these days.
2023-11-23 15:48:52 +01:00
Nick Wellnhofer
f5d4d33bfa tests: Regenerate testapi.c 2023-11-23 15:39:30 +01:00
Nick Wellnhofer
e42faa6d78 tests: Remove special handling of const pointers in gentest.py 2023-11-23 15:36:39 +01:00
Nick Wellnhofer
ff6c318862 include: Remove useless 'const' from function arguments 2023-11-23 15:27:00 +01:00
makise-homura
19b9c59b61 Regenerate testapi.c 2023-11-22 05:34:56 +00:00
makise-homura
a3971573b4 Don't let gentest.py cast types to 'const somethingPtr' to avoid -Wignored-qualifiers 2023-11-22 05:34:56 +00:00
makise-homura
873c171165 Avoid EDG -Wignored-qualifiers warnings on wrong 'const *' to '* const' conversions 2023-11-22 05:34:56 +00:00
makise-homura
6bc86405d1 Avoid EDG deprecation warnings for LCC compiler 2023-11-22 05:34:56 +00:00
makise-homura
c1e9f761e0 Avoid EDG -Woverflow warnings on truncating conversions by manually truncating operand 2023-11-22 05:34:56 +00:00
makise-homura
595c19a592 Avoid EDG -Wtype-limits warnings on unsigned comparisons with zero by conversion from unsigned int to int 2023-11-22 05:34:56 +00:00
makise-homura
f8394adf14 Avoid using no_sanitize attribute on EDG even if compiler shows as GCC 2023-11-22 05:34:56 +00:00
Nick Wellnhofer
f3c24112d3 autotools: Stop checking for snprintf
This works around a bug when cross-compiling to 32-bit MinGW:

https://sourceforge.net/p/mingw-w64/bugs/935/

This means that we don't fall back to the bundled Trio library if
snprintf couldn't be detected. Trio support is completely untested, most
likely broken and will be removed soon.

Fixes #625.
2023-11-22 02:12:44 +01:00
Nick Wellnhofer
a2b5c90a44 hash: Fix deletion of entries during scan
Functions like xmlCleanSpecialAttr scan a hash table and possibly delete
entries in the callback. xmlHashScanFull must detect such deletions and
rescan the entry.

This regressed when rewriting the hash table code in 4a513d56.

Fixes #626.
2023-11-21 15:28:59 +01:00