1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2026-01-26 21:41:34 +03:00
Commit Graph

5756 Commits

Author SHA1 Message Date
Nick Wellnhofer
be0ec005f3 xinclude: Abort immediately if max depth was exceeded
Avoids resource exhaustion if the maximum recursion depth was exceeded.

Note that the XInclude engine offers no protection against other
"billion laughs"-style amplification attacks as long as they stay below
the maximum depth.
2023-02-13 11:29:26 +01:00
Nick Wellnhofer
dc2dde1ab9 malloc-fail: Fix null deref in xmlXIncludeLoadTxt
Found with libFuzzer, see #344.
2023-02-13 11:19:55 +01:00
Nick Wellnhofer
a3749551e6 malloc-fail: Fix reallocation in xmlXIncludeNewRef
Avoid null deref.

Found with libFuzzer, see #344.
2023-02-13 11:19:55 +01:00
Nick Wellnhofer
d1272c2ed6 fuzz: Add xinclude to .gitignore 2023-02-13 11:16:57 +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
15c9f43533 xpath: Only report the first error
Don't overwrite the original error code. Besides, subsequent error
reports are somewhat unreliable and not really useful.
2023-02-03 13:38:24 +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
7ec314efcd malloc-fail: Add error checks in xmlXPathEqualValuesCommon
Avoid null deref.

Found with libFuzzer, see #344.
2023-02-03 12:40:15 +01:00
Nick Wellnhofer
08695683db malloc-fail: Add error check in xmlXPathEqualNodeSetFloat
Avoid null deref.

Found with libFuzzer, see #344.
2023-02-03 12:40:15 +01:00
Nick Wellnhofer
621c222efe malloc-fail: Fix error check in xmlXPathCompareValues
Avoid null deref.

Found with libFuzzer, see #344.
2023-02-03 12:40:15 +01:00
Nick Wellnhofer
755344013e malloc-fail: Record malloc failure in xmlXPathCompLiteral
Avoid OOB array access.

Found with libFuzzer, see #344.
2023-02-03 12:40:15 +01:00
Nick Wellnhofer
0e4421e793 malloc-fail: Check return value of xmlXPathNodeSetDupNs
Avoid null deref if allocation fails.

Found with libFuzzer, see #344.
2023-02-03 12:40:15 +01:00
Nick Wellnhofer
c7260a47f1 malloc-fail: Don't call xmlErrMemory in xmlstring.c
Functions like xmlStrdup are called in the error handling code
(__xmlRaiseError) which can cause problems like use-after-free or
infinite loops when invoked recursively.

Calling xmlErrMemory without a context argument isn't helpful anyway.

Found with libFuzzer, see #344.
2023-01-24 11:47:33 +01:00
Nick Wellnhofer
e6d22f925a malloc-fail: Fix reallocation in inputPush
Store xmlRealloc result in temporary variable to avoid null deref in
error handler.

Found with libFuzzer, see #344.
2023-01-24 11:47:33 +01:00
Nick Wellnhofer
6fd8904108 malloc-fail: Fix use-after-free in xmlParseStartTag2
Fix error handling in xmlCtxtGrowAttrs.

Found with libFuzzer, see #344.
2023-01-24 11:47:33 +01:00
Nick Wellnhofer
c266a22023 malloc-fail: Handle memory errors in xmlTextReaderEntPush
Unfortunately, there's no way to properly report memory errors.

Found with libFuzzer, see #344.
2023-01-24 11:32:15 +01:00
Nick Wellnhofer
d1b8785693 malloc-fail: Fix infinite loop in xmlParseTextDecl
Memory errors can set `instate` to `XML_PARSER_EOF` which results in
`NEXT` making no progress.

Found with libFuzzer, see #344.
2023-01-24 11:32:15 +01:00
Nick Wellnhofer
bd9de3a31f malloc-fail: Fix null deref in xmlAddDefAttrs
Found with libFuzzer, see #344.
2023-01-24 11:32:15 +01:00
Nick Wellnhofer
2355eac59e malloc-fail: Fix null deref if growing input buffer fails
Also add some error checks.

Found with libFuzzer, see #344.
2023-01-24 11:32:15 +01:00
Nick Wellnhofer
0c5f40b788 malloc-fail: Fix null deref in xmlSAX2AttributeInternal
Found with libFuzzer, see #344.
2023-01-24 11:32:15 +01:00
Nick Wellnhofer
1aabc9db40 malloc-fail: Fix null deref in xmlBufResize
Found with libFuzzer, see #344.
2023-01-24 11:32:15 +01:00
Nick Wellnhofer
b3b53dcce4 malloc-fail: Fix null deref in xmlSAX2Text
Found with libFuzzer, see #344.
2023-01-24 11:32:15 +01:00
Nick Wellnhofer
33d4a0fe40 parser: Fix progress check in xmlParseExternalSubset
Avoid infinite loop. Short-lived regression from f61b8a62.

Found with libFuzzer.
2023-01-24 11:32:15 +01:00
Nick Wellnhofer
f65133fc04 uri: Add explicit cast in xmlSaveUri
Fix -fsanitize=implicit-conversion error. We should probably
percent-escape the host name here.
2023-01-24 11:32:15 +01:00
Nick Wellnhofer
f8c5e7fb75 buf: Fix return value of xmlBufGetInputBase
Don't return (size_t) -1 in error case.

Found with libFuzzer and -fsanitize=implicit-conversion.
2023-01-24 11:32:15 +01:00
Nick Wellnhofer
74aa61e0bd parser: Halt parser on DTD errors
If we try to continue parsing after an error in the internal or external
subset, entity expansion accounting gets more complicated. Simply halt
the parser.

Found with libFuzzer.
2023-01-24 11:32:15 +01:00
Nick Wellnhofer
d9a8dab3a3 error: Don't move past current position
Make sure that we never move past the current position in
xmlParserPrintFileContextInternal.

Found with libFuzzer and -fsanitize=implicit-conversion.
2023-01-24 11:12:31 +01:00
Nick Wellnhofer
608c65bb8e xpath: number('-') should return NaN
Fixes https://gitlab.gnome.org/GNOME/libxslt/-/issues/81
2023-01-18 15:15:41 +01:00
Nick Wellnhofer
bbb2b8f136 Remove symbols from version script
The version script didn't account for symbols disabled by configuration
options. This has caused problems on some OSs in the past and breaks
lld 16 which enables --no-undefined-version by default.

A proper fix would be rather involved, so we simply remove all symbols
from the version script. This is an ELF-only feature and libxml2 never
made use of symbol versioning anyway. Ultimately, this removes the need
for a lot of bookkeeping without tangible benefits.

We have to keep the version nodes to avoid errors when running binaries
linked against older versions of libxml2.

Fixes #473.
2023-01-17 16:18:48 +01:00
Nick Wellnhofer
e6401b68df tree: Fix recursion check in xmlStringGetNodeList
Use the new entity flag to check for recursion.
2023-01-17 14:01:23 +01:00
Nick Wellnhofer
d320a683d1 parser: Fix entity check in attributes
Don't set the "checked" flag when checking entities in default attribute
values. These entities could reference other entities which weren't
defined yet, so the check isn't reliable.

This fixes a short-lived regression which could lead to a call stack
overflow later in xmlStringGetNodeList.
2023-01-17 13:59:24 +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
ba910d344f fuzz: Add test/recurse to seed corpus 2022-12-26 18:12:26 +01:00
Nick Wellnhofer
09dac45ab9 fuzz: Add separate XInclude fuzzer
XIncludes involve XPath processing which can still lead to timeouts when
fuzzing. This will probably take a while to fix. The rest of the XML
parsing code should hopefully run without timeouts now. OSS-Fuzz only
shows a single timeout test case, so separate the XInclude from the core
XML fuzzer.
2022-12-26 18:12:26 +01:00
Nick Wellnhofer
66e9fd66e8 parser: Fix infinite loop with push parser in recovery mode
Short-lived regression from commit b1f9c193. Found by OSS-Fuzz.
2022-12-25 21:30:32 +01:00
Nick Wellnhofer
49b54d7e2b parser: Fix null deref in xmlStringDecodeEntitiesInt
Short-lived regression.
2022-12-25 15:06:51 +01:00
Nick Wellnhofer
c885bebb5d fuzz: Remove size limit, disable XInclude
Now that entity expansion issues should be fixed, we should get more
interesting timeout errors from OSS-Fuzz. Disable XInclude for now,
since it often timeouts in XPath computations. The XInclude tests should
be moved to a separate fuzz target.
2022-12-23 23:12:52 +01:00
Nick Wellnhofer
1865668b61 parser: Fix accounting of consumed input bytes
Only add consumed bytes if

- we're not parsing an entity
- we're parsing external parameter entities for the first time.

Always ignore internal parameter entities.
2022-12-23 23:11:11 +01:00
Nick Wellnhofer
bc18f4a67c parser: Lower entity nesting limit with XML_PARSE_HUGE
The old limit of 1024 could lead to excessively deep call stacks. This
could probably be set much lower without causing issues.
2022-12-23 22:11:18 +01:00
Nick Wellnhofer
dd62e541ec parser: Don't increase depth twice when parsing internal entities
Fix xmlParseBalancedChunkMemoryInternal.
2022-12-23 22:11:18 +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
d972393f30 parser: Only report a single entity error
Don't report errors multiple times for nested entity references.
2022-12-23 22:10:39 +01:00
Nick Wellnhofer
28b3777e6d runsuite: Some errors are expected 2022-12-22 15:35:28 +01:00
Nick Wellnhofer
077df27eb1 parser: Fix integer overflow of input ID
Applies a patch from Chromium. Also stop incrementing input ID of
subcontexts. This isn't necessary.

Fixes #465.
2022-12-22 15:22:01 +01:00
David Kilzer
0bd4e4e032 xmlParseStartTag2() contains typo when checking for default definitions for an attribute in a namespace
* parser.c:
(xmlParseStartTag2):
- Fix index into defaults->values.  It is only correct the first
  time through the loop when i == 0.

Fixes #467.
2022-12-21 19:35:33 -08:00
Nick Wellnhofer
78c4430f4e doc: Remove ancient files 2022-12-22 00:03:10 +01:00
Nick Wellnhofer
4c763dd092 gitlab-ci: Revert accidental change to setup_mingw.sh
Commit 3aaaf5ca shouldn't have changed this line. We need these
libraries for a full libxml2 build.
2022-12-21 22:30:25 +01:00
Nick Wellnhofer
c74e590395 Remove ancient TODOs 2022-12-21 22:30:25 +01:00
Nick Wellnhofer
101a542eb8 Remove RPM build, Makefile.tests, README.tests 2022-12-21 22:05:47 +01:00
Nick Wellnhofer
b47ebf047e parser: Deprecate xmlString*DecodeEntities
These are internal functions.
2022-12-21 21:06:03 +01:00