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

307 Commits

Author SHA1 Message Date
Nick Wellnhofer
3061b56a1e valid: Check for NULL text content in xmlValidateOneElement
Shouldn't occur in parsed documents but you can create text nodes with
NULL content through the API.
2024-03-15 19:47:08 +01:00
Nick Wellnhofer
af3d80b9a0 valid: Check for elem->name in xmlIsID
elem->name can be NULL is xmlNodeSetDoc failed.
2024-03-15 19:47:08 +01:00
Nick Wellnhofer
1233805dcb valid: Fix some return codes after errors 2024-03-15 19:47:08 +01:00
Nick Wellnhofer
04c691f7ea valid: Eliminate xmlCtxtGetDtdElementDesc
Improves malloca failure reporting without parser context.
2024-03-15 19:47:08 +01:00
Nick Wellnhofer
ab345338a4 valid: Report malloc failure in legacy DTD serialization 2024-03-15 19:47:08 +01:00
Nick Wellnhofer
264b283c27 valid: Fix hash removal in xmlRemoveRef
Don't create a NULL entry.
2024-03-15 19:47:08 +01:00
Nick Wellnhofer
802ad903f8 valid: Don't report errors with null context 2024-03-15 19:47:08 +01:00
Nick Wellnhofer
f797cdabf5 valid: Remove id before updating attribute type 2024-03-15 19:47:08 +01:00
Nick Wellnhofer
a3e11e3de1 valid: Fix id handling in xmlValidateDtd
Free id table before and after validation.
2024-03-15 19:47:08 +01:00
Nick Wellnhofer
c4e0db6a9e valid: Reset attribute in xmlFreeID 2024-03-15 19:47:08 +01:00
Nick Wellnhofer
bbbd7f7786 valid: Rework checks in xmlValidateOneElement
Don't check element for extra members and missing content.

Consolidate checks for unexpected elements.
2024-03-15 19:47:08 +01:00
Nick Wellnhofer
b23175d1d8 valid: Check element type in xmlIsID
Also rearrange code for readability.
2024-03-15 19:47:07 +01:00
Nick Wellnhofer
0ddd63dbab valid: Change error code to XML_ERR_ARGUMENT 2024-03-15 19:47:07 +01:00
Nick Wellnhofer
d0d6174e81 valid: Rework xmlAddID 2024-03-15 19:47:07 +01:00
Nick Wellnhofer
9835ec2b97 valid: Fix xmlAddIDSafe in "streaming" mode
Make sure that IDs and attributes never reference each other in
streaming (XML reader) mode, even when attributes are copied from an
entity.

Also update lineno.

Fixes a short-lived use-after-free.
2024-02-13 12:05:21 +01:00
Nick Wellnhofer
2807df9a4a valid: Fix another use-after-free in xmlAddIDSafe
Short-lived regression.
2024-02-06 12:07:19 +01:00
Nick Wellnhofer
70da4c089c valid: Fix use-after-free in xmlAddIDSafe
Short-lived regression.
2024-02-04 14:33:19 +01:00
Nick Wellnhofer
cf8751942b valid: Deprecate old DTD serialization API 2024-02-04 14:33:19 +01:00
Nick Wellnhofer
fbe10a466f save: Move DTD serialization code to xmlsave.c 2024-02-04 14:33:19 +01:00
Nick Wellnhofer
661ef93694 valid: Fix some error codes 2024-01-02 19:48:23 +01:00
Nick Wellnhofer
d025cfbb4b parser: Always copy content from entity to target.
Make sure that references from IDs are updated.

Note that if there are IDs with the same value in a document, the last
one will now be returned. IDs should be unique, but maybe this should be
addressed.
2023-12-29 01:22:11 +01:00
Nick Wellnhofer
130436917c parser: Rename xmlErrParser to xmlCtxtErr 2023-12-21 15:02:24 +01:00
Nick Wellnhofer
54c70ed57f parser: Improve error handling
Introduce xmlCtxtSetErrorHandler allowing to set a structured error for
a parser context. There already was the "serror" SAX handler but this
always receives the parser context as argument.

Start to use xmlRaiseMemoryError.

Remove useless arguments from memory error functions. Rename
xmlErrMemory to xmlCtxtErrMemory.

Remove a few calls to xmlGenericError.

Remove support for runtime entity debugging.
2023-12-21 02:46:27 +01:00
Nick Wellnhofer
355fbe3ab7 valid: Fix handling of enumerations
Make xmlFreeEnumeration, xmlCopyEnumeration and xmlDumpEnumeration
non-recursive. Report malloc failure in xmlCopyEnumeration.
2023-12-16 15:10:15 +01:00
Nick Wellnhofer
61b4c42f38 valid: Report malloc failures
Fix many places where malloc failures aren't reported.
2023-12-11 22:13:06 +01:00
Nick Wellnhofer
e34a49b78e valid: Improve addition and deletion of IDs
Introduce a new API function xmlAddIDSafe that returns a separate error
code if a memory allocation fails.

Store a pointer to the ID struct in xmlAttr so attributes can be
freed without allocating memory. It's impossible to report malloc
failures in deallocation code.
2023-12-11 22:13:05 +01:00
Nick Wellnhofer
8c084ebdc7 doc: Make apibuild.py happy 2023-09-21 22:57:33 +02:00
Nick Wellnhofer
699299cae3 globals: Stop including globals.h 2023-09-20 22:07:40 +02:00
Nick Wellnhofer
4e1c13ebfd debug: Remove debugging code
This is barely useful these days and only clutters the code base.
2023-09-19 17:35:09 +02:00
Nick Wellnhofer
58de9d31da valid: Fix c1->parent pointer in xmlCopyDocElementContent
Fixes #572.
2023-08-03 12:00:55 +02:00
David Kilzer
cb1b8b8516 xmlValidatePopElement() can return invalid value (-1)
Covered by:  test/VC/ElementValid5

This only affects XML Reader API with LIBXML_REGEXP_ENABLED and
LIBXML_VALID_ENABLED turned on.

* result/VC/ElementValid5.rdr:
- Update result to add missing error message.

* python/tests/reader2.py:
* result/VC/ElementValid6.rdr:
* result/VC/ElementValid7.rdr:
* result/valid/781333.xml.err.rdr:
- Update result to fix grammar issue.

* valid.c:
(xmlValidatePopElement):
- Check return value of xmlRegExecPushString() to handle -1, and
  assign 'ret = 0;' to return 0 from xmlValidatePopElement().
  This change affects xmlTextReaderValidatePop() from
  xmlreader.c.
- Fix grammar of error message by changing 'child' to
  'children'.
2023-04-10 13:21:53 -07:00
Nick Wellnhofer
08f9d319eb valid: Make xmlValidateElement non-recursive
Fixes call stack overflows when validating deeply nested documents.

Found by OSS-Fuzz.
2023-03-16 17:01:05 +01:00
Nick Wellnhofer
a57a7549fa valid: Allow xmlFreeValidCtxt(NULL) 2023-03-12 16:06:19 +01:00
Nick Wellnhofer
9fa1b228a5 malloc-fail: Fix memory leak in xmlGetDtdElementDesc2
Found with libFuzzer, see #344.
2023-02-17 17:16:51 +01:00
Nick Wellnhofer
dd3569eaa5 Remove XMLDECL macro from .c files 2022-12-08 02:43:17 +01:00
Alex Richardson
4b959ee168 Remove hacky heuristic from b2dc5675e9
Checking whether the context is close to the parent context by hardcoding
250 is not portable (I noticed tests were failing on Morello since the value
is 288 there due to pointers being 128 bits). Instead we should ensure
that the XML_VCTXT_USE_PCTXT flag is not set in cases where the user data
is not actually a parser context (or ideally add a separate field but that
would be an ABI break.

From what I can see in the source, the XML_VCTXT_USE_PCTXT is only set if
the userData field points to a valid context, and if this is not the case
the flag should be cleared when changing userData rather than relying on
the offset between the two. Looking at the history, I think
d7cb33cf44 fixed most of the need for this
workaround, but it looks like there are a few more locations that need
updating; This commit changes two more places to set/clear/copy the
XML_VCTXT_USE_PCTXT flag, so this heuristic should not be needed anymore.
I've also drop two = NULL assignment in xmllint since this is not needed
after a call to memset().

There was also an uninitialized vctxt.flags (and other fields) in
`xmlShellValidate()`, which I've fixed by adding a memset() call.
2022-12-01 15:31:25 +00:00
Nick Wellnhofer
c714979293 Fix --with-valid --without-regexps build
This build config resulted in segfaults in 'runtest'  because a special
xmlElementContentPtr showed up in a few places. I'm not sure if this is
the right fix.

An error message was changed to conform to the --with-regexps build.

There are still a few missing validity errors, so the tests don't pass.
2022-09-02 18:33:35 +02:00
Nick Wellnhofer
ad338ca737 Remove explicit integer casts
Remove explicit integer casts as final operation

- in assignments
- when passing arguments
- when returning values

Remove casts

- to the same type
- from certain range-bound values

The main motivation is that these explicit casts don't change the result
of operations and only render UBSan's implicit-conversion checks
useless. Removing these casts allows UBSan to detect cases where
truncation or sign-changes occur unexpectedly.

Document some explicit casts as truncating and add a few missing ones.
2022-09-01 02:33:57 +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
David Kilzer
b7e8e4c7f7 Fix leak of xmlElementContent
* valid.c:
(xmlCopyDocElementContent):
- Set `tmp->parent` properly to fix a leak that occurs in
  xmlFreeDocElementContent().
- Appears to be a regresion from cee2b3a5f1.

Found by OSS-Fuzz Issue 44509.
2022-04-07 12:02:02 +00:00
Nick Wellnhofer
4a8c71eb7c Remove DOCBparser
This code has been broken and deprecated since version 2.6.0, released
in 2003. Because of a bug in commit 961b535c, DOCBparser.c was never
compiled since 2012. I couldn't find a Debian package using any of its
symbols, so it seems safe to remove this module.
2022-03-04 22:56:21 +01:00
Nick Wellnhofer
776d15d383 Don't check for standard C89 headers
Don't check for

- ctype.h
- errno.h
- float.h
- limits.h
- math.h
- signal.h
- stdarg.h
- stdlib.h
- string.h
- time.h

Stop including non-standard headers

- malloc.h
- strings.h
2022-03-02 00:43:54 +01:00
Nick Wellnhofer
d05317cee5 Fix --without-valid build
Regressed in commit 652dd12a.
2022-02-22 11:51:08 +01:00
Nick Wellnhofer
004fe9de53 Deprecate IDREF-related functions in valid.h
These functions are only needed internally for validation.

xmlGetRefs is inherently unsafe because the ref table isn't updated
if attributes are removed (unlike the ids table).

None of the Ubuntu 20.04 packages depending on libxml2 use any of these
functions (except xmlFreeRefTable in libxslt), so it seems perfectly
safe to deprecate them.

Remove xmlIsRef and xmlRemoveRef from the Python bindings.
2022-02-20 21:49:05 +01:00
Nick Wellnhofer
346c3a930c Remove elfgcchack.h
The same optimization can be enabled with -fno-semantic-interposition
since GCC 5. clang has always used this option by default.
2022-02-20 21:49:04 +01:00
Nick Wellnhofer
d7cb33cf44 Rework validation context flags
Use a bitmask instead of magic values to

- keep track whether the validation context is part of a parser context
- keep track whether xmlValidateDtdFinal was called

This allows to add addtional flags later.

Note that this deliberately changes the name of a public struct member,
assuming that this was always private data never to be used by client
code.
2022-02-20 21:49:04 +01:00
Nick Wellnhofer
652dd12a85 [CVE-2022-23308] Use-after-free of ID and IDREF attributes
If a document is parsed with XML_PARSE_DTDVALID and without
XML_PARSE_NOENT, the value of ID attributes has to be normalized after
potentially expanding entities in xmlRemoveID. Otherwise, later calls
to xmlGetID can return a pointer to previously freed memory.

ID attributes which are empty or contain only whitespace after
entity expansion are affected in a similar way. This is fixed by
not storing such attributes in the ID table.

The test to detect streaming mode when validating against a DTD was
broken. In connection with the defects above, this could result in a
use-after-free when using the xmlReader interface with validation.
Fix detection of streaming mode to avoid similar issues. (This changes
the expected result of a test case. But as far as I can tell, using the
XML reader with XIncludes referencing the root document never worked
properly, anyway.)

All of these issues can result in denial of service. Using xmlReader
with validation could result in disclosure of memory via the error
channel, typically stderr. The security impact of xmlGetID returning
a pointer to freed memory depends on the application. The typical use
case of calling xmlGetID on an unmodified document is not affected.
2022-02-19 19:26:42 +01:00
Nick Wellnhofer
20c60886e4 Fix typos
Resolves #133.
2020-03-08 17:41:53 +01:00
Nick Wellnhofer
9bd7abfba4 Remove useless comparisons
Found by lgtm.com
2020-01-02 14:14:48 +01: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