Compare commits

..
370 Commits
Author SHA1 Message Date
Sebastian Pipping fa75b96546 Merge pull request #843 from libexpat/issue-838-prepare-release
Prepare release 2.6.2 (part of #838, ETA 2024-03-13)
2024-03-13 17:37:37 +01:00
Sebastian Pipping 8548bc03fd Changes: Add call for help 2024-03-13 14:37:05 +01:00
Sebastian Pipping 86d6052c5e Set release date for 2.6.2 2024-03-13 14:37:05 +01:00
Sebastian Pipping 13cff445fa Bump version to 2.6.2 2024-03-13 14:37:05 +01:00
Sebastian Pipping 557f1255f9 Bump version info from 10:1:9 to 10:2:9
See https://verbump.de/ for what these numbers do
2024-03-13 14:37:05 +01:00
Sebastian Pipping 98ee1baef8 Changes: Document changes in release Expat 2.6.2 2024-03-13 14:37:05 +01:00
Sebastian Pipping 5bf8ed66ef Merge pull request #847 from TomasKorbar/doc-makefile
[2.6.1] Fix DOCBOOK_TO_MAN variable use in doc Makefile
2024-03-13 14:22:48 +01:00
Tomas Korbar c32ed08191 Fix DOCBOOK_TO_MAN variable use in doc Makefile
Not using quotes causes problems when DOCBOOK_TO_MAN contains
command and argument
2024-03-13 11:01:52 +01:00
Sebastian Pipping 5026213864 Merge pull request #842 from libexpat/issue-839-billion-laughs-isolated-external-parser
Prevent billion laughs attacks in isolated external parser (part of #839)
2024-03-07 22:14:09 +01:00
Sebastian Pipping 27525adabd Merge pull request #841 from libexpat/issue-839-reject-direct-parameter-entity-recursion
Reject direct parameter entity recursion (part of #839)
2024-03-07 20:24:13 +01:00
Sebastian Pipping 072eca0b72 tests: Cover amplification tracking for isolated external parser 2024-03-06 23:41:33 +01:00
Sebastian Pipping 1d50b80cf3 lib/xmlparse.c: Detect billion laughs attack with isolated external parser
When parsing DTD content with code like ..

  XML_Parser parser = XML_ParserCreate(NULL);
  XML_Parser ext_parser = XML_ExternalEntityParserCreate(parser, NULL, NULL);
  enum XML_Status status = XML_Parse(ext_parser, doc, (int)strlen(doc), XML_TRUE);

.. there are 0 bytes accounted as direct input and all input from `doc` accounted
as indirect input.  Now function accountingGetCurrentAmplification cannot calculate
the current amplification ratio as "(direct + indirect) / direct", and it did refuse
to divide by 0 as one would expect, but it returned 1.0 for this case to indicate
no amplification over direct input.  As a result, billion laughs attacks from
DTD-only input were not detected with this isolated way of using an external parser.

The new approach is to assume direct input of length not 0 but 22 -- derived from
ghost input "<!ENTITY a SYSTEM 'b'>", the shortest possible way to include an external
DTD --, and do the usual "(direct + indirect) / direct" math with "direct := 22".

GitHub issue #839 has more details on this issue and its origin in ClusterFuzz
finding 66812.
2024-03-06 23:41:07 +01:00
Sebastian Pipping 565ab44a42 tests: Cover rejection of direct parameter entity recursion 2024-03-06 22:34:26 +01:00
Sebastian Pipping a4c86a395e lib/xmlparse.c: Reject directly recursive parameter entities 2024-03-06 22:34:26 +01:00
Sebastian Pipping 6bcb991574 Merge pull request #837 from libexpat/extend-2-6-1-change-log
Add missing #821 #824 to 2.6.1 change log
2024-03-01 20:15:09 +01:00
Sebastian Pipping 8f75c53615 Changes: Add missing #821 #824 to 2.6.1 change log 2024-02-29 22:09:53 +01:00
Sebastian Pipping a590b2d584 Merge pull request #834 from libexpat/issue-832-prepare-release
Prepare release 2.6.1 (part of #832, ETA 2024-02-29)
2024-02-29 21:19:01 +01:00
Sebastian Pipping 1cf882e79c Merge pull request #836 from libexpat/issue-828-expose-billion-laughs-api-with-xml-dtd-without-xml-ge
Expose billion laughs API with `XML_DTD` without `XML_GE` (fixes #828)
2024-02-29 20:07:11 +01:00
Sebastian Pipping 58ff7c39ea Sync file headers 2024-02-28 23:41:43 +01:00
Sebastian Pipping fce4b9f3b3 Set release date for 2.6.1 2024-02-28 23:41:42 +01:00
Sebastian Pipping dfe043fe6a Bump version to 2.6.1 2024-02-28 23:41:31 +01:00
Sebastian Pipping fbe7b9345b Bump version info from 10:0:9 to 10:1:9
See https://verbump.de/ for what these numbers do
2024-02-28 23:41:31 +01:00
Sebastian Pipping 3dc137ea05 Changes: Document changes in release Expat 2.6.1 2024-02-28 23:41:29 +01:00
Sebastian Pipping ea52834709 doc/reference.html: Drop inaccurate statement about XML_* macros
The statement is falsified by these macros:
- XML_ATTR_INFO
- XML_DTD
- XML_GE
2024-02-28 20:47:45 +01:00
Sebastian Pipping 1e028f2ef7 lib/expat.h: Expose billion laughs API for XML_DTD without XML_GE
Regression from commit caa2719863 .
2024-02-28 20:47:45 +01:00
Sebastian Pipping a387201ca4 Merge pull request #833 from libexpat/configure-ac-protect-multilib
`configure.ac`: Protect against `expat_config.h.in` defining `SIZEOF_VOID_P`
2024-02-28 00:55:34 +01:00
Sebastian Pipping 0106682ea6 configure.ac: Protect against expat_config.h.in defining SIZEOF_VOID_P 2024-02-27 00:33:53 +01:00
Sebastian Pipping 9dcb74f552 Merge pull request #829 from libexpat/hide-test-only-code-behind-new-macro
Hide test-only code behind new (internal) macro `XML_TESTING` (alternative to #826)
2024-02-26 21:41:30 +01:00
Sebastian Pipping 7e2a0da9ba lib: Hide some test-only code behind new macro XML_TESTING 2024-02-21 13:07:35 +01:00
Sebastian Pipping a4a420eedc Autotools: Turn libexpatinternal.la into standalone library
.. so that we can now have code in say xmlparse.c that does not
end up in libexpat.so but still runs when executing the test suite.
2024-02-21 12:53:03 +01:00
Sebastian Pipping 5b940f4a65 Merge pull request #824 from libexpat/issue-821-improve-make-clean-for-configure-without-docbook
Autotools: Re-work handling of xmlwf.1 (fixes #821)
2024-02-20 20:40:41 +01:00
Sebastian Pipping 0f6b39d2f5 Autotools: Re-work handling of xmlwf.1
File "doc/xmlwf.1" should not be cleaned when building with
"./configure --without-docbook", and re-compilation of the file
should take precedence over a pre-built copy where available.

Also, variable CLEANFILES can be used to simplify things a bit
in Makefile.am.
2024-02-13 20:12:15 +01:00
Sebastian Pipping b7e1a11011 Merge pull request #817 from SonyMobile/clockless-test
tests: Replace clock counting with counting scanned bytes
2024-02-13 18:30:35 +01:00
Snild Dolkow dc8499f295 tests: Replace clock counting with scanned bytes in linear-time test
This removes the dependency on CLOCKS_PER_SEC that prevented this test
from running properly on some platforms, as well as the inherent
flakiness of time measurements.

Since later commits have introduced g_bytesScanned (and before that,
g_parseAttempts), we can use that value as a proxy for parse time
instead of clock().
2024-02-13 14:05:44 +01:00
Snild Dolkow fe0177cd3f tests: Replace g_parseAttempts with g_bytesScanned
This was used to estimate the number of scanned bytes. Just exposing
that number directly will be more precise.
2024-02-13 13:57:35 +01:00
Sebastian Pipping 4ff4c544aa Merge pull request #820 from libexpat/dependabot/github_actions/actions/upload-artifact-4.3.1
Actions(deps): Bump actions/upload-artifact from 4.3.0 to 4.3.1
2024-02-12 14:52:18 +01:00
dependabot[bot] aed1ed769d Actions(deps): Bump actions/upload-artifact from 4.3.0 to 4.3.1
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.3.0 to 4.3.1.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/26f96dfa697d77e81fd5907df203aa23a56210a8...5d5d22a31266ced268874388b861e4b58bb5c2f3)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-12 12:09:58 +00:00
Sebastian Pipping 226201d10d Merge pull request #819 from th1722/patch-1
Fix compiler warnings
2024-02-11 16:45:16 +01:00
Taichi Haradaguchi 3f60a47cb5 Fix compiler warnings
> In file included from ./../lib/internal.h:149,
>                  from codepage.c:38:
> ./../lib/expat.h:1045:5: warning: "XML_GE" is not defined, evaluates to 0 [-Wundef]
>  1045 | #if XML_GE == 1
>       |     ^~~~~~
> ./../lib/internal.h:158:5: warning: "XML_GE" is not defined, evaluates to 0 [-Wundef]
>   158 | #if XML_GE == 1
>       |     ^~~~~~
2024-02-10 23:08:03 +09:00
Sebastian Pipping 4033d6dc57 Merge pull request #818 from libexpat/fix-clang-format-ci
Get clang-format CI back in sync
2024-02-08 17:24:26 +01:00
clang-format 18.1.0 d4f958e345 Mass-apply clang-format 18.1.0 2024-02-08 15:21:53 +01:00
Sebastian Pipping 849da3e3fe Merge pull request #776 from libexpat/issue-775-prepare-release
Prepare release 2.6.0 (part of #775, ETA is 2024-02-07)
2024-02-06 17:49:41 +01:00
Sebastian Pipping 2a10e173ab Sync file headers 2024-02-06 14:13:00 +01:00
Sebastian Pipping 92f10eb800 .mailmap: Add Joyce Brum and Owain Davies 2024-02-06 14:08:05 +01:00
Sebastian Pipping b5ae2481b0 Set release date for 2.6.0 2024-02-06 14:08:05 +01:00
Sebastian Pipping 310a1977f4 Bump version to 2.6.0 2024-02-06 14:08:05 +01:00
Sebastian Pipping b9fd465231 Bump version info from 9:10:8 to 10:0:9
See https://verbump.de/ for what these numbers do
2024-02-06 14:08:05 +01:00
Sebastian Pipping ae06168b64 Changes: Document changes in release Expat 2.6.0 2024-02-06 14:08:05 +01:00
Sebastian Pipping 8198e4bfed Merge pull request #815 from libexpat/fix-pkg-config-file-for-static-build-on-windows
pkg-config: Add missing `-DXML_STATIC` for Windows (alternative to #805)
2024-02-06 11:09:42 +01:00
Sebastian Pipping 9c16d1c5b4 pkg-config: Add missing -DXML_STATIC (for Windows)
This affects the output of command "pkg-config --cflags --static expat".
2024-02-06 00:17:30 +01:00
Sebastian Pipping 9944b71234 Merge pull request #813 from libexpat/issue-812-protect-against-closing-entities-out-of-order
Protect against closing entities out of order (fixes #812)
2024-02-06 00:16:23 +01:00
Sebastian Pipping b6243248a9 Merge pull request #814 from libexpat/fix-make-check-for-arm64-freebsd
tests: Fix `CLOCKS_PER_SEC` guard for arm64 FreeBSD reality
2024-02-06 00:00:00 +01:00
Sebastian Pipping aba268e2c0 tests/basic_tests.c: Fix CLOCKS_PER_SEC guard for arm64 FreeBSD reality
CLOCKS_PER_SEC turned out to be as small as 128 in practice
on machine cfarm240.cfarm.net .
2024-02-02 18:11:12 +01:00
Sebastian Pipping 127aa340d3 Merge pull request #809 from libexpat/clang-format-18
CI: Upgrade to clang-format 18
2024-01-31 01:49:59 +01:00
Sebastian Pipping 7352d3035b clang-*.yml: Fix accidental trailing whitespace 2024-01-30 22:58:48 +01:00
Sebastian Pipping 37d0184781 clang-format.yml: Bump to clang-format 18 2024-01-30 22:57:10 +01:00
clang-format 18.1.0 137a578087 Mass-apply clang-format 18.1.0 2024-01-30 22:57:09 +01:00
Sebastian Pipping c594eedfa8 apply-clang-format.sh: Drop workaround for lib/siphash.h
Does not seem needed anymore (or running the script would
produce a diff).
2024-01-30 22:57:09 +01:00
Sebastian Pipping 5d2a438af2 apply-clang-format.sh: Use "git ls-files" rather than "find"
.. and reduce difference with sibling script apply-clang-tidy.sh .
2024-01-30 22:57:09 +01:00
Sebastian Pipping 34b598c5f5 Merge pull request #789 from SonyMobile/partial-token-perf
Speed up parsing of big tokens
2024-01-30 22:54:37 +01:00
Sebastian Pipping bc7490a4a7 tests/misc_tests.c: Add regression test for closing entities out of order 2024-01-30 03:39:46 +01:00
Sebastian Pipping c4208e7fd1 lib/xmlparse.c: Protect against closing entities out of order 2024-01-30 02:40:31 +01:00
Sebastian Pipping d5b02e96ab xmlwf: Document argument "-q"
Rebased-and-adapted-by: Snild Dolkow <snild@sony.com>
2024-01-29 19:59:18 +01:00
Sebastian Pipping 09fdf998e7 xmlwf: Support disabling reparse deferral
Rebased-and-adapted-by: Snild Dolkow <snild@sony.com>
2024-01-29 19:59:18 +01:00
Snild Dolkow 8f8aaf5c8e tests: Check heuristic bypass with varying buffer fill sizes
The bypass works on the assumption that the application uses a
consistent fill size. Let's make some assertions about what should
happen when the application doesn't do that -- most importantly,
that parsing does happen eventually, and that the number of scanned
bytes doesn't explode.
2024-01-29 19:59:18 +01:00
Snild Dolkow 182bbc350e tests: Make it clear to clang-tidy that assert_true may not return
The key is to have __attribute__((noreturn)) somewhere that clang-tidy
can see it. In this case, this is the _fail() function, which is
conditionally called from the assert_true() macro.

This will ensure that clang-tidy doesn't complain about NULL values
that we've asserted against in tests.
2024-01-29 19:57:54 +01:00
Sebastian Pipping 2becc8a81d Merge pull request #811 from libexpat/dependabot/github_actions/actions/upload-artifact-4.3.0
Actions(deps): Bump actions/upload-artifact from 4.2.0 to 4.3.0
2024-01-29 17:58:59 +01:00
Snild Dolkow 3d8141d26a Bypass partial token heuristic when nearing full buffer
...instead of only when approaching the maximum buffer size INT/2+1.

We'd like to give applications a chance to finish parsing a large token
before buffer reallocation, in case the reallocation fails.

By bypassing the reparse deferral heuristic when getting close to the
filling the buffer, we give them this chance -- if the whole token is
present in the buffer, it will be parsed at that time.

This may come at the cost of some extra reparse attempts. For a token
of n bytes, these extra parses cause us to scan over a maximum of
2n bytes (... + n/8 + n/4 + n/2 + n). Therefore, parsing of big tokens
remains O(n) in regard how many bytes we scan in attempts to parse. The
cost in reality is lower than that, since the reparses that happen due
to the bypass will affect m_partialTokenBytesBefore, delaying the next
ratio-based reparse. Furthermore, only the first token that "breaks
through" a buffer ceiling takes that extra reparse attempt; subsequent
large tokens will only bypass the heuristic if they manage to hit the
new buffer ceiling.

Note that this cost analysis depends on the assumption that Expat grows
its buffer by doubling it (or, more generally, grows it exponentially).
If this changes, the cost of this bypass may increase. Hopefully, this
would be caught by test_big_tokens_take_linear_time or the new test.

The bypass logic assumes that the application uses a consistent fill.
If the app increases its fill size, it may miss the bypass (and the
normal heuristic will apply). If the app decreases its fill size, the
bypass may be hit multiple times for the same buffer size. The very
worst case would be to always fill half of the remaining buffer space,
in which case parsing of a large n-byte token becomes O(n log n).

As an added bonus, the new test case should be faster than the old one,
since it doesn't have to go all the way to 1GiB to check the behavior.

Finally, this change necessitated a small modification to two existing
tests related to reparse deferral. These tests are testing the deferral
enabled setting, and assume that reparsing will not happen for any other
reason. By pre-growing the buffer, we make sure that this new deferral
does not affect those test cases.
2024-01-29 17:09:36 +01:00
Snild DolkowandSebastian Pipping 60b7420989 Bypass partial token heuristic when close to maximum buffer size
For huge tokens, we may end up in a situation where the partial token
parse deferral heuristic demands more bytes than Expat's maximum buffer
size (currently ~half of INT_MAX) could fit.

INT_MAX/2 is 1024 MiB on most systems. Clearly, a token of 950 MiB could
fit in that buffer, but the reparse threshold might be such that
callProcessor() will defer it, allowing the app to keep filling the
buffer until XML_GetBuffer() eventually returns a memory error.

By bypassing the heuristic when we're getting close to the maximum
buffer size, it will once again be possible to parse tokens in the size
range INT_MAX/2/ratio < size < INT_MAX/2 reliably.

We subtract the last buffer fill size as a way to detect that the next
XML_GetBuffer() call has a risk of returning a memory error -- assuming
that the application is likely to keep using the same (or smaller) fill.

We subtract XML_CONTEXT_BYTES because that's the maximum amount of bytes
that could remain at the start of the buffer, preceding the partial
token. Technically, it could be fewer bytes, but XML_CONTEXT_BYTES is
normally small relative to INT_MAX, and is much simpler to use.

Co-authored-by: Sebastian Pipping <sebastian@pipping.org>
2024-01-29 17:09:36 +01:00
Snild Dolkow ad9c01be8e Make external entity parser inherit partial token heuristic setting
The test is essentially a copy of the existing test for the setter,
adapted to run on the external parser instead of the original one.

Suggested-by: Sebastian Pipping <sebastian@pipping.org>
CI-fighting-assistance-by: Sebastian Pipping <sebastian@pipping.org>
2024-01-29 17:09:36 +01:00
Snild Dolkow 8ddd8e86aa Try to parse even when incoming len is zero
If the reparse deferral setting has changed, it may be possible to
finish a token.
2024-01-29 17:09:36 +01:00
Snild Dolkow 1d3162da8a Add app setting for enabling/disabling reparse heuristic
Suggested-by: Sebastian Pipping <sebastian@pipping.org>
CI-fighting-assistance-by: Sebastian Pipping <sebastian@pipping.org>
2024-01-29 17:09:36 +01:00
Snild Dolkow 09957b8ced Allow XML_GetBuffer() with len=0 on a fresh parser
len=0 was previously OK if there had previously been a non-zero call.
It makes sense to allow an application to work the same way on a
newly-created parser, and not have to care if its incoming buffer
happens to be 0.
2024-01-29 17:09:36 +01:00
Snild Dolkow f1eea784d0 tests: Add max_slowdown info in test_big_tokens_take_linear_time
Suggested-by: Sebastian Pipping <sebastian@pipping.org>
2024-01-29 17:09:36 +01:00
Snild Dolkow 9fe3672459 tests: Run both with and without partial token heuristic
If we always run with the heuristic enabled, it may hide some bugs by
grouping up input into bigger parse attempts.

CI-fighting-assistance-by: Sebastian Pipping <sebastian@pipping.org>
2024-01-29 17:09:36 +01:00
Snild Dolkow 1b9d398517 Don't update partial token heuristic on error
Suggested-by: Sebastian Pipping <sebastian@pipping.org>
2024-01-29 17:09:35 +01:00
Snild Dolkow 9cdf9b8d77 Skip parsing after repeated partials on the same token
When the parse buffer contains the starting bytes of a token but not
all of them, we cannot parse the token to completion. We call this a
partial token.  When this happens, the parse position is reset to the
start of the token, and the parse() call returns. The client is then
expected to provide more data and call parse() again.

In extreme cases, this means that the bytes of a token may be parsed
many times: once for every buffer refill required before the full token
is present in the buffer.

Math:
  Assume there's a token of T bytes
  Assume the client fills the buffer in chunks of X bytes
  We'll try to parse X, 2X, 3X, 4X ... until mX == T (technically >=)
  That's (m²+m)X/2 = (T²/X+T)/2 bytes parsed (arithmetic progression)
  While it is alleviated by larger refills, this amounts to O(T²)

Expat grows its internal buffer by doubling it when necessary, but has
no way to inform the client about how much space is available. Instead,
we add a heuristic that skips parsing when we've repeatedly stopped on
an incomplete token. Specifically:

 * Only try to parse if we have a certain amount of data buffered
 * Every time we stop on an incomplete token, double the threshold
 * As soon as any token completes, the threshold is reset

This means that when we get stuck on an incomplete token, the threshold
grows exponentially, effectively making the client perform larger buffer
fills, limiting how many times we can end up re-parsing the same bytes.

Math:
  Assume there's a token of T bytes
  Assume the client fills the buffer in chunks of X bytes
  We'll try to parse X, 2X, 4X, 8X ... until (2^k)X == T (or larger)
  That's (2^(k+1)-1)X bytes parsed -- e.g. 15X if T = 8X
  This is equal to 2T-X, which amounts to O(T)

We could've chosen a faster growth rate, e.g. 4 or 8. Those seem to
increase performance further, at the cost of further increasing the
risk of growing the buffer more than necessary. This can easily be
adjusted in the future, if desired.

This is all completely transparent to the client, except for:
1. possible delay of some callbacks (when our heuristic overshoots)
2. apps that never do isFinal=XML_TRUE could miss data at the end

For the affected testdata, this change shows a 100-400x speedup.
The recset.xml benchmark shows no clear change either way.

Before:
benchmark -n ../testdata/largefiles/recset.xml 65535 3
  3 loops, with buffer size 65535. Average time per loop: 0.270223
benchmark -n ../testdata/largefiles/aaaaaa_attr.xml 4096 3
  3 loops, with buffer size 4096. Average time per loop: 15.033048
benchmark -n ../testdata/largefiles/aaaaaa_cdata.xml 4096 3
  3 loops, with buffer size 4096. Average time per loop: 0.018027
benchmark -n ../testdata/largefiles/aaaaaa_comment.xml 4096 3
  3 loops, with buffer size 4096. Average time per loop: 11.775362
benchmark -n ../testdata/largefiles/aaaaaa_tag.xml 4096 3
  3 loops, with buffer size 4096. Average time per loop: 11.711414
benchmark -n ../testdata/largefiles/aaaaaa_text.xml 4096 3
  3 loops, with buffer size 4096. Average time per loop: 0.019362

After:
./run.sh benchmark -n ../testdata/largefiles/recset.xml 65535 3
  3 loops, with buffer size 65535. Average time per loop: 0.269030
./run.sh benchmark -n ../testdata/largefiles/aaaaaa_attr.xml 4096 3
  3 loops, with buffer size 4096. Average time per loop: 0.044794
./run.sh benchmark -n ../testdata/largefiles/aaaaaa_cdata.xml 4096 3
  3 loops, with buffer size 4096. Average time per loop: 0.016377
./run.sh benchmark -n ../testdata/largefiles/aaaaaa_comment.xml 4096 3
  3 loops, with buffer size 4096. Average time per loop: 0.027022
./run.sh benchmark -n ../testdata/largefiles/aaaaaa_tag.xml 4096 3
  3 loops, with buffer size 4096. Average time per loop: 0.099360
./run.sh benchmark -n ../testdata/largefiles/aaaaaa_text.xml 4096 3
  3 loops, with buffer size 4096. Average time per loop: 0.017956
2024-01-29 17:09:35 +01:00
Snild Dolkow 60dffa148c tests: Use normal XML_Parse in test_suspend_resume_internal_entity
When the parser is suspended, _XML_Parse_SINGLE_BYTES() will return
early. At that point, there could be some amount of bytes that haven't
been fed into Expat at all yet. This leaves us with an incomplete
document.

Furthermore, the last internal XML_Parse() call with isFinal=XML_TRUE
will not have happened, so the parser will not know that no more input
is to be expected. This is what allowed the test to pass when it was
originally changed to use SINGLE_BYTES.

With the new partial token heuristic, the lack of a final parse call
means that we don't even reach the "Ho" text, and fail the test.

The simplest solution is to go back to using XML_Parse() in this test.
Another option would be to let SINGLE_BYTES expose how far it got in
its loop, allowing for later continuation, but it doesn't seem worth the
extra complexity.
2024-01-29 17:09:35 +01:00
Snild Dolkow 3484383fa7 Add aaaaaa_*.xml with unreasonably large tokens
Some of these currently take a very long time to parse. I set those to
only run one loop in the run-benchmark make target.

4096 may be a fairly small buffer, and definitely make the problem worse
than it otherwise would've been, but similar sizes exist in real code:

 * 2048 bytes in cpython Modules/pyexpat.c
 * 4096 bytes in skia SkXMLParser.cpp
 * BUFSIZ bytes (8192 on my machine) in expat/examples

The files, too, are inspired by real-life examples: Android stores
depth and gain maps as base64-encoded JPEGs inside the XMP data of
other JPEGs. Sometimes as a text element, sometimes as an attribute
value. I've seen attribute values slightly over 5 MiB in size.
2024-01-29 17:09:35 +01:00
dependabot[bot] b04a01d431 Actions(deps): Bump actions/upload-artifact from 4.2.0 to 4.3.0
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.2.0 to 4.3.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/694cdabd8bdb0f10b2cea11669e1bf5453eed0a6...26f96dfa697d77e81fd5907df203aa23a56210a8)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-29 12:14:39 +00:00
Sebastian Pipping 183270d565 Merge pull request #810 from libexpat/clang-18
CI: Upgrade to Clang 18 (except clang-tidy and clang-format)
2024-01-26 19:10:31 +01:00
Sebastian Pipping f7ada131b7 Merge pull request #808 from libexpat/clang-tidy-18
CI: Upgrade to clang-tidy 18
2024-01-26 18:30:17 +01:00
Sebastian Pipping 6880fe4948 CI: Upgrade to Clang 18 (except clang-tidy and clang-format) 2024-01-26 16:20:04 +01:00
Sebastian Pipping fc0b026ce5 clang-format.yml: De-couple clang-format from Clang
.. so that we can bump their versions independently
2024-01-26 16:19:59 +01:00
Sebastian Pipping 7acda8d16a clang-tidy.yml: Upgrade to clang-tidy 18 2024-01-26 16:19:02 +01:00
Sebastian Pipping 737e8ea183 tests/misc_tests.c: Address clang-tidy 18 warning EnumCastOutOfRange
clang-tidy output was:
> [..]/libexpat/expat/tests/misc_tests.c:112:23: note: The value '-1' provided to the cast expression is not in the valid range of values for 'XML_Error'
>   112 |   if (XML_ErrorString((enum XML_Error) - 1) != NULL)
>       |                       ^~~~~~~~~~~~~~~~~~~~
> [..]/libexpat/expat/tests/misc_tests.c:114:23: error: The value '100' provided to the cast expression is not in the valid range of values for 'XML_Error' [clang-analyzer-optin.core.EnumCastOutOfRange,-warnings-as-errors]
>   114 |   if (XML_ErrorString((enum XML_Error)100) != NULL)
>       |                       ^~~~~~~~~~~~~~~~~~~
2024-01-26 16:19:02 +01:00
Sebastian Pipping abd9542b32 Merge pull request #806 from libexpat/dependabot/github_actions/actions/upload-artifact-4.2.0
Actions(deps): Bump actions/upload-artifact from 4.0.0 to 4.2.0
2024-01-22 14:52:20 +01:00
dependabot[bot] 2c37fc7d7d Actions(deps): Bump actions/upload-artifact from 4.0.0 to 4.2.0
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.0.0 to 4.2.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v4...694cdabd8bdb0f10b2cea11669e1bf5453eed0a6)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-22 12:09:43 +00:00
Sebastian Pipping 86a3623a9a Merge pull request #801 from catenacyber/fuzzcovstop
fuzz: Improve coverage by maybe stopping the parser
2024-01-17 17:36:43 +01:00
Sebastian Pipping 5b70d3ac44 fuzz/xml_parsebuffer_fuzzer.c: Be more robust towards ouf-of-memory 2024-01-17 10:08:42 +01:00
Philippe Antoine 34af886238 fuzz: improve coverage by maybe stopping parser 2024-01-16 11:08:44 +01:00
Sebastian Pipping 2640b1d97c Merge pull request #799 from libexpat/ci-fuzzing
Make CI run fuzzing regression tests (fixes #367)
2024-01-16 02:26:43 +01:00
Sebastian Pipping c47e191797 Merge pull request #803 from libexpat/fix-cppcheck-ci
Fix Cppcheck CI for Cppcheck 2.13.0
2024-01-16 01:14:12 +01:00
Sebastian Pipping 24ffba44bd Make CI run fuzzing regression tests 2024-01-15 23:57:02 +01:00
Sebastian Pipping 73ebe0bfb3 fuzz: Address warning -Wunused-function with regard to sip24_valid 2024-01-15 23:57:02 +01:00
Sebastian Pipping ed38687779 mass-cppcheck.sh: Fix for Cppcheck 2.13.0
Cppcheck output was:
> expat/lib/xmlparse.c:67:4: error: #error XML_GE (for general entities) must be defined, [..]
> #  error XML_GE (for general entities) must be defined, [..]
>    ^
2024-01-15 23:29:19 +01:00
Sebastian Pipping 3ff1d00dc2 cppcheck.yml: Bump to macOS 12
Homebrew output was:
> Warning: You are using macOS 11.
> We (and Apple) do not provide support for this old version.
> [..]
2024-01-15 23:29:19 +01:00
Sebastian Pipping 9e603b35e0 Merge pull request #802 from libexpat/dependabot/github_actions/actions/upload-artifact-4.1.0
Actions(deps): Bump actions/upload-artifact from 4.0.0 to 4.1.0
2024-01-15 17:06:21 +01:00
dependabot[bot] 2d9bc9aec6 Actions(deps): Bump actions/upload-artifact from 4.0.0 to 4.1.0
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4.0.0 to 4.1.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/c7d193f32edcb7bfad88892161225aeda64e9392...1eb3cb2b3e0f29609092a73eb033bb759a334595)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-15 12:39:38 +00:00
Sebastian Pipping 19af57f2dd Merge pull request #800 from libexpat/clang-tidy-more
clang-tidy: Address warnings `readability-avoid-const-params-in-decls` and `readability-named-parameter`
2024-01-13 01:59:22 +01:00
Sebastian Pipping 226a1527cf clang-tidy: Address warning readability-named-parameter 2024-01-12 23:27:19 +01:00
Sebastian Pipping 225ebd45e1 clang-tidy: Address warning readability-avoid-const-params-in-decls
clang-tidy output was:
> [..]/tests/handlers.h:502:64: error: parameter 'index' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls,-warnings-as-errors]
>   502 | _handler_record_get(const struct handler_record_list *storage, const int index,
>       |                                                                ^~~~~
> [..]/tests/handlers.h:503:39: error: parameter 'line' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls,-warnings-as-errors]
>   503 |                     const char *file, const int line);
>       |                                       ^~~~~
2024-01-12 22:19:05 +01:00
Sebastian Pipping 7664ecdbae Merge pull request #798 from libexpat/clang-tidy
Make GitHub Actions enforce clang-tidy clean code + address current clang-tidy warnings
2024-01-12 21:38:35 +01:00
Sebastian Pipping f832f7b981 Make GitHub Actions enforce clang-tidy clean code 2024-01-12 17:26:50 +01:00
Sebastian Pipping 10cded2493 tests/basic_tests.c: Address clang-tidy warning clang-analyzer-core.NullDereference
clang-tidy output was:
> [..]/tests/basic_tests.c:2083:19: warning: Dereference of null pointer [clang-analyzer-core.NullDereference]
>  2083 |   errorFlags |= ((model[0].type == XML_CTYPE_SEQ) ? 0 : (1u << 2));
>       |                   ^~~~~~~~~~~~~
2024-01-12 17:25:27 +01:00
Sebastian Pipping e23c300f25 tests/acc_tests.c: Address clang-tidy warning clang-analyzer-core.NonNullParamChecker
clang-tidy output was:
> [..]/tests/acc_tests.c:368:9: warning: Null pointer passed to 1st parameter expecting 'nonnull' [clang-analyzer-core.NonNullParamChecker]
>   368 |     if (strlen(printable) < (size_t)1)
>       |         ^      ~~~~~~~~~

Note: It was harmless because fail(..) right before catches that case.
2024-01-12 17:25:27 +01:00
Sebastian Pipping 0b424cb9ae examples/element_declarations.c: Simplify first call to stackPushMalloc
.. where stackTop is NULL anyway
2024-01-12 17:25:27 +01:00
Sebastian Pipping 0ebca2b10f examples/element_declarations.c: Fix memleak in dumpContentModel on OOM
clang-tidy output was:
> [..]/examples/element_declarations.c:163:16: warning: Potential leak of memory pointed to by 'stackTop' [clang-analyzer-unix.Malloc]
>   163 |         return false;
>       |                ^
2024-01-12 04:46:47 +01:00
Sebastian Pipping 716fd10bd4 Merge pull request #797 from catenacyber/fuzzcov
fuzz: improve coverage
2024-01-10 23:07:00 +01:00
Philippe Antoine bb58abd4e0 fuzz: improve coverage 2024-01-10 22:06:37 +01:00
Sebastian Pipping be47f6d5e8 Merge pull request #796 from libexpat/ci-control-flow-integrity
Make CI cover Clang's Control Flow Integrity sanitizer
2023-12-19 18:39:44 +01:00
Sebastian Pipping 64912b70fb Merge pull request #795 from libexpat/autotools-install-shipped-xmlwf-manpage
Autotools: Make installation of shipped `doc/xmlwf.1` independent of docbook2man availability
2023-12-19 18:38:44 +01:00
Sebastian Pipping 18b44c980e linux.yml: Cover Clang's Control Flow Integrity sanitizer 2023-12-19 01:31:10 +01:00
Sebastian Pipping 9495cefd94 qa.sh: Fix dropping of QA_SANITIZER 2023-12-19 01:31:10 +01:00
Sebastian Pipping 4b878938bb qa.sh: Support Clang's Control Flow Integrity sanitizer
https://clang.llvm.org/docs/ControlFlowIntegrity.html
2023-12-19 01:31:10 +01:00
Sebastian Pipping 7384c88f9a configure.ac: Make installation of shipped doc/xmlwf.1 independent of docbook2man availability 2023-12-18 23:59:25 +01:00
Sebastian Pipping 822d1706b2 Merge pull request #794 from libexpat/dependabot/github_actions/actions/upload-artifact-4.0.0
Actions(deps): Bump actions/upload-artifact from 3.1.3 to 4.0.0
2023-12-18 17:48:34 +01:00
dependabot[bot] 8c87ca470d Actions(deps): Bump actions/upload-artifact from 3.1.3 to 4.0.0
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3.1.3 to 4.0.0.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/a8a3f3ad30e3422c9c7b888a15615d19a852ae32...c7d193f32edcb7bfad88892161225aeda64e9392)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-18 12:12:08 +00:00
Sebastian Pipping b9fcca0aaa Merge pull request #793 from libexpat/fix-bug-report-target
CMake|Autotools: Fix `PACKAGE_BUGREPORT` variable to something working
2023-12-17 23:09:46 +01:00
Sebastian Pipping 5a3c419e6a CMake|Autotools: Fix PACKAGE_BUGREPORT variable to something working 2023-12-17 03:34:27 +01:00
Sebastian Pipping 85ee77d31f Merge pull request #792 from libexpat/autotools-sync-cmake-files
autotools: Sync CMake templates with CMake 3.26
2023-12-16 16:50:45 +01:00
Sebastian Pipping 141cdab714 autotools: Sync CMake templates with CMake 3.26 2023-12-15 05:02:23 +01:00
Sebastian Pipping fb702e6c0e Merge pull request #790 from libexpat/cmake-build-benchmark-also
CMake: Build `tests/benchmark/benchmark.c` for `EXPAT_BUILD_TESTS`
2023-11-22 13:04:23 +01:00
Sebastian Pipping a55b7925b2 benchmark.c: Address MSVC warnings C4267 and C4244
Compiler output was:
> tests\benchmark\benchmark.c(102): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
> tests\benchmark\benchmark.c(117): warning C4244: 'initializing': conversion from '__int64' to 'int', possible loss of data
2023-11-21 21:42:50 +01:00
Sebastian Pipping 038040447e CMake: Build tests/benchmark/benchmark.c for EXPAT_BUILD_TESTS
.. like the Autotools build system does.
2023-11-21 20:27:24 +01:00
Sebastian Pipping 3588720613 Merge pull request #787 from libexpat/tests-more-chunk-size-coverage
tests: Migrate more tests to variable chunk size parsing
2023-11-13 15:21:37 +01:00
Sebastian PippingandSnild Dolkow d2b31760cd tests: Simplify _XML_Parse_SINGLE_BYTES
Co-authored-by: Snild Dolkow <snild@sony.com>
2023-11-11 02:15:44 +01:00
Sebastian Pipping 3e5f6d6601 tests: Migrate more tests to variable chunk size parsing 2023-11-09 20:27:20 +01:00
Sebastian Pipping 795cf99922 tests: Make _XML_Parse_SINGLE_BYTES deny use with pathological input 2023-11-09 20:26:38 +01:00
Sebastian Pipping df1e3d6f1e Merge pull request #788 from SonyMobile/narrower-mingw-workaround
tests: Narrow test_buffer_can_grow_to_max mingw allocation workaround at compile time
2023-11-09 15:50:38 +01:00
Snild Dolkow dcbc143680 tests: Narrow test_buffer_can_grow_to_max mingw allocation workaround
Instead of applying it to all less-than-64-bit platforms, let's narrow
the workaround to just the known failure: 32-bit mingw.
2023-11-09 10:46:51 +01:00
Sebastian Pipping 3a0c5d6ae5 Merge pull request #777 from libexpat/xml-dtd-undefined
Fix issues for compilation with XML_DTD undefined
2023-11-08 14:05:03 +01:00
Sebastian Pipping d11ed9fa48 Merge pull request #786 from libexpat/tests-nan-and-infinity
tests: Use NAN and INFINITY of C99 and C++11
2023-11-07 16:37:38 +01:00
Sebastian Pipping 9411ac625b tests: Use NAN and INFINITY of C99 and C++11
Effectively reverts commit f6f5d9bb4c.
2023-11-07 14:22:31 +01:00
Sebastian PippingandSnild Dolkow 8a6c61de4a lib: Add XML_GE to XML_GetFeatureList and XML_FeatureEnum
Co-authored-by: Snild Dolkow <snild@sony.com>
2023-11-07 13:00:42 +01:00
clang-format ac14808b26 Mass-apply clang-format 17.0.3 using ./apply-clang-format.sh 2023-11-07 13:00:42 +01:00
Sebastian PippingandSnild Dolkow 55fecd6aa4 Drop redundant "XML_GE == 1" guards
These are redundant because further out there is a guard
for "XML_GE == 1" already.  In the visual world, the pattern
is this:

> #if XML_GE == 1
> [..]
> #  if XML_GE == 1
> [..]
> #  endif
> [..]
> #endif

Spotted by Snild Dolkow, thanks!

Co-authored-by: Snild Dolkow <snild@sony.com>
2023-11-07 13:00:42 +01:00
Sebastian Pipping caa2719863 Simplify "defined(XML_DTD) || XML_GE == 1" to "XML_GE == 1" 2023-11-07 13:00:42 +01:00
Sebastian Pipping 2848dc4e70 Simplify "! defined(XML_DTD) && XML_GE == 0" to "XML_GE == 0" 2023-11-07 13:00:42 +01:00
Sebastian Pipping e3aaa06cdf linux.yml: Add a dedicated run for -DEXPAT_GE=OFF 2023-11-07 13:00:42 +01:00
Sebastian Pipping d269f90975 coverage.sh: Cover XML_DTD undefined (with and without XML_GE) 2023-11-07 13:00:42 +01:00
Sebastian Pipping cdead241d4 doc/reference.html: Clarify effect of XML_DTD on external entities
Defining XML_DTD emnables support for external parameter(!)
entities.  External general(!) entities have been supported
even with XML_DTD undefined.  (Only now with Expat 2.6.0
defining XML_GE as 0 can take that away.)
2023-11-07 13:00:42 +01:00
Sebastian Pipping d3f7bbd37b doc/reference.html: Document build time macro XML_GE 2023-11-07 13:00:42 +01:00
Sebastian Pipping 2f18bacfcd tests: Cover and adjust to XML_GE==0 self-references 2023-11-07 13:00:42 +01:00
Sebastian Pipping 2b127c20b2 lib: Make XML_GE==0 use self-references as entity replacement text 2023-11-06 21:02:42 +01:00
Sebastian Pipping 7767efe1aa tests/handlers.c: Make accumulate_entity_decl robust towards value==NULL 2023-11-06 21:02:42 +01:00
Sebastian Pipping b0975cb73a lib: Fail the build if XML_GE is not set to 1 or 0 2023-11-06 20:43:09 +01:00
Sebastian Pipping 00089ed745 tests: Fix tests for XML_GE==0 + broaden for XML_GE==1 2023-11-06 20:43:09 +01:00
Sebastian Pipping 0f075ec8ec lib|xmlwf|cmake: Extend scope of billion laughs attack protection
.. from "defined(XML_DTD)" to "defined(XML_DTD) || XML_GE==1".
2023-11-06 20:43:09 +01:00
Sebastian Pipping ed87a47934 configure.ac: Define macro XML_GE as 1 2023-11-06 20:43:09 +01:00
Sebastian Pipping daa89e42c0 cmake: Introduce option EXPAT_GE to control macro XML_GE 2023-11-06 20:43:09 +01:00
Sebastian Pipping d285fafaca Merge pull request #785 from libexpat/fix-dll-version-info
win32|cmake: Fix FileVersion and ProductVersion in DLL version info
2023-11-04 00:20:34 +01:00
Sebastian Pipping 781269f4a8 win32|cmake: Fix FileVersion and ProductVersion in DLL version info
Before: {'FileVersion': 'VER_FILEVERSION', 'ProductVersion': 'VER_FILEVERSION'}
After: {'FileVersion': '2.5.0.0', 'ProductVersion': '2.5.0.0'}

Thanks to @spookyahell for helpful gist "exe2version_info.py":
https://gist.github.com/spookyahell/b317bdf0712aac5fd37dd79f70bfbe69
2023-11-03 21:55:49 +01:00
Sebastian Pipping d4e0eeb77b Merge pull request #771 from SonyMobile/buffer-limit
Grow buffer based on current size
2023-10-26 15:53:18 +02:00
Snild Dolkow 119ae277ab Grow buffer based on current size
Until now, the buffer size to grow to has been calculated based on the
distance from the current parse position to the end of the buffer. This
means that the size of any already-parsed data was not considered,
leading to inconsistent buffer growth.

There was also a special case in XML_Parse() when XML_CONTEXT_BYTES was
zero, where the buffer size would be set to twice the incoming string
length. This patch replaces this with an XML_GetBuffer() call.

Growing the buffer based on its total size makes its growth consistent.

The commit includes a test that checks that we can reach the max buffer
size (usually INT_MAX/2 + 1) regardless of previously parsed content.

GitHub CI couldn't allocate the full 1GiB with MinGW/wine32, though it
works locally with the same compiler and wine version. As a workaround,
the test tries to malloc 1GiB, and reduces `maxbuf` to 512MiB in case
of failure.
2023-10-26 08:21:51 +02:00
Sebastian Pipping adf413c56c Merge pull request #784 from libexpat/tests-drop-unused-type
tests/handlers.h: Drop unused type XmlParseFunction
2023-10-26 00:26:15 +02:00
Sebastian Pipping 4a4e7cfae6 tests/handlers.h: Drop unused type XmlParseFunction
Last use removed in commit b3d14b0d3c
2023-10-25 22:08:04 +02:00
Sebastian Pipping 5347517942 Merge pull request #783 from SonyMobile/remove-singlebytes-switching
tests: Stop switching between XML_Parse and _XML_Parse_SINGLE_BYTES
2023-10-25 18:38:53 +02:00
Snild Dolkow 1222ae34fb tests: Use SINGLE_BYTES in test_nobom_utf16_le
All tests now run one instance where SINGLE_BYTES is equivalent to a
single XML_Parse call. Using SINGLE_BYTES therefore gives more coverage,
as evidenced by the new failure we now have to avoid in the test, until
it can be fixed.
2023-10-25 17:25:48 +02:00
Snild Dolkow 29babedcab tests: Remove EE_PARSE_FULL_BUFFER
All tests now run one instance where SINGLE_BYTES is equivalent to a
single XML_Parse call. There is no longer a need for individual tests
to switch between them.
2023-10-25 17:25:05 +02:00
Snild Dolkow b3d14b0d3c tests: Remove choice between XML_Parse and SINGLE_BYTES
Since commit 091ba48d ("tests: Run SINGLE_BYTES with no chunking"),
all tests are run an extra time with SINGLE_BYTES set to perform just
a single XML_Parse() call. There is no longer a need for individual
tests to switch between them.
2023-10-25 17:25:00 +02:00
Sebastian Pipping 9e1c41343c Merge pull request #780 from libexpat/xml-dtd-undefined-fix-ext-parser-create-null-dereference
xmlparse.c: Fix `NULL` pointer dereference in `setContext` via `XML_ExternalEntityParserCreate` for `XML_DTD` undefined
2023-10-24 17:05:31 +02:00
Sebastian Pipping 7b814b8220 Merge pull request #781 from libexpat/tests-move-to-the-right-place
tests/acc_tests.c: Move second BOM accounting test to the right place
2023-10-24 17:02:20 +02:00
Sebastian Pipping 258abf00fe Merge pull request #782 from libexpat/tests-drop-mistaken-unused-variable-marker
tests/handlers.c: Drop mistaken unused variable marker
2023-10-24 17:01:35 +02:00
Sebastian Pipping 54f1c4595f tests/handlers.c: Drop mistaken unused variable marker 2023-10-23 21:18:04 +02:00
Sebastian Pipping 6e1ddc3b9c tests/acc_tests.c: Move second BOM accounting test to the right place
The test makes use of general entities (not parameter entities)
but was mis-filed under parameter entities.
2023-10-23 20:30:45 +02:00
Sebastian Pipping 4eeaf49262 xmlparse.c: Fix NULL pointer dereference in XML_ExternalEntityParserCreate
.. for context NULL inside function setContext
when macro XML_DTD is not defined at compile time.
2023-10-23 18:14:56 +02:00
Sebastian Pipping a39a2f5c65 Merge pull request #779 from libexpat/doc-reference-html-add-macro-anchors
doc/reference.html: Add HTML anchors to definition of XML_* macros
2023-10-23 18:12:08 +02:00
Sebastian Pipping 7b0cf18e6f Merge pull request #778 from libexpat/dependabot/github_actions/actions/checkout-4.1.1
Actions(deps): Bump actions/checkout from 4.1.0 to 4.1.1
2023-10-23 15:38:46 +02:00
Sebastian Pipping 76d60929c2 doc/reference.html: Add HTML anchors to definition of XML_* macros 2023-10-23 15:33:08 +02:00
Sebastian Pipping a83a941898 Merge pull request #774 from libexpat/tests-rename-fail-unless
tests: Rename fail_unless to assert_true for clarity
2023-10-23 14:46:12 +02:00
dependabot[bot] dcaa886004 Actions(deps): Bump actions/checkout from 4.1.0 to 4.1.1
Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.0 to 4.1.1.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/8ade135a41bc03ea155e62e844d188df1ea18608...b4ffde65f46336ab88eb53be808477a3936bae11)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-23 12:20:43 +00:00
Sebastian Pipping 2604c59eb9 Merge pull request #773 from libexpat/clang-17
Upgrade Clang from 15 to 17
2023-10-21 15:52:09 +02:00
Sebastian Pipping cf2a57bbe6 linux.yml: Make note about .ci.sh harder to overlook 2023-10-20 23:58:13 +02:00
Sebastian Pipping e07ee1ec32 Actions: Upgrade Clang from 15 to 17 2023-10-20 23:58:13 +02:00
clang-format a392427d3a Mass-apply clang-format 17.0.3 using ./apply-clang-format.sh 2023-10-20 23:49:51 +02:00
Sebastian Pipping 0cfeab4f1c Merge pull request #772 from libexpat/tests-warnings-mingw
tests/memcheck.c: Avoid false positive -Wuse-after-free
2023-10-20 23:49:06 +02:00
Sebastian Pipping da64791736 tests: Rename fail_unless to assert_true for clarity 2023-10-20 23:41:04 +02:00
Sebastian Pipping cce19de59f tests: Rename _fail_unless to _assert_true for clarity 2023-10-20 23:24:46 +02:00
Sebastian Pipping eeab6366b0 tests/memcheck.c: Avoid false positive -Wuse-after-free
Symptom was this compile warning from MinGW GCC 12:
> [..]/expat/tests/memcheck.c: In function ‘tracking_realloc’:
> [..]/expat/tests/memcheck.c:169:25: error: pointer ‘ptr’ may be used after ‘realloc’ [-Werror=use-after-free]
>   169 |       entry->allocation = ptr;
>       |       ~~~~~~~~~~~~~~~~~~^~~~~
> [..]/expat/tests/memcheck.c:166:25: note: call to ‘realloc’ here
>   166 |     entry->allocation = realloc(ptr, size);
>       |                         ^~~~~~~~~~~~~~~~~~

The warning is a false positive since the code was only using ptr
when realloc failed where it is documented that the original pointer is
not freed.

The workaround is to no longer override-and-restore entry->allocation
but to only write to it when realloc was successful.  The original
value was equal to ptr so the result is the same.
2023-10-20 20:19:37 +02:00
Sebastian Pipping a68399a05b Merge pull request #770 from libexpat/xmlwf-sync-man-page
xmlwf: Get man page back in sync (i.e. add `--help`, `--version` and `-g <bytes>`)
2023-10-18 21:46:41 +02:00
Sebastian Pipping 4d475d97d6 doc/xmlwf.xml: Add missing entry on "-g <bytes>" 2023-10-18 16:48:03 +02:00
Sebastian Pipping 1746075001 doc/xmlwf.xml: Add missing entry on -h|--help 2023-10-18 16:48:03 +02:00
Sebastian Pipping 114cb042ae doc/xmlwf.xml: Add --help and --version where missing 2023-10-18 16:48:03 +02:00
Sebastian Pipping 28347d9586 Merge pull request #764 from libexpat/xml-context-bytes-zero
Be stricter about macro XML_CONTEXT_BYTES at build time
2023-10-06 14:21:36 +02:00
Sebastian Pipping 96985a1a07 lib/xmlparse.c: Make clang-format 16.0.6 happy again 2023-10-05 15:44:10 +02:00
Sebastian Pipping 23110a864d Be stricter about macro XML_CONTEXT_BYTES
- Start treating -DXML_CONTEXT_BYTES=0 as "no context"
  rather than "context of size 0".  Was documented as
  "must be set to a positive integer", previously.

- Enforce that macro XML_CONTEXT_BYTES is defined at build time to
  avoid accidental misbuilds lacking context in environments that
  bypass both of Expats official build systems.

- Detect and reject use of negative context size at compile time.
2023-10-05 15:44:10 +02:00
Sebastian Pipping acbcd0915d Merge pull request #766 from libexpat/doc-parse-buffer-variables
lib/xmlparse.c: Improve parse buffer variables documentation
2023-10-05 14:50:10 +02:00
Sebastian Pipping 32f64cf174 Merge pull request #762 from libexpat/doc-reference-html-promote-xml-parsebuffer-more
doc/reference.html: Promote function XML_ParseBuffer more
2023-10-05 14:49:29 +02:00
Sebastian Pipping 3ae5431d22 Merge pull request #765 from libexpat/consistent-expat-config-h-includes
Make inclusion to expat_config.h consistent
2023-10-05 01:35:26 +02:00
Sebastian Pipping dd34d0e65c lib/xmlparse.c: Improve parse buffer variables documentation 2023-10-04 22:40:31 +02:00
Sebastian Pipping ab43d8d116 Make inclusion to expat_config.h consistent
.. and priorize the local build over the system header.
2023-10-04 19:58:28 +02:00
Sebastian Pipping 1d3ee5133e doc/reference.html: Make XML_Parse promote XML_ParseBuffer 2023-10-04 18:01:31 +02:00
Sebastian Pipping 81a705b6ae doc/reference.html: Wrap paragraphs by <p> for function XML_Parse 2023-10-03 23:25:09 +02:00
Sebastian Pipping 60654a3255 Merge pull request #763 from libexpat/fix-codespell-ci
Fix codespell CI + mass-replace "re-use[d]" by "reuse[d]"
2023-10-03 23:23:29 +02:00
Sebastian Pipping c135d7a118 codespell.yml: Ignore "[p]arameter" in xmlwf help output 2023-10-03 21:33:55 +02:00
Sebastian Pipping c1d4c439a1 docs: Mass-replace "re-use[d]" by "reuse[d]"
Pointed out by codespell.
2023-10-03 21:33:55 +02:00
Sebastian Pipping 1763071577 Merge pull request #761 from libexpat/xmlwf-help-version
xmlwf: Support --help and --version
2023-09-29 17:48:21 +02:00
Sebastian Pipping 92cdc783f1 xmlwf: Get help output alignment back in order 2023-09-29 12:55:17 +02:00
Sebastian Pipping 4c6731ad11 xmlwf: Use XMLWF_EXIT_SUCCESS where missing 2023-09-29 12:55:17 +02:00
Sebastian Pipping 0b3ef852bc xmlwf: Support --help and --version 2023-09-29 12:55:17 +02:00
Sebastian Pipping 900d2a7cd2 xmlwf: Better document that usage(..) calls exit(..) 2023-09-29 12:55:17 +02:00
Sebastian Pipping bc26bc5896 xmlwf: Break up conditional before upcoming extension 2023-09-29 12:06:05 +02:00
Sebastian Pipping 8741d2a1db Merge pull request #760 from libexpat/doc-reference-html-okcss-1-2-0
doc/reference.html: Upgrade to OK.css 1.2.0
2023-09-29 11:42:12 +02:00
Sebastian Pipping 0cf825c342 doc/reference.html: Add paragraph wrap for XML_ParserCreate
.. in order to fix styling.
2023-09-28 21:00:00 +02:00
Sebastian Pipping 08efcde3be Merge pull request #759 from libexpat/xmlwf-custom-buffer-size
xmlwf: Support custom buffer size for XML_GetBuffer and read
2023-09-28 20:54:24 +02:00
Sebastian Pipping cc3079f149 doc/reference.html: Upgrade to OK.css 1.2.0 2023-09-28 20:13:12 +02:00
Sebastian Pipping d248e7e923 xmlwf: Support custom buffer size for XML_GetBuffer and read 2023-09-28 17:06:39 +02:00
Sebastian Pipping f2a9d1155b Merge pull request #758 from SonyMobile/chunk-tests-with-0
Run SINGLE_BYTES with no chunking, too
2023-09-28 15:47:44 +02:00
Snild Dolkow 091ba48d7a tests: Run SINGLE_BYTES with no chunking
...in addition to 1-to-5-byte chunks as we've done so far.

By starting g_chunkSize at 0, we get to run all the tests that call
_XML_Parse_SINGLE_BYTES() as if they just called XML_Parse(). This
gives us extra test coverage.
2023-09-28 13:49:41 +02:00
Snild Dolkow 7b0e27a698 tests: Replace invalid entity expansion in test_alloc_nested_entities
%pe2; would ultimately expand to a plain "ABCDEF...", which is not
valid in this context. This was not normally hit, since the test would
get its expected XML_ERROR_NO_MEMORY before expanding this far.

With g_chunkSize=0 and EXPAT_CONTEXT_BYTES=OFF, the number of allocs
required to reach that point becomes *just* low enough to reach the
final expansion, making the test fail with a very unexpected syntax
error.

Nesting %pe2; in another entity declaration avoids the problem.
2023-09-28 13:49:41 +02:00
Snild Dolkow b4d2b76a97 tests: Exit parser_stop_character_handler if parser is finished
When test_repeated_stop_parser_between_char_data_calls runs without
chunking the input -- which I am about to do in my next commit -- the
parser_stop_character_handler callback happens multiple times. This is
because stopping the parser doesn't stop all callbacks immediately,
which is valid (documented) behavior.

The second callback tried to stop the parser again, getting unexpected
errors. Let's check the parser status on entry and return early if it's
already finished.
2023-09-28 13:49:41 +02:00
Sebastian Pipping e1dc3383e3 Merge pull request #757 from SonyMobile/more-is-final
Add isFinal=XML_TRUE to more tests
2023-09-27 17:37:56 +02:00
Snild Dolkow a5993b2d42 tests: Remove early comment count check in test_user_parameters
Before a parse call with isFinal=XML_TRUE, there is no guarantee that
all supplied data has been parsed. Removing the first comment count
check removes the test's assumption of such a guarantee.
2023-09-26 10:33:43 +02:00
Snild Dolkow bb3c171980 tests: set isFinal in test_reset_in_entity
Without this, parsing may be deferred so that the suspending callback
hasn't been called when the test checks for it.
2023-09-26 10:33:43 +02:00
Snild Dolkow 2e12534145 tests: set isFinal in test_line_number_after_parse
Without this, parsing of the start or end tag may be deferred, yielding
an unexpected line number.
2023-09-26 10:33:43 +02:00
Sebastian Pipping 2ed4410e07 Merge pull request #756 from libexpat/dependabot/github_actions/actions/checkout-4.1.0
Actions(deps): Bump actions/checkout from 4.0.0 to 4.1.0
2023-09-25 16:06:29 +02:00
Sebastian Pipping 365b156d9d Merge pull request #755 from SonyMobile/chunk-tests
Repeat tests with different SINGLE_BYTES chunk sizes
2023-09-25 15:27:42 +02:00
dependabot[bot] b63e902b8f Actions(deps): Bump actions/checkout from 4.0.0 to 4.1.0
Bumps [actions/checkout](https://github.com/actions/checkout) from 4.0.0 to 4.1.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/3df4ab11eba7bda6032a0b82a6bb43b11571feac...8ade135a41bc03ea155e62e844d188df1ea18608)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-25 12:48:26 +00:00
Snild Dolkow 1d8ceb26aa tests: Run SINGLE_BYTES with variously-sized chunks
The _XML_Parse_SINGLE_BYTES function currently calls XML_Parse() one
byte at a time. This is useful to detect possible parsing bugs related
to having to exit parsing, wait for more data, and resume.

This commit makes SINGLE_BYTES even more useful by repeating all tests,
changing the chunk size every time. So instead of just one byte at a
time, we now also test two bytes at a time, and so on. Tests that don't
use the SINGLE_BYTES also run multiple times, but are otherwise not
affected.

This uncovered some issues, which have been fixed in preceding commits.

On failure, the chunk size is included in the "FAIL" log prints.
2023-09-25 14:01:53 +02:00
Snild Dolkow 4978d285d2 tests: Look for single-char match in test_abort_epilog
...instead of a full-string match.

These tests were depending on getting handler callbacks with exactly
one character of data at a time. For example, if test_abort_epilog got
"\n\r\n" in one callback, it would fail to match on the '\r', and would
not abort parsing as expected.

By searching the callback arg for the magic character rather than
expecting a full match, the test no longer depends on exact callback
timing.

`userData` is never NULL in these tests, so that check was left out of
the new version.
2023-09-25 14:01:53 +02:00
Snild Dolkow 7474fe3d3f tests: Make test_default_current insensitive to callback chunking
Instead of testing the exact number and sequence of callbacks, we now
test that we get the exact data lengths and sequence of callbacks. The
checks become much more verbose, but will now accept any buffer fill
strategy -- single bytes, multiple bytes, or any combination thereof.
2023-09-25 14:01:46 +02:00
Snild Dolkow a4a4552313 tests: Add subtest names to test_default_current 2023-09-25 08:45:37 +02:00
Snild Dolkow d825624d92 minicheck: Add fail_unless() macro
...and fix _fail_unless() so that it doesn't always fail. All existing
calls to it pass 0, so there's no immediate change in behavior in this
commit.
2023-09-25 08:45:37 +02:00
Donghee Na e52b6b8b8c Update legal name of Donghee Na (#754) 2023-09-24 18:13:03 +02:00
Sebastian Pipping bcdc25b04d Merge pull request #753 from SonyMobile/consume-bom
Fix parse-size-dependent "invalid token" error for external entities that start with a byte order mark
2023-09-22 18:06:57 +02:00
Snild Dolkow b1e955449c Always consume BOM bytes when found in prolog
The byte order mark is not correctly consumed when followed by an
incomplete token in a non-final parse. This results in the BOM staying
in the buffer, causing an invalid token error later.

This was not detected by existing tests because they either parse
everything in one call, or add a single byte at a time.

By moving `s` forward when we find a BOM, we make sure that the BOM
bytes are properly consumed in all cases.
2023-09-22 17:14:22 +02:00
Sebastian Pipping a642ba0920 Merge pull request #749 from libexpat/cmake-3-5-0-plus
CMake: Require CMake >=3.5.0
2023-09-21 22:53:58 +02:00
Sebastian Pipping 298f407021 Merge pull request #750 from libexpat/tests-cxx-11
tests: Require a C++11 compiler
2023-09-21 22:47:48 +02:00
Sebastian Pipping bb6ec6ad0f Merge pull request #751 from libexpat/cmake-c99
CMake: Require a C99 compiler
2023-09-21 21:45:34 +02:00
Sebastian Pipping 9666cc5e38 qa.sh: Stop passing -Wno-long-long
.. since we have C99 and C++11 now: Both understand long long.
2023-09-21 21:32:28 +02:00
Sebastian Pipping 1bf3ddfdad CI: Request C++11 rather than C++98 2023-09-21 19:34:23 +02:00
Sebastian Pipping 47b86b5d46 CMake: Require a C++11 compiler for the optional test suite 2023-09-21 19:34:23 +02:00
Sebastian Pipping 2a24068ec8 CMake: Require a C99 compiler 2023-09-21 19:30:30 +02:00
Sebastian Pipping 6162b99065 Merge pull request #748 from libexpat/runtests-cxx-restore
tests: Restore that all of runtestspp is run through a C++ compiler
2023-09-21 13:25:09 +02:00
Sebastian Pipping ede28c8fe0 configure.ac: Require a C++11 compiler for the optional test suite 2023-09-20 19:09:30 +02:00
Sebastian Pipping 8c96dcad17 list_exported_macros.sh: Avoid producing word "if"
.. as use of macro AX_CXX_COMPILE_STDCXX_11 would.
2023-09-20 19:09:30 +02:00
Sebastian Pipping 74dbef1552 CMake: Pass -Wno-format with MinGW 2023-09-20 19:08:05 +02:00
Sebastian Pipping 4642553bb8 CMake: Stop redefining STDC_HEADERS 2023-09-20 19:08:03 +02:00
Sebastian Pipping 899a775a2e CMake: Require CMake >=3.5.0
> CMake Deprecation Warning at CMakeLists.txt:37 (cmake_minimum_required):
>   Compatibility with CMake < 3.5 will be removed from a future version of
>   CMake.
>
>   Update the VERSION argument <min> value or use a ...<max> suffix to tell
>   CMake that the project does not need compatibility with older versions.
2023-09-19 19:45:05 +02:00
Sebastian Pipping 07b6d0089f tests: Rename "runtestspp" to "runtests_cxx" 2023-09-19 19:25:19 +02:00
Sebastian Pipping aacc14f4b4 tests: Restore that all of runtestspp is run through a C++ compiler
.. as originally intended before the big split-up refactoring.
2023-09-19 19:22:20 +02:00
Sebastian Pipping 322ac581e3 tests: Cast malloc/calloc/realloc results to allow use as C and C++ 2023-09-19 19:20:11 +02:00
Sebastian Pipping f5e20fcb9d tests: Add more const near malloc/calloc/realloc 2023-09-19 19:19:33 +02:00
Sebastian Pipping 34dc95a08a tests/structdata.c: Avoid name "new" to allow reuse from C++ 2023-09-19 19:14:14 +02:00
Sebastian Pipping 2fb1aee9aa tests/Makefile.am: Sort libruntests_a_SOURCES alphabetically 2023-09-19 18:51:41 +02:00
Sebastian Pipping 8192058e2a Merge pull request #747 from libexpat/tests-explicit-expat-config-h
tests/handlers.h: Be explicit about direct dependency expat_config.h
2023-09-19 18:34:29 +02:00
Sebastian Pipping 41762d1cf2 Merge pull request #746 from libexpat/cmake-sort-xmlwf-sources
CMake: Sort xmlwf sources alphabetically
2023-09-19 17:58:47 +02:00
Sebastian Pipping b709ce2b0a CMake: Sort xmlwf sources alphabetically 2023-09-19 16:19:47 +02:00
Sebastian Pipping 48f15bfa1c tests/handlers.h: Be explicit about direct dependency expat_config.h
The file checks for XML_DTD being defined.
2023-09-19 16:16:54 +02:00
Snild Dolkow c803b93e87 minicheck: Add simple subtest support
This will be useful when a test runs through several examples and
fails somewhere in the middle. The subtest string replaces the
phase_info string (i.e. "during actual test") in the failure output.

Added subtest info to various tests where I found for loops.
2023-09-18 10:46:01 +02:00
Sebastian Pipping 4811d55b12 Merge pull request #745 from SonyMobile/is-final
Document the importance of isFinal + adjust tests accordingly
2023-09-14 16:05:54 +02:00
Snild Dolkow d4105a9080 tests: Set isFinal=1 in line/column-number-after-error tests 2023-09-14 11:16:40 +02:00
Snild Dolkow 2cee1061e2 tests: Set isFinal in test_column_number_after_parse
Without this, parsing of the end tag may be deferred, yielding an
unexpected column number.
2023-09-14 11:16:36 +02:00
Snild Dolkow d52b414149 tests: Move triplet_start_checker flag check after isFinal=1 call
There is no guarantee that the callback will happen before the parse
call with isFinal=XML_TRUE. Let's move the assertion to a location
where we know it must have happened.
2023-09-14 11:16:29 +02:00
Snild Dolkow 355a123b92 docs: Document the importance of isFinal
Before the concluding `isFinal=XML_TRUE` parse call, there is no
guarantee that all input has been parsed. An application that omits
that call risks missing handler callbacks and/or parsing errors.
2023-09-14 11:15:59 +02:00
Sebastian Pipping 9d715b1062 Merge pull request #744 from libexpat/xmlwf-help-fixes
xmlwf: Improve language and URL clickability in help output
2023-09-11 23:13:19 +02:00
Sebastian Pipping 2f2cda0a2a xmlwf: Improve language and URL clickability in help output 2023-09-11 21:54:24 +02:00
Sebastian Pipping ac5faf7d2d Merge pull request #743 from libexpat/dependabot/github_actions/actions/checkout-4.0.0
Actions(deps): Bump actions/checkout from 3.6.0 to 4.0.0
2023-09-11 21:11:59 +02:00
Sebastian Pipping 3e92d68ce2 Merge pull request #742 from libexpat/dependabot/github_actions/actions/upload-artifact-3.1.3
Actions(deps): Bump actions/upload-artifact from 3.1.2 to 3.1.3
2023-09-11 15:36:24 +02:00
dependabot[bot] 37a2262af4 Actions(deps): Bump actions/checkout from 3.6.0 to 4.0.0
Bumps [actions/checkout](https://github.com/actions/checkout) from 3.6.0 to 4.0.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/f43a0e5ff2bd294095638e18286ca9a3d1956744...3df4ab11eba7bda6032a0b82a6bb43b11571feac)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-11 12:19:44 +00:00
dependabot[bot] d644e679d4 Actions(deps): Bump actions/upload-artifact from 3.1.2 to 3.1.3
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 3.1.2 to 3.1.3.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/0b7f8abb1508181956e8e162db84b466c27e18ce...a8a3f3ad30e3422c9c7b888a15615d19a852ae32)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-11 12:19:39 +00:00
Sebastian Pipping 8b5c9e1a01 Merge pull request #740 from libexpat/pull-674-sandwich
Merge branch `pull-674-sandwich` into `master`
2023-09-02 23:11:31 +02:00
Sebastian Pipping f4071b8417 Merge pull request #739 from libexpat/codespell-action
codespell.yml: Make CI reject spelling errors using codespell + fix two typos
2023-09-02 22:14:31 +02:00
Sebastian Pipping 66435e268f Merge pull request #738 from libexpat/pull-674-topping
Make branch `pull-674-sandwich` mergable to `master`
2023-09-02 20:50:34 +02:00
Sebastian Pipping 181d06421d codespell.yml: Make CI reject spelling errors using codespell 2023-09-02 19:04:38 +02:00
Sebastian Pipping c0a78d0511 Changes: Fix typo "curruption" in section on release 2.5.0 2023-09-02 19:04:38 +02:00
Sebastian Pipping 1264df28b3 CMake: Fix in-comment typo "compatiblity" 2023-09-02 19:04:38 +02:00
Sebastian Pipping 2ac0600db5 Merge pull request #737 from libexpat/dependabot/github_actions/actions/checkout-3.6.0
Actions(deps): Bump actions/checkout from 3.5.3 to 3.6.0
2023-09-02 18:46:29 +02:00
Sebastian Pipping ca6050827d tests/ns_tests.c: Be explicit about direct dependency expat_config.h 2023-09-02 18:38:03 +02:00
Sebastian Pipping 26c33a2dcc tests: Undef NDEBUG where needed more after refactoring
All other test files using assert(..) and <assert.h> have the same.
2023-09-02 18:37:35 +02:00
Sebastian Pipping 17367a5642 tests/runtests.c: Re-apply 883115d0a3 and c094e450a1
This effectively reverts commit 42dc2c2c4e.
2023-09-02 18:36:36 +02:00
Sebastian Pipping 014a303dc1 Merge pull request #674 from RMJ10/test_refactor_2
Refactor coverage and conformance tests
2023-09-02 18:33:53 +02:00
dependabot[bot] fab7fdd903 Actions(deps): Bump actions/checkout from 3.5.3 to 3.6.0
Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.3 to 3.6.0.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/c85c95e3d7251135ab7dc9ce3241c5835cc595a9...f43a0e5ff2bd294095638e18286ca9a3d1956744)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-08-28 12:05:56 +00:00
Sebastian Pipping 42dc2c2c4e tests/runtests.c: Revert 883115d0a3 and c094e450a1
.. to not break a ~100 commit refactoring during rebase.  Will be re-applied after refactoring.

Related command was:
$ git checkout c094e450a136ffdf4d3e128588b615008a35489e^ -- ./tests/runtests.c
2023-08-26 15:31:34 +02:00
Rhodri James 2ed94f7435 Trim list of include files in runtests.c 2022-11-01 12:13:43 +00:00
Rhodri James 8f704f9771 Move accounting tests out of runtests.c 2022-11-01 12:10:03 +00:00
Rhodri James 4261de44a6 Move framework for accounting tests out of runtests.c 2022-11-01 11:50:10 +00:00
Rhodri James 83b3a0fc70 Move remaining nsalloc tests out of runtests.c 2022-11-01 11:28:30 +00:00
Rhodri James 224dd46041 Move first tranche of nsalloc tests out of runtests.c 2022-11-01 11:19:12 +00:00
Rhodri James a434478dac Move framework for namespace allocation tests out of runtests.c
Note that nsalloc_setup and nsalloc_teardown are not static for
the moment, since they are used in the tests still in runtests.c
2022-11-01 11:11:58 +00:00
Rhodri James 8d2b621dcd Move final allocation test out of runtests.c and tidy up 2022-11-01 10:58:46 +00:00
Rhodri James 156eabde7d Move most remaining allocation tests out of runtests.c 2022-10-31 17:48:11 +00:00
Rhodri James ef34e67014 Move more alloc tests out of runtests.c
Also eliminates the last (ab)used of intptr_t
2022-10-31 17:43:59 +00:00
Rhodri James 8000770127 Move a bunch more allocation tests out of runtests.c 2022-10-31 17:38:41 +00:00
Rhodri James b81eca3052 Move test_alloc_external_entity out of runtests.c
Again modify slightly to avoid use of intptr_t
2022-10-31 17:32:38 +00:00
Rhodri James 639cb93f78 Move test_alloc_dtd_copy_default_atts outof runtests.c
Modify the test and handler slightly to avoid abusing UserData to
pass an integer to the handler instead of a pointer.  Mostly this
just avoids including stdint.h
2022-10-31 17:13:09 +00:00
Rhodri James 4c6d77c368 Move basic failing-allocator entity tests out of runtests.c 2022-10-31 17:03:07 +00:00
Rhodri James 932748bf1b Move remaining declaration, comment and PI tests out of runtests.c 2022-10-31 16:57:03 +00:00
Rhodri James e827f83974 Move first allocation test out of runtests.c 2022-10-31 16:36:21 +00:00
Rhodri James badcbe21f7 Move framework for allocation tests to new alloc_tests.c
Note that the alloc_setup and alloc_teardown functions are
not static for the moment, since they will be required in both
alloc_tests.c and runtests.c until the test case move is complete.
2022-10-31 16:32:54 +00:00
Rhodri James 38d65ef5f3 Move remaining misc tests out of runtests.c
It is unclear why these are misc tests rather than basic or
namespace tests.  They are also disappointingly cavalier about
checking return values (e.g. from the unnecessary mallocs). At
some point they need revisiting and tidying up.
2022-10-31 16:10:41 +00:00
Rhodri James 9a45d5f485 Move some more misc tests out of runtests.c 2022-10-31 15:55:17 +00:00
Rhodri James db4b5fe845 Move and fix the version test out of runtests.c
The tests can't be run with XML_UNICODE and XML_UNICODE_WCHAR_T
inconsistently set, both build systems protect against that.  The
second branch of the test is therefore redundant (as evidenced by
the stale version number it is testing against) and has been
deleted.
2022-10-31 14:24:10 +00:00
Rhodri James 88b1104792 Move the first tranche of misc tests out of runtests.c 2022-10-31 14:07:54 +00:00
Rhodri James a1dc75441c Set up to move misc tests from tests/runtests.c 2022-10-31 14:05:23 +00:00
Rhodri James e70f9b2d5b Move the fail-on-command allocators to tests/common.c
Also make the control variables int rather than intptr_t.  They
were previously typed for convenience of passing them as a user
data "pointer", but that's much less convenient when they are
externally linked.
2022-10-31 13:14:46 +00:00
Rhodri James b9686e7887 Move remaining namespace tests from runtests.c to ns_tests.c 2022-10-31 13:07:51 +00:00
Rhodri James 707e4af1d6 Move test_start_ns_clears_start_element out of runtests.c 2022-10-31 12:57:06 +00:00
Rhodri James afd8c08b80 Move first namespace tests out of runtests.c to new ns_tests.c
These two tests need to be moved together because test_ns_parser_reset
calls test_return_ns_triplet, and the START_TEST macro defines test
functions to be static.
2022-10-31 12:56:48 +00:00
Rhodri James f0976982b1 Move final basic tests out of runtests.c
Also make make_basic_test_case a void function, since the TCase
object is no longer needed elsewhere.
2022-10-28 22:18:42 +01:00
Rhodri James 959d3f43a4 Move most remaining basic tests out of runtests.c 2022-10-28 22:14:12 +01:00
Rhodri James b53efe051d Move more (mostly UTF16) tests out of runtests.c 2022-10-28 22:07:11 +01:00
Rhodri James eef3e9f4c2 Move more encoding tests out of runtests.c 2022-10-28 22:04:25 +01:00
Rhodri James 6933957fb6 Move (some) external entity UTF16 encoding tests out of runtests.c 2022-10-28 22:00:04 +01:00
Rhodri James df7d0caec1 Move unknown encoding tests out of runtests.c 2022-10-28 21:55:31 +01:00
Rhodri James dfbb39b755 Move some UTF16 comment tests out of runtests.c 2022-10-28 21:48:29 +01:00
Rhodri James bbbc7cfe79 Move the first batch of PI tests out of runtests.c 2022-10-28 21:45:29 +01:00
Rhodri James 02a58b9eb8 Move another tranche of basic tests out of runtests.c 2022-10-28 21:30:56 +01:00
Rhodri James 33343db13d Move another collection of tests out of runtests.c 2022-10-28 20:55:38 +01:00
Rhodri James dc9689b1c2 Move some entity suspension tests out of runtests.c 2022-10-28 20:52:32 +01:00
Rhodri James b08ce35a73 Move remaining basic epilog tests out of runtests.c 2022-10-28 20:47:51 +01:00
Rhodri James 9bece1957f Move (some) epilog tests out of runtests.c 2022-10-28 20:45:35 +01:00
Rhodri James b55c5df683 Move test_suspend_xdecl out of runtests.c 2022-10-28 20:43:31 +01:00
Rhodri James 123d2695a3 Remove redundant aborting_xdecl_handler from runtests.c 2022-10-28 20:42:11 +01:00
Rhodri James b4498d85c5 Move test_undefined_ext_entity_in_external_dtd out of runtests.c 2022-10-28 20:37:54 +01:00
Rhodri James 252e93dbdc Move some parameter entity tests out of runtests.c 2022-10-28 20:31:36 +01:00
Rhodri James 16ddb05e82 Move some group tests out of runtests.c 2022-10-28 20:31:36 +01:00
Rhodri James c4b41fbb17 Move still more tests out of runtests.c 2022-10-28 20:31:36 +01:00
Rhodri James 8d3fe6ce74 Move test_ext_entity_not_standalone out of runtests.c 2022-10-28 20:31:36 +01:00
Rhodri James 07b7a9f4fc Move test_external_entity_values out of runtests.c 2022-10-28 20:31:36 +01:00
Rhodri James 5509b7df8a Move remaining ignore section tests out of runtests.c 2022-10-28 20:31:36 +01:00
Rhodri James eda657484c Move more basic tests out of runtests.c 2022-10-28 20:31:36 +01:00
Rhodri James f25cea8669 Move more basic tests out of runtests.c 2022-10-28 20:31:36 +01:00
Rhodri James 991924c7da Move byte_character_handler out of runtests.c 2022-10-28 20:31:31 +01:00
Rhodri James bf11ca9025 Move (some) XML_GetBuffer tests out of runtests.c 2022-10-28 20:00:24 +01:00
Rhodri James 4c28bb1681 Move external_entity_ref_param_checker out of runtests.c 2022-10-28 19:56:09 +01:00
Rhodri James f0adbc47ef Move test_user_parameters out of runtests.c 2022-10-28 19:09:52 +01:00
Rhodri James 3946a35816 Move external entity CDATA test out of runtests.c 2022-10-28 18:59:57 +01:00
Rhodri James 8a54cd9fcd Move right square bracket handlers and tests out of runtests.c 2022-10-28 18:58:33 +01:00
Rhodri James 3971adaef6 Move CR test functions out of runtests.c 2022-10-28 18:51:42 +01:00
Rhodri James 8117bfa90b Move CR check support handlers out of runtests.c 2022-10-28 18:49:14 +01:00
Rhodri James 477fb31b8f Move more basic tests out of runtests.c 2022-10-28 18:45:30 +01:00
Rhodri James 755f1a28e6 Move external_entity_suspending_faulter out of runtests.c 2022-10-28 18:43:56 +01:00
Rhodri James be2daefd0f Move more basic external entity tests out of runtests.c 2022-10-28 18:40:31 +01:00
Rhodri James 1dafd3fb46 Move more external entity handlers out of runtests.c 2022-10-28 18:38:53 +01:00
Rhodri James aecea8915d Move test_subordinate_reset out of runtests.c 2022-10-28 18:34:22 +01:00
Rhodri James 2560f587e0 Move counting_start_element_handler and more tests out of runtests.c 2022-10-28 18:31:46 +01:00
Rhodri James ad2283fe92 Move null loader and more tests out of runtests.c 2022-10-28 18:27:45 +01:00
Rhodri James 7932f5502a Move some foreign DTD tests out of runtests.c 2022-10-28 18:17:31 +01:00
Rhodri James 8b4647bedd Move test_dtd_elements_nesting() out of runtests.c
Don't put element_decl_check_model in with the rest of the handlers
because it is strongly tied with this test and not likely to ever
be generally useful.
2022-10-28 18:02:22 +01:00
Rhodri James 5882280f3e Move more basic tests out of runtests.c 2022-10-28 17:57:49 +01:00
Rhodri James 80ed32698b Move simple recording test handlers out of runtests.c 2022-10-28 17:53:07 +01:00
Rhodri James 43664d0297 Move still more basic tests out of runtests.c 2022-10-28 17:50:06 +01:00
Rhodri James 29115b5a83 Move more constant data out of runtests.c 2022-10-28 17:48:29 +01:00
Rhodri James 49ec5ee0ee Move some more basic tests out of runtests.c 2022-10-28 17:46:42 +01:00
Rhodri James 44f595931c Move parser_stop_character_handler out of runtests.c
Also make "abortable" a global and rename it g_abortable.
2022-10-28 17:43:50 +01:00
Rhodri James c46bfeb5d3 Move stop/suspend character handler tests out of runtests.c 2022-10-28 17:38:14 +01:00
Rhodri James a66d239d11 Move clearing_aborting_character_handler out of runtests.c
Also make "resumable" a global and rename it as g_resumable.
2022-10-28 17:34:55 +01:00
Rhodri James 9c4efa8cfd Move constant test data to common.c 2022-10-28 16:32:10 +01:00
Rhodri James ce4eb21198 Move basic xmlns without namespaces tests out 2022-10-28 16:28:45 +01:00
Rhodri James d97a46b916 Move basic attribute list test out of runtests.c 2022-10-28 16:25:37 +01:00
Rhodri James 20cb700ee7 Move some more basic tests out of runtests.c 2022-10-28 16:20:17 +01:00
Rhodri James 8a2b69d1c0 Move basic NotStandalone tests out of runtests.c 2022-10-28 16:17:56 +01:00
Rhodri James 7d4eb0dc56 Move a swathe of external entity tests out of runtests.c 2022-10-28 16:13:32 +01:00
Rhodri James b784470d66 Move basic external entity tests out of runtests.c 2022-10-28 15:49:43 +01:00
Rhodri James 2c8ac7e582 Move encoding handlers and basic tests out of runtests.c 2022-10-28 15:45:43 +01:00
Rhodri James 24dc824ee1 Move XML declaration tests out of runtests.c 2022-10-28 15:40:19 +01:00
Rhodri James e5f762920d Move whitespace normalization tests out of runtests.c 2022-10-28 15:38:45 +01:00
Rhodri James 6c011a1a8d Wrap whitespace normalization checker in a proper test 2022-10-28 15:36:20 +01:00
Rhodri James dc518bedf0 Move element event test out of runtests.c 2022-10-28 15:29:42 +01:00
Rhodri James 6dcbd90d00 Move long line tests out of runtests.c 2022-10-28 15:26:34 +01:00
Rhodri James 6755cde416 Move row and column number tests to basic_tests.c 2022-10-28 15:22:10 +01:00
Rhodri James 9af04b70c3 Move remaining encoding tests out of runtests.c 2022-10-28 15:09:56 +01:00
Rhodri James 8a2b58b823 Move character and attribute data support functions to common.c 2022-10-28 15:02:26 +01:00
Rhodri James 5228e6e076 Move first tranche of character/encoding tests out of runtests.c
test_hash_collision is included to keep all the tests requiring
siphash.h together.
2022-10-28 14:51:17 +01:00
Rhodri James 51d83971f7 Move creation of basic test case to a separate file
Eventually this will contain all the basic test cases, at which
point make_basic_test_case() will be altered to return void.
2022-10-28 13:57:17 +01:00
Rhodri James b8ba93ce7c Move some handler functions to new handlers.c file
Specifically external_entity_optioner and param_entity_match_handler
2022-10-28 13:47:44 +01:00
Rhodri James bc06abd94c Move dummy handler functions to a new source file 2022-10-28 13:16:34 +01:00
Rhodri James f555f08853 Move common test support functions to a separate file.
A necessary first step if we are going to be able to reduce the
size of runtests.c by splitting test cases into separate files.
2022-10-28 13:15:58 +01:00
109 changed files with 18767 additions and 13165 deletions
+3 -5
View File
@@ -6,9 +6,10 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2017-2022 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2017-2024 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2017 Rolf Eike Beer <eike@sf-mail.de>
# Copyright (c) 2019 Mohammed Khajapasha <mohammed.khajapasha@intel.com>
# Copyright (c) 2019 Manish, Kumar <manish3.kumar@intel.com>
# Copyright (c) 2019 Philippe Antoine <contact@catenacyber.fr>
# Licensed under the MIT license:
#
@@ -39,7 +40,7 @@ if [[ ${RUNNER_OS} = macOS ]]; then
export PATH="/usr/local/opt/coreutils/libexec/gnubin${PATH:+:}${PATH}"
export PATH="/usr/local/opt/findutils/libexec/gnubin${PATH:+:}${PATH}"
elif [[ ${RUNNER_OS} = Linux ]]; then
export PATH="/usr/lib/llvm-15/bin:${PATH}"
export PATH="/usr/lib/llvm-18/bin:${PATH}"
else
echo "Unsupported RUNNER_OS \"${RUNNER_OS}\"." >&2
exit 1
@@ -65,9 +66,6 @@ elif [[ ${MODE} = cmake-oos ]]; then
make VERBOSE=1 CTEST_OUTPUT_ON_FAILURE=1 all test
make DESTDIR="${PWD}"/ROOT install
find ROOT -printf "%P\n" | sort
elif [[ ${MODE} = clang-format ]]; then
./apply-clang-format.sh
git diff --exit-code
elif [[ ${MODE} = coverage-sh ]]; then
./coverage.sh
else
+3 -2
View File
@@ -5,7 +5,8 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2021-2022 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2021-2023 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2023 Joyce Brum <joycebrum@google.com>
# Licensed under the MIT license:
#
# Permission is hereby granted, free of charge, to any person obtaining
@@ -58,7 +59,7 @@ jobs:
shell: bash
runs-on: "${{ matrix.os }}"
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: (Linux) Install build dependencies
if: "${{ runner.os == 'Linux' }}"
+68
View File
@@ -0,0 +1,68 @@
# __ __ _
# ___\ \/ /_ __ __ _| |_
# / _ \\ /| '_ \ / _` | __|
# | __// \| |_) | (_| | |_
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2021-2024 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2023 Joyce Brum <joycebrum@google.com>
# Licensed under the MIT license:
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the
# following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
# USE OR OTHER DEALINGS IN THE SOFTWARE.
name: Enforce clang-format clean code
on:
pull_request:
push:
schedule:
- cron: '0 2 * * 5' # Every Friday at 2am
workflow_dispatch:
permissions:
contents: read
jobs:
clang_format:
name: Enforce clang-format clean code
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install clang-format 18
run: |-
set -x
source /etc/os-release
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb https://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-18 main"
sudo apt-get update # due to new repository
sudo apt-get install --yes --no-install-recommends -V \
clang-format-18 \
moreutils
echo /usr/lib/llvm-18/bin >>"${GITHUB_PATH}"
- name: Run clang-format
run: |
set -x
cd expat/
./apply-clang-format.sh
git config color.diff always
git diff --exit-code # i.e. fail CI when there is a diff (and present it)
+65
View File
@@ -0,0 +1,65 @@
# __ __ _
# ___\ \/ /_ __ __ _| |_
# / _ \\ /| '_ \ / _` | __|
# | __// \| |_) | (_| | |_
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2021-2024 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2023 Joyce Brum <joycebrum@google.com>
# Licensed under the MIT license:
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the
# following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
# USE OR OTHER DEALINGS IN THE SOFTWARE.
name: Enforce clang-tidy clean code
on:
pull_request:
push:
schedule:
- cron: '0 2 * * 5' # Every Friday at 2am
workflow_dispatch:
permissions:
contents: read
jobs:
clang_tidy:
name: Enforce clang-tidy clean code
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install clang-tidy 18
run: |-
set -x
source /etc/os-release
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb https://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-18 main"
sudo apt-get update # due to new repository
sudo apt-get install --yes --no-install-recommends -V \
clang-tidy-18
echo /usr/lib/llvm-18/bin >>"${GITHUB_PATH}"
- name: Run clang-tidy
run: |
set -x
cd expat/
./apply-clang-tidy.sh
+3 -2
View File
@@ -5,7 +5,8 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2021-2022 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2021-2023 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2023 Joyce Brum <joycebrum@google.com>
# Licensed under the MIT license:
#
# Permission is hereby granted, free of charge, to any person obtaining
@@ -43,7 +44,7 @@ jobs:
name: Ensure realistic minimum CMake version requirement
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install ancient CMake
run: |
+53
View File
@@ -0,0 +1,53 @@
# __ __ _
# ___\ \/ /_ __ __ _| |_
# / _ \\ /| '_ \ / _` | __|
# | __// \| |_) | (_| | |_
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2021-2023 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2023 Joyce Brum <joycebrum@google.com>
# Licensed under the MIT license:
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the
# following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
# USE OR OTHER DEALINGS IN THE SOFTWARE.
name: Enforce codespell-clean spelling
on:
pull_request:
push:
schedule:
- cron: '0 2 * * 5' # Every Friday at 2am
permissions:
contents: read
jobs:
checks:
name: Enforce codespell-clean spelling
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: codespell-project/actions-codespell@94259cd8be02ad2903ba34a22d9c13de21a74461 # v2.0
with:
path: expat/
# "arameter" is from "[p]arameter" in xmlwf help output
# "otation" is from "[n]otation" in xmlwf help output
ignore_words_list: arameter,otation
+4 -3
View File
@@ -5,7 +5,8 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2021-2022 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2021-2023 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2023 Joyce Brum <joycebrum@google.com>
# Licensed under the MIT license:
#
# Permission is hereby granted, free of charge, to any person obtaining
@@ -45,7 +46,7 @@ jobs:
env:
CFLAGS: -g3 -pipe
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install build dependencies
run: |-
set -x -u
@@ -83,7 +84,7 @@ jobs:
exec ./.ci.sh
- name: Store coverage .info and HTML report
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: coverage
path: expat/coverage__*/
+4 -3
View File
@@ -5,7 +5,8 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2021-2022 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2021-2024 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2023 Joyce Brum <joycebrum@google.com>
# Licensed under the MIT license:
#
# Permission is hereby granted, free of charge, to any person obtaining
@@ -41,9 +42,9 @@ permissions:
jobs:
checks:
name: Run Cppcheck
runs-on: macos-11
runs-on: macos-12
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install runtime dependencies
run: |
exec brew install cppcheck findutils
@@ -34,4 +34,5 @@ XML_ATTR_INFO
XML_CONTEXT_BYTES
XML_DEV_URANDOM
XML_DTD
XML_GE
XML_NS
@@ -4,6 +4,7 @@ BYTEORDER
const
HAVE_ARC4RANDOM
HAVE_ARC4RANDOM_BUF
HAVE_CXX11
HAVE_DLFCN_H
HAVE_FCNTL_H
HAVE_GETPAGESIZE
@@ -38,4 +39,5 @@ XML_ATTR_INFO
XML_CONTEXT_BYTES
XML_DEV_URANDOM
XML_DTD
XML_GE
XML_NS
@@ -53,6 +53,7 @@ XML_SetNotationDeclHandler
XML_SetNotStandaloneHandler
XML_SetParamEntityParsing
XML_SetProcessingInstructionHandler
XML_SetReparseDeferralEnabled
XML_SetReturnNSTriplet
XML_SetSkippedEntityHandler
XML_SetStartCdataSectionHandler
+3 -2
View File
@@ -5,7 +5,8 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2020-2022 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2020-2023 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2023 Joyce Brum <joycebrum@google.com>
# Licensed under the MIT license:
#
# Permission is hereby granted, free of charge, to any person obtaining
@@ -43,7 +44,7 @@ jobs:
name: Check expat_config.h.{in,cmake} for regressions
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Check expat_config.h.{in,cmake} for regressions
run: |
set -v
+126
View File
@@ -0,0 +1,126 @@
# __ __ _
# ___\ \/ /_ __ __ _| |_
# / _ \\ /| '_ \ / _` | __|
# | __// \| |_) | (_| | |_
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2024 Sebastian Pipping <sebastian@pipping.org>
# Licensed under the MIT license:
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the
# following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
# USE OR OTHER DEALINGS IN THE SOFTWARE.
name: Run fuzzing regression tests
on:
pull_request:
push:
schedule:
- cron: '0 2 * * 5' # Every Friday at 2am
workflow_dispatch:
permissions:
contents: read
jobs:
run_fuzzers:
name: Run fuzzing regression tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install Clang 18
run: |-
set -x
source /etc/os-release
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb https://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-18 main"
sudo apt-get update # due to new repository
sudo apt-get install --yes --no-install-recommends -V \
clang-18 \
libclang-rt-18-dev \
llvm-18
echo /usr/lib/llvm-18/bin >>"${GITHUB_PATH}"
- name: Build Expat fuzzers
run: |
set -x -o pipefail
type -P clang clang++
clang --version | head -n1
clang++ --version | head -n1
cd expat/
args=(
# Build nothing but fuzzers
-DEXPAT_BUILD_DOCS=OFF
-DEXPAT_BUILD_EXAMPLES=OFF
-DEXPAT_BUILD_FUZZERS=ON
-DEXPAT_BUILD_PKGCONFIG=OFF
-DEXPAT_BUILD_TESTS=OFF
-DEXPAT_BUILD_TOOLS=OFF
# Tune compilation of fuzzers to use Clang with ASan and UBSan
-DCMAKE_C_COMPILER=clang
-DCMAKE_C_FLAGS='-Wall -Wextra -pedantic -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer -fno-common'
-DCMAKE_{EXE,MODULE,SHARED}_LINKER_FLAGS='-g -fsanitize=address,undefined'
-DEXPAT_WARNINGS_AS_ERRORS=ON
)
cmake "${args[@]}" -S . -B build
make -C build VERBOSE=1 -j$(nproc)
- name: Download and extract Expat fuzzing corpora
run: |-
set -x
cd expat/build/
wget -q -O expat_corpus_UTF-8.zip https://storage.googleapis.com/expat-backup.clusterfuzz-external.appspot.com/corpus/libFuzzer/expat_xml_parse_fuzzer_UTF-8/public.zip
wget -q -O expat_corpus_UTF-16LE.zip https://storage.googleapis.com/expat-backup.clusterfuzz-external.appspot.com/corpus/libFuzzer/expat_xml_parse_fuzzer_UTF-16LE/public.zip
unzip -q -d corpus_UTF-8 expat_corpus_UTF-8.zip
unzip -q -d corpus_UTF-16LE expat_corpus_UTF-16LE.zip
- name: Run fuzzing regression tests (10+ minutes)
run: |
fuzz_args=(
-jobs=$(nproc)
-print_final_stats=1
-rss_limit_mb=2560 # from oss-fuzz
-timeout=25 # from oss-fuzz
)
set -x -o pipefail
cd expat/build/
# vvvvv
find corpus_UTF-8/ -type f | sort | xargs \
fuzz/xml_parse_fuzzer_UTF-8 "${fuzz_args[@]}"
# ^^^^^
# vvvvvvvv
find corpus_UTF-16LE/ -type f | sort | xargs \
fuzz/xml_parsebuffer_fuzzer_UTF-16LE "${fuzz_args[@]}"
# ^^^^^^ ^^^^^^^^
- name: Store crashing test units
if: ${{ failure() }}
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
with:
name: expat_fuzzing_trouble_${{ github.sha }}
path: expat/build/*-????????????????????????????????????????
+14 -10
View File
@@ -5,7 +5,9 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2021-2022 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2021-2024 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2023 Joyce Brum <joycebrum@google.com>
# Copyright (c) 2023 Hanno Böck <hanno@gentoo.org>
# Licensed under the MIT license:
#
# Permission is hereby granted, free of charge, to any person obtaining
@@ -50,21 +52,24 @@ jobs:
- MODE: distcheck
- MODE: qa-sh
FLAT_ENV: CC=clang CXX=clang++ LD=clang++ QA_SANITIZER=address
- MODE: clang-format
- MODE: cmake-oos
FLAT_ENV: CMAKE_ARGS="-DEXPAT_ATTR_INFO=ON -DEXPAT_BUILD_FUZZERS=ON -DCMAKE_C_FLAGS=-fsanitize=address -DCMAKE_CXX_FLAGS=-fsanitize=address -DCMAKE_EXE_LINKER_FLAGS=-fsanitize=address -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++"
- MODE: qa-sh
FLAT_ENV: CC=clang CXX=clang++ LD=clang++ QA_SANITIZER=address CMAKE_ARGS=-DEXPAT_ATTR_INFO=ON
- MODE: qa-sh
FLAT_ENV: CC=clang CXX=clang++ LD=clang++ QA_SANITIZER=address CMAKE_ARGS=-DEXPAT_CONTEXT_BYTES=OFF
FLAT_ENV: CC=clang CXX=clang++ LD=clang++ QA_SANITIZER=address CMAKE_ARGS=-DEXPAT_CONTEXT_BYTES=0
- MODE: qa-sh
FLAT_ENV: CC=clang CXX=clang++ LD=clang++ QA_SANITIZER=address CMAKE_ARGS=-DEXPAT_DTD=OFF
FLAT_ENV: CC=clang CXX=clang++ LD=clang++ QA_SANITIZER=address CMAKE_ARGS="-DEXPAT_DTD=OFF -DEXPAT_GE=ON"
- MODE: qa-sh
FLAT_ENV: CC=clang CXX=clang++ LD=clang++ QA_SANITIZER=address CMAKE_ARGS="-DEXPAT_DTD=OFF -DEXPAT_GE=OFF"
- MODE: qa-sh
FLAT_ENV: CC=clang CXX=clang++ LD=clang++ QA_SANITIZER=address CMAKE_ARGS=-DEXPAT_LARGE_SIZE=ON
- MODE: qa-sh
FLAT_ENV: CC=clang CXX=clang++ LD=clang++ QA_SANITIZER=address CMAKE_ARGS=-DEXPAT_MIN_SIZE=ON
- MODE: qa-sh
FLAT_ENV: CC=clang CXX=clang++ LD=clang++ QA_SANITIZER=address CMAKE_ARGS=-DEXPAT_NS=OFF
- MODE: qa-sh
FLAT_ENV: CC=clang CXX=clang++ LD=clang++ QA_SANITIZER=cfi
- MODE: qa-sh
FLAT_ENV: CC=clang CXX=clang++ LD=clang++ QA_SANITIZER=memory
- MODE: qa-sh
@@ -83,7 +88,7 @@ jobs:
env:
CFLAGS: -g3 -pipe
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install build dependencies (MinGW)
if: "${{ contains(matrix.FLAT_ENV, 'mingw') }}"
run: |-
@@ -115,13 +120,12 @@ jobs:
set -x
source /etc/os-release
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb https://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-15 main"
sudo add-apt-repository "deb https://apt.llvm.org/${UBUNTU_CODENAME}/ llvm-toolchain-${UBUNTU_CODENAME}-18 main"
sudo apt-get update # due to new repository
# NOTE: Please note the version-specific ${PATH} extension for Clang in .ci.sh
# NOTE: Please note the version-specific ${PATH} extension for Clang adding /usr/lib/llvm-18/bin in .ci.sh
sudo apt-get install --yes --no-install-recommends -V \
clang-15 \
clang-format-15 \
libclang-rt-15-dev
clang-18 \
libclang-rt-18-dev
- name: Install build dependencies (common)
run: |-
sudo apt-get install --yes --no-install-recommends -V \
+3 -2
View File
@@ -5,7 +5,8 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2020-2022 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2020-2023 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2023 Joyce Brum <joycebrum@google.com>
# Licensed under the MIT license:
#
# Permission is hereby granted, free of charge, to any person obtaining
@@ -53,7 +54,7 @@ jobs:
FLAT_ENV: CC=clang CXX=clang++ LD=clang++ QA_SANITIZER=address
runs-on: macos-11
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install build dependencies
run: |
sudo rm /usr/local/bin/2to3 # so that "brew link" will work
@@ -6,7 +6,7 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2020-2021 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2020-2023 Sebastian Pipping <sebastian@pipping.org>
# Licensed under the MIT license:
#
# Permission is hereby granted, free of charge, to any person obtaining
@@ -28,4 +28,4 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
# USE OR OTHER DEALINGS IN THE SOFTWARE.
grep -Eo '(define|undef) [a-zA-Z0-9_]+' "${1}" | awk '{print $2}' | sort -u
grep -Eo '(define|undef) [a-zA-Z0-9_]+' "${1}" | awk '{print $2}' | grep -vw if | sort -u
+26 -20
View File
@@ -6,7 +6,7 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2021 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2021-2024 Sebastian Pipping <sebastian@pipping.org>
# Licensed under the MIT license:
#
# Permission is hereby granted, free of charge, to any person obtaining
@@ -39,24 +39,30 @@ cppcheck --version
find --version | head -n1
cppcheck_args=(
--quiet
--error-exitcode=1
--force
--suppress=objectIndex
--suppress=unknownMacro
)
for xml_context_bytes in 0 1024; do
for xml_ge in 0 1; do
cppcheck_args=(
--quiet
--error-exitcode=1
--force
--suppress=objectIndex
--suppress=unknownMacro
-DXML_CONTEXT_BYTES=${xml_context_bytes}
-DXML_GE=${xml_ge}
)
find_args=(
-type f \(
-name \*.cpp
-o -name \*.c
\)
-not \( # Exclude .c files that are merely included by other files
-name xmltok_ns.c
-o -name xmltok_impl.c
\)
-exec cppcheck "${cppcheck_args[@]}" {} +
)
find_args=(
-type f \(
-name \*.cpp
-o -name \*.c
\)
-not \( # Exclude .c files that are merely included by other files
-name xmltok_ns.c
-o -name xmltok_impl.c
\)
-exec cppcheck "${cppcheck_args[@]}" {} +
)
exec find "${find_args[@]}"
time find "${find_args[@]}"
done
done
+3 -2
View File
@@ -5,7 +5,8 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2021-2022 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2021-2023 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2023 Joyce Brum <joycebrum@google.com>
# Licensed under the MIT license:
#
# Permission is hereby granted, free of charge, to any person obtaining
@@ -43,7 +44,7 @@ jobs:
name: Ensure well-formed and valid XML
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Install build dependencies
run: |-
+3
View File
@@ -1,13 +1,16 @@
# This file is used by "git log"
Ben Wagner <bungeman@chromium.org>
Donghee Na <donghee.na@python.org>
Franek Korta <fkorta@gmail.com>
Hanno Böck <hanno@gentoo.org>
James Clark <jjc@jclark.com> <jclark@users.sourceforge.net>
José Gutiérrez de la Concha <jose@zeroc.com>
Joyce Brum <joycebrum@google.com>
Karl Waclawek <karl@waclawek.net> <karl.waclawek@qlinesolutions.com>
Karl Waclawek <karl@waclawek.net> <kwaclaw@users.sourceforge.net>
Kishore Kunche <kishore.kunche@intel.com>
Martin Ettl <ettl.martin78@googlemail.com> <orbitcowboy@web.de>
Owain Davies <owaind@bath.edu>
Rhodri James <rhodri@wildebeest.org.uk> <rhodri@kynesim.co.uk>
Rolf Eike Beer <eike@sf-mail.de> <eb@emlix.com>
Sebastian Pipping <sebastian@pipping.org> <hartwork@users.sourceforge.net>
+6 -6
View File
@@ -3,25 +3,25 @@
The cmake based buildsystem for expat works on Windows (cygwin, mingw, Visual
Studio) and should work on all other platform cmake supports.
Assuming ~/expat-2.5.0 is the source directory of expat, add a subdirectory
Assuming ~/expat-2.6.2 is the source directory of expat, add a subdirectory
build and change into that directory:
~/expat-2.5.0$ mkdir build && cd build
~/expat-2.5.0/build$
~/expat-2.6.2$ mkdir build && cd build
~/expat-2.6.2/build$
From that directory, call cmake first, then call make, make test and
make install in the usual way:
~/expat-2.5.0/build$ cmake ..
~/expat-2.6.2/build$ cmake ..
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
....
-- Configuring done
-- Generating done
-- Build files have been written to: /home/patrick/expat-2.5.0/build
-- Build files have been written to: /home/patrick/expat-2.6.2/build
If you want to specify the install location for your files, append
-DCMAKE_INSTALL_PREFIX=/your/install/path to the cmake call.
~/expat-2.5.0/build$ make && make test && make install
~/expat-2.6.2/build$ make && make test && make install
Scanning dependencies of target expat
[ 5%] Building C object CMakeFiles/expat.dir/lib/xmlparse.c.o
[ 11%] Building C object CMakeFiles/expat.dir/lib/xmlrole.c.o
+87 -26
View File
@@ -7,12 +7,12 @@
#
# Copyright (c) 2010 Patrick Spendrin <ps_ml@gmx.de>
# Copyright (c) 2012 Karl Waclawek <karl@waclawek.net>
# Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2016 Sergei Nikulov <sergey.nikulov@gmail.com>
# Copyright (c) 2016 Björn Lindahl <bjorn.lindahl@foi.se>
# Copyright (c) 2016 Tobias Taschner <github@tc84.de>
# Copyright (c) 2016 Ben Boeckel <ben.boeckel@kitware.com>
# Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
# Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
# Copyright (c) 2017 Rolf Eike Beer <eike@sf-mail.de>
# Copyright (c) 2017 Stephen Groat <stephen@groat.us>
# Copyright (c) 2017 Franek Korta <fkorta@gmail.com>
@@ -34,16 +34,19 @@
# Unlike most of Expat,
# this file is copyrighted under the BSD-license for buildsystem files of KDE.
cmake_minimum_required(VERSION 3.1.3)
cmake_minimum_required(VERSION 3.5.0)
project(expat
VERSION
2.5.0
2.6.2
LANGUAGES
C
)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF) # i.e. -std=c99 rather than default -std=gnu99
set(PACKAGE_BUGREPORT "expat-bugs@libexpat.org")
set(PACKAGE_BUGREPORT "https://github.com/libexpat/libexpat/issues")
set(PACKAGE_NAME "expat")
set(PACKAGE_VERSION "${PROJECT_VERSION}")
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
@@ -136,10 +139,12 @@ if(UNIX OR _EXPAT_HELP)
expat_shy_set(EXPAT_WITH_LIBBSD OFF CACHE BOOL "Utilize libbsd (for arc4random_buf)")
endif()
expat_shy_set(EXPAT_ENABLE_INSTALL ON CACHE BOOL "Install expat files in cmake install target")
expat_shy_set(EXPAT_CONTEXT_BYTES 1024 CACHE STRING "Define to specify how much context to retain around the current parse point")
expat_shy_set(EXPAT_CONTEXT_BYTES 1024 CACHE STRING "Define to specify how much context to retain around the current parse point, 0 to disable")
mark_as_advanced(EXPAT_CONTEXT_BYTES)
expat_shy_set(EXPAT_DTD ON CACHE BOOL "Define to make parameter entity parsing functionality available")
mark_as_advanced(EXPAT_DTD)
expat_shy_set(EXPAT_GE ON CACHE BOOL "Define to make general entity parsing functionality available")
mark_as_advanced(EXPAT_GE)
expat_shy_set(EXPAT_NS ON CACHE BOOL "Define to make XML Namespaces functionality available")
mark_as_advanced(EXPAT_NS)
expat_shy_set(EXPAT_WARNINGS_AS_ERRORS OFF CACHE BOOL "Treat all compiler warnings as errors")
@@ -167,11 +172,20 @@ endif()
if(EXPAT_BUILD_TESTS)
# We have to call enable_language() before modifying any CMAKE_CXX_* variables
enable_language(CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) # i.e. -std=c++11 rather than default -std=gnu++11
endif()
#
# Environment checks
#
if(EXPAT_DTD AND NOT EXPAT_GE)
message(SEND_ERROR "Option EXPAT_DTD requires that EXPAT_GE is also enabled.")
message(SEND_ERROR "Please either enable option EXPAT_GE (recommended) or disable EXPAT_DTD also.")
endif()
if(EXPAT_WITH_LIBBSD)
find_library(LIB_BSD NAMES bsd)
if(NOT LIB_BSD)
@@ -274,12 +288,16 @@ endif()
_expat_copy_bool_int(EXPAT_ATTR_INFO XML_ATTR_INFO)
_expat_copy_bool_int(EXPAT_DTD XML_DTD)
_expat_copy_bool_int(EXPAT_GE XML_GE)
_expat_copy_bool_int(EXPAT_LARGE_SIZE XML_LARGE_SIZE)
_expat_copy_bool_int(EXPAT_MIN_SIZE XML_MIN_SIZE)
_expat_copy_bool_int(EXPAT_NS XML_NS)
if(NOT WIN32)
_expat_copy_bool_int(EXPAT_DEV_URANDOM XML_DEV_URANDOM)
endif()
if(NOT EXPAT_CONTEXT_BYTES GREATER 0) # in particular with -DEXPAT_CONTEXT_BYTES=OFF
set(EXPAT_CONTEXT_BYTES 0)
endif()
set(XML_CONTEXT_BYTES ${EXPAT_CONTEXT_BYTES})
macro(expat_install)
@@ -311,6 +329,10 @@ if (EXPAT_WARNINGS_AS_ERRORS)
add_definitions(/WX)
else()
set(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -Werror")
if(MINGW)
# To avoid "error: unknown conversion type character ‘l’ in format [-Werror=format=]"
set(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -Wno-format")
endif()
endif()
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_COMPILE_FLAGS}")
@@ -366,7 +388,6 @@ set(_EXPAT_C_SOURCES
lib/xmlrole.c
lib/xmltok.c
# NOTE: ISO C forbids an empty translation unit
# lib/xcsinc.c
# lib/xmltok_impl.c
# lib/xmltok_ns.c
)
@@ -382,7 +403,13 @@ if(EXPAT_SHARED_LIBS)
endif()
endmacro()
_expat_def_file_toggle(EXPAT_DTD _EXPAT_COMMENT_DTD)
if(EXPAT_DTD OR EXPAT_GE)
set(_EXPAT_DTD_OR_GE TRUE)
else()
set(_EXPAT_DTD_OR_GE FALSE)
endif()
_expat_def_file_toggle(_EXPAT_DTD_OR_GE _EXPAT_COMMENT_DTD_OR_GE)
_expat_def_file_toggle(EXPAT_ATTR_INFO _EXPAT_COMMENT_ATTR_INFO)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lib/libexpat.def.cmake" "${CMAKE_CURRENT_BINARY_DIR}/lib/libexpat.def")
@@ -390,7 +417,8 @@ if(EXPAT_SHARED_LIBS)
# Add DLL version
string(REPLACE "." "," _EXPAT_DLL_VERSION ${PROJECT_VERSION}.0)
set(_EXPAT_EXTRA_SOURCES ${_EXPAT_EXTRA_SOURCES} win32/version.rc)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/win32/version.rc.cmake" "${CMAKE_CURRENT_BINARY_DIR}/win32/version.rc")
set(_EXPAT_EXTRA_SOURCES ${_EXPAT_EXTRA_SOURCES} "${CMAKE_CURRENT_BINARY_DIR}/win32/version.rc")
endif()
else()
set(_SHARED STATIC)
@@ -437,9 +465,9 @@ foreach(build_type_upper
set_property(TARGET expat PROPERTY ${build_type_upper}_POSTFIX ${EXPAT_${build_type_upper}_POSTFIX})
endforeach()
set(LIBCURRENT 9) # sync
set(LIBREVISION 10) # with
set(LIBAGE 8) # configure.ac!
set(LIBCURRENT 10) # sync
set(LIBREVISION 2) # with
set(LIBAGE 9) # configure.ac!
math(EXPR LIBCURRENT_MINUS_AGE "${LIBCURRENT} - ${LIBAGE}")
if(NOT WIN32)
@@ -452,7 +480,7 @@ if(NOT WIN32)
message(FATAL_ERROR "Expat requires CMake >=3.17 on platform \"APPLE\".")
endif()
# NOTE: This intends to talk CMake into compatiblity with GNU Libtool
# NOTE: This intends to talk CMake into compatibility with GNU Libtool
math(EXPR _EXPAT_MACHO_COMPATIBILITY_VERSION "${LIBCURRENT} + 1")
set(_EXPAT_MACHO_CURRENT_VERSION "${_EXPAT_MACHO_COMPATIBILITY_VERSION}.${LIBREVISION}")
set_property(TARGET expat PROPERTY MACHO_COMPATIBILITY_VERSION ${_EXPAT_MACHO_COMPATIBILITY_VERSION})
@@ -542,10 +570,10 @@ endif()
#
if(EXPAT_BUILD_TOOLS)
set(xmlwf_SRCS
xmlwf/xmlwf.c
xmlwf/xmlfile.c
xmlwf/codepage.c
xmlwf/readfilemap.c
xmlwf/xmlfile.c
xmlwf/xmlwf.c
)
add_executable(xmlwf ${xmlwf_SRCS})
@@ -594,14 +622,6 @@ if(EXPAT_BUILD_TESTS)
## these are unittests that can be run on any platform
enable_testing()
set(test_SRCS
tests/chardata.c
tests/memcheck.c
tests/minicheck.c
tests/structdata.c
${_EXPAT_C_SOURCES}
)
if(NOT MSVC)
if(MINGW)
set(host whatever-mingw32) # for nothing but run.sh
@@ -617,11 +637,47 @@ if(EXPAT_BUILD_TESTS)
endif()
endfunction()
set(_EXPAT_TEST_TARGETS runtests runtestspp)
add_executable(runtests tests/runtests.c ${test_SRCS})
add_executable(runtestspp tests/runtestspp.cpp ${test_SRCS})
set(_EXPAT_TEST_TARGETS runtests runtests_cxx)
add_executable(runtests
tests/acc_tests.c
tests/alloc_tests.c
tests/basic_tests.c
tests/chardata.c
tests/common.c
tests/dummy.c
tests/handlers.c
tests/memcheck.c
tests/minicheck.c
tests/misc_tests.c
tests/ns_tests.c
tests/nsalloc_tests.c
tests/runtests.c
tests/structdata.c
${_EXPAT_C_SOURCES}
)
add_executable(runtests_cxx
tests/acc_tests_cxx.cpp
tests/alloc_tests_cxx.cpp
tests/basic_tests_cxx.cpp
tests/chardata_cxx.cpp
tests/common_cxx.cpp
tests/dummy_cxx.cpp
tests/handlers_cxx.cpp
tests/memcheck_cxx.cpp
tests/minicheck_cxx.cpp
tests/misc_tests_cxx.cpp
tests/ns_tests_cxx.cpp
tests/nsalloc_tests_cxx.cpp
tests/runtests_cxx.cpp
tests/structdata_cxx.cpp
${_EXPAT_C_SOURCES}
)
foreach(_target ${_EXPAT_TEST_TARGETS})
target_compile_definitions(${_target} PRIVATE -DXML_TESTING)
set_property(TARGET ${_target} PROPERTY RUNTIME_OUTPUT_DIRECTORY tests)
expat_add_test(${_target} $<TARGET_FILE:${_target}>)
@@ -633,6 +689,10 @@ if(EXPAT_BUILD_TESTS)
target_link_libraries(${_target} ${LIB_BSD})
endif()
endforeach()
add_executable(benchmark tests/benchmark/benchmark.c)
set_property(TARGET benchmark PROPERTY RUNTIME_OUTPUT_DIRECTORY tests/benchmark)
target_link_libraries(benchmark expat)
endif()
#
@@ -892,6 +952,7 @@ message(STATUS " // Advanced options, changes not advised")
message(STATUS " Attributes info .......... ${EXPAT_ATTR_INFO}")
message(STATUS " Context bytes ............ ${EXPAT_CONTEXT_BYTES}")
message(STATUS " DTD support .............. ${EXPAT_DTD}")
message(STATUS " General entities ......... ${EXPAT_GE}")
message(STATUS " Large size ............... ${EXPAT_LARGE_SIZE}")
message(STATUS " Minimum size ............. ${EXPAT_MIN_SIZE}")
message(STATUS " Namespace support ........ ${EXPAT_NS}")
+190 -9
View File
@@ -1,15 +1,196 @@
NOTE: We are looking for help with a few things:
https://github.com/libexpat/libexpat/labels/help%20wanted
If you can help, please get in touch. Thanks!
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! <blink>Expat is UNDERSTAFFED and WITHOUT FUNDING.</blink> !!
!! ~~~~~~~~~~~~ !!
!! The following topics need *additional skilled C developers* to progress !!
!! in a timely manner or at all (loosely ordered by descending priority): !!
!! !!
!! - <blink>fixing a complex non-public security issue</blink>, !!
!! - teaming up on researching and fixing future security reports and !!
!! ClusterFuzz findings with few-days-max response times in communication !!
!! in order to (1) have a sound fix ready before the end of a 90 days !!
!! grace period and (2) in a sustainable manner, !!
!! - implementing and auto-testing XML 1.0r5 support !!
!! (needs discussion before pull requests), !!
!! - smart ideas on fixing the Autotools CMake files generation issue !!
!! without breaking CI (needs discussion before pull requests), !!
!! - the Windows binaries topic (needs requirements engineering first), !!
!! - pushing migration from `int` to `size_t` further !!
!! including edge-cases test coverage (needs discussion before anything). !!
!! !!
!! For details, please reach out via e-mail to sebastian@pipping.org so we !!
!! can schedule a voice call on the topic, in English or German. !!
!! !!
!! THANK YOU! Sebastian Pipping -- Berlin, 2024-03-09 !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Release 2.6.2 Wed March 13 2024
Security fixes:
#839 #842 CVE-2024-28757 -- Prevent billion laughs attacks with
isolated use of external parsers. Please see the commit
message of commit 1d50b80cf31de87750103656f6eb693746854aa8
for details.
Bug fixes:
#839 #841 Reject direct parameter entity recursion
and avoid the related undefined behavior
Release 2.5.1 xxx xxxxxxx xx xxxx
Other changes:
#673 examples: Add new example "element_declarations.c"
#678 #706 #733 Autotools: Sync CMake templates with CMake 3.25
#565 Replace some loops by memcmp, memcpy, strlen, wcslen
#847 Autotools: Fix build for DOCBOOK_TO_MAN containing spaces
#837 Add missing #821 and #824 to 2.6.1 change log
#838 #843 Version info bumped from 10:1:9 (libexpat*.so.1.9.1)
to 10:2:9 (libexpat*.so.1.9.2); see https://verbump.de/
for what these numbers do
Special thanks to:
Philippe Antoine
Tomas Korbar
and
Clang UndefinedBehaviorSanitizer
OSS-Fuzz / ClusterFuzz
Release 2.6.1 Thu February 29 2024
Bug fixes:
#817 Make tests independent of CPU speed, and thus more robust
#828 #836 Expose billion laughs API with XML_DTD defined and
XML_GE undefined, regression from 2.6.0
Other changes:
#829 Hide test-only code behind new internal macro
#833 Autotools: Reject expat_config.h.in defining SIZEOF_VOID_P
#821 #824 Autotools: Fix "make clean" for case:
./configure --without-docbook && make clean all
#819 Address compiler warnings
#832 #834 Version info bumped from 10:0:9 (libexpat*.so.1.9.0)
to 10:1:9 (libexpat*.so.1.9.1); see https://verbump.de/
for what these numbers do
Infrastructure:
#818 CI: Adapt to breaking changes in clang-format
Special thanks to:
David Hall
Snild Dolkow
Release 2.6.0 Tue February 6 2024
Security fixes:
#789 #814 CVE-2023-52425 -- Fix quadratic runtime issues with big tokens
that can cause denial of service, in partial where
dealing with compressed XML input. Applications
that parsed a document in one go -- a single call to
functions XML_Parse or XML_ParseBuffer -- were not affected.
The smaller the chunks/buffers you use for parsing
previously, the bigger the problem prior to the fix.
Backporters should be careful to no omit parts of
pull request #789 and to include earlier pull request #771,
in order to not break the fix.
#777 CVE-2023-52426 -- Fix billion laughs attacks for users
compiling *without* XML_DTD defined (which is not common).
Users with XML_DTD defined have been protected since
Expat >=2.4.0 (and that was CVE-2013-0340 back then).
Bug fixes:
#753 Fix parse-size-dependent "invalid token" error for
external entities that start with a byte order mark
#780 Fix NULL pointer dereference in setContext via
XML_ExternalEntityParserCreate for compilation with
XML_DTD undefined
#812 #813 Protect against closing entities out of order
Other changes:
#723 Improve support for arc4random/arc4random_buf
#771 #788 Improve buffer growth in XML_GetBuffer and XML_Parse
#761 #770 xmlwf: Support --help and --version
#759 #770 xmlwf: Support custom buffer size for XML_GetBuffer and read
#744 xmlwf: Improve language and URL clickability in help output
#673 examples: Add new example "element_declarations.c"
#764 Be stricter about macro XML_CONTEXT_BYTES at build time
#765 Make inclusion to expat_config.h consistent
#726 #727 Autotools: configure.ac: Support --disable-maintainer-mode
#678 #705 ..
#706 #733 #792 Autotools: Sync CMake templates with CMake 3.26
#795 Autotools: Make installation of shipped man page doc/xmlwf.1
independent of docbook2man availability
#815 Autotools|CMake: Add missing -DXML_STATIC to pkg-config file
section "Cflags.private" in order to fix compilation
against static libexpat using pkg-config on Windows
#724 #751 Autotools|CMake: Require a C99 compiler
(a de-facto requirement already since Expat 2.2.2 of 2017)
#793 Autotools|CMake: Fix PACKAGE_BUGREPORT variable
#750 #786 Autotools|CMake: Make test suite require a C++11 compiler
#749 CMake: Require CMake >=3.5.0
#672 CMake: Lowercase off_t and size_t to help a bug in Meson
#746 CMake: Sort xmlwf sources alphabetically
#785 CMake|Windows: Fix generation of DLL file version info
#790 CMake: Build tests/benchmark/benchmark.c as well for
a build with -DEXPAT_BUILD_TESTS=ON
#745 #757 docs: Document the importance of isFinal + adjust tests
accordingly
#736 docs: Improve use of "NULL" and "null"
#713 docs: Be specific about version of XML (XML 1.0r4)
and version of C (C99); (XML 1.0r5 will need a sponsor.)
#762 docs: reference.html: Promote function XML_ParseBuffer more
#779 docs: reference.html: Add HTML anchors to XML_* macros
#760 docs: reference.html: Upgrade to OK.css 1.2.0
#763 #739 docs: Fix typos
#696 docs|CI: Use HTTPS URLs instead of HTTP at various places
#669 #670 ..
#692 #703 ..
#733 #772 Address compiler warnings
#798 #800 Address clang-tidy warnings
#775 #776 Version info bumped from 9:10:8 (libexpat*.so.1.8.10)
to 10:0:9 (libexpat*.so.1.9.0); see https://verbump.de/
for what these numbers do
Infrastructure:
#700 #701 docs: Document security policy in file SECURITY.md
#766 docs: Improve parse buffer variables in-code documentation
#674 #738 ..
#740 #747 ..
#748 #781 #782 Refactor coverage and conformance tests
#714 #716 Refactor debug level variables to unsigned long
#671 Improve handling of empty environment variable value
in function getDebugLevel (without visible user effect)
#755 #774 ..
#758 #783 ..
#784 #787 tests: Improve test coverage with regard to parse chunk size
#660 #797 #801 Fuzzing: Improve fuzzing coverage
#367 #799 Fuzzing|CI: Start running OSS-Fuzz fuzzing regression tests
#698 #721 CI: Resolve some Travis CI leftovers
#669 CI: Be robust towards absence of Git tags
#693 #694 CI: Set permissions to "contents: read" for security
#709 CI: Pin all GitHub Actions to specific commits for security
#739 CI: Reject spelling errors using codespell
#798 CI: Enforce clang-tidy clean code
#773 #808 ..
#809 #810 CI: Upgrade Clang from 15 to 18
#796 CI: Start using Clang's Control Flow Integrity sanitizer
#675 #720 #722 CI: Adapt to breaking changes in GitHub Actions Ubuntu images
#689 CI: Adapt to breaking changes in Clang/LLVM Debian packaging
#763 CI: Adapt to breaking changes in codespell
#803 CI: Adapt to breaking changes in Cppcheck
Special thanks to:
Ivan Galkin
Joyce Brum
Philippe Antoine
Rhodri James
Snild Dolkow
spookyahell
Steven Garske
and
Clang AddressSanitizer
Clang UndefinedBehaviorSanitizer
codespell
GCC Farm Project
OSS-Fuzz
Sony Mobile
Release 2.5.0 Tue October 25 2022
Security fixes:
@@ -20,7 +201,7 @@ Release 2.5.0 Tue October 25 2022
arbitrary code execution.
Bug fixes:
#612 #645 Fix curruption from undefined entities
#612 #645 Fix corruption from undefined entities
#613 #654 Fix case when parsing was suspended while processing nested
entities
#616 #652 #653 Stop leaking opening tag bindings after a closing tag
@@ -327,7 +508,7 @@ Release 2.4.2 Sun December 19 2021
see https://verbump.de/ for what these numbers do
Special thanks to:
Dong-hee Na
Donghee Na
Joergen Ibsen
Kai Pastor
+8 -2
View File
@@ -6,9 +6,10 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2017-2021 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2018 KangLin <kl222@126.com>
# Copyright (c) 2022 Johnny Jazeix <jazeix@gmail.com>
# Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com>
# Licensed under the MIT license:
#
# Permission is hereby granted, free of charge, to any person obtaining
@@ -84,7 +85,7 @@ _EXTRA_DIST_WINDOWS = \
win32/expat.iss \
win32/MANIFEST.txt \
win32/README.txt \
win32/version.rc
win32/version.rc.cmake
EXTRA_DIST = \
$(_EXTRA_DIST_CMAKE) \
@@ -131,6 +132,11 @@ buildlib:
run-benchmark:
$(MAKE) -C tests/benchmark
./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/recset.xml 65535 3
./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/aaaaaa_attr.xml 4096 3
./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/aaaaaa_cdata.xml 4096 3
./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/aaaaaa_comment.xml 4096 3
./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/aaaaaa_tag.xml 4096 3
./run.sh tests/benchmark/benchmark@EXEEXT@ -n $(top_srcdir)/../testdata/largefiles/aaaaaa_text.xml 4096 3
.PHONY: download-xmlts-zip
download-xmlts-zip:
+1 -1
View File
@@ -5,7 +5,7 @@
[![Downloads GitHub](https://img.shields.io/github/downloads/libexpat/libexpat/total?label=Downloads%20GitHub)](https://github.com/libexpat/libexpat/releases)
# Expat, Release 2.5.0
# Expat, Release 2.6.2
This is Expat, a C99 library for parsing
[XML 1.0 Fourth Edition](https://www.w3.org/TR/2006/REC-xml-20060816/), started by
+2
View File
@@ -8,5 +8,7 @@ m4_include(conftools/ax-append-flag.m4)
m4_include(conftools/ax-append-compile-flags.m4)
m4_include(conftools/ax-append-link-flags.m4)
m4_include(conftools/expatcfg-compiler-supports-visibility.m4)
m4_include(conftools/ax-cxx-compile-stdcxx.m4)
m4_include(conftools/ax-cxx-compile-stdcxx-11.m4)
### end of file
+14 -16
View File
@@ -6,7 +6,7 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2019-2022 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2019-2024 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2022 Rosen Penev <rosenp@gmail.com>
# Licensed under the MIT license:
#
@@ -29,31 +29,29 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
# USE OR OTHER DEALINGS IN THE SOFTWARE.
set -e
set -u
set -o pipefail
set -e -u -o pipefail
clang-format --version
cd "$(dirname "$(type -P "$0")")"
clang_format_args=(
args=(
-i
-style=file
-verbose
)
if [[ $# -ge 1 ]]; then
exec clang-format "${clang_format_args[@]}" "$@"
if [[ $# -gt 0 ]]; then
files=( "$@" )
else
files=( $(git ls-files -- '*.[ch]' '*.cpp' '*.cxx' '*.h.cmake') )
fi
expand --tabs=2 --initial lib/siphash.h | sponge lib/siphash.h
set -x
find . \
-name '*.[ch]' \
-o -name '*.cpp' \
-o -name '*.cxx' \
-o -name '*.h.cmake' \
| sort \
| xargs clang-format "${clang_format_args[@]}"
type -P clang-format
clang-format --version
clang-format "${args[@]}" -- "${files[@]}"
sed \
-e 's, @$,@,' \
+107
View File
@@ -0,0 +1,107 @@
#! /usr/bin/env bash
# __ __ _
# ___\ \/ /_ __ __ _| |_
# / _ \\ /| '_ \ / _` | __|
# | __// \| |_) | (_| | |_
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2024 Sebastian Pipping <sebastian@pipping.org>
# Licensed under the MIT license:
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the
# following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
# USE OR OTHER DEALINGS IN THE SOFTWARE.
set -e -u -o pipefail
cd "$(dirname "$(type -P "$0")")"
checks_to_enable=(
readability-avoid-const-params-in-decls
readability-named-parameter
)
checks_to_enable_flat="${checks_to_enable[*]}" # i.e. flat string separated by spaces
checks_to_disable=(
# Would need a closer look before any adjustments
clang-analyzer-optin.performance.Padding
# Used only in xmlwf, manually checked to be good enough for now
clang-analyzer-security.insecureAPI.strcpy
# Disabling because buggy, see https://github.com/llvm/llvm-project/issues/40656
clang-analyzer-valist.Uninitialized
)
checks_to_disable_flat="${checks_to_disable[*]}" # i.e. flat string separated by spaces
checks="${checks_to_enable_flat// /,},-${checks_to_disable_flat// /,-}"
args=(
--checks="${checks}"
--header-filter='.*' # .. to display errors from all non-system headers
--warnings-as-errors=\*
)
flags=(
-std=c99
-Ilib/
-DENCODING_FOR_FUZZING=UTF-8
-DXML_ATTR_INFO
-DXML_DTD
-DXML_GE
-DXML_NS
-DXML_TESTING
)
if [[ $# -gt 0 ]]; then
files=( "$@" )
else
# For the list of excluded files please note:
# https://github.com/libexpat/libexpat/issues/119
files=( $(
git ls-files -- \*.c | grep -v \
-e '^xmlwf/ct\.c$' \
-e '^xmlwf/xmlmime\.c$' \
-e '^xmlwf/win32filemap\.c$' \
) )
fi
set -x
type -P clang-tidy
clang-tidy --version
clang-tidy --checks="${checks}" --verify-config
clang-tidy --checks="${checks}" --list-checks
# These are the checks clang-tidy has *more* that so far we are missing out on,
# for good and for bad
clang-tidy --checks=\* --list-checks \
| grep -v -f <(clang-tidy --checks="${checks}" --list-checks | xargs -n1) \
| sed 's,\(\s*\)\([^-]\+\)-[^ ]\+,\1\2-*,' \
| sort -u \
| sed 's/^$/Disabled checks (simplified):/'
pwd
exec clang-tidy "${args[@]}" "${files[@]}" -- "${flags[@]}"
+1 -1
View File
@@ -7,7 +7,7 @@ if(CMAKE_VERSION VERSION_LESS "2.8.3")
message(FATAL_ERROR "CMake >= 2.8.3 required")
endif()
cmake_policy(PUSH)
cmake_policy(VERSION 2.8.3...3.25)
cmake_policy(VERSION 2.8.3...3.26)
#----------------------------------------------------------------
# Generated CMake target import file.
#----------------------------------------------------------------
+38 -10
View File
@@ -11,7 +11,7 @@ dnl Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net>
dnl Copyright (c) 2000-2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
dnl Copyright (c) 2001-2003 Greg Stein <gstein@users.sourceforge.net>
dnl Copyright (c) 2006-2012 Karl Waclawek <karl@waclawek.net>
dnl Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
dnl Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org>
dnl Copyright (c) 2017 S. P. Zeidler <spz@netbsd.org>
dnl Copyright (c) 2017 Stephen Groat <stephen@groat.us>
dnl Copyright (c) 2017-2020 Joe Orton <jorton@redhat.com>
@@ -60,7 +60,7 @@ m4_define([expat_version],
m4_ifdef([__gnu__],
[esyscmd(conftools/get-version.sh lib/expat.h)],
[2.2.x]))
AC_INIT([expat], expat_version, [expat-bugs@libexpat.org])
AC_INIT([expat], expat_version, [https://github.com/libexpat/libexpat/issues])
m4_undefine([expat_version])
AC_CONFIG_SRCDIR([Makefile.in])
@@ -82,9 +82,9 @@ dnl
dnl If the API changes incompatibly set LIBAGE back to 0
dnl
LIBCURRENT=9 # sync
LIBREVISION=10 # with
LIBAGE=8 # CMakeLists.txt!
LIBCURRENT=10 # sync
LIBREVISION=2 # with
LIBAGE=9 # CMakeLists.txt!
AC_CONFIG_HEADERS([expat_config.h])
AH_TOP([#ifndef EXPAT_CONFIG_H
@@ -180,6 +180,8 @@ AC_ARG_WITH([tests],
[with_tests=yes])
AM_CONDITIONAL([WITH_TESTS], [test x${with_tests} = xyes])
AS_IF([test x${with_tests} = xyes],
[AX_CXX_COMPILE_STDCXX_11([noext], [mandatory])])
AS_VAR_SET([EXPATCFG_ON_MINGW],[no])
AS_CASE("${host_os}",
@@ -301,6 +303,8 @@ AC_SUBST(FILEMAP)
dnl Some basic configuration:
AC_DEFINE([XML_NS], 1,
[Define to make XML Namespaces functionality available.])
AC_DEFINE([XML_GE], 1,
[Define as 1/0 to enable/disable support for general entities.])
AC_DEFINE([XML_DTD], 1,
[Define to make parameter entity parsing functionality available.])
AC_DEFINE([XML_DEV_URANDOM], 1,
@@ -325,9 +329,10 @@ AS_HELP_STRING([--disable-xml-context],
AS_IF([test "x${enable_xml_context}" != "xno"],
[AS_IF([test "x${enable_xml_context}" = "xyes" \
-o "x${enable_xml_context}" = "x"],
[AS_VAR_SET(enable_xml_context,1024)])
AC_DEFINE_UNQUOTED([XML_CONTEXT_BYTES], [${enable_xml_context}],
[Define to specify how much context to retain around the current parse point.])])
[AS_VAR_SET(enable_xml_context,1024)])],
[AS_VAR_SET(enable_xml_context,0)])
AC_DEFINE_UNQUOTED([XML_CONTEXT_BYTES], [${enable_xml_context}],
[Define to specify how much context to retain around the current parse point, 0 to disable.])
AC_ARG_WITH([docbook],
[AS_HELP_STRING([--with-docbook],
@@ -351,8 +356,23 @@ AS_IF([test "x${DOCBOOK_TO_MAN}" != x -a "x$with_docbook" != xno],
You can also configure using --without-docbook if you can do without a man
page for xmlwf.])])])
AM_CONDITIONAL(WITH_DOCBOOK, [test "x${DOCBOOK_TO_MAN}" != x])
dnl This will make sure that a release tarball shipping a pre-rendered xmlwf man page will
dnl get it installed, when no working flavor of docbook2man is available (or wanted).
dnl This relies on file xmlwf.1 being at least as recent as its source file xmlwf.xml.
AS_IF([test -f "${srcdir}"/doc/xmlwf.1],
[AM_CONDITIONAL(WITH_MANPAGE, [true])
AS_IF([test "x$with_docbook" = xno -o "x${DOCBOOK_TO_MAN}" = x],
[AM_CONDITIONAL(WITH_PREBUILT_MANPAGE, [true])
AM_CONDITIONAL(WITH_DISTRIBUTABLE_MANPAGE, [false])],
[AM_CONDITIONAL(WITH_PREBUILT_MANPAGE, [false])
AM_CONDITIONAL(WITH_DISTRIBUTABLE_MANPAGE, [true])])
],
[AS_IF([test "x$with_docbook" != xno -a "x${DOCBOOK_TO_MAN}" != x],
[AM_CONDITIONAL(WITH_MANPAGE, [true])
AM_CONDITIONAL(WITH_DISTRIBUTABLE_MANPAGE, [true])],
[AM_CONDITIONAL(WITH_MANPAGE, [false])
AM_CONDITIONAL(WITH_DISTRIBUTABLE_MANPAGE, [false])])
AM_CONDITIONAL(WITH_PREBUILT_MANPAGE, [false])])
dnl Configure CMake file templates
dnl NOTE: The *_TRUE variables read here are Automake conditionals
@@ -398,6 +418,14 @@ AC_SUBST([SO_MINOR])
AC_SUBST([SO_PATCH])
AC_SUBST([ac_cv_sizeof_void_p])
dnl Protect against generating an expat_config.h that would break multilib
AS_IF([grep -F -q SIZEOF_VOID_P "${srcdir}"/expat_config.h.in],
[AC_MSG_ERROR(
[Plain autoreconf/autoheader does not cut it,
please use ./buildconf.sh or imitate its effect
through other means, so that file expat_config.h.in
no longer defines macro SIZEOF_VOID_P, as that would
break multilib support. Thank you.])])
dnl write the Automake flags we set
AC_SUBST([AM_CPPFLAGS])
@@ -0,0 +1,39 @@
# =============================================================================
# https://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
# =============================================================================
#
# SYNOPSIS
#
# AX_CXX_COMPILE_STDCXX_11([ext|noext], [mandatory|optional])
#
# DESCRIPTION
#
# Check for baseline language coverage in the compiler for the C++11
# standard; if necessary, add switches to CXX and CXXCPP to enable
# support.
#
# This macro is a convenience alias for calling the AX_CXX_COMPILE_STDCXX
# macro with the version set to C++11. The two optional arguments are
# forwarded literally as the second and third argument respectively.
# Please see the documentation for the AX_CXX_COMPILE_STDCXX macro for
# more information. If you want to use this macro, you also need to
# download the ax_cxx_compile_stdcxx.m4 file.
#
# LICENSE
#
# Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
# Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
# Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
# Copyright (c) 2014, 2015 Google Inc.; contributed by Alexey Sokolov <sokolov@google.com>
# Copyright (c) 2015 Paul Norman <penorman@mac.com>
# Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 18
AX_REQUIRE_DEFINED([AX_CXX_COMPILE_STDCXX])
AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [AX_CXX_COMPILE_STDCXX([11], [$1], [$2])])
File diff suppressed because it is too large Load Diff
+23 -4
View File
@@ -6,7 +6,7 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2017-2022 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
# Copyright (c) 2019 Mohammed Khajapasha <mohammed.khajapasha@intel.com>
# Licensed under the MIT license:
@@ -68,7 +68,17 @@ _get_build_dir() {
m32_part=__m32
fi
echo "build__${version}__xml_context_${xml_context}${libbsd_part}${mingw_part}${char_part}${xml_attr_part}${m32_part}"
local ge_part=
if ${with_ge}; then
ge_part=__ge
fi
local dtd_part=
if ${with_dtd}; then
dtd_part=__dtd
fi
echo "build__${version}__xml_context_${xml_context}${libbsd_part}${mingw_part}${char_part}${ge_part}${dtd_part}${xml_attr_part}${m32_part}"
}
@@ -95,6 +105,8 @@ _call_cmake() {
${with_libbsd} && cmake_args+=( -DEXPAT_WITH_LIBBSD=ON )
${with_mingw} && cmake_args+=( -DCMAKE_TOOLCHAIN_FILE="${abs_source_dir}"/cmake/mingw-toolchain.cmake )
${with_m32} && cmake_args+=( -D_EXPAT_M32=ON )
${with_ge} || cmake_args+=( -DEXPAT_GE=OFF )
${with_dtd} || cmake_args+=( -DEXPAT_DTD=OFF )
(
set -x
@@ -159,7 +171,7 @@ _run() {
${with_unsigned_char} && BASE_FLAGS="${BASE_FLAGS} -funsigned-char"
local CFLAGS="-std=c99 ${BASE_FLAGS}"
local CXXFLAGS="-std=c++98 ${BASE_FLAGS}"
local CXXFLAGS="-std=c++11 ${BASE_FLAGS}"
(
set -e
@@ -184,7 +196,10 @@ _run() {
fi
set -x
make CTEST_OUTPUT_ON_FAILURE=1 test run-xmltest
make CTEST_OUTPUT_ON_FAILURE=1 test
if ${with_dtd}; then
make run-xmltest
fi
lcov -c -d "${capture_dir}" -o "${coverage_info}-test" &>> run.log
lcov \
@@ -291,6 +306,8 @@ _main() {
with_unsigned_char=false
with_libbsd=false
with_m32=false
with_dtd=true
with_ge=true
for with_mingw in true false ; do
for unicode_enabled in true false ; do
if ${unicode_enabled} && ! ${with_mingw} ; then
@@ -309,6 +326,8 @@ _main() {
with_libbsd=true _build_case
with_unsigned_char=true _build_case
with_m32=true _build_case
with_dtd=false with_ge=true _build_case
with_dtd=false with_ge=false _build_case
echo
echo 'Merging coverage files...'
+9 -11
View File
@@ -6,7 +6,7 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2017-2022 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2017-2024 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2017 Stephen Groat <stephen@groat.us>
# Copyright (c) 2017 Joe Orton <jorton@redhat.com>
# Licensed under the MIT license:
@@ -32,26 +32,24 @@
.PHONY: dist-hook # not inside conditional to avoid automake warning
if WITH_DOCBOOK
if WITH_MANPAGE
dist_man_MANS = xmlwf.1
xmlwf.1: xmlwf.xml
-rm -f $@
$(DOCBOOK_TO_MAN) $<
test "x$(DOCBOOK_TO_MAN)" != x && $(DOCBOOK_TO_MAN) $<
test -f $@ || mv XMLWF.1 $@
else
endif
if !WITH_DISTRIBUTABLE_MANPAGE
dist-hook:
@echo 'ERROR: Configure with --with-docbook for "make dist".' 1>&2
@false
endif
# https://www.gnu.org/software/automake/manual/automake.html#What-Gets-Cleaned
.PHONY: clean-local
clean-local: clean-local-check
.PHONY: clean-local-check
clean-local-check:
$(RM) xmlwf.1
if !WITH_PREBUILT_MANPAGE
CLEANFILES = xmlwf.1
endif
EXTRA_DIST = \
ok.min.css \
+2 -2
View File
File diff suppressed because one or more lines are too long
+110 -24
View File
@@ -14,11 +14,13 @@
Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net>
Copyright (c) 2000-2004 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2002-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2017-2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2024 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017 Jakub Wilk <jwilk@jwilk.net>
Copyright (c) 2021 Tomas Korbar <tkorbar@redhat.com>
Copyright (c) 2021 Nicolas Cavallari <nicolas.cavallari@green-communications.fr>
Copyright (c) 2022 Thijs Schreijer <thijs@thijsschreijer.nl>
Copyright (c) 2023 Hanno Böck <hanno@gentoo.org>
Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
@@ -50,7 +52,7 @@
<div>
<h1>
The Expat XML Parser
<small>Release 2.5.0</small>
<small>Release 2.6.2</small>
</h1>
</div>
<div class="content">
@@ -151,10 +153,11 @@ interface.</p>
</ul>
</li>
<li>
<a href="#billion-laughs">Billion Laughs Attack Protection</a>
<a href="#attack-protection">Attack Protection</a>
<ul>
<li><a href="#XML_SetBillionLaughsAttackProtectionMaximumAmplification">XML_SetBillionLaughsAttackProtectionMaximumAmplification</a></li>
<li><a href="#XML_SetBillionLaughsAttackProtectionActivationThreshold">XML_SetBillionLaughsAttackProtectionActivationThreshold</a></li>
<li><a href="#XML_SetReparseDeferralEnabled">XML_SetReparseDeferralEnabled</a></li>
</ul>
</li>
<li><a href="#miscellaneous">Miscellaneous Functions</a>
@@ -353,43 +356,67 @@ library and header would get installed in
<h3>Configuring Expat Using the Pre-Processor</h3>
<p>Expat's feature set can be configured using a small number of
pre-processor definitions. The definition of this symbols does not
affect the set of entry points for Expat, only the behavior of the API
and the definition of character types in the case of
<code>XML_UNICODE_WCHAR_T</code>. The symbols are:</p>
pre-processor definitions. The symbols are:</p>
<dl class="cpp-symbols">
<dt>XML_DTD</dt>
<dt><a name="XML_GE">XML_GE</a></dt>
<dd>
Added in Expat 2.6.0.
Include support for
<a href="https://www.w3.org/TR/2006/REC-xml-20060816/#sec-physical-struct">general entities</a>
(syntax <code>&amp;e1;</code> to reference and
syntax <code>&lt;!ENTITY e1 'value1'&gt;</code> (an internal general entity) or
<code>&lt;!ENTITY e2 SYSTEM 'file2'&gt;</code> (an external general entity) to declare).
With <code>XML_GE</code> enabled, general entities will be replaced by their declared replacement text;
for this to work for <em>external</em> general entities, in addition an
<code><a href="#XML_SetExternalEntityRefHandler">XML_ExternalEntityRefHandler</a></code> must be set using
<code><a href="#XML_SetExternalEntityRefHandler">XML_SetExternalEntityRefHandler</a></code>.
Also, enabling <code>XML_GE</code> makes
the functions <code><a href="#XML_SetBillionLaughsAttackProtectionMaximumAmplification">
XML_SetBillionLaughsAttackProtectionMaximumAmplification</a></code> and <code>
<a href="#XML_SetBillionLaughsAttackProtectionActivationThreshold">
XML_SetBillionLaughsAttackProtectionActivationThreshold</a></code> available.
<br/>
With <code>XML_GE</code> disabled, Expat has a smaller memory footprint and can be faster, but will
not load external general entities and will replace all general entities
(except the <a href="https://www.w3.org/TR/2006/REC-xml-20060816/#sec-predefined-ent">predefined five</a>:
<code>amp</code>, <code>apos</code>, <code>gt</code>, <code>lt</code>, <code>quot</code>)
with a self-reference:
for example, referencing an entity <code>e1</code> via <code>&amp;e1;</code> will be replaced
by text <code>&amp;e1;</code>.
</dd>
<dt><a name="XML_DTD">XML_DTD</a></dt>
<dd>Include support for using and reporting DTD-based content. If
this is defined, default attribute values from an external DTD subset
are reported and attribute value normalization occurs based on the
type of attributes defined in the external subset. Without
this, Expat has a smaller memory footprint and can be faster, but will
not load external entities or process conditional sections. If defined, makes
not load external parameter entities or process conditional sections. If defined, makes
the functions <code><a
href="#XML_SetBillionLaughsAttackProtectionMaximumAmplification">
XML_SetBillionLaughsAttackProtectionMaximumAmplification</a></code> and <code>
<a href="#XML_SetBillionLaughsAttackProtectionActivationThreshold">
XML_SetBillionLaughsAttackProtectionActivationThreshold</a></code> available.</dd>
<dt>XML_NS</dt>
<dt><a name="XML_NS">XML_NS</a></dt>
<dd>When defined, support for the <cite><a href=
"https://www.w3.org/TR/REC-xml-names/" >Namespaces in XML</a></cite>
specification is included.</dd>
<dt>XML_UNICODE</dt>
<dt><a name="XML_UNICODE">XML_UNICODE</a></dt>
<dd>When defined, character data reported to the application is
encoded in UTF-16 using wide characters of the type
<code>XML_Char</code>. This is implied if
<code>XML_UNICODE_WCHAR_T</code> is defined.</dd>
<dt>XML_UNICODE_WCHAR_T</dt>
<dt><a name="XML_UNICODE_WCHAR_T">XML_UNICODE_WCHAR_T</a></dt>
<dd>If defined, causes the <code>XML_Char</code> character type to be
defined using the <code>wchar_t</code> type; otherwise, <code>unsigned
short</code> is used. Defining this implies
<code>XML_UNICODE</code>.</dd>
<dt>XML_LARGE_SIZE</dt>
<dt><a name="XML_LARGE_SIZE">XML_LARGE_SIZE</a></dt>
<dd>If defined, causes the <code>XML_Size</code> and <code>XML_Index</code>
integer types to be at least 64 bits in size. This is intended to support
processing of very large input streams, where the return values of
@@ -399,23 +426,23 @@ processing of very large input streams, where the return values of
could overflow. It may not be supported by all compilers, and is turned
off by default.</dd>
<dt>XML_CONTEXT_BYTES</dt>
<dt><a name="XML_CONTEXT_BYTES">XML_CONTEXT_BYTES</a></dt>
<dd>The number of input bytes of markup context which the parser will
ensure are available for reporting via <code><a href=
"#XML_GetInputContext" >XML_GetInputContext</a></code>. This is
normally set to 1024, and must be set to a positive integer. If this
is not defined, the input context will not be available and <code><a
normally set to 1024, and must be set to a positive integer to enable.
If this is set to zero, the input context will not be available and <code><a
href= "#XML_GetInputContext" >XML_GetInputContext</a></code> will
always report <code>NULL</code>. Without this, Expat has a smaller memory
footprint and can be faster.</dd>
<dt>XML_STATIC</dt>
<dt><a name="XML_STATIC">XML_STATIC</a></dt>
<dd>On Windows, this should be set if Expat is going to be linked
statically with the code that calls it; this is required to get all
the right MSVC magic annotations correct. This is ignored on other
platforms.</dd>
<dt>XML_ATTR_INFO</dt>
<dt><a name="XML_ATTR_INFO">XML_ATTR_INFO</a></dt>
<dd>If defined, makes the additional function <code><a href=
"#XML_GetAttributeInfo" >XML_GetAttributeInfo</a></code> available
for reporting attribute byte offsets.</dd>
@@ -948,16 +975,20 @@ XML_Parser XMLCALL
XML_ParserCreate(const XML_Char *encoding);
</pre>
<div class="fcndef">
<p>
Construct a new parser. If encoding is non-<code>NULL</code>, it specifies a
character encoding to use for the document. This overrides the document
encoding declaration. There are four built-in encodings:
</p>
<ul>
<li>US-ASCII</li>
<li>UTF-8</li>
<li>UTF-16</li>
<li>ISO-8859-1</li>
</ul>
<p>
Any other value will invoke a call to the UnknownEncodingHandler.
</p>
</div>
<h4 id="XML_ParserCreateNS">XML_ParserCreateNS</h4>
@@ -1078,6 +1109,11 @@ exceed the maximum integer value. Input data at the end of a buffer
will remain unprocessed if it is part of an XML token for which the
end is not part of that buffer.</p>
<p><a name="isFinal"></a>The application <em>must</em> make a concluding
<code><a href="#XML_Parse">XML_Parse</a></code> or
<code><a href="#XML_ParseBuffer">XML_ParseBuffer</a></code> call
with <code>isFinal</code> set to <code>XML_TRUE</code>.</p>
<h4 id="XML_Parse">XML_Parse</h4>
<pre class="fcndec">
enum XML_Status XMLCALL
@@ -1093,6 +1129,7 @@ enum XML_Status {
};
</pre>
<div class="fcndef">
<p>
Parse some more of the document. The string <code>s</code> is a buffer
containing part (or perhaps all) of the document. The number of bytes of s
that are part of the document is indicated by <code>len</code>. This means
@@ -1102,8 +1139,40 @@ memory that <code>s</code> points at, then a memory fault is likely. The
<code>isFinal</code> parameter informs the parser that this is the last
piece of the document. Frequently, the last piece is empty (i.e.
<code>len</code> is zero.)
</p>
<p>
If a parse error occurred, it returns <code>XML_STATUS_ERROR</code>.
Otherwise it returns <code>XML_STATUS_OK</code> value.
Note that regardless of the return value, there is no guarantee that all
provided input has been parsed; only after <a href="#isFinal">the
concluding call</a> will all handler callbacks and parsing errors have
happened.
</p>
<p>
Simplified, <code>XML_Parse</code> can be considered a convenience wrapper
that is pairing calls
to <code><a href="#XML_GetBuffer">XML_GetBuffer</a></code>
and <code><a href="#XML_ParseBuffer">XML_ParseBuffer</a></code>
(when Expat is built with macro <code>XML_CONTEXT_BYTES</code>
defined to a positive value, which is both common and default).
<code>XML_Parse</code> is then functionally equivalent to calling
<code><a href="#XML_GetBuffer">XML_GetBuffer</a></code>,
<code>memcpy</code>, and
<code><a href="#XML_ParseBuffer">XML_ParseBuffer</a></code>.
</p>
<p>
To avoid double copying of the input, direct use of functions
<code><a href="#XML_GetBuffer">XML_GetBuffer</a></code> and
<code><a href="#XML_ParseBuffer">XML_ParseBuffer</a></code> is advised
for most production use, e.g.
if you're using <code>read</code> or similar functionality to fill your
buffers, fill directly into the buffer from
<code><a href="#XML_GetBuffer">XML_GetBuffer</a></code>,
then parse with <code><a href="#XML_ParseBuffer">XML_ParseBuffer</a></code>.
</p>
</div>
<h4 id="XML_ParseBuffer">XML_ParseBuffer</h4>
@@ -2093,15 +2162,11 @@ untranslated bytes of the input.</p>
triggering a call spans over a very large amount of input, the actual
parse position may be before the beginning of the buffer.</p>
<p>If <code>XML_CONTEXT_BYTES</code> is not defined, this will always
<p>If <code>XML_CONTEXT_BYTES</code> is zero, this will always
return <code>NULL</code>.</p>
</div>
<h3><a name="billion-laughs">Billion Laughs Attack Protection</a></h3>
<p>The functions in this section configure the built-in
protection against various forms of
<a href="https://en.wikipedia.org/wiki/Billion_laughs_attack">billion laughs attacks</a>.</p>
<h3><a name="attack-protection">Attack Protection</a><a name="billion-laughs"></a></h3>
<h4 id="XML_SetBillionLaughsAttackProtectionMaximumAmplification">XML_SetBillionLaughsAttackProtectionMaximumAmplification</h4>
<pre class="fcndec">
@@ -2189,6 +2254,27 @@ XML_SetBillionLaughsAttackProtectionActivationThreshold(XML_Parser p,
</p>
</div>
<h4 id="XML_SetReparseDeferralEnabled">XML_SetReparseDeferralEnabled</h4>
<pre class="fcndec">
/* Added in Expat 2.6.0. */
XML_Bool XMLCALL
XML_SetReparseDeferralEnabled(XML_Parser parser, XML_Bool enabled);
</pre>
<div class="fcndef">
<p>
Large tokens may require many parse calls before enough data is available for Expat to parse it in full.
If Expat retried parsing the token on every parse call, parsing could take quadratic time.
To avoid this, Expat only retries once a significant amount of new data is available.
This function allows disabling this behavior.
</p>
<p>
The <code>enabled</code> argument should be <code>XML_TRUE</code> or <code>XML_FALSE</code>.
</p>
<p>
Returns <code>XML_TRUE</code> on success, and <code>XML_FALSE</code> on error.
</p>
</div>
<h3><a name="miscellaneous">Miscellaneous functions</a></h3>
<p>The functions in this section either obtain state information from
+45 -5
View File
@@ -9,7 +9,7 @@
Copyright (c) 2001 Scott Bronson <bronson@rinspin.com>
Copyright (c) 2002-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2009 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2016 Ardo van Rangelrooij <ardo@debian.org>
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2020 Joe Orton <jorton@redhat.com>
@@ -21,7 +21,7 @@
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
<!ENTITY dhfirstname "<firstname>Scott</firstname>">
<!ENTITY dhsurname "<surname>Bronson</surname>">
<!ENTITY dhdate "<date>October 25, 2022</date>">
<!ENTITY dhdate "<date>March 13, 2024</date>">
<!-- Please adjust this^^ date whenever cutting a new release. -->
<!ENTITY dhsection "<manvolnum>1</manvolnum>">
<!ENTITY dhemail "<email>bronson@rinspin.com</email>">
@@ -66,11 +66,17 @@
</cmdsynopsis>
<cmdsynopsis>
<command>&dhpackage;</command>
<arg choice="plain"><option>-h</option></arg>
<group choice="plain">
<arg><option>-h</option></arg>
<arg><option>--help</option></arg>
</group>
</cmdsynopsis>
<cmdsynopsis>
<command>&dhpackage;</command>
<arg choice="plain"><option>-v</option></arg>
<group choice="plain">
<arg><option>-v</option></arg>
<arg><option>--version</option></arg>
</group>
</cmdsynopsis>
</refsynopsisdiv>
@@ -251,6 +257,29 @@ supports both.
</listitem>
</varlistentry>
<varlistentry>
<term><option>-g</option> <replaceable>bytes</replaceable></term>
<listitem>
<para>
Sets the buffer size to request per call pair to
<function>XML_GetBuffer</function> and <function>read</function>
(default: 8 KiB).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-h</option></term>
<term><option>--help</option></term>
<listitem>
<para>
Prints short usage information on command <command>&dhpackage;</command>,
and then exits.
Similar to this man page but more concise.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-k</option></term>
<listitem>
@@ -313,6 +342,16 @@ supports both.
</listitem>
</varlistentry>
<varlistentry>
<term><option>-q</option></term>
<listitem>
<para>
Disable reparse deferral, and allow quadratic parse runtime
on large tokens (default: reparse deferral enabled).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-r</option></term>
<listitem>
@@ -362,6 +401,7 @@ supports both.
<varlistentry>
<term><option>-v</option></term>
<term><option>--version</option></term>
<listitem>
<para>
Prints the version of the Expat library being used, including some
@@ -461,7 +501,7 @@ supports both.
<refsect1>
<title>EXIT STATUS</title>
<para>For option <option>-v</option> or <option>-h</option>, <command>&dhpackage;</command> always exits with status code 0. For other cases, the following exit status codes are returned:
<para>For options <option>-v</option>|<option>--version</option> or <option>-h</option>|<option>--help</option>, <command>&dhpackage;</command> always exits with status code 0. For other cases, the following exit status codes are returned:
<variablelist>
<varlistentry>
<term><option>0</option></term>
+10 -5
View File
@@ -12,7 +12,7 @@
Copyright (c) 2001-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2004-2006 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2019 Zhongyuan Zhou <zhouzhongyuan@huawei.com>
Licensed under the MIT license:
@@ -142,8 +142,7 @@ dumpContentModelElement(const XML_Content *model, unsigned level,
static bool
dumpContentModel(const XML_Char *name, const XML_Content *root) {
printf("Element \"%" XML_FMT_STR "\":\n", name);
Stack *stackTop = NULL;
stackTop = stackPushMalloc(stackTop, root, 1);
Stack *stackTop = stackPushMalloc(NULL, root, 1);
if (! stackTop) {
return false;
}
@@ -157,11 +156,17 @@ dumpContentModel(const XML_Char *name, const XML_Content *root) {
stackTop = stackPopFree(stackTop);
for (size_t u = model->numchildren; u >= 1; u--) {
stackTop
Stack *const newStackTop
= stackPushMalloc(stackTop, model->children + (u - 1), level + 1);
if (! stackTop) {
if (! newStackTop) {
// We ran out of memory, so let's free all memory allocated
// earlier in this function, to be leak-clean:
while (stackTop != NULL) {
stackTop = stackPopFree(stackTop);
}
return false;
}
stackTop = newStackTop;
}
}
+1
View File
@@ -10,3 +10,4 @@ URL: https://libexpat.github.io/
Libs: -L${libdir} -l$<TARGET_PROPERTY:expat,pkgconfig_$<LOWER_CASE:$<CONFIG>>_output_name>
Libs.private: $<TARGET_PROPERTY:expat,pkgconfig_libm>
Cflags: -I${includedir}
Cflags.private: -DXML_STATIC
+1
View File
@@ -10,3 +10,4 @@ URL: https://libexpat.github.io/
Libs: -L${libdir} -l@PACKAGE_NAME@
Libs.private: @LIBM@
Cflags: -I${includedir}
Cflags.private: -DXML_STATIC
+7 -2
View File
@@ -82,7 +82,9 @@
#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@"
/* Define to 1 if you have the ANSI C header files. */
#ifndef STDC_HEADERS
#cmakedefine STDC_HEADERS
#endif
/* whether byteorder is bigendian */
#cmakedefine WORDS_BIGENDIAN
@@ -92,8 +94,8 @@
#cmakedefine XML_ATTR_INFO
/* Define to specify how much context to retain around the current parse
point. */
#cmakedefine XML_CONTEXT_BYTES @XML_CONTEXT_BYTES@
point, 0 to disable. */
#define XML_CONTEXT_BYTES @XML_CONTEXT_BYTES@
#if ! defined(_WIN32)
/* Define to include code reading entropy from `/dev/urandom'. */
@@ -103,6 +105,9 @@
/* Define to make parameter entity parsing functionality available. */
#cmakedefine XML_DTD
/* Define as 1/0 to enable/disable support for general entities. */
#define XML_GE @XML_GE@
/* Define to make XML Namespaces functionality available. */
#cmakedefine XML_NS
+47 -6
View File
@@ -47,18 +47,59 @@ end(void *userData, const XML_Char *name) {
(void)name;
}
int
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
XML_Parser p = XML_ParserCreate(xstr(ENCODING_FOR_FUZZING));
assert(p);
static void XMLCALL
may_stop_character_handler(void *userData, const XML_Char *s, int len) {
XML_Parser parser = (XML_Parser)userData;
if (len > 1 && s[0] == 's') {
XML_StopParser(parser, s[1] == 'r' ? XML_FALSE : XML_TRUE);
}
}
static void
ParseOneInput(XML_Parser p, const uint8_t *data, size_t size) {
// Set the hash salt using siphash to generate a deterministic hash.
struct sipkey *key = sip_keyof(hash_key);
XML_SetHashSalt(p, (unsigned long)siphash24(data, size, key));
(void)sip24_valid;
XML_SetUserData(p, p);
XML_SetElementHandler(p, start, end);
XML_SetCharacterDataHandler(p, may_stop_character_handler);
XML_Parse(p, (const XML_Char *)data, size, 0);
XML_Parse(p, (const XML_Char *)data, size, 1);
XML_ParserFree(p);
if (XML_Parse(p, (const XML_Char *)data, size, 1) == XML_STATUS_ERROR) {
XML_ErrorString(XML_GetErrorCode(p));
}
XML_GetCurrentLineNumber(p);
if (size % 2) {
XML_ParserReset(p, NULL);
}
}
int
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
XML_Parser parentParser = XML_ParserCreate(xstr(ENCODING_FOR_FUZZING));
assert(parentParser);
ParseOneInput(parentParser, data, size);
// not freed yet, but used later and freed then
XML_Parser namespaceParser = XML_ParserCreateNS(NULL, '!');
assert(namespaceParser);
ParseOneInput(namespaceParser, data, size);
XML_ParserFree(namespaceParser);
XML_Parser externalEntityParser
= XML_ExternalEntityParserCreate(parentParser, "e1", NULL);
assert(externalEntityParser);
ParseOneInput(externalEntityParser, data, size);
XML_ParserFree(externalEntityParser);
XML_Parser externalDtdParser
= XML_ExternalEntityParserCreate(parentParser, NULL, NULL);
assert(externalDtdParser);
ParseOneInput(externalDtdParser, data, size);
XML_ParserFree(externalDtdParser);
// finally frees this parser which served as parent
XML_ParserFree(parentParser);
return 0;
}
+57 -11
View File
@@ -48,24 +48,70 @@ end(void *userData, const XML_Char *name) {
(void)name;
}
static void XMLCALL
may_stop_character_handler(void *userData, const XML_Char *s, int len) {
XML_Parser parser = (XML_Parser)userData;
if (len > 1 && s[0] == 's') {
XML_StopParser(parser, s[1] == 'r' ? XML_FALSE : XML_TRUE);
}
}
static void
ParseOneInput(XML_Parser p, const uint8_t *data, size_t size) {
// Set the hash salt using siphash to generate a deterministic hash.
struct sipkey *key = sip_keyof(hash_key);
XML_SetHashSalt(p, (unsigned long)siphash24(data, size, key));
(void)sip24_valid;
XML_SetUserData(p, p);
XML_SetElementHandler(p, start, end);
XML_SetCharacterDataHandler(p, may_stop_character_handler);
void *buf = XML_GetBuffer(p, size);
assert(buf);
memcpy(buf, data, size);
XML_ParseBuffer(p, size, 0);
buf = XML_GetBuffer(p, size);
if (buf == NULL) {
return;
}
memcpy(buf, data, size);
if (XML_ParseBuffer(p, size, 1) == XML_STATUS_ERROR) {
XML_ErrorString(XML_GetErrorCode(p));
}
XML_GetCurrentLineNumber(p);
if (size % 2) {
XML_ParserReset(p, NULL);
}
}
int
LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size == 0)
return 0;
XML_Parser p = XML_ParserCreate(xstr(ENCODING_FOR_FUZZING));
assert(p);
XML_SetElementHandler(p, start, end);
XML_Parser parentParser = XML_ParserCreate(xstr(ENCODING_FOR_FUZZING));
assert(parentParser);
ParseOneInput(parentParser, data, size);
// not freed yet, but used later and freed then
// Set the hash salt using siphash to generate a deterministic hash.
struct sipkey *key = sip_keyof(hash_key);
XML_SetHashSalt(p, (unsigned long)siphash24(data, size, key));
XML_Parser namespaceParser = XML_ParserCreateNS(NULL, '!');
assert(namespaceParser);
ParseOneInput(namespaceParser, data, size);
XML_ParserFree(namespaceParser);
void *buf = XML_GetBuffer(p, size);
assert(buf);
XML_Parser externalEntityParser
= XML_ExternalEntityParserCreate(parentParser, "e1", NULL);
assert(externalEntityParser);
ParseOneInput(externalEntityParser, data, size);
XML_ParserFree(externalEntityParser);
memcpy(buf, data, size);
XML_ParseBuffer(p, size, size == 0);
XML_ParserFree(p);
XML_Parser externalDtdParser
= XML_ExternalEntityParserCreate(parentParser, NULL, NULL);
assert(externalDtdParser);
ParseOneInput(externalDtdParser, data, size);
XML_ParserFree(externalDtdParser);
// finally frees this parser which served as parent
XML_ParserFree(parentParser);
return 0;
}
+10 -10
View File
@@ -6,7 +6,7 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2017-2022 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2017-2024 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2017 Tomasz Kłoczko <kloczek@fedoraproject.org>
# Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
# Licensed under the MIT license:
@@ -36,7 +36,9 @@ include_HEADERS = \
expat_external.h
lib_LTLIBRARIES = libexpat.la
noinst_LTLIBRARIES = libexpatinternal.la
if WITH_TESTS
noinst_LTLIBRARIES = libtestpat.la
endif
libexpat_la_LDFLAGS = \
@AM_LDFLAGS@ \
@@ -44,17 +46,16 @@ libexpat_la_LDFLAGS = \
-no-undefined \
-version-info @LIBCURRENT@:@LIBREVISION@:@LIBAGE@
libexpat_la_SOURCES =
# This layer of indirection allows
# the test suite to access internal symbols
# despite compiling with -fvisibility=hidden
libexpatinternal_la_SOURCES = \
libexpat_la_SOURCES = \
xmlparse.c \
xmltok.c \
xmlrole.c
libexpat_la_LIBADD = libexpatinternal.la
if WITH_TESTS
libtestpat_la_CPPFLAGS = -DXML_TESTING
libtestpat_la_SOURCES = $(libexpat_la_SOURCES)
endif
doc_DATA = \
../AUTHORS \
@@ -79,7 +80,6 @@ EXTRA_DIST = \
siphash.h \
utf8tab.h \
winconfig.h \
xcsinc.c \
xmlrole.h \
xmltok.h \
xmltok_impl.c \
+20 -9
View File
@@ -11,11 +11,14 @@
Copyright (c) 2000-2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2001-2002 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2002-2016 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2016 Cristian Rodríguez <crrodriguez@opensuse.org>
Copyright (c) 2016 Thomas Beutlich <tc@tbeu.de>
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2022 Thijs Schreijer <thijs@thijsschreijer.nl>
Copyright (c) 2023 Hanno Böck <hanno@gentoo.org>
Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com>
Copyright (c) 2024 Taichi Haradaguchi <20001722@ymail.ne.jp>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
@@ -269,7 +272,7 @@ XML_ParserCreate_MM(const XML_Char *encoding,
const XML_Memory_Handling_Suite *memsuite,
const XML_Char *namespaceSeparator);
/* Prepare a parser object to be re-used. This is particularly
/* Prepare a parser object to be reused. This is particularly
valuable when memory allocation overhead is disproportionately high,
such as when a large number of small documnents need to be parsed.
All handlers are cleared from the parser, except for the
@@ -951,7 +954,7 @@ XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser);
XMLPARSEAPI(int)
XML_GetCurrentByteCount(XML_Parser parser);
/* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets
/* If XML_CONTEXT_BYTES is >=1, returns the input buffer, sets
the integer pointed to by offset to the offset within this buffer
of the current parse position, and sets the integer pointed to by size
to the size of this buffer (the number of input bytes). Otherwise
@@ -1025,7 +1028,9 @@ enum XML_FeatureEnum {
XML_FEATURE_ATTR_INFO,
/* Added in Expat 2.4.0. */
XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT,
XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT
XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT,
/* Added in Expat 2.6.0. */
XML_FEATURE_GE
/* Additional features must be added to the end of this enum. */
};
@@ -1038,24 +1043,30 @@ typedef struct {
XMLPARSEAPI(const XML_Feature *)
XML_GetFeatureList(void);
#ifdef XML_DTD
/* Added in Expat 2.4.0. */
#if defined(XML_DTD) || (defined(XML_GE) && XML_GE == 1)
/* Added in Expat 2.4.0 for XML_DTD defined and
* added in Expat 2.6.0 for XML_GE == 1. */
XMLPARSEAPI(XML_Bool)
XML_SetBillionLaughsAttackProtectionMaximumAmplification(
XML_Parser parser, float maximumAmplificationFactor);
/* Added in Expat 2.4.0. */
/* Added in Expat 2.4.0 for XML_DTD defined and
* added in Expat 2.6.0 for XML_GE == 1. */
XMLPARSEAPI(XML_Bool)
XML_SetBillionLaughsAttackProtectionActivationThreshold(
XML_Parser parser, unsigned long long activationThresholdBytes);
#endif
/* Added in Expat 2.6.0. */
XMLPARSEAPI(XML_Bool)
XML_SetReparseDeferralEnabled(XML_Parser parser, XML_Bool enabled);
/* Expat follows the semantic versioning convention.
See https://semver.org
*/
#define XML_MAJOR_VERSION 2
#define XML_MINOR_VERSION 5
#define XML_MICRO_VERSION 0
#define XML_MINOR_VERSION 6
#define XML_MICRO_VERSION 2
#ifdef __cplusplus
}
+13 -2
View File
@@ -28,9 +28,11 @@
Copyright (c) 2002-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2002-2006 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2018 Yury Gribov <tetra2005@gmail.com>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild@sony.com>
Copyright (c) 2024 Taichi Haradaguchi <20001722@ymail.ne.jp>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
@@ -154,12 +156,21 @@ extern "C" {
void _INTERNAL_trim_to_complete_utf8_characters(const char *from,
const char **fromLimRef);
#if defined(XML_DTD)
#if defined(XML_GE) && XML_GE == 1
unsigned long long testingAccountingGetCountBytesDirect(XML_Parser parser);
unsigned long long testingAccountingGetCountBytesIndirect(XML_Parser parser);
const char *unsignedCharToPrintable(unsigned char c);
#endif
extern
#if ! defined(XML_TESTING)
const
#endif
XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c
#if defined(XML_TESTING)
extern unsigned int g_bytesScanned; // used for testing only
#endif
#ifdef __cplusplus
}
#endif
+4 -2
View File
@@ -75,5 +75,7 @@ EXPORTS
XML_SetHashSalt @67
; internal @68 removed with version 2.3.1
; added with version 2.4.0
@_EXPAT_COMMENT_DTD@ XML_SetBillionLaughsAttackProtectionActivationThreshold @69
@_EXPAT_COMMENT_DTD@ XML_SetBillionLaughsAttackProtectionMaximumAmplification @70
@_EXPAT_COMMENT_DTD_OR_GE@ XML_SetBillionLaughsAttackProtectionActivationThreshold @69
@_EXPAT_COMMENT_DTD_OR_GE@ XML_SetBillionLaughsAttackProtectionMaximumAmplification @70
; added with version 2.6.0
XML_SetReparseDeferralEnabled @71
+2 -1
View File
@@ -9,7 +9,8 @@
Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net>
Copyright (c) 2002 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2017-2021 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2023 Orgad Shaneh <orgad.shaneh@audiocodes.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
+436 -302
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -12,10 +12,10 @@
Copyright (c) 2002-2006 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2002-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2005-2009 Steven Solie <steven@solie.ca>
Copyright (c) 2016-2021 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2021 Dong-hee Na <donghee.na@python.org>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
@@ -38,7 +38,7 @@
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <expat_config.h>
#include "expat_config.h"
#include <stddef.h>
+3 -3
View File
@@ -10,7 +10,7 @@
Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net>
Copyright (c) 2002 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2024 Sebastian Pipping <sebastian@pipping.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
@@ -127,9 +127,9 @@ typedef struct prolog_state {
#endif /* XML_DTD */
} PROLOG_STATE;
void XmlPrologStateInit(PROLOG_STATE *);
void XmlPrologStateInit(PROLOG_STATE *state);
#ifdef XML_DTD
void XmlPrologStateInitExternalEntity(PROLOG_STATE *);
void XmlPrologStateInitExternalEntity(PROLOG_STATE *state);
#endif /* XML_DTD */
#define XmlTokenRole(state, tok, ptr, end, enc) \
+7 -5
View File
@@ -12,7 +12,7 @@
Copyright (c) 2002 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2002-2016 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2005-2009 Steven Solie <steven@solie.ca>
Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2016 Pascal Cuoq <cuoq@trust-in-soft.com>
Copyright (c) 2016 Don Lewis <truckman@apache.org>
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
@@ -20,8 +20,10 @@
Copyright (c) 2017 Benbuck Nason <bnason@netflix.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2021 Dong-hee Na <donghee.na@python.org>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Copyright (c) 2022 Martin Ettl <ettl.martin78@googlemail.com>
Copyright (c) 2022 Sean McBride <sean@rogue-research.com>
Copyright (c) 2023 Hanno Böck <hanno@gentoo.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
@@ -44,7 +46,7 @@
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <expat_config.h>
#include "expat_config.h"
#include <stddef.h>
#include <string.h> /* memcpy */
@@ -76,7 +78,7 @@
#define VTABLE VTABLE1, PREFIX(toUtf8), PREFIX(toUtf16)
#define UCS2_GET_NAMING(pages, hi, lo) \
(namingBitmap[(pages[hi] << 3) + ((lo) >> 5)] & (1u << ((lo)&0x1F)))
(namingBitmap[(pages[hi] << 3) + ((lo) >> 5)] & (1u << ((lo) & 0x1F)))
/* A 2 byte UTF-8 representation splits the characters 11 bits between
the bottom 5 and 6 bits of the bytes. We need 8 bits to index into
@@ -225,7 +227,7 @@ struct normal_encoding {
/* isNmstrt2 */ NULL, /* isNmstrt3 */ NULL, /* isNmstrt4 */ NULL, \
/* isInvalid2 */ NULL, /* isInvalid3 */ NULL, /* isInvalid4 */ NULL
static int FASTCALL checkCharRefNumber(int);
static int FASTCALL checkCharRefNumber(int result);
#include "xmltok_impl.h"
#include "ascii.h"
+5 -3
View File
@@ -10,7 +10,7 @@
Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net>
Copyright (c) 2002 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2002-2005 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2017 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
Licensed under the MIT license:
@@ -289,7 +289,8 @@ int XmlParseXmlDecl(int isGeneralTextEntity, const ENCODING *enc,
const char **encodingNamePtr,
const ENCODING **namedEncodingPtr, int *standalonePtr);
int XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name);
int XmlInitEncoding(INIT_ENCODING *p, const ENCODING **encPtr,
const char *name);
const ENCODING *XmlGetUtf8InternalEncoding(void);
const ENCODING *XmlGetUtf16InternalEncoding(void);
int FASTCALL XmlUtf8Encode(int charNumber, char *buf);
@@ -307,7 +308,8 @@ int XmlParseXmlDeclNS(int isGeneralTextEntity, const ENCODING *enc,
const char **encodingNamePtr,
const ENCODING **namedEncodingPtr, int *standalonePtr);
int XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name);
int XmlInitEncodingNS(INIT_ENCODING *p, const ENCODING **encPtr,
const char *name);
const ENCODING *XmlGetUtf8InternalEncodingNS(void);
const ENCODING *XmlGetUtf16InternalEncodingNS(void);
ENCODING *XmlInitUnknownEncodingNS(void *mem, int *table, CONVERTER convert,
+1 -1
View File
@@ -126,7 +126,7 @@
# endif
# define HAS_CHARS(enc, ptr, end, count) \
((end) - (ptr) >= ((count)*MINBPC(enc)))
((end) - (ptr) >= ((count) * MINBPC(enc)))
# define HAS_CHAR(enc, ptr, end) HAS_CHARS(enc, ptr, end, 1)
+14 -9
View File
@@ -6,7 +6,7 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2019 Philippe Antoine <contact@catenacyber.fr>
# Copyright (c) 2019 Hanno Böck <hanno@gentoo.org>
# Licensed under the MIT license:
@@ -76,7 +76,7 @@ populate_environment() {
;;
esac
: ${BASE_COMPILE_FLAGS:="-pipe -Wall -Wextra -pedantic -Wno-overlength-strings -Wno-long-long"}
: ${BASE_COMPILE_FLAGS:="-pipe -Wall -Wextra -pedantic -Wno-overlength-strings"}
: ${BASE_LINK_FLAGS:=}
if [[ ${QA_COMPILER} = clang ]]; then
@@ -91,6 +91,10 @@ populate_environment() {
export ASAN_OPTIONS=detect_leaks=1
fi
;;
cfi)
BASE_COMPILE_FLAGS+=' -fsanitize=cfi -flto -fvisibility=hidden -fno-sanitize-trap=all -fsanitize-cfi-cross-dso'
BASE_LINK_FLAGS+=' -fuse-ld=gold'
;;
memory)
# http://clang.llvm.org/docs/MemorySanitizer.html
BASE_COMPILE_FLAGS+=" -fsanitize=memory -fno-omit-frame-pointer -g -O2 -fsanitize-memory-track-origins -fsanitize-blacklist=$PWD/memory-sanitizer-blacklist.txt"
@@ -114,7 +118,7 @@ populate_environment() {
CFLAGS="-std=c99 ${BASE_COMPILE_FLAGS} ${CFLAGS:-}"
CXXFLAGS="-std=c++98 ${BASE_COMPILE_FLAGS} ${CXXFLAGS:-}"
CXXFLAGS="-std=c++11 ${BASE_COMPILE_FLAGS} ${CXXFLAGS:-}"
LDFLAGS="${BASE_LINK_FLAGS} ${LDFLAGS:-}"
}
@@ -227,7 +231,7 @@ dump_config() {
Configuration:
QA_COMPILER=${QA_COMPILER} # auto-detected from \$CC and \$CXX
QA_PROCESSOR=${QA_PROCESSOR} # GCC only
QA_SANITIZER=${QA_SANITIZER} # Clang only
QA_SANITIZER=${QA_SANITIZER}
CFLAGS=${CFLAGS}
CXXFLAGS=${CXXFLAGS}
@@ -271,12 +275,13 @@ process_config() {
esac
if [[ ${QA_COMPILER} != clang && -n ${QA_SANITIZER:-} ]]; then
if [[ ${QA_COMPILER} != clang && ( ${QA_SANITIZER:-} == cfi || ${QA_SANITIZER:-} == memory ) ]]; then
WARNING "QA_COMPILER=${QA_COMPILER} is not 'clang' -- ignoring QA_SANITIZER=${QA_SANITIZER}" >&2
QA_SANITIZER=
fi
case "${QA_SANITIZER:=address}" in
address|memory|undefined) ;;
address|cfi|memory|undefined) ;;
*) usage; exit 1 ;;
esac
}
@@ -288,9 +293,9 @@ Usage:
$ ./qa.sh [ARG ..]
Environment variables
QA_COMPILER=(clang|gcc) # default: auto-detected
QA_PROCESSOR=(egypt|gcov) # default: gcov
QA_SANITIZER=(address|memory|undefined) # default: address
QA_COMPILER=(clang|gcc) # default: auto-detected
QA_PROCESSOR=(egypt|gcov) # default: gcov
QA_SANITIZER=(address|cfi|memory|undefined) # default: address
EOF
}
+1 -1
View File
@@ -6,7 +6,7 @@
/xmltest.log
Makefile
runtests
runtestspp
runtests_cxx
xmlts.zip
XML-Test-Suite
.libs
+46 -19
View File
@@ -6,8 +6,8 @@
# \___/_/\_\ .__/ \__,_|\__|
# |_| XML parser
#
# Copyright (c) 2017-2021 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
# Copyright (c) 2017-2024 Sebastian Pipping <sebastian@pipping.org>
# Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
# Copyright (c) 2020 Jeffrey Walton <noloader@gmail.com>
# Licensed under the MIT license:
#
@@ -32,36 +32,63 @@
SUBDIRS = . benchmark
AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(srcdir)/../lib
AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(srcdir)/../lib -DXML_TESTING
noinst_LIBRARIES = libruntests.a
check_PROGRAMS = runtests runtestspp
TESTS = runtests runtestspp
check_PROGRAMS = runtests runtests_cxx
TESTS = runtests runtests_cxx
# To support MinGW and Non-MinGW at the same time:
LOG_DRIVER = $(srcdir)/../test-driver-wrapper.sh
libruntests_a_SOURCES = \
chardata.c \
structdata.c \
memcheck.c \
minicheck.c
runtests_SOURCES = \
runtests.c
acc_tests.c \
alloc_tests.c \
basic_tests.c \
chardata.c \
common.c \
dummy.c \
handlers.c \
memcheck.c \
minicheck.c \
misc_tests.c \
ns_tests.c \
nsalloc_tests.c \
runtests.c \
structdata.c
runtestspp_SOURCES = \
runtestspp.cpp
runtests_cxx_SOURCES = \
acc_tests_cxx.cpp \
alloc_tests_cxx.cpp \
basic_tests_cxx.cpp \
chardata_cxx.cpp \
common_cxx.cpp \
dummy_cxx.cpp \
handlers_cxx.cpp \
memcheck_cxx.cpp \
minicheck_cxx.cpp \
misc_tests_cxx.cpp \
nsalloc_tests_cxx.cpp \
ns_tests_cxx.cpp \
runtests_cxx.cpp \
structdata_cxx.cpp
runtests_LDADD = libruntests.a ../lib/libexpatinternal.la
runtestspp_LDADD = libruntests.a ../lib/libexpatinternal.la
runtests_LDADD = ../lib/libtestpat.la
runtests_cxx_LDADD = ../lib/libtestpat.la
runtests_LDFLAGS = @AM_LDFLAGS@ @LIBM@
runtestspp_LDFLAGS = @AM_LDFLAGS@ @LIBM@
runtests_cxx_LDFLAGS = @AM_LDFLAGS@ @LIBM@
EXTRA_DIST = \
acc_tests.h \
alloc_tests.h \
basic_tests.h \
chardata.h \
common.h \
dummy.h \
handlers.h \
misc_tests.h \
ns_tests.h \
nsalloc_tests.h \
structdata.h \
minicheck.h \
memcheck.h \
+455
View File
@@ -0,0 +1,455 @@
/* Tests in the "accounting" test case for the Expat test suite
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <math.h> /* NAN, INFINITY */
#include <stdio.h>
#include <string.h>
#include "expat_config.h"
#include "expat.h"
#include "internal.h"
#include "common.h"
#include "minicheck.h"
#include "chardata.h"
#include "handlers.h"
#include "acc_tests.h"
#if XML_GE == 1
START_TEST(test_accounting_precision) {
struct AccountingTestCase cases[] = {
{"<e/>", NULL, NULL, 0},
{"<e></e>", NULL, NULL, 0},
/* Attributes */
{"<e k1=\"v2\" k2=\"v2\"/>", NULL, NULL, 0},
{"<e k1=\"v2\" k2=\"v2\"></e>", NULL, NULL, 0},
{"<p:e xmlns:p=\"https://domain.invalid/\" />", NULL, NULL, 0},
{"<e k=\"&amp;&apos;&gt;&lt;&quot;\" />", NULL, NULL,
sizeof(XML_Char) * 5 /* number of predefined entities */},
{"<e1 xmlns='https://example.org/'>\n"
" <e2 xmlns=''/>\n"
"</e1>",
NULL, NULL, 0},
/* Text */
{"<e>text</e>", NULL, NULL, 0},
{"<e1><e2>text1<e3/>text2</e2></e1>", NULL, NULL, 0},
{"<e>&amp;&apos;&gt;&lt;&quot;</e>", NULL, NULL,
sizeof(XML_Char) * 5 /* number of predefined entities */},
{"<e>&#65;&#41;</e>", NULL, NULL, 0},
/* Prolog */
{"<?xml version=\"1.0\"?><root/>", NULL, NULL, 0},
/* Whitespace */
{" <e1> <e2> </e2> </e1> ", NULL, NULL, 0},
{"<e1 ><e2 /></e1 >", NULL, NULL, 0},
{"<e1><e2 k = \"v\"/><e3 k = 'v'/></e1>", NULL, NULL, 0},
/* Comments */
{"<!-- Comment --><e><!-- Comment --></e>", NULL, NULL, 0},
/* Processing instructions */
{"<?xml-stylesheet type=\"text/xsl\" href=\"https://domain.invalid/\" media=\"all\"?><e/>",
NULL, NULL, 0},
{"<?pi0?><?pi1 ?><?pi2 ?><r/><?pi4?>", NULL, NULL, 0},
# ifdef XML_DTD
{"<?pi0?><?pi1 ?><?pi2 ?><!DOCTYPE r SYSTEM 'first.ent'><r/>",
"<?pi3?><!ENTITY % e1 SYSTEM 'second.ent'><?pi4?>%e1;<?pi5?>", "<?pi6?>",
0},
# endif /* XML_DTD */
/* CDATA */
{"<e><![CDATA[one two three]]></e>", NULL, NULL, 0},
/* The following is the essence of this OSS-Fuzz finding:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=34302
https://oss-fuzz.com/testcase-detail/4860575394955264
*/
{"<!DOCTYPE r [\n"
"<!ENTITY e \"111<![CDATA[2 <= 2]]>333\">\n"
"]>\n"
"<r>&e;</r>\n",
NULL, NULL, sizeof(XML_Char) * strlen("111<![CDATA[2 <= 2]]>333")},
# ifdef XML_DTD
/* Conditional sections */
{"<!DOCTYPE r [\n"
"<!ENTITY % draft 'INCLUDE'>\n"
"<!ENTITY % final 'IGNORE'>\n"
"<!ENTITY % import SYSTEM \"first.ent\">\n"
"%import;\n"
"]>\n"
"<r/>\n",
"<![%draft;[<!--1-->]]>\n"
"<![%final;[<!--22-->]]>",
NULL, sizeof(XML_Char) * (strlen("INCLUDE") + strlen("IGNORE"))},
# endif /* XML_DTD */
/* General entities */
{"<!DOCTYPE root [\n"
"<!ENTITY nine \"123456789\">\n"
"]>\n"
"<root>&nine;</root>",
NULL, NULL, sizeof(XML_Char) * strlen("123456789")},
{"<!DOCTYPE root [\n"
"<!ENTITY nine \"123456789\">\n"
"]>\n"
"<root k1=\"&nine;\"/>",
NULL, NULL, sizeof(XML_Char) * strlen("123456789")},
{"<!DOCTYPE root [\n"
"<!ENTITY nine \"123456789\">\n"
"<!ENTITY nine2 \"&nine;&nine;\">\n"
"]>\n"
"<root>&nine2;&nine2;&nine2;</root>",
NULL, NULL,
sizeof(XML_Char) * 3 /* calls to &nine2; */ * 2 /* calls to &nine; */
* (strlen("&nine;") + strlen("123456789"))},
{"<!DOCTYPE r [\n"
" <!ENTITY five SYSTEM 'first.ent'>\n"
"]>\n"
"<r>&five;</r>",
"12345", NULL, 0},
{"<!DOCTYPE r [\n"
" <!ENTITY five SYSTEM 'first.ent'>\n"
"]>\n"
"<r>&five;</r>",
"\xEF\xBB\xBF" /* UTF-8 BOM */, NULL, 0},
# ifdef XML_DTD
/* Parameter entities */
{"<!DOCTYPE r [\n"
"<!ENTITY % comment \"<!---->\">\n"
"%comment;\n"
"]>\n"
"<r/>",
NULL, NULL, sizeof(XML_Char) * strlen("<!---->")},
{"<!DOCTYPE r [\n"
"<!ENTITY % ninedef \"&#60;!ENTITY nine &#34;123456789&#34;&#62;\">\n"
"%ninedef;\n"
"]>\n"
"<r>&nine;</r>",
NULL, NULL,
sizeof(XML_Char)
* (strlen("<!ENTITY nine \"123456789\">") + strlen("123456789"))},
{"<!DOCTYPE r [\n"
"<!ENTITY % comment \"<!--1-->\">\n"
"<!ENTITY % comment2 \"&#37;comment;<!--22-->&#37;comment;\">\n"
"%comment2;\n"
"]>\n"
"<r/>\n",
NULL, NULL,
sizeof(XML_Char)
* (strlen("%comment;<!--22-->%comment;") + 2 * strlen("<!--1-->"))},
{"<!DOCTYPE r [\n"
" <!ENTITY % five \"12345\">\n"
" <!ENTITY % five2def \"&#60;!ENTITY five2 &#34;[&#37;five;][&#37;five;]]]]&#34;&#62;\">\n"
" %five2def;\n"
"]>\n"
"<r>&five2;</r>",
NULL, NULL, /* from "%five2def;": */
sizeof(XML_Char)
* (strlen("<!ENTITY five2 \"[%five;][%five;]]]]\">")
+ 2 /* calls to "%five;" */ * strlen("12345")
+ /* from "&five2;": */ strlen("[12345][12345]]]]"))},
{"<!DOCTYPE r SYSTEM \"first.ent\">\n"
"<r/>",
"<!ENTITY % comment '<!--1-->'>\n"
"<!ENTITY % comment2 '<!--22-->%comment;<!--22-->%comment;<!--22-->'>\n"
"%comment2;",
NULL,
sizeof(XML_Char)
* (strlen("<!--22-->%comment;<!--22-->%comment;<!--22-->")
+ 2 /* calls to "%comment;" */ * strlen("<!---->"))},
{"<!DOCTYPE r SYSTEM 'first.ent'>\n"
"<r/>",
"<!ENTITY % e1 PUBLIC 'foo' 'second.ent'>\n"
"<!ENTITY % e2 '<!--22-->%e1;<!--22-->'>\n"
"%e2;\n",
"<!--1-->", sizeof(XML_Char) * strlen("<!--22--><!--1--><!--22-->")},
{
"<!DOCTYPE r SYSTEM 'first.ent'>\n"
"<r/>",
"<!ENTITY % e1 SYSTEM 'second.ent'>\n"
"<!ENTITY % e2 '%e1;'>",
"<?xml version='1.0' encoding='utf-8'?>\n"
"hello\n"
"xml" /* without trailing newline! */,
0,
},
{
"<!DOCTYPE r SYSTEM 'first.ent'>\n"
"<r/>",
"<!ENTITY % e1 SYSTEM 'second.ent'>\n"
"<!ENTITY % e2 '%e1;'>",
"<?xml version='1.0' encoding='utf-8'?>\n"
"hello\n"
"xml\n" /* with trailing newline! */,
0,
},
{"<!DOCTYPE doc SYSTEM 'first.ent'>\n"
"<doc></doc>\n",
"<!ELEMENT doc EMPTY>\n"
"<!ENTITY % e1 SYSTEM 'second.ent'>\n"
"<!ENTITY % e2 '%e1;'>\n"
"%e1;\n",
"\xEF\xBB\xBF<!ATTLIST doc a1 CDATA 'value'>" /* UTF-8 BOM */,
strlen("\xEF\xBB\xBF<!ATTLIST doc a1 CDATA 'value'>")},
# endif /* XML_DTD */
};
const size_t countCases = sizeof(cases) / sizeof(cases[0]);
size_t u = 0;
for (; u < countCases; u++) {
const unsigned long long expectedCountBytesDirect
= strlen(cases[u].primaryText);
const unsigned long long expectedCountBytesIndirect
= (cases[u].firstExternalText ? strlen(cases[u].firstExternalText) : 0)
+ (cases[u].secondExternalText ? strlen(cases[u].secondExternalText)
: 0)
+ cases[u].expectedCountBytesIndirectExtra;
XML_Parser parser = XML_ParserCreate(NULL);
XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS);
if (cases[u].firstExternalText) {
XML_SetExternalEntityRefHandler(parser,
accounting_external_entity_ref_handler);
XML_SetUserData(parser, (void *)&cases[u]);
}
enum XML_Status status
= _XML_Parse_SINGLE_BYTES(parser, cases[u].primaryText,
(int)strlen(cases[u].primaryText), XML_TRUE);
if (status != XML_STATUS_OK) {
_xml_failure(parser, __FILE__, __LINE__);
}
const unsigned long long actualCountBytesDirect
= testingAccountingGetCountBytesDirect(parser);
const unsigned long long actualCountBytesIndirect
= testingAccountingGetCountBytesIndirect(parser);
XML_ParserFree(parser);
if (actualCountBytesDirect != expectedCountBytesDirect) {
fprintf(
stderr,
"Document " EXPAT_FMT_SIZE_T("") " of " EXPAT_FMT_SIZE_T("") ": Expected " EXPAT_FMT_ULL(
"") " count direct bytes, got " EXPAT_FMT_ULL("") " instead.\n",
u + 1, countCases, expectedCountBytesDirect, actualCountBytesDirect);
fail("Count of direct bytes is off");
}
if (actualCountBytesIndirect != expectedCountBytesIndirect) {
fprintf(
stderr,
"Document " EXPAT_FMT_SIZE_T("") " of " EXPAT_FMT_SIZE_T("") ": Expected " EXPAT_FMT_ULL(
"") " count indirect bytes, got " EXPAT_FMT_ULL("") " instead.\n",
u + 1, countCases, expectedCountBytesIndirect,
actualCountBytesIndirect);
fail("Count of indirect bytes is off");
}
}
}
END_TEST
START_TEST(test_billion_laughs_attack_protection_api) {
XML_Parser parserWithoutParent = XML_ParserCreate(NULL);
XML_Parser parserWithParent = XML_ExternalEntityParserCreate(
parserWithoutParent, XCS("entity123"), NULL);
if (parserWithoutParent == NULL)
fail("parserWithoutParent is NULL");
if (parserWithParent == NULL)
fail("parserWithParent is NULL");
// XML_SetBillionLaughsAttackProtectionMaximumAmplification, error cases
if (XML_SetBillionLaughsAttackProtectionMaximumAmplification(NULL, 123.0f)
== XML_TRUE)
fail("Call with NULL parser is NOT supposed to succeed");
if (XML_SetBillionLaughsAttackProtectionMaximumAmplification(parserWithParent,
123.0f)
== XML_TRUE)
fail("Call with non-root parser is NOT supposed to succeed");
if (XML_SetBillionLaughsAttackProtectionMaximumAmplification(
parserWithoutParent, NAN)
== XML_TRUE)
fail("Call with NaN limit is NOT supposed to succeed");
if (XML_SetBillionLaughsAttackProtectionMaximumAmplification(
parserWithoutParent, -1.0f)
== XML_TRUE)
fail("Call with negative limit is NOT supposed to succeed");
if (XML_SetBillionLaughsAttackProtectionMaximumAmplification(
parserWithoutParent, 0.9f)
== XML_TRUE)
fail("Call with positive limit <1.0 is NOT supposed to succeed");
// XML_SetBillionLaughsAttackProtectionMaximumAmplification, success cases
if (XML_SetBillionLaughsAttackProtectionMaximumAmplification(
parserWithoutParent, 1.0f)
== XML_FALSE)
fail("Call with positive limit >=1.0 is supposed to succeed");
if (XML_SetBillionLaughsAttackProtectionMaximumAmplification(
parserWithoutParent, 123456.789f)
== XML_FALSE)
fail("Call with positive limit >=1.0 is supposed to succeed");
if (XML_SetBillionLaughsAttackProtectionMaximumAmplification(
parserWithoutParent, INFINITY)
== XML_FALSE)
fail("Call with positive limit >=1.0 is supposed to succeed");
// XML_SetBillionLaughsAttackProtectionActivationThreshold, error cases
if (XML_SetBillionLaughsAttackProtectionActivationThreshold(NULL, 123)
== XML_TRUE)
fail("Call with NULL parser is NOT supposed to succeed");
if (XML_SetBillionLaughsAttackProtectionActivationThreshold(parserWithParent,
123)
== XML_TRUE)
fail("Call with non-root parser is NOT supposed to succeed");
// XML_SetBillionLaughsAttackProtectionActivationThreshold, success cases
if (XML_SetBillionLaughsAttackProtectionActivationThreshold(
parserWithoutParent, 123)
== XML_FALSE)
fail("Call with non-NULL parentless parser is supposed to succeed");
XML_ParserFree(parserWithParent);
XML_ParserFree(parserWithoutParent);
}
END_TEST
START_TEST(test_helper_unsigned_char_to_printable) {
// Smoke test
unsigned char uc = 0;
for (; uc < (unsigned char)-1; uc++) {
set_subtest("char %u", (unsigned)uc);
const char *const printable = unsignedCharToPrintable(uc);
if (printable == NULL)
fail("unsignedCharToPrintable returned NULL");
else if (strlen(printable) < (size_t)1)
fail("unsignedCharToPrintable returned empty string");
}
// Two concrete samples
set_subtest("char 'A'");
if (strcmp(unsignedCharToPrintable('A'), "A") != 0)
fail("unsignedCharToPrintable result mistaken");
set_subtest("char '\\'");
if (strcmp(unsignedCharToPrintable('\\'), "\\\\") != 0)
fail("unsignedCharToPrintable result mistaken");
}
END_TEST
START_TEST(test_amplification_isolated_external_parser) {
// NOTE: Length 44 is precisely twice the length of "<!ENTITY a SYSTEM 'b'>"
// (22) that is used in function accountingGetCurrentAmplification in
// xmlparse.c.
// 1.........1.........1.........1.........1..4 => 44
const char doc[] = "<!ENTITY % p1 '123456789_123456789_1234567'>";
const int docLen = (int)sizeof(doc) - 1;
const float maximumToleratedAmplification = 2.0f;
struct TestCase {
int offsetOfThreshold;
enum XML_Status expectedStatus;
};
struct TestCase cases[] = {
{-2, XML_STATUS_ERROR}, {-1, XML_STATUS_ERROR}, {0, XML_STATUS_ERROR},
{+1, XML_STATUS_OK}, {+2, XML_STATUS_OK},
};
for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
const int offsetOfThreshold = cases[i].offsetOfThreshold;
const enum XML_Status expectedStatus = cases[i].expectedStatus;
const unsigned long long activationThresholdBytes
= docLen + offsetOfThreshold;
set_subtest("offsetOfThreshold=%d, expectedStatus=%d", offsetOfThreshold,
expectedStatus);
XML_Parser parser = XML_ParserCreate(NULL);
assert_true(parser != NULL);
assert_true(XML_SetBillionLaughsAttackProtectionMaximumAmplification(
parser, maximumToleratedAmplification)
== XML_TRUE);
assert_true(XML_SetBillionLaughsAttackProtectionActivationThreshold(
parser, activationThresholdBytes)
== XML_TRUE);
XML_Parser ext_parser = XML_ExternalEntityParserCreate(parser, NULL, NULL);
assert_true(ext_parser != NULL);
const enum XML_Status actualStatus
= _XML_Parse_SINGLE_BYTES(ext_parser, doc, docLen, XML_TRUE);
assert_true(actualStatus == expectedStatus);
if (actualStatus != XML_STATUS_OK) {
assert_true(XML_GetErrorCode(ext_parser)
== XML_ERROR_AMPLIFICATION_LIMIT_BREACH);
}
XML_ParserFree(ext_parser);
XML_ParserFree(parser);
}
}
END_TEST
#endif // XML_GE == 1
void
make_accounting_test_case(Suite *s) {
#if XML_GE == 1
TCase *tc_accounting = tcase_create("accounting tests");
suite_add_tcase(s, tc_accounting);
tcase_add_test(tc_accounting, test_accounting_precision);
tcase_add_test(tc_accounting, test_billion_laughs_attack_protection_api);
tcase_add_test(tc_accounting, test_helper_unsigned_char_to_printable);
tcase_add_test__ifdef_xml_dtd(tc_accounting,
test_amplification_isolated_external_parser);
#else
UNUSED_P(s);
#endif /* XML_GE == 1 */
}
+56
View File
@@ -0,0 +1,56 @@
/* Tests in the "accounting" test case for the Expat test suite
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef XML_ACC_TESTS_H
# define XML_ACC_TESTS_H
extern void make_accounting_test_case(Suite *s);
#endif /* XML_ACC_TESTS_H */
#ifdef __cplusplus
}
#endif
@@ -1,4 +1,4 @@
/* This file is included from other .c files!
/* C++ compilation harness for the test suite.
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
@@ -6,7 +6,7 @@
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
@@ -29,20 +29,4 @@
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
static size_t
xcslen(const XML_Char *s) {
#ifdef XML_UNICODE
# ifdef XML_UNICODE_WCHAR_T
return wcslen(s);
# else
// XML_Char is unsigned short
size_t len = 0;
while (s[len]) {
len++;
}
return len;
# endif
#else
return strlen(s);
#endif
}
#include "acc_tests.c"
File diff suppressed because it is too large Load Diff
+56
View File
@@ -0,0 +1,56 @@
/* Tests in the "allocation" test case for the Expat test suite
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef XML_ALLOC_TESTS_H
# define XML_ALLOC_TESTS_H
extern void make_alloc_test_case(Suite *s);
#endif /* XML_ALLOC_TESTS_H */
#ifdef __cplusplus
}
#endif
+32
View File
@@ -0,0 +1,32 @@
/* C++ compilation harness for the test suite.
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "alloc_tests.c"
File diff suppressed because it is too large Load Diff
+56
View File
@@ -0,0 +1,56 @@
/* Tests in the "basic" test case for the Expat test suite
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef XML_BASIC_TESTS_H
# define XML_BASIC_TESTS_H
extern void make_basic_test_case(Suite *s);
#endif /* XML_BASIC_TESTS_H */
#ifdef __cplusplus
}
#endif
+32
View File
@@ -0,0 +1,32 @@
/* C++ compilation harness for the test suite.
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "basic_tests.c"
+9 -5
View File
@@ -8,7 +8,7 @@
Copyright (c) 2003-2006 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
Licensed under the MIT license:
@@ -33,6 +33,8 @@
*/
#include <sys/stat.h>
#include <assert.h>
#include <stddef.h> // ptrdiff_t
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
@@ -62,7 +64,8 @@ main(int argc, char *argv[]) {
char *XMLBuf, *XMLBufEnd, *XMLBufPtr;
FILE *fd;
struct stat fileAttr;
int nrOfLoops, bufferSize, fileSize, i, isFinal;
int nrOfLoops, bufferSize, i, isFinal;
size_t fileSize;
int j = 0, ns = 0;
clock_t tstart, tend;
double cpuTime = 0.0;
@@ -114,12 +117,13 @@ main(int argc, char *argv[]) {
isFinal = 0;
tstart = clock();
do {
int parseBufferSize = XMLBufEnd - XMLBufPtr;
if (parseBufferSize <= bufferSize)
ptrdiff_t parseBufferSize = XMLBufEnd - XMLBufPtr;
if (parseBufferSize <= (ptrdiff_t)bufferSize)
isFinal = 1;
else
parseBufferSize = bufferSize;
if (! XML_Parse(parser, XMLBufPtr, parseBufferSize, isFinal)) {
assert(parseBufferSize <= (ptrdiff_t)bufferSize);
if (! XML_Parse(parser, XMLBufPtr, (int)parseBufferSize, isFinal)) {
fprintf(stderr,
"error '%" XML_FMT_STR "' at line %" XML_FMT_INT_MOD
"u character %" XML_FMT_INT_MOD "u\n",
+18 -5
View File
@@ -9,9 +9,10 @@
Copyright (c) 2002-2004 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2016 Gilles Espinasse <g.esp@free.fr>
Copyright (c) 2016-2021 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2022 Sean McBride <sean@rogue-research.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
@@ -34,7 +35,11 @@
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <expat_config.h>
#if defined(NDEBUG)
# undef NDEBUG /* because test suite relies on assert(...) at the moment */
#endif
#include "expat_config.h"
#include "minicheck.h"
#include <assert.h>
@@ -42,7 +47,15 @@
#include <string.h>
#include "chardata.h"
#include "../lib/xcsinc.c"
static int
xmlstrlen(const XML_Char *s) {
int len = 0;
assert(s != NULL);
while (s[len] != 0)
++len;
return len;
}
void
CharData_Init(CharData *storage) {
@@ -60,7 +73,7 @@ CharData_AppendXMLChars(CharData *storage, const XML_Char *s, int len) {
if (storage->count < 0)
storage->count = 0;
if (len < 0)
len = (int)xcslen(s);
len = xmlstrlen(s);
if ((len + storage->count) > maxchars) {
len = (maxchars - storage->count);
}
@@ -72,7 +85,7 @@ CharData_AppendXMLChars(CharData *storage, const XML_Char *s, int len) {
int
CharData_CheckXMLChars(CharData *storage, const XML_Char *expected) {
int len = (int)xcslen(expected);
int len = xmlstrlen(expected);
int count;
assert(storage != NULL);
+32
View File
@@ -0,0 +1,32 @@
/* C++ compilation harness for the test suite.
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "chardata.c"
+325
View File
@@ -0,0 +1,325 @@
/* Commonly used functions for the Expat test suite
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild@sony.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "expat_config.h"
#include "expat.h"
#include "internal.h"
#include "chardata.h"
#include "minicheck.h"
#include "common.h"
/* Common test data */
const char *long_character_data_text
= "<?xml version='1.0' encoding='iso-8859-1'?><s>"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"</s>";
const char *long_cdata_text
= "<s><![CDATA["
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"012345678901234567890123456789012345678901234567890123456789"
"]]></s>";
/* Having an element name longer than 1024 characters exercises some
* of the pool allocation code in the parser that otherwise does not
* get executed. The count at the end of the line is the number of
* characters (bytes) in the element name by that point.x
*/
const char *get_buffer_test_text
= "<documentwitharidiculouslylongelementnametotease" /* 0x030 */
"aparticularcorneroftheallocationinXML_GetBuffers" /* 0x060 */
"othatwecanimprovethecoverageyetagain012345678901" /* 0x090 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x0c0 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x0f0 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x120 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x150 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x180 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x1b0 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x1e0 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x210 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x240 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x270 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x2a0 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x2d0 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x300 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x330 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x360 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x390 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x3c0 */
"123456789abcdef0123456789abcdef0123456789abcdef0" /* 0x3f0 */
"123456789abcdef0123456789abcdef0123456789>\n<ef0"; /* 0x420 */
/* Test control globals */
/* Used as the "resumable" parameter to XML_StopParser by some tests */
XML_Bool g_resumable = XML_FALSE;
/* Used to control abort checks in some tests */
XML_Bool g_abortable = XML_FALSE;
/* Used to control _XML_Parse_SINGLE_BYTES() chunk size */
int g_chunkSize = 1;
/* Common test functions */
void
tcase_add_test__ifdef_xml_dtd(TCase *tc, tcase_test_function test) {
#ifdef XML_DTD
tcase_add_test(tc, test);
#else
UNUSED_P(tc);
UNUSED_P(test);
#endif
}
void
tcase_add_test__if_xml_ge(TCase *tc, tcase_test_function test) {
#if XML_GE == 1
tcase_add_test(tc, test);
#else
UNUSED_P(tc);
UNUSED_P(test);
#endif
}
void
basic_teardown(void) {
if (g_parser != NULL) {
XML_ParserFree(g_parser);
g_parser = NULL;
}
}
/* Generate a failure using the parser state to create an error message;
this should be used when the parser reports an error we weren't
expecting.
*/
void
_xml_failure(XML_Parser parser, const char *file, int line) {
char buffer[1024];
enum XML_Error err = XML_GetErrorCode(parser);
snprintf(buffer, sizeof(buffer),
" %d: %" XML_FMT_STR " (line %" XML_FMT_INT_MOD
"u, offset %" XML_FMT_INT_MOD "u)\n reported from %s, line %d\n",
err, XML_ErrorString(err), XML_GetCurrentLineNumber(parser),
XML_GetCurrentColumnNumber(parser), file, line);
_fail(file, line, buffer);
}
enum XML_Status
_XML_Parse_SINGLE_BYTES(XML_Parser parser, const char *s, int len,
int isFinal) {
// This ensures that tests have to run pathological parse cases
// (e.g. when `s` is NULL) against plain XML_Parse rather than
// chunking _XML_Parse_SINGLE_BYTES.
assert((parser != NULL) && (s != NULL) && (len >= 0));
const int chunksize = g_chunkSize;
if (chunksize > 0) {
// parse in chunks of `chunksize` bytes as long as not exhausting
for (; len > chunksize; len -= chunksize, s += chunksize) {
enum XML_Status res = XML_Parse(parser, s, chunksize, XML_FALSE);
if (res != XML_STATUS_OK) {
return res;
}
}
}
// parse the final chunk, the size of which will be <= chunksize
return XML_Parse(parser, s, len, isFinal);
}
void
_expect_failure(const char *text, enum XML_Error errorCode,
const char *errorMessage, const char *file, int lineno) {
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
== XML_STATUS_OK)
/* Hackish use of _fail() macro, but lets us report
the right filename and line number. */
_fail(file, lineno, errorMessage);
if (XML_GetErrorCode(g_parser) != errorCode)
_xml_failure(g_parser, file, lineno);
}
/* Character data support for handlers, built on top of the code in
* chardata.c
*/
void XMLCALL
accumulate_characters(void *userData, const XML_Char *s, int len) {
CharData_AppendXMLChars((CharData *)userData, s, len);
}
void XMLCALL
accumulate_attribute(void *userData, const XML_Char *name,
const XML_Char **atts) {
CharData *storage = (CharData *)userData;
UNUSED_P(name);
/* Check there are attributes to deal with */
if (atts == NULL)
return;
while (storage->count < 0 && atts[0] != NULL) {
/* "accumulate" the value of the first attribute we see */
CharData_AppendXMLChars(storage, atts[1], -1);
atts += 2;
}
}
void
_run_character_check(const char *text, const XML_Char *expected,
const char *file, int line) {
CharData storage;
CharData_Init(&storage);
XML_SetUserData(g_parser, &storage);
XML_SetCharacterDataHandler(g_parser, accumulate_characters);
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
== XML_STATUS_ERROR)
_xml_failure(g_parser, file, line);
CharData_CheckXMLChars(&storage, expected);
}
void
_run_attribute_check(const char *text, const XML_Char *expected,
const char *file, int line) {
CharData storage;
CharData_Init(&storage);
XML_SetUserData(g_parser, &storage);
XML_SetStartElementHandler(g_parser, accumulate_attribute);
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
== XML_STATUS_ERROR)
_xml_failure(g_parser, file, line);
CharData_CheckXMLChars(&storage, expected);
}
void XMLCALL
ext_accumulate_characters(void *userData, const XML_Char *s, int len) {
ExtTest *test_data = (ExtTest *)userData;
accumulate_characters(test_data->storage, s, len);
}
void
_run_ext_character_check(const char *text, ExtTest *test_data,
const XML_Char *expected, const char *file, int line) {
CharData *const storage = (CharData *)malloc(sizeof(CharData));
CharData_Init(storage);
test_data->storage = storage;
XML_SetUserData(g_parser, test_data);
XML_SetCharacterDataHandler(g_parser, ext_accumulate_characters);
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
== XML_STATUS_ERROR)
_xml_failure(g_parser, file, line);
CharData_CheckXMLChars(storage, expected);
free(storage);
}
/* Control variable; the number of times duff_allocator() will successfully
* allocate */
#define ALLOC_ALWAYS_SUCCEED (-1)
#define REALLOC_ALWAYS_SUCCEED (-1)
int g_allocation_count = ALLOC_ALWAYS_SUCCEED;
int g_reallocation_count = REALLOC_ALWAYS_SUCCEED;
/* Crocked allocator for allocation failure tests */
void *
duff_allocator(size_t size) {
if (g_allocation_count == 0)
return NULL;
if (g_allocation_count != ALLOC_ALWAYS_SUCCEED)
g_allocation_count--;
return malloc(size);
}
/* Crocked reallocator for allocation failure tests */
void *
duff_reallocator(void *ptr, size_t size) {
if (g_reallocation_count == 0)
return NULL;
if (g_reallocation_count != REALLOC_ALWAYS_SUCCEED)
g_reallocation_count--;
return realloc(ptr, size);
}
+162
View File
@@ -0,0 +1,162 @@
/* Commonly used functions for the Expat test suite
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef XML_COMMON_H
# define XML_COMMON_H
# include "expat_config.h"
# include "minicheck.h"
# include "chardata.h"
# ifdef XML_LARGE_SIZE
# define XML_FMT_INT_MOD "ll"
# else
# define XML_FMT_INT_MOD "l"
# endif
# ifdef XML_UNICODE_WCHAR_T
# define XML_FMT_STR "ls"
# include <wchar.h>
# define xcstrlen(s) wcslen(s)
# define xcstrcmp(s, t) wcscmp((s), (t))
# define xcstrncmp(s, t, n) wcsncmp((s), (t), (n))
# define XCS(s) _XCS(s)
# define _XCS(s) L##s
# else
# ifdef XML_UNICODE
# error "No support for UTF-16 character without wchar_t in tests"
# else
# define XML_FMT_STR "s"
# define xcstrlen(s) strlen(s)
# define xcstrcmp(s, t) strcmp((s), (t))
# define xcstrncmp(s, t, n) strncmp((s), (t), (n))
# define XCS(s) s
# endif /* XML_UNICODE */
# endif /* XML_UNICODE_WCHAR_T */
extern XML_Parser g_parser;
extern XML_Bool g_resumable;
extern XML_Bool g_abortable;
extern int g_chunkSize;
extern const char *long_character_data_text;
extern const char *long_cdata_text;
extern const char *get_buffer_test_text;
extern void tcase_add_test__ifdef_xml_dtd(TCase *tc, tcase_test_function test);
extern void tcase_add_test__if_xml_ge(TCase *tc, tcase_test_function test);
extern void basic_teardown(void);
extern void _xml_failure(XML_Parser parser, const char *file, int line);
# define xml_failure(parser) _xml_failure((parser), __FILE__, __LINE__)
extern enum XML_Status _XML_Parse_SINGLE_BYTES(XML_Parser parser, const char *s,
int len, int isFinal);
extern void _expect_failure(const char *text, enum XML_Error errorCode,
const char *errorMessage, const char *file,
int lineno);
# define expect_failure(text, errorCode, errorMessage) \
_expect_failure((text), (errorCode), (errorMessage), __FILE__, __LINE__)
/* Support functions for handlers to collect up character and attribute data.
*/
extern void XMLCALL accumulate_characters(void *userData, const XML_Char *s,
int len);
extern void XMLCALL accumulate_attribute(void *userData, const XML_Char *name,
const XML_Char **atts);
extern void _run_character_check(const char *text, const XML_Char *expected,
const char *file, int line);
# define run_character_check(text, expected) \
_run_character_check(text, expected, __FILE__, __LINE__)
extern void _run_attribute_check(const char *text, const XML_Char *expected,
const char *file, int line);
# define run_attribute_check(text, expected) \
_run_attribute_check(text, expected, __FILE__, __LINE__)
typedef struct ExtTest {
const char *parse_text;
const XML_Char *encoding;
CharData *storage;
} ExtTest;
extern void XMLCALL ext_accumulate_characters(void *userData, const XML_Char *s,
int len);
extern void _run_ext_character_check(const char *text, ExtTest *test_data,
const XML_Char *expected, const char *file,
int line);
# define run_ext_character_check(text, test_data, expected) \
_run_ext_character_check(text, test_data, expected, __FILE__, __LINE__)
# define ALLOC_ALWAYS_SUCCEED (-1)
# define REALLOC_ALWAYS_SUCCEED (-1)
extern int g_allocation_count;
extern int g_reallocation_count;
extern void *duff_allocator(size_t size);
extern void *duff_reallocator(void *ptr, size_t size);
#endif /* XML_COMMON_H */
#ifdef __cplusplus
}
#endif
+32
View File
@@ -0,0 +1,32 @@
/* C++ compilation harness for the test suite.
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "common.c"
+261
View File
@@ -0,0 +1,261 @@
/* Dummy handler functions for the Expat test suite
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "expat.h"
#include "internal.h"
#include "common.h"
#include "dummy.h"
/* Dummy handlers for when we need to set a handler to tickle a bug,
but it doesn't need to do anything.
*/
static unsigned long dummy_handler_flags = 0;
void
init_dummy_handlers(void) {
dummy_handler_flags = 0;
}
unsigned long
get_dummy_handler_flags(void) {
return dummy_handler_flags;
}
void XMLCALL
dummy_xdecl_handler(void *userData, const XML_Char *version,
const XML_Char *encoding, int standalone) {
UNUSED_P(userData);
UNUSED_P(version);
UNUSED_P(encoding);
UNUSED_P(standalone);
}
void XMLCALL
dummy_start_doctype_handler(void *userData, const XML_Char *doctypeName,
const XML_Char *sysid, const XML_Char *pubid,
int has_internal_subset) {
UNUSED_P(userData);
UNUSED_P(doctypeName);
UNUSED_P(sysid);
UNUSED_P(pubid);
UNUSED_P(has_internal_subset);
dummy_handler_flags |= DUMMY_START_DOCTYPE_HANDLER_FLAG;
}
void XMLCALL
dummy_end_doctype_handler(void *userData) {
UNUSED_P(userData);
dummy_handler_flags |= DUMMY_END_DOCTYPE_HANDLER_FLAG;
}
void XMLCALL
dummy_entity_decl_handler(void *userData, const XML_Char *entityName,
int is_parameter_entity, const XML_Char *value,
int value_length, const XML_Char *base,
const XML_Char *systemId, const XML_Char *publicId,
const XML_Char *notationName) {
UNUSED_P(userData);
UNUSED_P(entityName);
UNUSED_P(is_parameter_entity);
UNUSED_P(value);
UNUSED_P(value_length);
UNUSED_P(base);
UNUSED_P(systemId);
UNUSED_P(publicId);
UNUSED_P(notationName);
dummy_handler_flags |= DUMMY_ENTITY_DECL_HANDLER_FLAG;
}
void XMLCALL
dummy_notation_decl_handler(void *userData, const XML_Char *notationName,
const XML_Char *base, const XML_Char *systemId,
const XML_Char *publicId) {
UNUSED_P(userData);
UNUSED_P(notationName);
UNUSED_P(base);
UNUSED_P(systemId);
UNUSED_P(publicId);
dummy_handler_flags |= DUMMY_NOTATION_DECL_HANDLER_FLAG;
}
void XMLCALL
dummy_element_decl_handler(void *userData, const XML_Char *name,
XML_Content *model) {
UNUSED_P(userData);
UNUSED_P(name);
/* The content model must be freed by the handler. Unfortunately
* we cannot pass the parser as the userData because this is used
* with other handlers that require other userData.
*/
XML_FreeContentModel(g_parser, model);
dummy_handler_flags |= DUMMY_ELEMENT_DECL_HANDLER_FLAG;
}
void XMLCALL
dummy_attlist_decl_handler(void *userData, const XML_Char *elname,
const XML_Char *attname, const XML_Char *att_type,
const XML_Char *dflt, int isrequired) {
UNUSED_P(userData);
UNUSED_P(elname);
UNUSED_P(attname);
UNUSED_P(att_type);
UNUSED_P(dflt);
UNUSED_P(isrequired);
dummy_handler_flags |= DUMMY_ATTLIST_DECL_HANDLER_FLAG;
}
void XMLCALL
dummy_comment_handler(void *userData, const XML_Char *data) {
UNUSED_P(userData);
UNUSED_P(data);
dummy_handler_flags |= DUMMY_COMMENT_HANDLER_FLAG;
}
void XMLCALL
dummy_pi_handler(void *userData, const XML_Char *target, const XML_Char *data) {
UNUSED_P(userData);
UNUSED_P(target);
UNUSED_P(data);
dummy_handler_flags |= DUMMY_PI_HANDLER_FLAG;
}
void XMLCALL
dummy_start_element(void *userData, const XML_Char *name,
const XML_Char **atts) {
UNUSED_P(userData);
UNUSED_P(name);
UNUSED_P(atts);
dummy_handler_flags |= DUMMY_START_ELEMENT_HANDLER_FLAG;
}
void XMLCALL
dummy_end_element(void *userData, const XML_Char *name) {
UNUSED_P(userData);
UNUSED_P(name);
}
void XMLCALL
dummy_start_cdata_handler(void *userData) {
UNUSED_P(userData);
dummy_handler_flags |= DUMMY_START_CDATA_HANDLER_FLAG;
}
void XMLCALL
dummy_end_cdata_handler(void *userData) {
UNUSED_P(userData);
dummy_handler_flags |= DUMMY_END_CDATA_HANDLER_FLAG;
}
void XMLCALL
dummy_cdata_handler(void *userData, const XML_Char *s, int len) {
UNUSED_P(userData);
UNUSED_P(s);
UNUSED_P(len);
}
void XMLCALL
dummy_start_namespace_decl_handler(void *userData, const XML_Char *prefix,
const XML_Char *uri) {
UNUSED_P(userData);
UNUSED_P(prefix);
UNUSED_P(uri);
dummy_handler_flags |= DUMMY_START_NS_DECL_HANDLER_FLAG;
}
void XMLCALL
dummy_end_namespace_decl_handler(void *userData, const XML_Char *prefix) {
UNUSED_P(userData);
UNUSED_P(prefix);
dummy_handler_flags |= DUMMY_END_NS_DECL_HANDLER_FLAG;
}
/* This handler is obsolete, but while the code exists we should
* ensure that dealing with the handler is covered by tests.
*/
void XMLCALL
dummy_unparsed_entity_decl_handler(void *userData, const XML_Char *entityName,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId,
const XML_Char *notationName) {
UNUSED_P(userData);
UNUSED_P(entityName);
UNUSED_P(base);
UNUSED_P(systemId);
UNUSED_P(publicId);
UNUSED_P(notationName);
dummy_handler_flags |= DUMMY_UNPARSED_ENTITY_DECL_HANDLER_FLAG;
}
void XMLCALL
dummy_default_handler(void *userData, const XML_Char *s, int len) {
UNUSED_P(userData);
UNUSED_P(s);
UNUSED_P(len);
}
void XMLCALL
dummy_start_doctype_decl_handler(void *userData, const XML_Char *doctypeName,
const XML_Char *sysid, const XML_Char *pubid,
int has_internal_subset) {
UNUSED_P(userData);
UNUSED_P(doctypeName);
UNUSED_P(sysid);
UNUSED_P(pubid);
UNUSED_P(has_internal_subset);
dummy_handler_flags |= DUMMY_START_DOCTYPE_DECL_HANDLER_FLAG;
}
void XMLCALL
dummy_end_doctype_decl_handler(void *userData) {
UNUSED_P(userData);
dummy_handler_flags |= DUMMY_END_DOCTYPE_DECL_HANDLER_FLAG;
}
void XMLCALL
dummy_skip_handler(void *userData, const XML_Char *entityName,
int is_parameter_entity) {
UNUSED_P(userData);
UNUSED_P(entityName);
UNUSED_P(is_parameter_entity);
dummy_handler_flags |= DUMMY_SKIP_HANDLER_FLAG;
}
+150
View File
@@ -0,0 +1,150 @@
/* Dummy handler functions for the Expat test suite
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef XML_DUMMY_H
# define XML_DUMMY_H
# define DUMMY_START_DOCTYPE_HANDLER_FLAG (1UL << 0)
# define DUMMY_END_DOCTYPE_HANDLER_FLAG (1UL << 1)
# define DUMMY_ENTITY_DECL_HANDLER_FLAG (1UL << 2)
# define DUMMY_NOTATION_DECL_HANDLER_FLAG (1UL << 3)
# define DUMMY_ELEMENT_DECL_HANDLER_FLAG (1UL << 4)
# define DUMMY_ATTLIST_DECL_HANDLER_FLAG (1UL << 5)
# define DUMMY_COMMENT_HANDLER_FLAG (1UL << 6)
# define DUMMY_PI_HANDLER_FLAG (1UL << 7)
# define DUMMY_START_ELEMENT_HANDLER_FLAG (1UL << 8)
# define DUMMY_START_CDATA_HANDLER_FLAG (1UL << 9)
# define DUMMY_END_CDATA_HANDLER_FLAG (1UL << 10)
# define DUMMY_UNPARSED_ENTITY_DECL_HANDLER_FLAG (1UL << 11)
# define DUMMY_START_NS_DECL_HANDLER_FLAG (1UL << 12)
# define DUMMY_END_NS_DECL_HANDLER_FLAG (1UL << 13)
# define DUMMY_START_DOCTYPE_DECL_HANDLER_FLAG (1UL << 14)
# define DUMMY_END_DOCTYPE_DECL_HANDLER_FLAG (1UL << 15)
# define DUMMY_SKIP_HANDLER_FLAG (1UL << 16)
# define DUMMY_DEFAULT_HANDLER_FLAG (1UL << 17)
extern void init_dummy_handlers(void);
extern unsigned long get_dummy_handler_flags(void);
extern void XMLCALL dummy_xdecl_handler(void *userData, const XML_Char *version,
const XML_Char *encoding,
int standalone);
extern void XMLCALL dummy_start_doctype_handler(void *userData,
const XML_Char *doctypeName,
const XML_Char *sysid,
const XML_Char *pubid,
int has_internal_subset);
extern void XMLCALL dummy_end_doctype_handler(void *userData);
extern void XMLCALL dummy_entity_decl_handler(
void *userData, const XML_Char *entityName, int is_parameter_entity,
const XML_Char *value, int value_length, const XML_Char *base,
const XML_Char *systemId, const XML_Char *publicId,
const XML_Char *notationName);
extern void XMLCALL dummy_notation_decl_handler(void *userData,
const XML_Char *notationName,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern void XMLCALL dummy_element_decl_handler(void *userData,
const XML_Char *name,
XML_Content *model);
extern void XMLCALL dummy_attlist_decl_handler(
void *userData, const XML_Char *elname, const XML_Char *attname,
const XML_Char *att_type, const XML_Char *dflt, int isrequired);
extern void XMLCALL dummy_comment_handler(void *userData, const XML_Char *data);
extern void XMLCALL dummy_pi_handler(void *userData, const XML_Char *target,
const XML_Char *data);
extern void XMLCALL dummy_start_element(void *userData, const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL dummy_end_element(void *userData, const XML_Char *name);
extern void XMLCALL dummy_start_cdata_handler(void *userData);
extern void XMLCALL dummy_end_cdata_handler(void *userData);
extern void XMLCALL dummy_cdata_handler(void *userData, const XML_Char *s,
int len);
extern void XMLCALL dummy_start_namespace_decl_handler(void *userData,
const XML_Char *prefix,
const XML_Char *uri);
extern void XMLCALL dummy_end_namespace_decl_handler(void *userData,
const XML_Char *prefix);
extern void XMLCALL dummy_unparsed_entity_decl_handler(
void *userData, const XML_Char *entityName, const XML_Char *base,
const XML_Char *systemId, const XML_Char *publicId,
const XML_Char *notationName);
extern void XMLCALL dummy_default_handler(void *userData, const XML_Char *s,
int len);
extern void XMLCALL dummy_start_doctype_decl_handler(
void *userData, const XML_Char *doctypeName, const XML_Char *sysid,
const XML_Char *pubid, int has_internal_subset);
extern void XMLCALL dummy_end_doctype_decl_handler(void *userData);
extern void XMLCALL dummy_skip_handler(void *userData,
const XML_Char *entityName,
int is_parameter_entity);
#endif /* XML_DUMMY_H */
#ifdef __cplusplus
}
#endif
+32
View File
@@ -0,0 +1,32 @@
/* C++ compilation harness for the test suite.
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "dummy.c"
File diff suppressed because it is too large Load Diff
+595
View File
@@ -0,0 +1,595 @@
/* XML handler functions for the Expat test suite
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef XML_HANDLERS_H
# define XML_HANDLERS_H
# include "expat_config.h"
# include "expat.h"
/* Variable holding the expected handler userData */
extern const void *g_handler_data;
/* Count of the number of times the comment handler has been invoked */
extern int g_comment_count;
/* Count of the number of skipped entities */
extern int g_skip_count;
/* Count of the number of times the XML declaration handler is invoked */
extern int g_xdecl_count;
/* Start/End Element Handlers */
extern void XMLCALL start_element_event_handler(void *userData,
const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL end_element_event_handler(void *userData,
const XML_Char *name);
# define STRUCT_START_TAG 0
# define STRUCT_END_TAG 1
extern void XMLCALL start_element_event_handler2(void *userData,
const XML_Char *name,
const XML_Char **attr);
extern void XMLCALL end_element_event_handler2(void *userData,
const XML_Char *name);
typedef struct attrInfo {
const XML_Char *name;
const XML_Char *value;
} AttrInfo;
typedef struct elementInfo {
const XML_Char *name;
int attr_count;
const XML_Char *id_name;
AttrInfo *attributes;
} ElementInfo;
extern void XMLCALL counting_start_element_handler(void *userData,
const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL suspending_end_handler(void *userData, const XML_Char *s);
extern void XMLCALL start_element_suspender(void *userData,
const XML_Char *name,
const XML_Char **atts);
extern int g_triplet_start_flag;
extern int g_triplet_end_flag;
extern void XMLCALL triplet_start_checker(void *userData, const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL triplet_end_checker(void *userData, const XML_Char *name);
extern void XMLCALL overwrite_start_checker(void *userData,
const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL overwrite_end_checker(void *userData, const XML_Char *name);
extern void XMLCALL start_element_fail(void *userData, const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL start_ns_clearing_start_element(void *userData,
const XML_Char *prefix,
const XML_Char *uri);
typedef struct {
XML_Parser parser;
int deep;
} DataIssue240;
extern void XMLCALL start_element_issue_240(void *userData,
const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL end_element_issue_240(void *userData, const XML_Char *name);
/* Text encoding handlers */
extern int XMLCALL UnknownEncodingHandler(void *data, const XML_Char *encoding,
XML_Encoding *info);
extern int XMLCALL UnrecognisedEncodingHandler(void *data,
const XML_Char *encoding,
XML_Encoding *info);
extern int XMLCALL unknown_released_encoding_handler(void *data,
const XML_Char *encoding,
XML_Encoding *info);
extern int XMLCALL MiscEncodingHandler(void *data, const XML_Char *encoding,
XML_Encoding *info);
extern int XMLCALL long_encoding_handler(void *userData,
const XML_Char *encoding,
XML_Encoding *info);
/* External Entity Handlers */
typedef struct ExtOption {
const XML_Char *system_id;
const char *parse_text;
} ExtOption;
extern int XMLCALL external_entity_optioner(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_loader(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
typedef struct ext_faults {
const char *parse_text;
const char *fail_text;
const XML_Char *encoding;
enum XML_Error error;
} ExtFaults;
extern int XMLCALL external_entity_faulter(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_failer__if_not_xml_ge(
XML_Parser parser, const XML_Char *context, const XML_Char *base,
const XML_Char *systemId, const XML_Char *publicId);
extern int XMLCALL external_entity_null_loader(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_resetter(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_suspender(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_suspend_xmldecl(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_suspending_faulter(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_cr_catcher(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_bad_cr_catcher(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_rsqb_catcher(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_good_cdata_ascii(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
/* Entity declaration handlers */
extern void XMLCALL entity_suspending_decl_handler(void *userData,
const XML_Char *name,
XML_Content *model);
extern void XMLCALL entity_suspending_xdecl_handler(void *userData,
const XML_Char *version,
const XML_Char *encoding,
int standalone);
extern int XMLCALL external_entity_param_checker(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_ref_param_checker(XML_Parser parameter,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_param(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_load_ignore(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_load_ignore_utf16(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_load_ignore_utf16_be(
XML_Parser parser, const XML_Char *context, const XML_Char *base,
const XML_Char *systemId, const XML_Char *publicId);
extern int XMLCALL external_entity_valuer(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_not_standalone(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_value_aborter(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_public(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_devaluer(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
typedef struct ext_hdlr_data {
const char *parse_text;
XML_ExternalEntityRefHandler handler;
} ExtHdlrData;
extern int XMLCALL external_entity_oneshot_loader(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
typedef struct ExtTest2 {
const char *parse_text;
int parse_len;
const XML_Char *encoding;
CharData *storage;
} ExtTest2;
extern int XMLCALL external_entity_loader2(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
typedef struct ExtFaults2 {
const char *parse_text;
int parse_len;
const char *fail_text;
const XML_Char *encoding;
enum XML_Error error;
} ExtFaults2;
extern int XMLCALL external_entity_faulter2(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_unfinished_attlist(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_handler(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_duff_loader(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_dbl_handler(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_dbl_handler_2(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_alloc_set_encoding(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_reallocator(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_alloc(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
extern int XMLCALL external_entity_parser_create_alloc_fail_handler(
XML_Parser parser, const XML_Char *context, const XML_Char *base,
const XML_Char *systemId, const XML_Char *publicId);
struct AccountingTestCase {
const char *primaryText;
const char *firstExternalText; /* often NULL */
const char *secondExternalText; /* often NULL */
const unsigned long long expectedCountBytesIndirectExtra;
};
extern int accounting_external_entity_ref_handler(XML_Parser parser,
const XML_Char *context,
const XML_Char *base,
const XML_Char *systemId,
const XML_Char *publicId);
/* NotStandalone handlers */
extern int XMLCALL reject_not_standalone_handler(void *userData);
extern int XMLCALL accept_not_standalone_handler(void *userData);
/* Attribute List handlers */
typedef struct AttTest {
const char *definition;
const XML_Char *element_name;
const XML_Char *attr_name;
const XML_Char *attr_type;
const XML_Char *default_value;
int is_required;
} AttTest;
extern void XMLCALL verify_attlist_decl_handler(
void *userData, const XML_Char *element_name, const XML_Char *attr_name,
const XML_Char *attr_type, const XML_Char *default_value, int is_required);
/* Character data handlers */
extern void XMLCALL clearing_aborting_character_handler(void *userData,
const XML_Char *s,
int len);
extern void XMLCALL parser_stop_character_handler(void *userData,
const XML_Char *s, int len);
extern void XMLCALL cr_cdata_handler(void *userData, const XML_Char *s,
int len);
extern void XMLCALL rsqb_handler(void *userData, const XML_Char *s, int len);
typedef struct ByteTestData {
int start_element_len;
int cdata_len;
int total_string_len;
} ByteTestData;
extern void XMLCALL byte_character_handler(void *userData, const XML_Char *s,
int len);
extern void XMLCALL ext2_accumulate_characters(void *userData,
const XML_Char *s, int len);
/* Handlers that record their `len` arg and a single identifying character */
struct handler_record_entry {
const char *name;
int arg;
};
struct handler_record_list {
int count;
struct handler_record_entry entries[50]; // arbitrary big-enough max count
};
extern void XMLCALL record_default_handler(void *userData, const XML_Char *s,
int len);
extern void XMLCALL record_cdata_handler(void *userData, const XML_Char *s,
int len);
extern void XMLCALL record_cdata_nodefault_handler(void *userData,
const XML_Char *s, int len);
extern void XMLCALL record_skip_handler(void *userData,
const XML_Char *entityName,
int is_parameter_entity);
extern void XMLCALL record_element_start_handler(void *userData,
const XML_Char *name,
const XML_Char **atts);
extern void XMLCALL record_element_end_handler(void *userData,
const XML_Char *name);
extern const struct handler_record_entry *
_handler_record_get(const struct handler_record_list *storage, int index,
const char *file, int line);
# define handler_record_get(storage, index) \
_handler_record_get((storage), (index), __FILE__, __LINE__)
# define assert_record_handler_called(storage, index, expected_name, \
expected_arg) \
do { \
const struct handler_record_entry *e \
= handler_record_get(storage, index); \
assert_true(strcmp(e->name, expected_name) == 0); \
assert_true(e->arg == (expected_arg)); \
} while (0)
/* Entity Declaration Handlers */
# define ENTITY_MATCH_FAIL (-1)
# define ENTITY_MATCH_NOT_FOUND (0)
# define ENTITY_MATCH_SUCCESS (1)
extern void XMLCALL param_entity_match_handler(
void *userData, const XML_Char *entityName, int is_parameter_entity,
const XML_Char *value, int value_length, const XML_Char *base,
const XML_Char *systemId, const XML_Char *publicId,
const XML_Char *notationName);
extern void param_entity_match_init(const XML_Char *name,
const XML_Char *value);
extern int get_param_entity_match_flag(void);
/* Misc handlers */
extern void XMLCALL xml_decl_handler(void *userData, const XML_Char *version,
const XML_Char *encoding, int standalone);
extern void XMLCALL param_check_skip_handler(void *userData,
const XML_Char *entityName,
int is_parameter_entity);
extern void XMLCALL data_check_comment_handler(void *userData,
const XML_Char *data);
extern void XMLCALL selective_aborting_default_handler(void *userData,
const XML_Char *s,
int len);
extern void XMLCALL suspending_comment_handler(void *userData,
const XML_Char *data);
extern void XMLCALL element_decl_suspender(void *userData, const XML_Char *name,
XML_Content *model);
extern void XMLCALL accumulate_pi_characters(void *userData,
const XML_Char *target,
const XML_Char *data);
extern void XMLCALL accumulate_comment(void *userData, const XML_Char *data);
extern void XMLCALL accumulate_entity_decl(
void *userData, const XML_Char *entityName, int is_parameter_entity,
const XML_Char *value, int value_length, const XML_Char *base,
const XML_Char *systemId, const XML_Char *publicId,
const XML_Char *notationName);
extern void XMLCALL accumulate_char_data(void *userData, const XML_Char *s,
int len);
extern void XMLCALL accumulate_start_element(void *userData,
const XML_Char *name,
const XML_Char **atts);
typedef struct default_check {
const XML_Char *expected;
const int expectedLen;
XML_Bool seen;
} DefaultCheck;
void XMLCALL checking_default_handler(void *userData, const XML_Char *s,
int len);
typedef struct {
XML_Parser parser;
CharData *storage;
} ParserPlusStorage;
extern void XMLCALL
accumulate_and_suspend_comment_handler(void *userData, const XML_Char *data);
#endif /* XML_HANDLERS_H */
#ifdef __cplusplus
}
#endif
+32
View File
@@ -0,0 +1,32 @@
/* C++ compilation harness for the test suite.
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "handlers.c"
+9 -8
View File
@@ -6,8 +6,9 @@
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2022 Sean McBride <sean@rogue-research.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
@@ -54,7 +55,8 @@ static AllocationEntry *find_allocation(const void *ptr);
/* Allocate some memory and keep track of it. */
void *
tracking_malloc(size_t size) {
AllocationEntry *entry = malloc(sizeof(AllocationEntry));
AllocationEntry *const entry
= (AllocationEntry *)malloc(sizeof(AllocationEntry));
if (entry == NULL) {
printf("Allocator failure\n");
@@ -140,7 +142,7 @@ tracking_realloc(void *ptr, size_t size) {
entry = find_allocation(ptr);
if (entry == NULL) {
printf("Attempting to realloc unallocated memory at %p\n", ptr);
entry = malloc(sizeof(AllocationEntry));
entry = (AllocationEntry *)malloc(sizeof(AllocationEntry));
if (entry == NULL) {
printf("Reallocator failure\n");
return NULL;
@@ -162,12 +164,11 @@ tracking_realloc(void *ptr, size_t size) {
alloc_tail = entry;
}
} else {
entry->allocation = realloc(ptr, size);
if (entry->allocation == NULL) {
/* Realloc semantics say the original is still allocated */
entry->allocation = ptr;
void *const reallocated = realloc(ptr, size);
if (reallocated == NULL) {
return NULL;
}
entry->allocation = reallocated;
}
entry->num_bytes = size;
+32
View File
@@ -0,0 +1,32 @@
/* C++ compilation harness for the test suite.
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "memcheck.c"
+46 -12
View File
@@ -11,10 +11,11 @@
|_| XML parser
Copyright (c) 2004-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2016-2020 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild@sony.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
@@ -37,6 +38,11 @@
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#if defined(NDEBUG)
# undef NDEBUG /* because test suite relies on assert(...) at the moment */
#endif
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
@@ -88,7 +94,8 @@ tcase_add_test(TCase *tc, tcase_test_function test) {
if (tc->allocated == tc->ntests) {
int nalloc = tc->allocated + 100;
size_t new_size = sizeof(tcase_test_function) * nalloc;
tcase_test_function *new_tests = realloc(tc->tests, new_size);
tcase_test_function *const new_tests
= (tcase_test_function *)realloc(tc->tests, new_size);
assert(new_tests != NULL);
tc->tests = new_tests;
tc->allocated = nalloc;
@@ -123,7 +130,7 @@ suite_free(Suite *suite) {
SRunner *
srunner_create(Suite *suite) {
SRunner *runner = calloc(1, sizeof(SRunner));
SRunner *const runner = (SRunner *)calloc(1, sizeof(SRunner));
if (runner != NULL) {
runner->suite = suite;
}
@@ -132,17 +139,35 @@ srunner_create(Suite *suite) {
static jmp_buf env;
#define SUBTEST_LEN (50) // informative, but not too long
static char const *_check_current_function = NULL;
static char _check_current_subtest[SUBTEST_LEN];
static int _check_current_lineno = -1;
static char const *_check_current_filename = NULL;
void
_check_set_test_info(char const *function, char const *filename, int lineno) {
_check_current_function = function;
set_subtest("%s", "");
_check_current_lineno = lineno;
_check_current_filename = filename;
}
void
set_subtest(char const *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vsnprintf(_check_current_subtest, SUBTEST_LEN, fmt, ap);
va_end(ap);
// replace line feeds with spaces, for nicer error logs
for (size_t i = 0; i < SUBTEST_LEN; ++i) {
if (_check_current_subtest[i] == '\n') {
_check_current_subtest[i] = ' ';
}
}
_check_current_subtest[SUBTEST_LEN - 1] = '\0'; // ensure termination
}
static void
handle_success(int verbosity) {
if (verbosity >= CK_VERBOSE) {
@@ -151,16 +176,20 @@ handle_success(int verbosity) {
}
static void
handle_failure(SRunner *runner, int verbosity, const char *phase_info) {
handle_failure(SRunner *runner, int verbosity, const char *context,
const char *phase_info) {
runner->nfailures++;
if (verbosity != CK_SILENT) {
printf("FAIL: %s (%s at %s:%d)\n", _check_current_function, phase_info,
_check_current_filename, _check_current_lineno);
if (strlen(_check_current_subtest) != 0) {
phase_info = _check_current_subtest;
}
printf("FAIL [%s]: %s (%s at %s:%d)\n", context, _check_current_function,
phase_info, _check_current_filename, _check_current_lineno);
}
}
void
srunner_run_all(SRunner *runner, int verbosity) {
srunner_run_all(SRunner *runner, const char *context, int verbosity) {
Suite *suite;
TCase *volatile tc;
assert(runner != NULL);
@@ -170,26 +199,28 @@ srunner_run_all(SRunner *runner, int verbosity) {
volatile int i;
for (i = 0; i < tc->ntests; ++i) {
runner->nchecks++;
set_subtest("%s", "");
if (tc->setup != NULL) {
/* setup */
if (setjmp(env)) {
handle_failure(runner, verbosity, "during setup");
handle_failure(runner, verbosity, context, "during setup");
continue;
}
tc->setup();
}
/* test */
if (setjmp(env)) {
handle_failure(runner, verbosity, "during actual test");
handle_failure(runner, verbosity, context, "during actual test");
continue;
}
(tc->tests[i])();
set_subtest("%s", "");
/* teardown */
if (tc->teardown != NULL) {
if (setjmp(env)) {
handle_failure(runner, verbosity, "during teardown");
handle_failure(runner, verbosity, context, "during teardown");
continue;
}
tc->teardown();
@@ -199,6 +230,10 @@ srunner_run_all(SRunner *runner, int verbosity) {
}
tc = tc->next_tcase;
}
}
void
srunner_summarize(SRunner *runner, int verbosity) {
if (verbosity != CK_SILENT) {
int passed = runner->nchecks - runner->nfailures;
double percentage = ((double)passed) / runner->nchecks;
@@ -209,12 +244,11 @@ srunner_run_all(SRunner *runner, int verbosity) {
}
void
_fail_unless(int condition, const char *file, int line, const char *msg) {
_fail(const char *file, int line, const char *msg) {
/* Always print the error message so it isn't lost. In this case,
we have a failure, so there's no reason to be quiet about what
it is.
*/
UNUSED_P(condition);
_check_current_filename = file;
_check_current_lineno = line;
if (msg != NULL) {
+54 -21
View File
@@ -14,7 +14,9 @@
Copyright (c) 2004-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2006-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2017 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild@sony.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
@@ -41,30 +43,54 @@
extern "C" {
#endif
#define CK_NOFORK 0
#define CK_FORK 1
#ifndef XML_MINICHECK_H
# define XML_MINICHECK_H
#define CK_SILENT 0
#define CK_NORMAL 1
#define CK_VERBOSE 2
# define CK_NOFORK 0
# define CK_FORK 1
# define CK_SILENT 0
# define CK_NORMAL 1
# define CK_VERBOSE 2
/* Workaround for Microsoft's compiler and Tru64 Unix systems where the
C compiler has a working __func__, but the C++ compiler only has a
working __FUNCTION__. This could be fixed in configure.in, but it's
not worth it right now. */
#if defined(_MSC_VER) || (defined(__osf__) && defined(__cplusplus))
# define __func__ __FUNCTION__
#endif
# if defined(_MSC_VER) || (defined(__osf__) && defined(__cplusplus))
# define __func__ __FUNCTION__
# endif
#define START_TEST(testname) \
static void testname(void) { \
_check_set_test_info(__func__, __FILE__, __LINE__); \
{
#define END_TEST \
} \
}
/* PRINTF_LIKE has two effects:
1. Make clang's -Wformat-nonliteral stop warning about non-literal format
strings in annotated functions' code.
2. Make both clang and gcc's -Wformat-nonliteral warn about *callers* of
the annotated function that use a non-literal format string.
*/
# if defined(__GNUC__)
# define PRINTF_LIKE(fmtpos, argspos) \
__attribute__((format(printf, fmtpos, argspos)))
# else
# define PRINTF_LIKE(fmtpos, argspos)
# endif
#define fail(msg) _fail_unless(0, __FILE__, __LINE__, msg)
# define START_TEST(testname) \
static void testname(void) { \
_check_set_test_info(__func__, __FILE__, __LINE__); \
{
# define END_TEST \
} \
}
void PRINTF_LIKE(1, 2) set_subtest(char const *fmt, ...);
# define fail(msg) _fail(__FILE__, __LINE__, msg)
# define assert_true(cond) \
do { \
if (! (cond)) { \
_fail(__FILE__, __LINE__, "check failed: " #cond); \
} \
} while (0)
typedef void (*tcase_setup_function)(void);
typedef void (*tcase_teardown_function)(void);
@@ -103,18 +129,25 @@ void _check_set_test_info(char const *function, char const *filename,
* Prototypes for the actual implementation.
*/
void _fail_unless(int condition, const char *file, int line, const char *msg);
# if defined(__GNUC__)
__attribute__((noreturn))
# endif
void
_fail(const char *file, int line, const char *msg);
Suite *suite_create(const char *name);
TCase *tcase_create(const char *name);
void suite_add_tcase(Suite *suite, TCase *tc);
void tcase_add_checked_fixture(TCase *, tcase_setup_function,
tcase_teardown_function);
void tcase_add_checked_fixture(TCase *tc, tcase_setup_function setup,
tcase_teardown_function teardown);
void tcase_add_test(TCase *tc, tcase_test_function test);
SRunner *srunner_create(Suite *suite);
void srunner_run_all(SRunner *runner, int verbosity);
void srunner_run_all(SRunner *runner, const char *context, int verbosity);
void srunner_summarize(SRunner *runner, int verbosity);
int srunner_ntests_failed(SRunner *runner);
void srunner_free(SRunner *runner);
#endif /* XML_MINICHECK_H */
#ifdef __cplusplus
}
#endif
+32
View File
@@ -0,0 +1,32 @@
/* C++ compilation harness for the test suite.
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "minicheck.c"
+523
View File
@@ -0,0 +1,523 @@
/* Tests in the "miscellaneous" test case for the Expat test suite
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#if defined(NDEBUG)
# undef NDEBUG /* because test suite relies on assert(...) at the moment */
#endif
#include <assert.h>
#include <string.h>
#include "expat_config.h"
#include "expat.h"
#include "internal.h"
#include "minicheck.h"
#include "memcheck.h"
#include "common.h"
#include "ascii.h" /* for ASCII_xxx */
#include "handlers.h"
#include "misc_tests.h"
/* Test that a failure to allocate the parser structure fails gracefully */
START_TEST(test_misc_alloc_create_parser) {
XML_Memory_Handling_Suite memsuite = {duff_allocator, realloc, free};
unsigned int i;
const unsigned int max_alloc_count = 10;
/* Something this simple shouldn't need more than 10 allocations */
for (i = 0; i < max_alloc_count; i++) {
g_allocation_count = i;
g_parser = XML_ParserCreate_MM(NULL, &memsuite, NULL);
if (g_parser != NULL)
break;
}
if (i == 0)
fail("Parser unexpectedly ignored failing allocator");
else if (i == max_alloc_count)
fail("Parser not created with max allocation count");
}
END_TEST
/* Test memory allocation failures for a parser with an encoding */
START_TEST(test_misc_alloc_create_parser_with_encoding) {
XML_Memory_Handling_Suite memsuite = {duff_allocator, realloc, free};
unsigned int i;
const unsigned int max_alloc_count = 10;
/* Try several levels of allocation */
for (i = 0; i < max_alloc_count; i++) {
g_allocation_count = i;
g_parser = XML_ParserCreate_MM(XCS("us-ascii"), &memsuite, NULL);
if (g_parser != NULL)
break;
}
if (i == 0)
fail("Parser ignored failing allocator");
else if (i == max_alloc_count)
fail("Parser not created with max allocation count");
}
END_TEST
/* Test that freeing a NULL parser doesn't cause an explosion.
* (Not actually tested anywhere else)
*/
START_TEST(test_misc_null_parser) {
XML_ParserFree(NULL);
}
END_TEST
#if defined(__has_feature)
# if __has_feature(undefined_behavior_sanitizer)
# define EXPAT_TESTS_UBSAN 1
# else
# define EXPAT_TESTS_UBSAN 0
# endif
#else
# define EXPAT_TESTS_UBSAN 0
#endif
/* Test that XML_ErrorString rejects out-of-range codes */
START_TEST(test_misc_error_string) {
#if ! EXPAT_TESTS_UBSAN // because this would trigger UBSan
union {
enum XML_Error xml_error;
int integer;
} trickery;
assert_true(sizeof(enum XML_Error) == sizeof(int)); // self-test
trickery.integer = -1;
if (XML_ErrorString(trickery.xml_error) != NULL)
fail("Negative error code not rejected");
trickery.integer = 100;
if (XML_ErrorString(trickery.xml_error) != NULL)
fail("Large error code not rejected");
#endif
}
END_TEST
/* Test the version information is consistent */
/* Since we are working in XML_LChars (potentially 16-bits), we
* can't use the standard C library functions for character
* manipulation and have to roll our own.
*/
static int
parse_version(const XML_LChar *version_text,
XML_Expat_Version *version_struct) {
if (! version_text)
return XML_FALSE;
while (*version_text != 0x00) {
if (*version_text >= ASCII_0 && *version_text <= ASCII_9)
break;
version_text++;
}
if (*version_text == 0x00)
return XML_FALSE;
/* version_struct->major = strtoul(version_text, 10, &version_text) */
version_struct->major = 0;
while (*version_text >= ASCII_0 && *version_text <= ASCII_9) {
version_struct->major
= 10 * version_struct->major + (*version_text++ - ASCII_0);
}
if (*version_text++ != ASCII_PERIOD)
return XML_FALSE;
/* Now for the minor version number */
version_struct->minor = 0;
while (*version_text >= ASCII_0 && *version_text <= ASCII_9) {
version_struct->minor
= 10 * version_struct->minor + (*version_text++ - ASCII_0);
}
if (*version_text++ != ASCII_PERIOD)
return XML_FALSE;
/* Finally the micro version number */
version_struct->micro = 0;
while (*version_text >= ASCII_0 && *version_text <= ASCII_9) {
version_struct->micro
= 10 * version_struct->micro + (*version_text++ - ASCII_0);
}
if (*version_text != 0x00)
return XML_FALSE;
return XML_TRUE;
}
static int
versions_equal(const XML_Expat_Version *first,
const XML_Expat_Version *second) {
return (first->major == second->major && first->minor == second->minor
&& first->micro == second->micro);
}
START_TEST(test_misc_version) {
XML_Expat_Version read_version = XML_ExpatVersionInfo();
/* Silence compiler warning with the following assignment */
XML_Expat_Version parsed_version = {0, 0, 0};
const XML_LChar *version_text = XML_ExpatVersion();
if (version_text == NULL)
fail("Could not obtain version text");
assert(version_text != NULL);
if (! parse_version(version_text, &parsed_version))
fail("Unable to parse version text");
if (! versions_equal(&read_version, &parsed_version))
fail("Version mismatch");
if (xcstrcmp(version_text, XCS("expat_2.6.2"))) /* needs bump on releases */
fail("XML_*_VERSION in expat.h out of sync?\n");
}
END_TEST
/* Test feature information */
START_TEST(test_misc_features) {
const XML_Feature *features = XML_GetFeatureList();
/* Prevent problems with double-freeing parsers */
g_parser = NULL;
if (features == NULL) {
fail("Failed to get feature information");
} else {
/* Loop through the features checking what we can */
while (features->feature != XML_FEATURE_END) {
switch (features->feature) {
case XML_FEATURE_SIZEOF_XML_CHAR:
if (features->value != sizeof(XML_Char))
fail("Incorrect size of XML_Char");
break;
case XML_FEATURE_SIZEOF_XML_LCHAR:
if (features->value != sizeof(XML_LChar))
fail("Incorrect size of XML_LChar");
break;
default:
break;
}
features++;
}
}
}
END_TEST
/* Regression test for GitHub Issue #17: memory leak parsing attribute
* values with mixed bound and unbound namespaces.
*/
START_TEST(test_misc_attribute_leak) {
const char *text = "<D xmlns:L=\"D\" l:a='' L:a=''/>";
XML_Memory_Handling_Suite memsuite
= {tracking_malloc, tracking_realloc, tracking_free};
g_parser = XML_ParserCreate_MM(XCS("UTF-8"), &memsuite, XCS("\n"));
expect_failure(text, XML_ERROR_UNBOUND_PREFIX, "Unbound prefixes not found");
XML_ParserFree(g_parser);
/* Prevent the teardown trying to double free */
g_parser = NULL;
if (! tracking_report())
fail("Memory leak found");
}
END_TEST
/* Test parser created for UTF-16LE is successful */
START_TEST(test_misc_utf16le) {
const char text[] =
/* <?xml version='1.0'?><q>Hi</q> */
"<\0?\0x\0m\0l\0 \0"
"v\0e\0r\0s\0i\0o\0n\0=\0'\0\x31\0.\0\x30\0'\0?\0>\0"
"<\0q\0>\0H\0i\0<\0/\0q\0>\0";
const XML_Char *expected = XCS("Hi");
CharData storage;
g_parser = XML_ParserCreate(XCS("UTF-16LE"));
if (g_parser == NULL)
fail("Parser not created");
CharData_Init(&storage);
XML_SetUserData(g_parser, &storage);
XML_SetCharacterDataHandler(g_parser, accumulate_characters);
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
CharData_CheckXMLChars(&storage, expected);
}
END_TEST
START_TEST(test_misc_stop_during_end_handler_issue_240_1) {
XML_Parser parser;
DataIssue240 *mydata;
enum XML_Status result;
const char *const doc1 = "<doc><e1/><e><foo/></e></doc>";
parser = XML_ParserCreate(NULL);
XML_SetElementHandler(parser, start_element_issue_240, end_element_issue_240);
mydata = (DataIssue240 *)malloc(sizeof(DataIssue240));
mydata->parser = parser;
mydata->deep = 0;
XML_SetUserData(parser, mydata);
result = _XML_Parse_SINGLE_BYTES(parser, doc1, (int)strlen(doc1), 1);
XML_ParserFree(parser);
free(mydata);
if (result != XML_STATUS_ERROR)
fail("Stopping the parser did not work as expected");
}
END_TEST
START_TEST(test_misc_stop_during_end_handler_issue_240_2) {
XML_Parser parser;
DataIssue240 *mydata;
enum XML_Status result;
const char *const doc2 = "<doc><elem/></doc>";
parser = XML_ParserCreate(NULL);
XML_SetElementHandler(parser, start_element_issue_240, end_element_issue_240);
mydata = (DataIssue240 *)malloc(sizeof(DataIssue240));
mydata->parser = parser;
mydata->deep = 0;
XML_SetUserData(parser, mydata);
result = _XML_Parse_SINGLE_BYTES(parser, doc2, (int)strlen(doc2), 1);
XML_ParserFree(parser);
free(mydata);
if (result != XML_STATUS_ERROR)
fail("Stopping the parser did not work as expected");
}
END_TEST
START_TEST(test_misc_deny_internal_entity_closing_doctype_issue_317) {
const char *const inputOne = "<!DOCTYPE d [\n"
"<!ENTITY % e ']><d/>'>\n"
"\n"
"%e;";
const char *const inputTwo = "<!DOCTYPE d [\n"
"<!ENTITY % e1 ']><d/>'><!ENTITY % e2 '&e1;'>\n"
"\n"
"%e2;";
const char *const inputThree = "<!DOCTYPE d [\n"
"<!ENTITY % e ']><d'>\n"
"\n"
"%e;";
const char *const inputIssue317 = "<!DOCTYPE doc [\n"
"<!ENTITY % foo ']>\n"
"<doc>Hell<oc (#PCDATA)*>'>\n"
"%foo;\n"
"]>\n"
"<doc>Hello, world</dVc>";
const char *const inputs[] = {inputOne, inputTwo, inputThree, inputIssue317};
size_t inputIndex = 0;
for (; inputIndex < sizeof(inputs) / sizeof(inputs[0]); inputIndex++) {
set_subtest("%s", inputs[inputIndex]);
XML_Parser parser;
enum XML_Status parseResult;
int setParamEntityResult;
XML_Size lineNumber;
XML_Size columnNumber;
const char *const input = inputs[inputIndex];
parser = XML_ParserCreate(NULL);
setParamEntityResult
= XML_SetParamEntityParsing(parser, XML_PARAM_ENTITY_PARSING_ALWAYS);
if (setParamEntityResult != 1)
fail("Failed to set XML_PARAM_ENTITY_PARSING_ALWAYS.");
parseResult = _XML_Parse_SINGLE_BYTES(parser, input, (int)strlen(input), 0);
if (parseResult != XML_STATUS_ERROR) {
parseResult = _XML_Parse_SINGLE_BYTES(parser, "", 0, 1);
if (parseResult != XML_STATUS_ERROR) {
fail("Parsing was expected to fail but succeeded.");
}
}
if (XML_GetErrorCode(parser) != XML_ERROR_INVALID_TOKEN)
fail("Error code does not match XML_ERROR_INVALID_TOKEN");
lineNumber = XML_GetCurrentLineNumber(parser);
if (lineNumber != 4)
fail("XML_GetCurrentLineNumber does not work as expected.");
columnNumber = XML_GetCurrentColumnNumber(parser);
if (columnNumber != 0)
fail("XML_GetCurrentColumnNumber does not work as expected.");
XML_ParserFree(parser);
}
}
END_TEST
START_TEST(test_misc_tag_mismatch_reset_leak) {
#ifdef XML_NS
const char *const text = "<open xmlns='https://namespace1.test'></close>";
XML_Parser parser = XML_ParserCreateNS(NULL, XCS('\n'));
if (_XML_Parse_SINGLE_BYTES(parser, text, (int)strlen(text), XML_TRUE)
!= XML_STATUS_ERROR)
fail("Call to parse was expected to fail");
if (XML_GetErrorCode(parser) != XML_ERROR_TAG_MISMATCH)
fail("Call to parse was expected to fail from a closing tag mismatch");
XML_ParserReset(parser, NULL);
if (_XML_Parse_SINGLE_BYTES(parser, text, (int)strlen(text), XML_TRUE)
!= XML_STATUS_ERROR)
fail("Call to parse was expected to fail");
if (XML_GetErrorCode(parser) != XML_ERROR_TAG_MISMATCH)
fail("Call to parse was expected to fail from a closing tag mismatch");
XML_ParserFree(parser);
#endif
}
END_TEST
START_TEST(test_misc_create_external_entity_parser_with_null_context) {
// With XML_DTD undefined, the only supported case of external entities
// is pattern "<!ENTITY entity123 SYSTEM 'filename123'>". A NULL context
// was causing a segfault through a null pointer dereference in function
// setContext, previously.
XML_Parser parser = XML_ParserCreate(NULL);
XML_Parser ext_parser = XML_ExternalEntityParserCreate(parser, NULL, NULL);
#ifdef XML_DTD
assert_true(ext_parser != NULL);
XML_ParserFree(ext_parser);
#else
assert_true(ext_parser == NULL);
#endif /* XML_DTD */
XML_ParserFree(parser);
}
END_TEST
START_TEST(test_misc_general_entities_support) {
const char *const doc
= "<!DOCTYPE r [\n"
"<!ENTITY e1 'v1'>\n"
"<!ENTITY e2 SYSTEM 'v2'>\n"
"]>\n"
"<r a1='[&e1;]'>[&e1;][&e2;][&amp;&apos;&gt;&lt;&quot;]</r>";
CharData storage;
CharData_Init(&storage);
XML_Parser parser = XML_ParserCreate(NULL);
XML_SetUserData(parser, &storage);
XML_SetStartElementHandler(parser, accumulate_start_element);
XML_SetExternalEntityRefHandler(parser,
external_entity_failer__if_not_xml_ge);
XML_SetEntityDeclHandler(parser, accumulate_entity_decl);
XML_SetCharacterDataHandler(parser, accumulate_char_data);
if (_XML_Parse_SINGLE_BYTES(parser, doc, (int)strlen(doc), XML_TRUE)
!= XML_STATUS_OK) {
xml_failure(parser);
}
XML_ParserFree(parser);
CharData_CheckXMLChars(&storage,
/* clang-format off */
#if XML_GE == 1
XCS("e1=v1\n")
XCS("e2=(null)\n")
XCS("(r(a1=[v1]))\n")
XCS("[v1][][&'><\"]")
#else
XCS("e1=&amp;e1;\n")
XCS("e2=(null)\n")
XCS("(r(a1=[&e1;]))\n")
XCS("[&e1;][&e2;][&'><\"]")
#endif
);
/* clang-format on */
}
END_TEST
static void XMLCALL
resumable_stopping_character_handler(void *userData, const XML_Char *s,
int len) {
UNUSED_P(s);
UNUSED_P(len);
XML_Parser parser = (XML_Parser)userData;
XML_StopParser(parser, XML_TRUE);
}
// NOTE: This test needs active LeakSanitizer to be of actual use
START_TEST(test_misc_char_handler_stop_without_leak) {
const char *const data
= "<!DOCTYPE t1[<!ENTITY e1 'angle<'><!ENTITY e2 '&e1;'>]><t1>&e2;";
XML_Parser parser = XML_ParserCreate(NULL);
assert_true(parser != NULL);
XML_SetUserData(parser, parser);
XML_SetCharacterDataHandler(parser, resumable_stopping_character_handler);
_XML_Parse_SINGLE_BYTES(parser, data, (int)strlen(data), XML_FALSE);
XML_ParserFree(parser);
}
END_TEST
void
make_miscellaneous_test_case(Suite *s) {
TCase *tc_misc = tcase_create("miscellaneous tests");
suite_add_tcase(s, tc_misc);
tcase_add_checked_fixture(tc_misc, NULL, basic_teardown);
tcase_add_test(tc_misc, test_misc_alloc_create_parser);
tcase_add_test(tc_misc, test_misc_alloc_create_parser_with_encoding);
tcase_add_test(tc_misc, test_misc_null_parser);
tcase_add_test(tc_misc, test_misc_error_string);
tcase_add_test(tc_misc, test_misc_version);
tcase_add_test(tc_misc, test_misc_features);
tcase_add_test(tc_misc, test_misc_attribute_leak);
tcase_add_test(tc_misc, test_misc_utf16le);
tcase_add_test(tc_misc, test_misc_stop_during_end_handler_issue_240_1);
tcase_add_test(tc_misc, test_misc_stop_during_end_handler_issue_240_2);
tcase_add_test__ifdef_xml_dtd(
tc_misc, test_misc_deny_internal_entity_closing_doctype_issue_317);
tcase_add_test(tc_misc, test_misc_tag_mismatch_reset_leak);
tcase_add_test(tc_misc,
test_misc_create_external_entity_parser_with_null_context);
tcase_add_test(tc_misc, test_misc_general_entities_support);
tcase_add_test(tc_misc, test_misc_char_handler_stop_without_leak);
}
+56
View File
@@ -0,0 +1,56 @@
/* Tests in the "miscellaneous" test case for the Expat test suite
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef XML_MISC_TESTS_H
# define XML_MISC_TESTS_H
extern void make_miscellaneous_test_case(Suite *s);
#endif /* XML_MISC_TESTS_H */
#ifdef __cplusplus
}
#endif
+32
View File
@@ -0,0 +1,32 @@
/* C++ compilation harness for the test suite.
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "misc_tests.c"
+754
View File
@@ -0,0 +1,754 @@
/* Tests in the "namespace" test case for the Expat test suite
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "expat_config.h"
#include <string.h>
#include "expat.h"
#include "internal.h"
#include "minicheck.h"
#include "common.h"
#include "dummy.h"
#include "handlers.h"
#include "ns_tests.h"
static void
namespace_setup(void) {
g_parser = XML_ParserCreateNS(NULL, XCS(' '));
if (g_parser == NULL)
fail("Parser not created.");
}
static void
namespace_teardown(void) {
basic_teardown();
}
START_TEST(test_return_ns_triplet) {
const char *text = "<foo:e xmlns:foo='http://example.org/' bar:a='12'\n"
" xmlns:bar='http://example.org/'>";
const char *epilog = "</foo:e>";
const XML_Char *elemstr[]
= {XCS("http://example.org/ e foo"), XCS("http://example.org/ a bar")};
XML_SetReturnNSTriplet(g_parser, XML_TRUE);
XML_SetUserData(g_parser, (void *)elemstr);
XML_SetElementHandler(g_parser, triplet_start_checker, triplet_end_checker);
XML_SetNamespaceDeclHandler(g_parser, dummy_start_namespace_decl_handler,
dummy_end_namespace_decl_handler);
g_triplet_start_flag = XML_FALSE;
g_triplet_end_flag = XML_FALSE;
init_dummy_handlers();
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
/* Check that unsetting "return triplets" fails while still parsing */
XML_SetReturnNSTriplet(g_parser, XML_FALSE);
if (_XML_Parse_SINGLE_BYTES(g_parser, epilog, (int)strlen(epilog), XML_TRUE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
if (! g_triplet_start_flag)
fail("triplet_start_checker not invoked");
if (! g_triplet_end_flag)
fail("triplet_end_checker not invoked");
if (get_dummy_handler_flags()
!= (DUMMY_START_NS_DECL_HANDLER_FLAG | DUMMY_END_NS_DECL_HANDLER_FLAG))
fail("Namespace handlers not called");
}
END_TEST
/* Test that the parsing status is correctly reset by XML_ParserReset().
* We use test_return_ns_triplet() for our example parse to improve
* coverage of tidying up code executed.
*/
START_TEST(test_ns_parser_reset) {
XML_ParsingStatus status;
XML_GetParsingStatus(g_parser, &status);
if (status.parsing != XML_INITIALIZED)
fail("parsing status doesn't start INITIALIZED");
test_return_ns_triplet();
XML_GetParsingStatus(g_parser, &status);
if (status.parsing != XML_FINISHED)
fail("parsing status doesn't end FINISHED");
XML_ParserReset(g_parser, NULL);
XML_GetParsingStatus(g_parser, &status);
if (status.parsing != XML_INITIALIZED)
fail("parsing status doesn't reset to INITIALIZED");
}
END_TEST
static void
run_ns_tagname_overwrite_test(const char *text, const XML_Char *result) {
CharData storage;
CharData_Init(&storage);
XML_SetUserData(g_parser, &storage);
XML_SetElementHandler(g_parser, overwrite_start_checker,
overwrite_end_checker);
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
CharData_CheckXMLChars(&storage, result);
}
/* Regression test for SF bug #566334. */
START_TEST(test_ns_tagname_overwrite) {
const char *text = "<n:e xmlns:n='http://example.org/'>\n"
" <n:f n:attr='foo'/>\n"
" <n:g n:attr2='bar'/>\n"
"</n:e>";
const XML_Char *result = XCS("start http://example.org/ e\n")
XCS("start http://example.org/ f\n")
XCS("attribute http://example.org/ attr\n")
XCS("end http://example.org/ f\n")
XCS("start http://example.org/ g\n")
XCS("attribute http://example.org/ attr2\n")
XCS("end http://example.org/ g\n")
XCS("end http://example.org/ e\n");
run_ns_tagname_overwrite_test(text, result);
}
END_TEST
/* Regression test for SF bug #566334. */
START_TEST(test_ns_tagname_overwrite_triplet) {
const char *text = "<n:e xmlns:n='http://example.org/'>\n"
" <n:f n:attr='foo'/>\n"
" <n:g n:attr2='bar'/>\n"
"</n:e>";
const XML_Char *result = XCS("start http://example.org/ e n\n")
XCS("start http://example.org/ f n\n")
XCS("attribute http://example.org/ attr n\n")
XCS("end http://example.org/ f n\n")
XCS("start http://example.org/ g n\n")
XCS("attribute http://example.org/ attr2 n\n")
XCS("end http://example.org/ g n\n")
XCS("end http://example.org/ e n\n");
XML_SetReturnNSTriplet(g_parser, XML_TRUE);
run_ns_tagname_overwrite_test(text, result);
}
END_TEST
/* Regression test for SF bug #620343. */
START_TEST(test_start_ns_clears_start_element) {
/* This needs to use separate start/end tags; using the empty tag
syntax doesn't cause the problematic path through Expat to be
taken.
*/
const char *text = "<e xmlns='http://example.org/'></e>";
XML_SetStartElementHandler(g_parser, start_element_fail);
XML_SetStartNamespaceDeclHandler(g_parser, start_ns_clearing_start_element);
XML_SetEndNamespaceDeclHandler(g_parser, dummy_end_namespace_decl_handler);
XML_UseParserAsHandlerArg(g_parser);
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
}
END_TEST
/* Regression test for SF bug #616863. */
START_TEST(test_default_ns_from_ext_subset_and_ext_ge) {
const char *text = "<?xml version='1.0'?>\n"
"<!DOCTYPE doc SYSTEM 'http://example.org/doc.dtd' [\n"
" <!ENTITY en SYSTEM 'http://example.org/entity.ent'>\n"
"]>\n"
"<doc xmlns='http://example.org/ns1'>\n"
"&en;\n"
"</doc>";
XML_SetParamEntityParsing(g_parser, XML_PARAM_ENTITY_PARSING_ALWAYS);
XML_SetExternalEntityRefHandler(g_parser, external_entity_handler);
/* We actually need to set this handler to tickle this bug. */
XML_SetStartElementHandler(g_parser, dummy_start_element);
XML_SetUserData(g_parser, NULL);
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
}
END_TEST
/* Regression test #1 for SF bug #673791. */
START_TEST(test_ns_prefix_with_empty_uri_1) {
const char *text = "<doc xmlns:prefix='http://example.org/'>\n"
" <e xmlns:prefix=''/>\n"
"</doc>";
expect_failure(text, XML_ERROR_UNDECLARING_PREFIX,
"Did not report re-setting namespace"
" URI with prefix to ''.");
}
END_TEST
/* Regression test #2 for SF bug #673791. */
START_TEST(test_ns_prefix_with_empty_uri_2) {
const char *text = "<?xml version='1.0'?>\n"
"<docelem xmlns:pre=''/>";
expect_failure(text, XML_ERROR_UNDECLARING_PREFIX,
"Did not report setting namespace URI with prefix to ''.");
}
END_TEST
/* Regression test #3 for SF bug #673791. */
START_TEST(test_ns_prefix_with_empty_uri_3) {
const char *text = "<!DOCTYPE doc [\n"
" <!ELEMENT doc EMPTY>\n"
" <!ATTLIST doc\n"
" xmlns:prefix CDATA ''>\n"
"]>\n"
"<doc/>";
expect_failure(text, XML_ERROR_UNDECLARING_PREFIX,
"Didn't report attr default setting NS w/ prefix to ''.");
}
END_TEST
/* Regression test #4 for SF bug #673791. */
START_TEST(test_ns_prefix_with_empty_uri_4) {
const char *text = "<!DOCTYPE doc [\n"
" <!ELEMENT prefix:doc EMPTY>\n"
" <!ATTLIST prefix:doc\n"
" xmlns:prefix CDATA 'http://example.org/'>\n"
"]>\n"
"<prefix:doc/>";
/* Packaged info expected by the end element handler;
the weird structuring lets us reuse the triplet_end_checker()
function also used for another test. */
const XML_Char *elemstr[] = {XCS("http://example.org/ doc prefix")};
XML_SetReturnNSTriplet(g_parser, XML_TRUE);
XML_SetUserData(g_parser, (void *)elemstr);
XML_SetEndElementHandler(g_parser, triplet_end_checker);
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
}
END_TEST
/* Test with non-xmlns prefix */
START_TEST(test_ns_unbound_prefix) {
const char *text = "<!DOCTYPE doc [\n"
" <!ELEMENT prefix:doc EMPTY>\n"
" <!ATTLIST prefix:doc\n"
" notxmlns:prefix CDATA 'http://example.org/'>\n"
"]>\n"
"<prefix:doc/>";
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
!= XML_STATUS_ERROR)
fail("Unbound prefix incorrectly passed");
if (XML_GetErrorCode(g_parser) != XML_ERROR_UNBOUND_PREFIX)
xml_failure(g_parser);
}
END_TEST
START_TEST(test_ns_default_with_empty_uri) {
const char *text = "<doc xmlns='http://example.org/'>\n"
" <e xmlns=''/>\n"
"</doc>";
/* Add some handlers to exercise extra code paths */
XML_SetStartNamespaceDeclHandler(g_parser,
dummy_start_namespace_decl_handler);
XML_SetEndNamespaceDeclHandler(g_parser, dummy_end_namespace_decl_handler);
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
}
END_TEST
/* Regression test for SF bug #692964: two prefixes for one namespace. */
START_TEST(test_ns_duplicate_attrs_diff_prefixes) {
const char *text = "<doc xmlns:a='http://example.org/a'\n"
" xmlns:b='http://example.org/a'\n"
" a:a='v' b:a='v' />";
expect_failure(text, XML_ERROR_DUPLICATE_ATTRIBUTE,
"did not report multiple attributes with same URI+name");
}
END_TEST
START_TEST(test_ns_duplicate_hashes) {
/* The hash of an attribute is calculated as the hash of its URI
* concatenated with a space followed by its name (after the
* colon). We wish to generate attributes with the same hash
* value modulo the attribute table size so that we can check that
* the attribute hash table works correctly. The attribute hash
* table size will be the smallest power of two greater than the
* number of attributes, but at least eight. There is
* unfortunately no programmatic way of getting the hash or the
* table size at user level, but the test code coverage percentage
* will drop if the hashes cease to point to the same row.
*
* The cunning plan is to have few enough attributes to have a
* reliable table size of 8, and have the single letter attribute
* names be 8 characters apart, producing a hash which will be the
* same modulo 8.
*/
const char *text = "<doc xmlns:a='http://example.org/a'\n"
" a:a='v' a:i='w' />";
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
}
END_TEST
/* Regression test for SF bug #695401: unbound prefix. */
START_TEST(test_ns_unbound_prefix_on_attribute) {
const char *text = "<doc a:attr=''/>";
expect_failure(text, XML_ERROR_UNBOUND_PREFIX,
"did not report unbound prefix on attribute");
}
END_TEST
/* Regression test for SF bug #695401: unbound prefix. */
START_TEST(test_ns_unbound_prefix_on_element) {
const char *text = "<a:doc/>";
expect_failure(text, XML_ERROR_UNBOUND_PREFIX,
"did not report unbound prefix on element");
}
END_TEST
/* Test that long element names with namespaces are handled correctly */
START_TEST(test_ns_long_element) {
const char *text
= "<foo:thisisalongenoughelementnametotriggerareallocation\n"
" xmlns:foo='http://example.org/' bar:a='12'\n"
" xmlns:bar='http://example.org/'>"
"</foo:thisisalongenoughelementnametotriggerareallocation>";
const XML_Char *elemstr[]
= {XCS("http://example.org/")
XCS(" thisisalongenoughelementnametotriggerareallocation foo"),
XCS("http://example.org/ a bar")};
XML_SetReturnNSTriplet(g_parser, XML_TRUE);
XML_SetUserData(g_parser, (void *)elemstr);
XML_SetElementHandler(g_parser, triplet_start_checker, triplet_end_checker);
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
}
END_TEST
/* Test mixed population of prefixed and unprefixed attributes */
START_TEST(test_ns_mixed_prefix_atts) {
const char *text = "<e a='12' bar:b='13'\n"
" xmlns:bar='http://example.org/'>"
"</e>";
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
}
END_TEST
/* Test having a long namespaced element name inside a short one.
* This exercises some internal buffer reallocation that is shared
* across elements with the same namespace URI.
*/
START_TEST(test_ns_extend_uri_buffer) {
const char *text = "<foo:e xmlns:foo='http://example.org/'>"
" <foo:thisisalongenoughnametotriggerallocationaction"
" foo:a='12' />"
"</foo:e>";
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
}
END_TEST
/* Test that xmlns is correctly rejected as an attribute in the xmlns
* namespace, but not in other namespaces
*/
START_TEST(test_ns_reserved_attributes) {
const char *text1
= "<foo:e xmlns:foo='http://example.org/' xmlns:xmlns='12' />";
const char *text2
= "<foo:e xmlns:foo='http://example.org/' foo:xmlns='12' />";
expect_failure(text1, XML_ERROR_RESERVED_PREFIX_XMLNS,
"xmlns not rejected as an attribute");
XML_ParserReset(g_parser, NULL);
if (_XML_Parse_SINGLE_BYTES(g_parser, text2, (int)strlen(text2), XML_TRUE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
}
END_TEST
/* Test more reserved attributes */
START_TEST(test_ns_reserved_attributes_2) {
const char *text1 = "<foo:e xmlns:foo='http://example.org/'"
" xmlns:xml='http://example.org/' />";
const char *text2
= "<foo:e xmlns:foo='http://www.w3.org/XML/1998/namespace' />";
const char *text3 = "<foo:e xmlns:foo='http://www.w3.org/2000/xmlns/' />";
expect_failure(text1, XML_ERROR_RESERVED_PREFIX_XML,
"xml not rejected as an attribute");
XML_ParserReset(g_parser, NULL);
expect_failure(text2, XML_ERROR_RESERVED_NAMESPACE_URI,
"Use of w3.org URL not faulted");
XML_ParserReset(g_parser, NULL);
expect_failure(text3, XML_ERROR_RESERVED_NAMESPACE_URI,
"Use of w3.org xmlns URL not faulted");
}
END_TEST
/* Test string pool handling of namespace names of 2048 characters */
/* Exercises a particular string pool growth path */
START_TEST(test_ns_extremely_long_prefix) {
/* C99 compilers are only required to support 4095-character
* strings, so the following needs to be split in two to be safe
* for all compilers.
*/
const char *text1
= "<doc "
/* 64 character on each line */
/* ...gives a total length of 2048 */
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
":a='12'";
const char *text2
= " xmlns:"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"
"='foo'\n>"
"</doc>";
if (_XML_Parse_SINGLE_BYTES(g_parser, text1, (int)strlen(text1), XML_FALSE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
if (_XML_Parse_SINGLE_BYTES(g_parser, text2, (int)strlen(text2), XML_TRUE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
}
END_TEST
/* Test unknown encoding handlers in namespace setup */
START_TEST(test_ns_unknown_encoding_success) {
const char *text = "<?xml version='1.0' encoding='prefix-conv'?>\n"
"<foo:e xmlns:foo='http://example.org/'>Hi</foo:e>";
XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL);
run_character_check(text, XCS("Hi"));
}
END_TEST
/* Test that too many colons are rejected */
START_TEST(test_ns_double_colon) {
const char *text = "<foo:e xmlns:foo='http://example.org/' foo:a:b='bar' />";
const enum XML_Status status
= _XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE);
#ifdef XML_NS
if ((status == XML_STATUS_OK)
|| (XML_GetErrorCode(g_parser) != XML_ERROR_INVALID_TOKEN)) {
fail("Double colon in attribute name not faulted"
" (despite active namespace support)");
}
#else
if (status != XML_STATUS_OK) {
fail("Double colon in attribute name faulted"
" (despite inactive namespace support");
}
#endif
}
END_TEST
START_TEST(test_ns_double_colon_element) {
const char *text = "<foo:bar:e xmlns:foo='http://example.org/' />";
const enum XML_Status status
= _XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE);
#ifdef XML_NS
if ((status == XML_STATUS_OK)
|| (XML_GetErrorCode(g_parser) != XML_ERROR_INVALID_TOKEN)) {
fail("Double colon in element name not faulted"
" (despite active namespace support)");
}
#else
if (status != XML_STATUS_OK) {
fail("Double colon in element name faulted"
" (despite inactive namespace support");
}
#endif
}
END_TEST
/* Test that non-name characters after a colon are rejected */
START_TEST(test_ns_bad_attr_leafname) {
const char *text = "<foo:e xmlns:foo='http://example.org/' foo:?ar='baz' />";
expect_failure(text, XML_ERROR_INVALID_TOKEN,
"Invalid character in leafname not faulted");
}
END_TEST
START_TEST(test_ns_bad_element_leafname) {
const char *text = "<foo:?oc xmlns:foo='http://example.org/' />";
expect_failure(text, XML_ERROR_INVALID_TOKEN,
"Invalid character in element leafname not faulted");
}
END_TEST
/* Test high-byte-set UTF-16 characters are valid in a leafname */
START_TEST(test_ns_utf16_leafname) {
const char text[] =
/* <n:e xmlns:n='URI' n:{KHO KHWAI}='a' />
* where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8
*/
"<\0n\0:\0e\0 \0x\0m\0l\0n\0s\0:\0n\0=\0'\0U\0R\0I\0'\0 \0"
"n\0:\0\x04\x0e=\0'\0a\0'\0 \0/\0>\0";
const XML_Char *expected = XCS("a");
CharData storage;
CharData_Init(&storage);
XML_SetStartElementHandler(g_parser, accumulate_attribute);
XML_SetUserData(g_parser, &storage);
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
CharData_CheckXMLChars(&storage, expected);
}
END_TEST
START_TEST(test_ns_utf16_element_leafname) {
const char text[] =
/* <n:{KHO KHWAI} xmlns:n='URI'/>
* where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8
*/
"\0<\0n\0:\x0e\x04\0 \0x\0m\0l\0n\0s\0:\0n\0=\0'\0U\0R\0I\0'\0/\0>";
#ifdef XML_UNICODE
const XML_Char *expected = XCS("URI \x0e04");
#else
const XML_Char *expected = XCS("URI \xe0\xb8\x84");
#endif
CharData storage;
CharData_Init(&storage);
XML_SetStartElementHandler(g_parser, start_element_event_handler);
XML_SetUserData(g_parser, &storage);
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
CharData_CheckXMLChars(&storage, expected);
}
END_TEST
START_TEST(test_ns_utf16_doctype) {
const char text[] =
/* <!DOCTYPE foo:{KHO KHWAI} [ <!ENTITY bar 'baz'> ]>\n
* where {KHO KHWAI} = U+0E04 = 0xe0 0xb8 0x84 in UTF-8
*/
"\0<\0!\0D\0O\0C\0T\0Y\0P\0E\0 \0f\0o\0o\0:\x0e\x04\0 "
"\0[\0 \0<\0!\0E\0N\0T\0I\0T\0Y\0 \0b\0a\0r\0 \0'\0b\0a\0z\0'\0>\0 "
"\0]\0>\0\n"
/* <foo:{KHO KHWAI} xmlns:foo='URI'>&bar;</foo:{KHO KHWAI}> */
"\0<\0f\0o\0o\0:\x0e\x04\0 "
"\0x\0m\0l\0n\0s\0:\0f\0o\0o\0=\0'\0U\0R\0I\0'\0>"
"\0&\0b\0a\0r\0;"
"\0<\0/\0f\0o\0o\0:\x0e\x04\0>";
#ifdef XML_UNICODE
const XML_Char *expected = XCS("URI \x0e04");
#else
const XML_Char *expected = XCS("URI \xe0\xb8\x84");
#endif
CharData storage;
CharData_Init(&storage);
XML_SetUserData(g_parser, &storage);
XML_SetStartElementHandler(g_parser, start_element_event_handler);
XML_SetUnknownEncodingHandler(g_parser, MiscEncodingHandler, NULL);
if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)sizeof(text) - 1, XML_TRUE)
== XML_STATUS_ERROR)
xml_failure(g_parser);
CharData_CheckXMLChars(&storage, expected);
}
END_TEST
START_TEST(test_ns_invalid_doctype) {
const char *text = "<!DOCTYPE foo:!bad [ <!ENTITY bar 'baz' ]>\n"
"<foo:!bad>&bar;</foo:!bad>";
expect_failure(text, XML_ERROR_INVALID_TOKEN,
"Invalid character in document local name not faulted");
}
END_TEST
START_TEST(test_ns_double_colon_doctype) {
const char *text = "<!DOCTYPE foo:a:doc [ <!ENTITY bar 'baz' ]>\n"
"<foo:a:doc>&bar;</foo:a:doc>";
expect_failure(text, XML_ERROR_SYNTAX,
"Double colon in document name not faulted");
}
END_TEST
START_TEST(test_ns_separator_in_uri) {
struct test_case {
enum XML_Status expectedStatus;
const char *doc;
XML_Char namesep;
};
struct test_case cases[] = {
{XML_STATUS_OK, "<doc xmlns='one_two' />", XCS('\n')},
{XML_STATUS_ERROR, "<doc xmlns='one&#x0A;two' />", XCS('\n')},
{XML_STATUS_OK, "<doc xmlns='one:two' />", XCS(':')},
};
size_t i = 0;
size_t failCount = 0;
for (; i < sizeof(cases) / sizeof(cases[0]); i++) {
set_subtest("%s", cases[i].doc);
XML_Parser parser = XML_ParserCreateNS(NULL, cases[i].namesep);
XML_SetElementHandler(parser, dummy_start_element, dummy_end_element);
if (_XML_Parse_SINGLE_BYTES(parser, cases[i].doc, (int)strlen(cases[i].doc),
/*isFinal*/ XML_TRUE)
!= cases[i].expectedStatus) {
failCount++;
}
XML_ParserFree(parser);
}
if (failCount) {
fail("Namespace separator handling is broken");
}
}
END_TEST
void
make_namespace_test_case(Suite *s) {
TCase *tc_namespace = tcase_create("XML namespaces");
suite_add_tcase(s, tc_namespace);
tcase_add_checked_fixture(tc_namespace, namespace_setup, namespace_teardown);
tcase_add_test(tc_namespace, test_return_ns_triplet);
tcase_add_test(tc_namespace, test_ns_parser_reset);
tcase_add_test(tc_namespace, test_ns_tagname_overwrite);
tcase_add_test(tc_namespace, test_ns_tagname_overwrite_triplet);
tcase_add_test(tc_namespace, test_start_ns_clears_start_element);
tcase_add_test__ifdef_xml_dtd(tc_namespace,
test_default_ns_from_ext_subset_and_ext_ge);
tcase_add_test(tc_namespace, test_ns_prefix_with_empty_uri_1);
tcase_add_test(tc_namespace, test_ns_prefix_with_empty_uri_2);
tcase_add_test(tc_namespace, test_ns_prefix_with_empty_uri_3);
tcase_add_test(tc_namespace, test_ns_prefix_with_empty_uri_4);
tcase_add_test(tc_namespace, test_ns_unbound_prefix);
tcase_add_test(tc_namespace, test_ns_default_with_empty_uri);
tcase_add_test(tc_namespace, test_ns_duplicate_attrs_diff_prefixes);
tcase_add_test(tc_namespace, test_ns_duplicate_hashes);
tcase_add_test(tc_namespace, test_ns_unbound_prefix_on_attribute);
tcase_add_test(tc_namespace, test_ns_unbound_prefix_on_element);
tcase_add_test(tc_namespace, test_ns_long_element);
tcase_add_test(tc_namespace, test_ns_mixed_prefix_atts);
tcase_add_test(tc_namespace, test_ns_extend_uri_buffer);
tcase_add_test(tc_namespace, test_ns_reserved_attributes);
tcase_add_test(tc_namespace, test_ns_reserved_attributes_2);
tcase_add_test(tc_namespace, test_ns_extremely_long_prefix);
tcase_add_test(tc_namespace, test_ns_unknown_encoding_success);
tcase_add_test(tc_namespace, test_ns_double_colon);
tcase_add_test(tc_namespace, test_ns_double_colon_element);
tcase_add_test(tc_namespace, test_ns_bad_attr_leafname);
tcase_add_test(tc_namespace, test_ns_bad_element_leafname);
tcase_add_test(tc_namespace, test_ns_utf16_leafname);
tcase_add_test(tc_namespace, test_ns_utf16_element_leafname);
tcase_add_test__if_xml_ge(tc_namespace, test_ns_utf16_doctype);
tcase_add_test(tc_namespace, test_ns_invalid_doctype);
tcase_add_test(tc_namespace, test_ns_double_colon_doctype);
tcase_add_test(tc_namespace, test_ns_separator_in_uri);
}
+56
View File
@@ -0,0 +1,56 @@
/* Tests in the "namespace" test case for the Expat test suite
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef XML_NS_TESTS_H
# define XML_NS_TESTS_H
extern void make_namespace_test_case(Suite *s);
#endif /* XML_NS_TESTS_H */
#ifdef __cplusplus
}
#endif
+32
View File
@@ -0,0 +1,32 @@
/* C++ compilation harness for the test suite.
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "ns_tests.c"
File diff suppressed because it is too large Load Diff
+56
View File
@@ -0,0 +1,56 @@
/* Tests in the "namespace allocation" test case for the Expat test suite
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2001-2006 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2003 Greg Stein <gstein@users.sourceforge.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2005-2012 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2022 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Joe Orton <jorton@redhat.com>
Copyright (c) 2017 José Gutiérrez de la Concha <jose@zeroc.com>
Copyright (c) 2018 Marco Maggi <marco.maggi-ipsu@poste.it>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2020 Tim Gates <tim.gates@iress.com>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef XML_NSALLOC_TESTS_H
# define XML_NSALLOC_TESTS_H
extern void make_nsalloc_test_case(Suite *s);
#endif /* XML_NSALLOC_TESTS_H */
#ifdef __cplusplus
}
#endif
+32
View File
@@ -0,0 +1,32 @@
/* C++ compilation harness for the test suite.
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nsalloc_tests.c"
+32 -12445
View File
File diff suppressed because it is too large Load Diff
@@ -9,8 +9,8 @@
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2017 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
+12 -7
View File
@@ -7,7 +7,8 @@
|_| XML parser
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017-2021 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2022 Sean McBride <sean@rogue-research.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
@@ -30,6 +31,10 @@
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#if defined(NDEBUG)
# undef NDEBUG /* because test suite relies on assert(...) at the moment */
#endif
#include "expat_config.h"
#include <assert.h>
@@ -56,7 +61,7 @@
static XML_Char *
xmlstrdup(const XML_Char *s) {
size_t byte_count = (xcstrlen(s) + 1) * sizeof(XML_Char);
XML_Char *dup = malloc(byte_count);
XML_Char *const dup = (XML_Char *)malloc(byte_count);
assert(dup != NULL);
memcpy(dup, s, byte_count);
@@ -79,13 +84,13 @@ StructData_AddItem(StructData *storage, const XML_Char *s, int data0, int data1,
assert(storage != NULL);
assert(s != NULL);
if (storage->count == storage->max_count) {
StructDataEntry *new;
StructDataEntry *new_entries;
storage->max_count += STRUCT_EXTENSION_COUNT;
new = realloc(storage->entries,
storage->max_count * sizeof(StructDataEntry));
assert(new != NULL);
storage->entries = new;
new_entries = (StructDataEntry *)realloc(
storage->entries, storage->max_count * sizeof(StructDataEntry));
assert(new_entries != NULL);
storage->entries = new_entries;
}
entry = &storage->entries[storage->count];
+32
View File
@@ -0,0 +1,32 @@
/* C++ compilation harness for the test suite.
__ __ _
___\ \/ /_ __ __ _| |_
/ _ \\ /| '_ \ / _` | __|
| __// \| |_) | (_| | |_
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
Copyright (c) 2023 Sebastian Pipping <sebastian@pipping.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "structdata.c"
+1
View File
@@ -8,3 +8,4 @@ expat.PR
expat.PRI
expat.PS
expat.WK3
version.rc
+3 -3
View File
@@ -14,7 +14,7 @@
; Copyright (c) 2001 Tim Peters <tim.peters@gmail.com>
; Copyright (c) 2001-2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
; Copyright (c) 2006-2017 Karl Waclawek <karl@waclawek.net>
; Copyright (c) 2007-2022 Sebastian Pipping <sebastian@pipping.org>
; Copyright (c) 2007-2024 Sebastian Pipping <sebastian@pipping.org>
; Copyright (c) 2022 Johnny Jazeix <jazeix@gmail.com>
; Licensed under the MIT license:
;
@@ -37,7 +37,7 @@
; OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
; USE OR OTHER DEALINGS IN THE SOFTWARE.
#define expatVer "2.5.0"
#define expatVer "2.6.2"
[Setup]
AppName=Expat
@@ -77,7 +77,7 @@ Flags: ignoreversion; Source: doc\*.css; DestDir: "{app}\Doc"
Flags: ignoreversion; Source: doc\*.xml; DestDir: "{app}\Doc"
Flags: ignoreversion; Source: win32\bin\Release\*.dll; DestDir: "{app}\Bin"
Flags: ignoreversion; Source: win32\bin\Release\*.lib; DestDir: "{app}\Bin"
Flags: ignoreversion; Source: win32\version.rc; DestDir: "{app}\Source\win32"
Flags: ignoreversion; Source: win32\version.rc.cmake; DestDir: "{app}\Source\win32"
Flags: ignoreversion; Source: win32\README.txt; DestDir: "{app}\Source"
Flags: ignoreversion; Source: AUTHORS; DestDir: "{app}\Source"
Flags: ignoreversion; Source: Changes; DestDir: "{app}\Source"
@@ -6,8 +6,8 @@ BEGIN
BEGIN
BLOCK "040904E4"
BEGIN
VALUE "FileVersion", "VER_FILEVERSION"
VALUE "ProductVersion", "VER_FILEVERSION"
VALUE "FileVersion", "${PROJECT_VERSION}.0"
VALUE "ProductVersion", "${PROJECT_VERSION}.0"
END
END
BLOCK "VarFileInfo"
+2 -1
View File
@@ -13,6 +13,7 @@
Copyright (c) 2016-2017 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2017 Franek Korta <fkorta@gmail.com>
Copyright (c) 2022 Sean McBride <sean@rogue-research.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
@@ -67,7 +68,7 @@
# ifndef S_IFMT
# define S_IFMT _S_IFMT
# endif
# define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#endif /* not S_ISREG */
#ifndef O_BINARY
+6 -10
View File
@@ -11,10 +11,10 @@
Copyright (c) 2002-2003 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
Copyright (c) 2004-2006 Karl Waclawek <karl@waclawek.net>
Copyright (c) 2005-2007 Steven Solie <steven@solie.ca>
Copyright (c) 2016-2021 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2016-2023 Sebastian Pipping <sebastian@pipping.org>
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
Copyright (c) 2019 David Loffredo <loffredo@steptools.com>
Copyright (c) 2021 Dong-hee Na <donghee.na@python.org>
Copyright (c) 2021 Donghee Na <donghee.na@python.org>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
@@ -37,7 +37,7 @@
USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <expat_config.h>
#include "expat_config.h"
#include <stdio.h>
#include <stdlib.h>
@@ -71,11 +71,7 @@
# endif
#endif
#ifdef _DEBUG
# define READ_SIZE 16
#else
# define READ_SIZE (1024 * 8)
#endif
int g_read_size_bytes = 1024 * 8;
typedef struct {
XML_Parser parser;
@@ -195,7 +191,7 @@ processStream(const XML_Char *filename, XML_Parser parser) {
}
for (;;) {
int nread;
char *buf = (char *)XML_GetBuffer(parser, READ_SIZE);
char *buf = (char *)XML_GetBuffer(parser, g_read_size_bytes);
if (! buf) {
if (filename != NULL)
close(fd);
@@ -203,7 +199,7 @@ processStream(const XML_Char *filename, XML_Parser parser) {
filename != NULL ? filename : T("xmlwf"));
return 0;
}
nread = read(fd, buf, READ_SIZE);
nread = read(fd, buf, g_read_size_bytes);
if (nread < 0) {
tperror(filename != NULL ? filename : T("STDIN"));
if (filename != NULL)

Some files were not shown because too many files have changed in this diff Show More