1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-02-19 09:57:23 +03:00

4861 Commits

Author SHA1 Message Date
Nick Wellnhofer
2a7b66846e Disable LeakSanitizer
The GitLab runner doesn't run in privileged mode anymore [1], at least
for projects outside the GNOME group. Disable LeakSanitizer for now
as it needs the ptrace capability.

[1] https://gitlab.gnome.org/Infrastructure/Infrastructure/issues/251
2020-03-02 12:20:23 +01:00
Nick Wellnhofer
c005c7a0f7 Stop calling SAX getEntity handler from XMLReader
The getEntity handler was already invoked by xmlParseReference, so it's
useless to call it again. After the recent change, xmlSAX2GetEntity
won't load any kind of entities anyway.
2020-02-11 17:36:43 +01:00
Nick Wellnhofer
32cb5dccda Add test case for recursive external parsed entities 2020-02-11 17:36:43 +01:00
Nick Wellnhofer
f20daa9e51 Enable error tests with entity substitution 2020-02-11 17:36:43 +01:00
Nick Wellnhofer
eddfbc38fa Don't load external entity from xmlSAX2GetEntity
Despite the comment, I can't see a reason why external entities must be
loaded in the SAX handler. For external entities, the handler is
typically first invoked via xmlParseReference which will later load the
entity on its own if it wasn't loaded yet.

The old code also lead to duplicated SAX events which makes it
basically impossible to reuse xmlSAX2GetEntity for a custom SAX parser.
See the change to the expected test output.

Note that xmlSAX2GetEntity was loading the entity via
xmlParseCtxtExternalEntity while xmlParseReference uses
xmlParseExternalEntityPrivate. In the previous commit, the two
functions were merged, trying to compensate for some slight differences
between the two mostly identical implementations.

But the more urgent reason for this change is that xmlParseReference
has the facility to abort early when recursive entities are detected,
avoiding what could practically amount to an infinite loop.

If you want to backport this change, note that the previous three
commits are required as well:

f9ea1a24 Fix copying of entities in xmlParseReference
5c7e0a9a Copy some XMLReader option flags to parser context
1a3e584a Merge code paths loading external entities

Found by OSS-Fuzz.
2020-02-11 17:35:42 +01:00
Nick Wellnhofer
1a3e584a5a Merge code paths loading external entities
Merge xmlParseCtxtExternalEntity into xmlParseExternalEntityPrivate.
2020-02-11 16:55:00 +01:00
Nick Wellnhofer
5c7e0a9a46 Copy some XMLReader option flags to parser context
The parser context stores some options both in the "options" bits and
extra members like "validate" or "replaceEntities". Which of these
are actually read is inconsistent, so make sure to also update the
bit field.
2020-02-11 16:37:52 +01:00
Nick Wellnhofer
f9ea1a24ed Fix copying of entities in xmlParseReference
Before, reader mode would end up in a branch that didn't handle
entities with multiple children and failed to update ent->last, so the
hack copying the "extra" reader data wouldn't trigger. Consequently,
some empty nodes in entities are correctly detected now in the test
suite. (The detection of empty nodes in entities is still buggy,
though.)
2020-02-11 16:37:52 +01:00
Zhipeng Xie
7ffcd44d7e Fix memory leak in xmlSchemaValidateStream
When ctxt->schema is NULL, xmlSchemaSAXPlug->xmlSchemaPreRun
alloc a new schema for ctxt->schema and set vctxt->xsiAssemble
to 1. Then xmlSchemaVStart->xmlSchemaPreRun initialize
vctxt->xsiAssemble to 0 again which cause the alloced schema
can not be freed anymore.

Found with libFuzzer.

Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
2020-02-11 11:38:56 +01:00
Kevin Puetz
e45e06de90 Fix xmlSchemaGetCanonValue formatting for date and dateTime
Per https://www.w3.org/TR/xmlschema-2/#dateTime-lexical-representation,
the date portion is supposed to use '-' as the delimiter
2020-02-11 11:35:46 +01:00
Kevin Puetz
c7c526d6d0 Fix memory leak when shared libxml.dll is unloaded
When a multiple modules (process/plugins) all link to libxml2.dll
they will in fact share a single loaded instance of it.
It is unsafe for any of them to call xmlCleanupParser,
as this would deinitialize the shared state and break others that might
still have ongoing use.

However, on windows atexit is per-module (rather process-wide), so if used
*within* libxml2 it is possible to register a clean up when all users
are done and libxml2.dll is about to actually unload.

This allows multiple plugins to link with and share libxml2 without
a premature cleanup if one is unloaded, while still cleaning up if *all*
such callers are themselves unloaded.
2020-02-11 11:34:59 +01:00
Kevin Puetz
453bdfb95e Fix potentially-uninitialized critical section in Win32 DLL builds
If non-parser parts of libxml (e.g. xmlwriter) are used before a parser,
xmlOnceInit may have run (e.g. via the many paths to xmlGetGlobalState),
but not xmlInitThreads (which is called only by xmlInitParser)

Once globalkey != TLS_OUT_OF_INDEXES (which can happen in many ways),
DLLMAIN(DLL_THREAD_DETACH) may attempt to lock cleanup_helpers_cs
before it is valid. This may happen even if the thread whose exit
is triggering DllMain is from code which is not linked to libxml.

globalkey and cleanup_helpers_cs should be initialized together,
with cleanup_helpers_cs initialized first and deleted last.
2020-02-11 11:34:15 +01:00
Nick Wellnhofer
c2e09f445c Add xmlPopOutputCallbacks
Add function to pop a single set of output callbacks from the stack.
This was only implemented for input callbacks before.

Fixes #135.
2020-02-11 11:32:23 +01:00
Nick Wellnhofer
b07251215e Fix integer overflow in xmlBufferResize
Found by OSS-Fuzz.
2020-01-10 15:55:07 +01:00
Nick Wellnhofer
3e7e75bed2 Minor fixes to configure.js
- Semicolon coding style
- Remove duplicated option check

Found by lgtm.com
2020-01-02 15:24:23 +01:00
Nick Wellnhofer
52649b63eb Check for overflow when allocating two-dimensional arrays
Found by lgtm.com
2020-01-02 15:24:23 +01:00
Nick Wellnhofer
9bd7abfba4 Remove useless comparisons
Found by lgtm.com
2020-01-02 14:14:48 +01:00
Nick Wellnhofer
c9faa29259 Fix overflow check in xmlNodeDump
Store return value of xmlBufNodeDump in a size_t before checking for
integer overflow.

Found by lgtm.com
2020-01-02 14:12:39 +01:00
Pieter van Oostrum
8f62ac92b2 Updated Python test reader2.py
Added all test cases that have a non-empty error in result/valid/*.xml.err
Restructured to make it easier extensible with new test cases
Added coding cookie because there is non-ASCII in the error messages
2020-01-02 13:50:10 +01:00
Pieter van Oostrum
8c3e52ebd9 Updated python/tests/tstLastError.py
libxml2.registerErrorHandler(None,None):
None is not acceptable as first argument
failUnlessEqual replaced by assertEqual
2020-01-02 13:49:31 +01:00
Zhipeng Xie
0e1a49c890 Fix infinite loop in xmlStringLenDecodeEntities
When ctxt->instate == XML_PARSER_EOF,xmlParseStringEntityRef
return NULL which cause a infinite loop in xmlStringLenDecodeEntities

Found with libFuzzer.

Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
2020-01-02 13:48:29 +01:00
Nick Wellnhofer
0815302dee Fix freeing of nested documents
Apparently, some libxslt RVTs can contain nested document nodes, see
issue #132. I'm not sure how this happens exactly but it can cause a
segfault in xmlFreeNodeList after the changes in commit 0762c9b6.

Make sure not to touch the (nonexistent) `content` member of xmlDocs.
2019-12-06 12:27:29 +01:00
Nick Wellnhofer
2c80fc9116 Fix more memory leaks in error paths of XPath parser
Found by OSS-Fuzz.
2019-12-02 11:30:30 +01:00
Ranier Vilela
3c8a3e9922 Use random seed in xmlDictComputeFastKey
xmlDictComputeFastKey is only used for small tables, so this shouldn't
be a security problem.
2019-11-11 14:10:28 +01:00
Nick Wellnhofer
42942066e1 Fix memory leaks of encoding handlers in xmlsave.c
Fix leak of iconv/ICU encoding handler in xmlSaveToBuffer.

Fix leaks of iconv/ICU encoding handlers in xmlSaveTo* error paths.

Closes #127.
2019-11-11 14:04:57 +01:00
Nick Wellnhofer
2a357ab99e Fix xml2-config error code
Return an error code if called with an unknown option.
2019-11-11 11:29:17 +01:00
Nick Wellnhofer
d5f2f74d0f Fix memory leak in error path of XPath expr parser
Also propagate memory errors.

Found by OSS-Fuzz.
2019-11-11 11:27:40 +01:00
Nick Wellnhofer
bf2e96173d Fix overflow handling in xmlBufBackToBuffer
Don't overwrite 'use' and 'size' members after clamping to INT_MAX.

Thanks to Ranier Vilela for pointing this out in merge request !56.
2019-11-07 12:54:01 +01:00
raniervf
d724861536 Null pointer handling in catalog.c
Fix potential deferencing potential null pointers;
Small optimizations.

Closes #123.
2019-11-06 11:47:57 +01:00
29740ed12f xml2-config.in: fix regressions introduced by commit 2f2bf4b2c
One of regressions introduced by commit
2f2bf4b2caa1cb9a4a5039b7a44db101943382d1 aka v2.9.10-rc1~56 is that
cflags and libs variables are used uninitialized, resulting to
the following behaviour:

$ cflags=foo libs=bar sh ./xml2-config.in --prefix
@prefix@
foo bar

Another regression is that the test for these variables is flawed.

Fixes: 2f2bf4b2c ("xml2-config.in: Output CFLAGS and LIBS on the same line")
2019-11-02 17:56:54 +01:00
Nick Wellnhofer
db0c0450db Enable more undefined behavior sanitizers
Minor fix to xmlStringLenGetNodeList to avoid a pointer overflow
during API test.

Enable pointer-overflow and unsigned-integer-overflow sanitizers in CI
tests. Technically, unsigned integer overflows aren't undefined
behavior, but they typically indicate programming errors. Some hash
functions that really require unsigned integer overflows have already
been annotated.
2019-11-02 17:53:23 +01:00
Daniel Veillard
41a34e1f4f Release of libxml2-2.9.10
* configure.ac doc/xml.html: updated for the release
* doc/*: regenerated docs, APIs, etc ...
v2.9.10
2019-10-30 20:14:56 +01:00
Nick Wellnhofer
a5bb6aaa25 Run XML conformance tests under CI
Also add llvm to Docker image so that backtraces can be symbolized.
2019-10-29 16:20:32 +01:00
Nick Wellnhofer
9737ec0717 Another fix for conditional sections at end of document
The previous fix introduced an uninitialized read.
2019-10-29 16:20:32 +01:00
Daniel Veillard
9acef28928 Fix some release issues on Fedora 30
* doc/Makefile.am: xzlib.html seems not generated anymore since it
  was only containing an internal define we can drop it
* libxml.spec.in: don't run python tests as part of %check as this
  is now breaking on F30
v2.9.10-rc1
2019-10-23 18:13:08 +02:00
Nick Wellnhofer
c1035664f9 Fix for conditional sections at end of document
Parsing conditional sections would fail if the final ']]>' was at the
end of the document. Short-lived regression caused by commit c51e38cb.
2019-10-23 11:40:34 +02:00
Nick Wellnhofer
d188eb921a Make sure that Python tests exit with error code
Closes #108.
2019-10-21 12:45:37 +02:00
Nick Wellnhofer
55d95dcf17 Update GitLab CI config
- Update Dockerfile
- Don't configure with -Werror
- Don't mention Travis in CONTRIBUTING
2019-10-20 18:15:34 +02:00
Nick Wellnhofer
bfc0f674cc Audit memory error handling in xpath.c
Memory allocation errors in the following functions a often ignored.
Add TODO comments.

- xmlXPathNodeSetCreate
- xmlXPathNodeSetAdd*
- xmlXPathNodeSetMerge*
- xmlXPathNodeSetDupNs

Note that the following functions currently lack a way to propagate
memory errors:

- xmlXPathCompareNodeSets
- xmlXPathEqualNodeSets
2019-10-20 14:39:46 +02:00
Nick Wellnhofer
429d4ecaae Propagate memory errors in valuePush
Currently, many memory allocation errors in xpath.c aren't propagated to
the parser/evaluation context and for the most part ignored. Most
XPath objects allocated via one of the New, Wrap or Copy functions end
up being pushed on the stack, so adding a check in valuePush handles
many cases without much effort.

Also simplify the code a little and make sure to return -1 in case of
error.
2019-10-20 14:38:05 +02:00
Nick Wellnhofer
390f05e703 Propagate memory errors in xmlXPathCompExprAdd
Make sure that memory errors in xmlXPathCompExprAdd are propagated to
the parser context. Hitting the step limit or running out of memory
without raising an error could also lead to an out-of-bounds read.

Also fixes a memory leak in xmlXPathErrMemory.

Found by OSS-Fuzz.
2019-10-20 14:13:05 +02:00
Nick Wellnhofer
aec2bf7153 Make xmlFreeDocElementContent non-recursive
Avoid call stack overflow when freeing element type declarations with
deeply nested contents.

Found by OSS-Fuzz.
2019-10-14 18:01:51 +02:00
Nick Wellnhofer
d8999b1da0 Fix error code in xmlTextWriterStartDocument
Return XML_ERR_UNSUPPORTED_ENCODING if no encoding handler could be
found.

Fixes bug #521808:
https://bugzilla.gnome.org/show_bug.cgi?id=521808

Resolves !53.
2019-10-14 17:06:36 +02:00
Nick Wellnhofer
40e00bc517 Fix integer overflow when counting written bytes
Check for integer overflow when updating the `written` member of
struct xmlOutputBuffer in xmlIO.c.

Closes #112. Resolves !54 and !55.
2019-10-14 17:06:20 +02:00
Daniel Richard G
1fda32480c Fix exponent digits when running tests under old MSVC
Switch printf output format to two-digit exponent under certain MSVC
versions.

Closes #111.
2019-10-14 16:48:32 +02:00
Nick Wellnhofer
f9f8df0a31 Fix uninitialized memory access in HTML parser
The SAX2 character handler expects NULL-terminated buffer.

Closes #106.

Also see https://github.com/lxml/lxml/pull/288
2019-10-14 16:39:21 +02:00
Nick Wellnhofer
5eeb9d5fbb Fix memory leak in xmlSchemaValAtomicType
Don't collapse anyUris twice.

Closes #104.
2019-10-14 16:35:00 +02:00
Nick Wellnhofer
61f2abb1f3 Enable continuous integration via GitLab CI
Port the Travis CI setup to GitLab. We currently run three builds:

- GCC with -std=c89
- clang with ASan and UBSan
- clang with MSan

Closes #110.
2019-10-14 15:52:10 +02:00
Nick Wellnhofer
b88ae6d2e1 Avoid ignored attribute warnings under GCC
GCC doesn't support the unsigned-integer-overflow sanitizer.
2019-10-14 15:40:32 +02:00
Nick Wellnhofer
24e3973bc0 Make xmlDumpElementContent non-recursive
Avoid call stack overflow when dumping deeply nested element
declarations.

Found by OSS-Fuzz.
2019-10-04 14:42:59 +02:00