1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-27 04:55:04 +03:00
Commit Graph

5084 Commits

Author SHA1 Message Date
Nick Wellnhofer
31ca4a728c Fix integer overflow in htmlParseCharRef
Fixes #115.
2020-06-15 21:23:54 +02:00
Nick Wellnhofer
2f9382033e Fix undefined behavior in UTF16LEToUTF8
Don't perform arithmetic on null pointer.

Found with libFuzzer and UBSan.
2020-06-15 21:23:54 +02:00
Nick Wellnhofer
536f421d37 Fuzz target for HTML parser 2020-06-15 15:23:38 +02:00
Nick Wellnhofer
a697ed1e24 Fix return value of xmlCharEncOutput
Commit 407b393d introduced a regression caused by xmlCharEncOutput
returning 0 in case of success instead of the number of bytes written.
Always use its return value for nbchars in xmlOutputBufferWrite.

Fixes #166.
2020-06-15 15:23:38 +02:00
Nick Wellnhofer
af893a58c6 Update GitLab CI container 2020-06-11 16:08:16 +02:00
Nick Wellnhofer
a28f7d8789 Never expand parameter entities in text declaration
When parsing the text declaration of external DTDs or entities, make
sure that parameter entities are not expanded. This also fixes a memory
leak in certain error cases.

The change to xmlSkipBlankChars assumes that the parser state is
maintained correctly when parsing external DTDs or parameter entities,
and might expose bugs in the code that were hidden previously.

Found by OSS-Fuzz.
2020-06-10 14:25:19 +02:00
Nick Wellnhofer
487871b0e3 Fix undefined behavior in xmlXPathTryStreamCompile
&NULL[0] is undefined behavior.
2020-06-10 13:23:43 +02:00
Nick Wellnhofer
e98150d444 Add options file for xml fuzzer
This will be picked up OSS-Fuzz, limiting the maximum input size to
80 KB and hopefully avoiding timeouts. Some of the timeouts seem to be
related to our suboptimal handling of excessive entity expansion.
The new fuzzers support external entities and make this problem even
more prominent.
2020-06-09 13:53:06 +02:00
Nick Wellnhofer
2af3c2a8b9 Fix use-after-free with validating reader
Just like IDs, IDREF attributes must be removed from the document's
refs table when they're freed by a reader. This bug is often hidden
because xmlAttr structs are reused and strings are stored in a
dictionary unless XML_PARSE_NODICT is specified.

Found by OSS-Fuzz.
2020-06-08 14:05:42 +02:00
Nick Wellnhofer
00ed736eec Add a couple of libFuzzer targets
- XML fuzzer
  Currently tests the pull parser, push parser and reader, as well as
  serialization. Supports splitting fuzz data into multiple documents
  for things like external DTDs or entities. The seed corpus is built
  from parts of the test suite.

- Regexp fuzzer
  Seed corpus was statically generated from test suite.

- URI fuzzer
  Tests parsing and most other functions from uri.c.
2020-06-05 13:53:11 +02:00
Nick Wellnhofer
2e8cc66d8f xmlParseBalancedChunkMemory must not be called with NULL doc
There is no way to avoid memory leaks without a document to hold the
namespace list.
2020-05-30 15:43:34 +02:00
Nick Wellnhofer
a0a8059b2c Revert "Fix memory leak in xmlParseBalancedChunkMemoryRecover"
This reverts commit 5a02583c7e.

Fixes #161.
2020-05-30 15:43:34 +02:00
Nick Wellnhofer
ff009f9913 Fix memory leak in xmlXIncludeLoadDoc error path
Found by OSS-Fuzz.
2020-05-30 15:43:34 +02:00
Michael Stahl
a230b728f1 win32: allow passing *FLAGS on command line
nmake is a primitive tool, so this is a primitive implementation:
append EXTRA_CFLAGS etc. variables.

Command line variables should be appended to allow overriding flags set
in the makefile.

It doesn't work to pass in CFLAGS like in make because that always
overrides the assignments in the makefile.
2020-05-04 14:16:13 +02:00
Nick Wellnhofer
4f2aee18f6 Make schema validation fail with multiple top-level elements
Closes #126.
2020-05-04 14:03:52 +02:00
Daniel Cheng
106757e8c1 Guard new calls to xmlValidatePopElement in xml_reader.c
Closes #154.
2020-05-04 13:53:11 +02:00
Łukasz Wojniłowicz
386fb27654 Add LIBXML_VALID_ENABLED to xmlreader
There are already LIBXML_VALID_ENABLED in this file to guard against
"--without-valid" at "./configure" step, but here they were missing.
2020-05-04 13:53:11 +02:00
Markus Rickert
e7ff2efc5d Configure file xmlwin32version.h.in on MSVC 2020-05-04 13:53:11 +02:00
Markus Rickert
e2f104940d List headers individually 2020-05-04 13:53:11 +02:00
Markus Rickert
2a2c38f3a3 Add CMake build files
Closes #24.
2020-05-04 13:53:11 +02:00
Samuel Thibault
9fa3200cb3 Call xmlCleanupParser on ELF destruction
Fixes #153.
2020-05-04 13:53:11 +02:00
Miro Hrončok
e4fb368418 Parenthesize Py<type>_Check() in ifs
In C, if expressions should be parenthesized.
PyLong_Check, PyUnicode_Check etc. happened to expand to a parenthesized
expression before, but that's not API to rely on.

Since Python 3.9.0a4 it needs to be parenthesized explicitly.

Fixes https://gitlab.gnome.org/GNOME/libxml2/issues/149
2020-03-10 14:21:27 +01:00
Nick Wellnhofer
20c60886e4 Fix typos
Resolves #133.
2020-03-08 17:41:53 +01:00
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