274 Commits

Author SHA1 Message Date
Nick Wellnhofer
422ae4623a xmllint: Make some strings const 2024-05-05 17:26:11 +02:00
Nick Wellnhofer
1cdfece12b memory: Remove memory debugging
This is useless compared to sanitizers or valgrind and has a
considerable performance impact if enabled accidentally.
2024-04-28 20:42:55 +02:00
Nick Wellnhofer
5e80f4381b tree: Deprecate xmlRegisterNodeDefault
This rarely used feature should be phased out.
2024-04-28 19:30:40 +02:00
Nick Wellnhofer
88169bfda6 tree: Deprecate xmlSetCompressMode 2024-04-28 19:30:39 +02:00
Nick Wellnhofer
87bebd25f1 xmllint: Return error code if XPath returns empty nodeset
Return an error code as before but make it possible to distinguish from
real errors.

Fixes #690.
2024-02-12 16:47:12 +01:00
Nick Wellnhofer
d7d300ba04 parser: Remove remnants of runtime debugging feature
Apparently, this feature was remove long ago.

Fixes #651.
2024-01-04 17:50:11 +01:00
Nick Wellnhofer
7e0bbbc143 parser: New input API
Provide a new set of functions to create xmlParserInputs. These can be
used for the document entity or from external entity loaders.

- Don't require xmlParserInputBuffer.
- All functions take a base URI.
- All functions take an encoding as string.
- xmlNewInputURL also takes a public ID.
- xmlNewInputMemory takes a size_t.
- Optimization hints for memory buffers.

Improve documentation.

Only call xmlInitParser before allocating a new parser context.

Call xmlCtxtUseOptions as early as possible.
2023-12-29 01:22:13 +01:00
Nick Wellnhofer
0a658c0f0a io: Don't use "-" to read from stdin
To implement this feature on such a low level is a disaster waiting to
happen. Remove these checks from the IO code and move them to xmllint.

Note that the serialization API will still treat "-" as stdout.
2023-12-21 15:02:24 +01:00
Nick Wellnhofer
f9f5c2d889 xmllint: Don't use xmlGenericError 2023-12-21 15:02:24 +01:00
Nick Wellnhofer
d6812f3a48 Fix compiler warnings with disabled modules 2023-12-14 13:37:03 +01:00
Nick Wellnhofer
699299cae3 globals: Stop including globals.h 2023-09-20 22:07:40 +02:00
Nick Wellnhofer
11a1839ddd globals: Move remaining globals back to correct header files
This undoes a lot of damage.
2023-09-20 22:06:49 +02:00
Nick Wellnhofer
692a5c40ce xmllint: Don't set deprecated globals 2023-09-20 22:06:49 +02:00
Nick Wellnhofer
bfd7d28698 xmllint: Fix more error messages 2023-08-29 21:16:34 +02:00
Nick Wellnhofer
373244bc66 xmllint: Fix error message when push parsing empty documents 2023-08-29 21:05:32 +02:00
Nick Wellnhofer
ed3bd05284 parser: Allow to set maximum amplification factor 2023-08-20 20:49:16 +02:00
Nick Wellnhofer
305a75ccbe malloc-fail: Fix null-deref with xmllint --copy
See #344. Fixes #552.
2023-06-06 13:15:46 +02:00
Nick Wellnhofer
886bf4e63b Stop calling xmlMemoryDump
This was used to check for memory leaks but could potentially create a
.memdump file. These days, there are better ways to check for memory
leaks.
2023-04-30 15:48:41 +02:00
Nick Wellnhofer
db32b09d50 xmllint: Validate --maxmem integer option
Fixes #520.
2023-04-20 16:22:11 +02:00
Nick Wellnhofer
64b76f8163 xmllint: Fix memory leak with --pattern --stream
Fixes #499.
2023-03-14 14:55:39 +01:00
Nick Wellnhofer
d7daf9fd96 xmllint: Fix use-after-free with --maxmem
Fixes #498.
2023-03-14 14:55:34 +01:00
Nick Wellnhofer
60d457be30 libxml.h: Don't include stdio.h 2022-12-08 04:24:57 +01:00
Nick Wellnhofer
dd3569eaa5 Remove XMLDECL macro from .c files 2022-12-08 02:43:17 +01:00
Alex Richardson
4b959ee168 Remove hacky heuristic from b2dc5675e94aa6b5557ba63f7d66b0f08dd17e4d
Checking whether the context is close to the parent context by hardcoding
250 is not portable (I noticed tests were failing on Morello since the value
is 288 there due to pointers being 128 bits). Instead we should ensure
that the XML_VCTXT_USE_PCTXT flag is not set in cases where the user data
is not actually a parser context (or ideally add a separate field but that
would be an ABI break.

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

There was also an uninitialized vctxt.flags (and other fields) in
`xmlShellValidate()`, which I've fixed by adding a memset() call.
2022-12-01 15:31:25 +00:00
Nick Wellnhofer
701beb4ec7 xmllint: Include <io.h> on Windows 2022-11-22 16:03:05 +01:00
Nick Wellnhofer
e85f9b98a5 xmllint: Improve handling of empty XPath node sets
Don't return an error if the result is an empty node set. Suppress the
"XPath set is empty" message in quiet mode.

Fixes #180.
2022-10-19 02:51:14 +02:00
Nick Wellnhofer
5bffa33a12 Stop including sys/types.h 2022-09-02 18:33:36 +02:00
Nick Wellnhofer
74c84a8c9f xmllint: Don't set deprecated globals
Setting parser options should be enough.
2022-08-24 16:15:04 +02:00
Nick Wellnhofer
ce93ee9051 xmllint: Stop calling xmlSAXDefaultVersion
This should already be handled by setting XML_PARSE_SAX1.
2022-08-24 14:07:57 +02:00
Nick Wellnhofer
9a82b94a94 Introduce xmlNewSAXParserCtxt and htmlNewSAXParserCtxt
Add API functions to create a parser context with a custom SAX handler
without having to mess with ctxt->sax manually.
2022-08-24 14:07:55 +02:00
David Seifert
865520f048 Respect --sysconfdir in source files
* Prefix installations need to point to a non-root `etc`
  - Gentoo Prefix has been patching this for over 10 years:
    https://bugs.gentoo.org/317891
  - MacPorts has to manually replace paths after patching:
    cc3bb736e9/textproc/libxml2/Portfile (L46)
2022-03-30 14:36:49 +00:00
Nick Wellnhofer
776d15d383 Don't check for standard C89 headers
Don't check for

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

Stop including non-standard headers

- malloc.h
- strings.h
2022-03-02 00:43:54 +01:00
Nick Wellnhofer
551b558db0 Remove useless call to xmlRelaxNGCleanupTypes
xmlRelaxNGCleanupTypes is called from xmlCleanupParser later.
2022-03-01 17:15:12 +01:00
Nick Wellnhofer
655cf3f46f Always fopen files with "rb"
We never want translation of newlines when reading files, so it should
be safe to always specify "rb". On sane platforms, the "b" flag is
simply ignored.
2022-02-28 23:39:00 +01:00
Nick Wellnhofer
3f8655db97 Remove __DJGPP__ checks
Drop broken support for DJGPP.
2022-02-28 23:22:50 +01:00
Nick Wellnhofer
2489c1d024 Remove useless __CYGWIN__ checks
From what I can tell, some really early Cygwin versions from around
1998-2000 used to erroneously define _WIN32. This was eventually fixed,
but these days, the `defined(_WIN32) && !defined(__CYGWIN__)` idiom is
unnecessary.

Now, we only check for __CYGWIN__ in xmlexports.h when deciding whether
to use __declspec.
2022-02-28 22:58:35 +01:00
Nick Wellnhofer
c41bc10da3 Fix unused variable warnings with disabled features 2022-02-22 19:57:12 +01:00
Nick Wellnhofer
1089111142 Redirect links to xmlsoft.org
Documentation and releases are now available on gitlab.gnome.org.
2022-02-13 23:10:00 +01:00
Nick Wellnhofer
8be44aeb16 Fix "xmllint -"
Short-lived regression from commit d12be00d.
2022-02-07 20:54:33 +01:00
Nick Wellnhofer
d12be00da8 Don't ignore xmllint options after "-"
There's no reason to ignore options after "-". This was probably
confused with the "--" mechanism which xmllint doesn't implement.

Fixes #290.
2022-02-04 14:13:59 +01:00
Nick Wellnhofer
247cfa27cc Fix parsing of xmllint --maxmem option
Fixes #195.
2022-02-01 16:38:29 +01:00
Nick Wellnhofer
18d1f9d42a Add more checks for malloc failures in xmllint.c
Also fix a few of the existing checks.

Fixes #197.
Fixes #198.
2022-02-01 16:38:17 +01:00
Nick Wellnhofer
eab8652216 Make xmllint return an error if arguments are missing
Before, xmllint would only return an error code if the argument
list was completely empty.

Fixes #285.
2022-01-31 14:45:09 +01:00
Nick Wellnhofer
9f4cb84c62 Fix xmllint --maxmem
xmlMemSetup must be called before initializing the parser, otherwise
some data structures will be allocated with system malloc instead of
our custom allocator. This throws off built-in memory debugging and
sanitizers.
2022-01-16 18:41:58 +01:00
Nick Wellnhofer
72b3c067ce Fix dangling pointer with xmllint --dropdtd
Reset doc->intSubset when dropping the DTD.
2021-04-22 19:24:50 +02:00
Nick Wellnhofer
1358d157d0 Fix use-after-free with xmllint --html --push
Call htmlCtxtUseOptions to make sure that names aren't stored in
dictionaries.

Note that this issue only affects xmllint using the HTML push parser.

Fixes #230.
2021-04-21 13:49:44 +02:00
hhb
02bee4c414 Add a flag to not output anything when xmllint succeeded 2021-02-20 16:49:45 +01:00
Nick Wellnhofer
2b4769a6bd Make "xmllint --push --recovery" work 2020-08-17 01:17:39 +02:00
Nick Wellnhofer
50f06b3efb Fix out-of-bounds read with 'xmllint --htmlout'
Make sure that truncated UTF-8 sequences don't cause an out-of-bounds
array access.

Thanks to @SuhwanSong and the Agency for Defense Development (ADD) for
the report.

Fixes #178.
2020-08-07 21:54:27 +02:00
Nick Wellnhofer
922bebccdd Make 'xmllint --html --push -' read from stdin 2020-07-15 14:20:42 +02:00