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

999 Commits

Author SHA1 Message Date
Nick Wellnhofer
4f0a0fb7a2 xinclude: Fix include guard 2023-02-22 14:24:24 +01:00
Nick Wellnhofer
905386ec35 autotools: Fix make distcheck
- Add private/xinclude.h to EXTRA_DIST
- Add runsuite.log to CLEANFILES

Fixes #485.
2023-02-13 11:14:34 +01:00
Nick Wellnhofer
6a12be77c6 malloc-fail: Avoid use-after-free after unsuccessful valuePush
In xpath.c there's a lot of code like:

    valuePush(ctxt, xmlCacheNewX());
    ...
    valuePop(ctxt);

If xmlCacheNewX fails, no value will be pushed on the stack. If there's
no error check in between, valuePop will pop an unrelated value which
can lead to use-after-free errors.

Instead of trying to fix all call sites, we simply stop popping values
if an error was signaled. This requires to change the CHECK_TYPE macro
which is often used to determine whether a value can be safely popped.

Found with libFuzzer, see #344.
2023-02-03 12:40:15 +01:00
Nick Wellnhofer
59b3366178 error: Limit number of parser errors
Reporting errors is expensive and some abusive test cases can generate
an error for each invalid input byte. This causes the parser to spend
most of the time with error handling. Limit the number of errors and
warnings to 100.
2022-12-27 14:41:19 +01:00
Nick Wellnhofer
a41b09c739 parser: Improve detection of entity loops
Set a flag to detect entity loops at once instead of processing until
the depth limit is exceeded.
2022-12-23 22:11:18 +01:00
Nick Wellnhofer
b47ebf047e parser: Deprecate xmlString*DecodeEntities
These are internal functions.
2022-12-21 21:06:03 +01:00
Nick Wellnhofer
ce76ebfd13 entities: Stop counting entities
This was only used in the old version of xmlParserEntityCheck.
2022-12-21 20:19:10 +01:00
Nick Wellnhofer
a3c8b1805e entities: Add entity flag for loop check 2022-12-21 20:19:10 +01:00
Nick Wellnhofer
463bbeeca1 entities: Rework entity amplification checks
This commit implements robust detection of entity amplification attacks,
better known as the "billion laughs" attack.

We now limit the size of the document after substitution of entities to
10 times the size before expansion. This guarantees linear behavior by
definition. There already was a similar check before, but the accounting
of "sizeentities" (size of external entities) and "sizeentcopy" (size of
all copies created by entity references) wasn't accurate.

We also need saturation arithmetic since we're historically limited to
"unsigned long" which is 32-bit on many platforms.

A maximum of 10 MB of substitutions is always allowed. This should make
use cases like DITA work which have caused problems in the past.

The old checks based on the number of entities were removed. This is
accounted for by adding a fixed cost to each entity reference.

Entity amplification checks are now enabled even if XML_PARSE_HUGE is
set. This option is mainly used to allow larger text nodes. Most users
were unaware that it also disabled entity expansion checks.

Some of the limits might be adjusted later. If this change turns out to
affect legitimate use cases, we can add a separate parser option to
disable the checks.

Fixes #294.
Fixes #345.
2022-12-21 20:19:10 +01:00
Nick Wellnhofer
7e3f469be9 entities: Use flags to store '<' check results
Instead of abusing the LSB of the "checked" member, store the result
of testing for occurrence of '<' character in "flags".

Also use the flags in xmlParseStringEntityRef instead of rescanning
every time.
2022-12-19 15:59:49 +01:00
Nick Wellnhofer
481d79d44c entities: Add XML_ENT_PARSED flag
To check whether an entity was already parsed, the code previously
tested whether "checked" was non-zero or "children" was non-null. The
"children" check could be unreliable because an empty entity also
results in an empty (NULL) node list. Use a separate flag to make this
check more reliable.
2022-12-19 15:26:46 +01:00
Nick Wellnhofer
f34f184f8e entities: Add "flags" member to struct xmlEntity
This will hold various flags and eventually replace the "checked"
member.
2022-12-19 15:24:53 +01:00
Nick Wellnhofer
93a01c46f1 libxml.h: Add comments and indentation 2022-12-08 04:39:03 +01:00
Nick Wellnhofer
a6debffd7f xmlexports.h: Disable docs for internal macro XMLPUBLIC 2022-12-08 04:22:11 +01:00
Nick Wellnhofer
3b6cc47ab9 xmlexports.h: Remove LIBXML_FASTCALL optimization
This was an experimental and undocumented micro-optimization for
Windows which apparently required different calling conventions for
variable-argument functions, making it impossible to maintain without
domain knowledge.
2022-12-08 04:19:02 +01:00
Nick Wellnhofer
ce9baf94d5 Remove XMLCALL and XMLCDECL macros from public headers 2022-12-08 02:48:27 +01:00
Nick Wellnhofer
ccb6d54409 Hide internal functions
These functions were never declared in public headers, so it should be
safe to hide them.

Fixes #139.
2022-11-27 02:20:53 +01:00
Nick Wellnhofer
c16fd705bb xpath: Make init function private 2022-11-27 02:11:07 +01:00
Nick Wellnhofer
53ab38408d encoding: Make init function private 2022-11-27 02:11:07 +01:00
Nick Wellnhofer
c73d464afb threads: Deprecate some internal functions 2022-11-25 15:12:56 +01:00
Nick Wellnhofer
65d381f32c threads: Allocate mutexes statically 2022-11-25 15:12:56 +01:00
Nick Wellnhofer
ed053c50cf dict: Make init/cleanup functions private 2022-11-25 15:02:04 +01:00
Nick Wellnhofer
7010d8779b threads: Rework initialization
Make init/cleanup functions private. Merge xmlOnceInit into
xmlInitThreadsInternal.
2022-11-25 15:02:04 +01:00
Nick Wellnhofer
9dbf137455 parser: Make some module init/cleanup functions private 2022-11-25 15:02:04 +01:00
Chun-wei Fan
707ade225c Visual Studio builds: Allow silencing deprecation warnings
Define XML_IGNORE_DEPRECATION_WARNINGS and the corresponding XML_POP_WARNINGS
for Visual Studio, and consequently define XML_IGNORE_FPTR_CAST_WARNINGS so
that we do not get a compiler warning on Visual Studio by doing a
__pragma(warning(pop)) without a corresponding __pragma(warning(push)).

Also correct the documentation a bit for XML_POP_WARNINGS.
2022-11-23 11:04:38 +08:00
Chun-wei Fan
b9590d5d81 Visual Studio: Define XML_DEPRECATED
We can mark APIs as deprecated using __declspec(deprecated) with Visual Studio
2005 and later, so add a definition of that so that we can help users avoid
using deprecated APIs when using Visual Studio as well.

For the existing GCC definition, check whether we are on GCC 3.1+ before
enabling the definition.
2022-11-23 10:41:08 +08:00
Nick Wellnhofer
68a6518c45 parser: Rewrite push parser boundary checks
Remove inaccurate xmlParseCheckTransition check.

Remove non-incremental xmlParseGetLasts check.

Add functions that check for several boundary constructs more
accurately, keeping track of progress in ctxt->checkIndex.

Fixes #439.
2022-11-20 21:27:08 +01:00
Nick Wellnhofer
2059df5358 buf: Deprecate static/immutable buffers 2022-11-20 21:16:03 +01:00
Nick Wellnhofer
46cd7d224e io: Remove xmlInputReadCallbackNop
In some cases, for example when using encoders, the read callback was
set to NULL, in other cases it was set to xmlInputReadCallbackNop.
xmlGROW only tested for xmlInputReadCallbackNop, resulting in errors
when parsing large encoded content from memory.

Always use a NULL callback for memory buffers to avoid ambiguities.

Fixes #262.
2022-11-20 21:12:18 +01:00
Nick Wellnhofer
b693905f9b doc: Remove xmlDllMain from documentation and version script
This is a Windows-only symbol.
2022-11-04 14:50:39 +01:00
Nick Wellnhofer
eef0a7395c xinclude: Implement "streaming" mode
When using xmlreader, XPointer expressions in XIncludes simply cannot
work. Expressions can reference nodes which weren't parsed yet or which
were already deleted.

After fixing nested XIncludes, we reference includes which were parsed
previously. When streaming, these nodes could have been deleted, leading
to use-after-free errors.

Disallow XPointer expressions and truncate the include table in
streaming mode.
2022-10-30 14:12:55 +01:00
Nick Wellnhofer
2fc8d12327 xinclude: Make xmlXIncludeCopyNode non-recursive
Avoid call stack overflows.

Also switch to xmlStaticCopyNode which avoids duplicate namespace
definitions.
2022-10-23 18:52:56 +02:00
Nick Wellnhofer
5bfaf23059 win32: Fix build with VS2013
Should fix #420.
2022-10-11 13:00:33 +02:00
Nick Wellnhofer
a9669679f5 error: Don't use initGenericErrorDefaultFunc
The code in xmlInitParser did only set the error handler if it was NULL
which should never happen.
2022-09-09 13:52:48 +02:00
Nick Wellnhofer
30c8d9bb23 http: Simplify IPv6 checks
This should also enable IPv6 support on Windows. Untested and mostly
useless anyway, since we don't support HTTPS.
2022-09-05 02:26:13 +02:00
Nick Wellnhofer
9e5a016ef0 autotools: Fix network checks on Windows 2022-09-05 01:25:35 +02:00
Nick Wellnhofer
0d90125859 Fix Windows compiler warnings in python/types.c 2022-09-04 18:36:04 +02:00
Nick Wellnhofer
fe02289fa5 Remove arg cast configure checks
We can simply cast to non-const char * unconditionally.
2022-09-04 03:19:01 +02:00
Nick Wellnhofer
1e60c76821 Remove HAVE_WIN32_THREADS configuration flag
Check for LIBXML_THREAD_ENABLED and _WIN32 instead.
2022-09-04 01:49:41 +02:00
Nick Wellnhofer
59f2f60e3e Remove "runtime debugging"
This doesn't seem useful as configuration option.
2022-09-02 18:33:35 +02:00
Nick Wellnhofer
65dc8a63ac Make xmlNewSAXParserCtx take a const sax handler
Also improve documentation.
2022-09-01 00:17:45 +02:00
Nick Wellnhofer
39dfb048a8 Don't forget to install xmlversion.h
Fixes 7f7961df.
2022-08-26 02:41:15 +02:00
Nick Wellnhofer
0f568c0b73 Consolidate private header files
Private functions were previously declared

- in header files in the root directory
- in public headers guarded with IN_LIBXML
- in libxml.h
- redundantly in source files that used them.

Consolidate all private header files in include/private.
2022-08-26 02:11:56 +02:00
Nick Wellnhofer
48f84ea8ed Remove internal macros from parserInternals.h
Replace MOVETO_ENDTAG with code that updates line and column numbers.
2022-08-25 21:31:08 +02:00
Nick Wellnhofer
58fc89e8a9 Deprecate internal parser functions 2022-08-25 21:04:57 +02:00
Nick Wellnhofer
a308c0cdf7 Deprecate old HTML SAX API 2022-08-25 21:04:57 +02:00
Nick Wellnhofer
51035c539e Generate deprecation warnings for old SAX API 2022-08-25 20:17:03 +02:00
Nick Wellnhofer
7f7961df25 Remove generated files from distribution
- libxml2.spec
- libxml-2.0.pc
- xml2-config
- include/libxml/xmlversion.h
- python/libxml2.py
- python/libxml2-export.c
- python/libxml2-py.c
- python/libxml2-py.h
- python/libxml2class.py
- python/libxml2class.txt
- python/setup.py
2022-08-25 14:35:31 +02:00
Nick Wellnhofer
34a050cdee Move some HTML functions to correct header file 2022-08-24 16:44:39 +02:00
Nick Wellnhofer
9a82b94a94 Introduce xmlNewSAXParserCtxt and htmlNewSAXParserCtxt
Add API functions to create a parser context with a custom SAX handler
without having to mess with ctxt->sax manually.
2022-08-24 14:07:55 +02:00