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

4851 Commits

Author SHA1 Message Date
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
2f2bf4b2ca 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 ...
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
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
Nick Wellnhofer
64966ebefd Rebuild docs 2019-09-30 18:05:45 +02:00
Nick Wellnhofer
2e55f6dc67 Make apibuild.py ignore ATTRIBUTE_NO_SANITIZE 2019-09-30 18:05:45 +02:00
Nick Wellnhofer
74a8a91fda Fix a few more typos ("fonction") 2019-09-30 18:05:42 +02:00
Jared Yanovich
2a350ee9b4 Large batch of typo fixes
Closes #109.
2019-09-30 18:04:38 +02:00
Nick Wellnhofer
80b110a95d Mark xmlExp* symbols as removed 2019-09-30 15:47:30 +02:00
Nick Wellnhofer
c2f209c09f Disallow conditional sections in internal subset
Conditional sections are only allowed in *external* parameter entities
referenced from the internal subset.
2019-09-30 15:47:30 +02:00
Nick Wellnhofer
c51e38cb3a Make xmlParseConditionalSections non-recursive
Avoid call stack overflow in deeply nested conditional sections.

Found by OSS-Fuzz.
2019-09-30 15:47:30 +02:00
Nick Wellnhofer
9d461ac7d0 Adjust expected error in Python tests
Closes #107.
2019-09-26 16:17:31 +02:00
Nick Wellnhofer
d56184a085 Disable xmlExp regex code
This is apparently another regex engine that was never used, see commit
81a8ec6.
2019-09-26 12:11:39 +02:00
Nick Wellnhofer
664f881008 Fix use-after-free in xmlTextReaderFreeNodeList
Recent commit 1fbcf40 caused a use-after-free read because it didn't
account for the fact that xmlTextReaderFreeDoc frees entities before
freeing entity references via xmlTextReaderFreeNodeList.

Found by OSS-Fuzz.
2019-09-26 11:09:17 +02:00