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

6341 Commits

Author SHA1 Message Date
Nick Wellnhofer
6cb8420a9e catalog: Improve error handling
Handle malloc failures from xmlRaiseError.

Remove arguments from memor error handler.

Remove TODO macro.

Make debugging code print to stderr instead of xmlGenericError.
2023-12-21 02:46:27 +01:00
Nick Wellnhofer
06c00f6582 schemas: Improve error handling
Introduce xmlSchema*ErrFull which checks for memory allocation failures
during error reporting.

Remove arguments from memory error handlers.

Use xmlRaiseMemoryError.

Remove TODO macro.
2023-12-21 02:46:27 +01:00
Nick Wellnhofer
ed6596a47a reader: Simplify error handling
Only use structured error handlers for parser, Schemas and RelaxNG
contexts. Also use structured error handler for XInclude context.

Remove TODO macro.
2023-12-21 02:46:27 +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
954b898494 xpath: Improve error handling
Introduce xmlXPathSetErrorHandler allowing to set a structured error
handler for an XPath context.

Remove arguments from memory error handlers.

Use xmlRaiseMemoryError.

Remove TODO, STRANGE and CHECK_CTXT macros.

Remove remaining uses of xmlGenericError.
2023-12-21 02:46:27 +01:00
Nick Wellnhofer
54c70ed57f parser: Improve error handling
Introduce xmlCtxtSetErrorHandler allowing to set a structured error for
a parser context. There already was the "serror" SAX handler but this
always receives the parser context as argument.

Start to use xmlRaiseMemoryError.

Remove useless arguments from memory error functions. Rename
xmlErrMemory to xmlCtxtErrMemory.

Remove a few calls to xmlGenericError.

Remove support for runtime entity debugging.
2023-12-21 02:46:27 +01:00
Nick Wellnhofer
c5a8aef2f6 error: Refactor error reporting
Introduce xmlStrVASPrintf, trying to handle buggy snprintf
implementations.

Introduce xmlSetError to set errors atomically.

Introduce xmlUpdateError to set an error, fixing up node, file and line.

Introduce helper function xmlRaiseMemoryError.

Make legacy error handlers call xmlReportError, avoiding checks in
xmlVRaiseError.

Remove fragile support for getting file and line info from XInclude
nodes.
2023-12-21 02:46:27 +01:00
Mike Dalessio
ed3ad3e173 Makefile.am: omit $(top_builddir) from DEPS and LDADDS
BSD make is less liberal than GNU make in matching targets, and so it
tries to resolve the dependency `./libxml2.la` and fails to match the
target `libxml2.la`.
2023-12-20 23:43:08 +00:00
Nick Wellnhofer
6fdc20ba36 xpath: Don't free nodes of XSLT result value trees
This feature hasn't been required for a long time and libxslt works
around by manually setting 'boolval' to 0.
2023-12-20 19:00:42 +01:00
Nick Wellnhofer
bcefef202e malloc-fail: Report malloc failure in xmlXPathNumberFunction 2023-12-20 14:40:27 +01:00
Nick Wellnhofer
355fbe3ab7 valid: Fix handling of enumerations
Make xmlFreeEnumeration, xmlCopyEnumeration and xmlDumpEnumeration
non-recursive. Report malloc failure in xmlCopyEnumeration.
2023-12-16 15:10:15 +01:00
Nick Wellnhofer
6ae98ebc64 malloc-fail: Report malloc failure in xmlXPathTranslateFunction 2023-12-15 15:03:39 +01:00
Nick Wellnhofer
69d88566b6 malloc-fail: Fix OOM error handling in xmlSwitchInputEncoding
Make sure that in->buffer won't be set to NULL if a memory allocation fails.

Short-lived regression.
2023-12-15 15:03:39 +01:00
Nick Wellnhofer
6c8acdecd2 save: Fix build --without-html
Fixes #646
2023-12-14 13:49:08 +01:00
Nick Wellnhofer
5d2dbe79fa parser: Fix build --without-output
Fixes #647
2023-12-14 13:48:41 +01:00
Nick Wellnhofer
d6812f3a48 Fix compiler warnings with disabled modules 2023-12-14 13:37:03 +01:00
Nick Wellnhofer
1c106edf2b parser: Allow recovery in xmlParseInNodeContext
Should fix #645.
2023-12-13 23:58:59 +01:00
Nick Wellnhofer
023aecc474 encoding: Support ASCII in xmlLookupCharEncodingHandler
Return our built-in ASCII handler. This was never implemented and
triggered the new and stricter error checks.
2023-12-13 23:58:45 +01:00
Nick Wellnhofer
79a9938d84 parser: Don't grow or shrink pull parser memory buffers
Readd check for memory buffers without a read callback to avoid
XML_MAX_LOOKUP_LIMIT errors if users provide a custom input buffer.
Regressed with commit 834b8123 and later changes.
2023-12-13 19:58:44 +01:00
Nick Wellnhofer
0e201722e4 python: Fix callback signature
Found with UBSan.
2023-12-13 15:52:29 +01:00
Nick Wellnhofer
862e9ce0e6 malloc-fail: Fix use-of-uninitialized-value in xmlParseConditionalSections
Short-lived regression.
2023-12-13 15:05:58 +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
c2bbeed1fd io: Fix memory lifetime issue with input buffers
xmlParserInputBufferCreateMem must make a copy of the buffer.

This fixes a regression from 2.11 which could cause reads from freed
memory depending on the use case.

Undeprecate xmlParserInputBufferCreateStatic which can avoid copying
the whole buffer.
2023-12-12 23:51:32 +01:00
Nick Wellnhofer
0e4a11bb30 doc: Add notes about breaking ABI in MAINTAINERS.md 2023-12-12 22:00:20 +01:00
Nick Wellnhofer
8e13133dbd malloc-fail: Don't truncate parser input buffer
We now follow a laissez-faire approach when handling malloc failures and
removed many checks whether the parser was stopped by such an error.
This means the parser input must not be truncated to avoid out-of-bounds
reads.

Short-lived regression.
2023-12-12 15:22:23 +01:00
Nick Wellnhofer
8583b9f1cd malloc-fail: Fix null deref in xmlXPathTranslateFunction
Short-lived regression.
2023-12-12 15:19:07 +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
4e23892cf0 fuzz: Enable value profile 2023-12-11 22:13:06 +01:00
Nick Wellnhofer
abd74186f9 html: Report malloc failures
Fix many places where malloc failures aren't reported.

Stop checking for ctxt->instate.
2023-12-11 22:13:06 +01:00
Nick Wellnhofer
e115194e6f fuzz: Check malloc failure reports in XML fuzzers 2023-12-11 22:13:06 +01:00
Nick Wellnhofer
9684e7a0f2 writer: Don't call SAX error handler directly 2023-12-11 22:13:06 +01:00
Nick Wellnhofer
61b4c42f38 valid: Report malloc failures
Fix many places where malloc failures aren't reported.
2023-12-11 22:13:06 +01:00
Nick Wellnhofer
157df34401 xmlreader: Report malloc failures
Fix many places where malloc failures aren't reported.

Introduce a new API function xmlTextReaderGetLastError.
2023-12-11 22:13:06 +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
e58ea29f17 SAX2: Report malloc failures
Fix many places where malloc failures aren't reported.

Improve error handling when parsing entity declarations.

Fixes #308.
2023-12-11 22:13:05 +01:00
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