236 Commits

Author SHA1 Message Date
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
Nick Wellnhofer
20c60886e4 Fix typos
Resolves #133.
2020-03-08 17:41:53 +01:00
Jared Yanovich
2a350ee9b4 Large batch of typo fixes
Closes #109.
2019-09-30 18:04:38 +02:00
Nick Wellnhofer
f209e55107 Fix build without reader but with pattern
Broken by commit dbc6b55b.
2019-06-25 11:45:16 +02:00
Nick Wellnhofer
dbc6b55b59 Fix warnings when compiling without reader or push parser 2019-05-16 21:06:56 +02:00
Nick Wellnhofer
c494a0ba67 Fix xmllint dump of XPath namespace nodes
Starting with commit da35eeae, xmllint uses the xmlNodeDump API to dump
XPath nodes. Make sure not to access node->doc which doesn't work with
namespace nodes.
2019-03-13 11:59:21 +01:00
Nick Wellnhofer
19f0950d30 Fix -Wcast-function-type warnings (GCC 8)
Use xmlGenericError instead of fprintf as error handler. It also prints
to stderr by default.
2019-01-06 14:25:12 +01:00
Nick Wellnhofer
da35eeae5b Add newlines to 'xmllint --xpath' output
Separate nodes in a node-set with newlines and always add a terminating
newline. This is a breaking change but the old behavior of dumping text
nodes without separator was mostly useless.

Also use buffered I/O when dumping node-sets.
2018-09-23 01:34:26 +02:00
Nick Wellnhofer
cb5541c9f3 Fix libz and liblzma detection
If libz or liblzma are detected with pkg-config, AC_CHECK_HEADERS must
not be run because the correct CPPFLAGS aren't set. It is actually not
required have separate checks for LIBXML_ZLIB_ENABLED and HAVE_ZLIB_H.
Only check for LIBXML_ZLIB_ENABLED and remove HAVE_ZLIB_H macro.

Fixes bug 764657, bug 787041.
2017-11-27 14:33:37 +01:00
Nick Wellnhofer
86615e43bb Fix IO callback signatures 2017-11-09 17:47:47 +01:00
Nick Wellnhofer
bee8f1e47b Don't include winsock2.h in xmllint.c
I'm not sure why xmllint.c did include winsock2.h at all. Stop
including the header as both MinGW and MSVC builds don't seem to
require it.
2017-10-09 13:59:44 +02:00
Nick Wellnhofer
45b0ebdc8d socklen_t is always int on Windows
Define XML_SOCKLEN_T as `int` unconditionally in wsockcompat.h. Fixes
compiler warnings and removes some duplicated code.
2017-10-09 13:57:42 +02:00
Nick Wellnhofer
f435365b59 Send xmllint usage error to stderr
Fixes bug 781459.
2017-07-04 18:51:28 +02:00
Nick Wellnhofer
030b1f7a27 Revert "Add an XML_PARSE_NOXXE flag to block all entities loading even local"
This reverts commit 2304078555896cf1638c628f50326aeef6f0e0d0.

The new flag doesn't work and the change even broke the XML_PARSE_NONET
option.
2017-06-06 15:53:42 +02:00
Doran Moppert
2304078555 Add an XML_PARSE_NOXXE flag to block all entities loading even local
For https://bugzilla.gnome.org/show_bug.cgi?id=772726

* include/libxml/parser.h: Add a new parser flag XML_PARSE_NOXXE
* elfgcchack.h, xmlIO.h, xmlIO.c: associated loading routine
* include/libxml/xmlerror.h: new error raised
* xmllint.c: adds --noxxe flag to activate the option
2017-04-07 16:55:05 +02:00
David Kilzer
4472c3a5a5 Fix some format string warnings with possible format string vulnerability
For https://bugzilla.gnome.org/show_bug.cgi?id=761029

Decorate every method in libxml2 with the appropriate
LIBXML_ATTR_FORMAT(fmt,args) macro and add some cleanups
following the reports.
2016-05-23 15:01:07 +08:00
Hugh Davenport
b8e0fa3489 Fix null pointer deref in docs with no root element
From https://bugzilla.gnome.org/show_bug.cgi?id=758514
2016-05-04 10:55:49 +08:00
Patrick Monnerat
11e805d397 xmllint: flush stdout before interactive shell input. 2016-05-01 18:31:57 +08:00
David Kilzer
783931fc59 Bug 721158: Missing ICU string when doing --version on xmllint <https://bugzilla.gnome.org/show_bug.cgi?id=721158>
* xmllint.c:
(showVersion): Add "ICU" to xmllint version string if libxml2 is
built with ICU enabled.
2016-04-08 10:16:54 +08:00
Fabien Degomme
b40c19405e Fix a small error in xmllint --format description
Obviously it operates on the output not the input
2015-10-23 19:35:02 +08:00
Sérgio Batista
d9ea913225 xmllint was not parsing the --c14n11 flag
Cut and paste error, using the wrong variable
2014-06-09 22:10:15 +08:00
Patrick Monnerat
1c43f43ce3 Portability patch for fopen on OS/400 2013-12-12 15:12:53 +08:00
Jan Pokorný
9a85d40cef Fix incorrect spelling entites->entities
Partially, a follow-up of 81d7a8245cf9a31a49499a5a195c2b89e6f91180.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2013-11-30 20:03:52 +08:00
Arnold Hendriks
826bc32020 Fix HTML push parser to accept HTML_PARSE_NODEFDTD
For https://bugzilla.gnome.org/show_bug.cgi?id=719515

fixes htmlParseTryOrFinish to interpret HTML_PARSE_NODEFDTD,
and updates xmllint to actually pass --nodefdtd to the push
version of the HTML parser
2013-11-29 14:12:12 +08:00
Tim Galeckas
2205ff4b0d xmllint --pretty crashed without following numeric argument
https://bugzilla.gnome.org/show_bug.cgi?id=674789

We need to check for NULL argument before calling atoi()
2013-08-29 16:44:33 +08:00
Daniel Veillard
b98c6a0ac6 Fix handling of mmap errors
https://bugzilla.gnome.org/show_bug.cgi?id=702320

as raised by Gaurav <ya1gaurav@gmail.com>
2013-07-12 12:08:40 +08:00
Daniel Veillard
e71dce18a1 Catch malloc error and exit accordingly
As pointed privately by Bill Parker <wp02855@gmail.com>
2013-07-11 15:41:22 +08:00
Daniel Veillard
a75a009d12 xmllint --memory should fail on empty files
Exposed by https://bugzilla.gnome.org/show_bug.cgi?id=699896
when doing analysis but a priori unrelated.
2013-05-08 13:45:48 +08:00
Daniel Veillard
113384f126 Add documentation for xmllint --xpath
https://bugzilla.gnome.org/show_bug.cgi?id=694822

this wasn't documented in the man page, and there was a typo in
xmllint help output.
2013-03-27 11:43:41 +08:00
Daniel Veillard
e4d16d7909 xmllint should not load DTD by default when using the reader 2012-12-21 10:58:14 +08:00
Daniel Veillard
1abd221be5 Add a --pushsmall option to xmllint
To test the push parser with small chunks or 10 bytes
2012-10-25 15:37:50 +08:00
Daniel Veillard
f933c89813 Keep non-significant blanks node in HTML parser
For https://bugzilla.gnome.org/show_bug.cgi?id=681822

Regardless if the option HTML_PARSE_NOBLANKS is set or not, blank nodes
are removed from a HTML document, for example:

<html>
  <head>
    <title>This is a test.</title>
  </head>
  <body>
    <p>This is a test.</p>
  </body>
</html>

is read as:

<html><head><title>This is a test.</title></head><body>
    <p>This is a test.</p>
  </body></html>

This changes the default behaviour but the old behaviour is available
as expected when using the parser flag HTML_PARSE_NOBLANKS

Based on original patch from Igor Ignatyuk <igor_ignatiouk@hotmail.com>

* HTMLparser.c: change various places in the parser where ignorable_space
  SAX callback was called without checking for the parser flag preference
* xmllint.c: make sure we use the new flag even for HTML parsing
* result/HTML/*: this modifies the output of a number of tests
2012-09-07 19:32:12 +08:00
Daniel Veillard
97fa5b3c8f Fix file and line report for XSD SAX and reader streaming validation
Things now work correctly at the xmllint level:
thinkpad:~/XML -> xmllint --sax --noout --schema test_schema.xsd
test_xml.xml
test_xml.xml:72721: Schemas validity error : Element 'level1': Missing
child element(s). Expected is ( level2 ).
test_xml.xml fails to validate
thinkpad:~/XML -> xmllint --stream --schema test_schema.xsd test_xml.xml
test_xml.xml:72721: Schemas validity error : Element 'level1': Missing
child element(s). Expected is ( level2 ).
test_xml.xml fails to validate
thinkpad:~/XML ->

* error.c: fix a corner case of not reporting lines when we should
* include/libxml/xmlschemas.h doc/symbols.xml: had to add new entry
  points to set the filename on a validation context and a locator
  callback used to fetch the line and file from the context
* xmlschemas.c: add the new entry points xmlSchemaValidateSetFilename()
  and xmlSchemaValidateSetLocator(), plus make sure the error reporting
  routine gets the information if available. Add a locator for SAX.
* xmlreader.c: add and plug a locator for readers.
2012-08-14 11:01:07 +08:00
Daniel Veillard
968a03a2e5 Add support for big line numbers in error reporting
Fix the lack of line number as reported by Johan Corveleyn <jcorvel@gmail.com>

* parser.c include/libxml/parser.h: add an XML_PARSE_BIG_LINES parser
  option not switch on by default, it's an opt-in
* SAX2.c: if XML_PARSE_BIG_LINES is set store the long line numbers
  in the psvi field of text nodes
* tree.c: expand xmlGetLineNo to extract those informations, also
  make sure we can't fail on recursive behaviour
* error.c: in __xmlRaiseError, if a node is provided, call
  xmlGetLineNo() if we can't get a valid line number.
* xmllint.c: switch on XML_PARSE_BIG_LINES in xmllint
2012-08-13 12:41:33 +08:00
Daniel Richard G
5706b6d876 Various "make distcheck" and portability fixups
Makefile.am:

* Don't use @VAR@, use $(VAR). Autoconf's AC_SUBST provides us the Make
   variable, it allows overriding the value at the command line, and
   (notably) it avoids a Make parse error in the libxml2_la_LDFLAGS
   assignment when @MODULE_PLATFORM_LIBS@ is empty

* Changed how the THREADS_W32 mechanism switches the build between
   testThreads.c and testThreadsWin32.c as appropriate; using AM_CONDITIONAL
   allows this to work cleanly and plays well with dependencies

* testapi.c should be specified as BUILT_SOURCES

* Create symlinks to the test/ and result/ subdirs so that the runtests
   target is usable in out-of-source-tree builds

* Don't do MAKEFLAGS+=--silent as this is not portable to non-GNU Makes

* Fixed incorrect find(1) syntax in the "cleanup" rule, and doing "rm -f"
   instead of just "rm" is good form

* (DIST)CLEANFILES needed a bit more coverage to allow "make distcheck" to
   pass

configure.in:

* Need AC_PROG_LN_S to create test/ and result/ symlinks in Makefile.am

* AC_LIBTOOL_WIN32_DLL and AM_PROG_LIBTOOL are obsolete; these have been
   superceded by LT_INIT

* Don't rebuild docs by default, as this requires GNU Make (as
   implemented)

* Check for uint32_t as some platforms don't provide it

* Check for some more functions, and undefine HAVE_MMAP if we don't also
   HAVE_MUNMAP (one system I tested on actually needed this)

* Changed THREADS_W32 from a filename insert into an Automake conditional

* The "Copyright" file will not be in the current directory if builddir !=
   srcdir

doc/Makefile.am:

* EXTRA_DIST cannot use wildcards when they refer to generated files; this
   breaks dependencies. What I did was define EXTRA_DIST_wc, which uses GNU
   Make $(wildcard) directives to build up a list of files, and EXTRA_DIST,
   as a literal expansion of EXTRA_DIST_wc. I also added a new rule,
   "check-extra-dist", to simplify checking that the two variables are
   equivalent. (Note that this works only when builddir == srcdir)

   (I can implement this differently if desired; this is just one way of
   doing it)

* Don't define an "all" target; this steps on Automake's toes

* Fixed up the "libxml2-api.xml ..." rule by using $(wildcard) for
   dependencies (as Make doesn't process the wildcards otherwise) and
   qualifying appropriate files with $(srcdir)

   (Note that $(srcdir) is not needed in the dependencies, thanks to VPATH,
   which we can count on as this is GNU-Make-only code anyway)

doc/devhelp/Makefile.am:

* Qualified appropriate files with $(srcdir)

* Added an "uninstall-local" rule so that "make distcheck" passes

doc/examples/Makefile.am:

* Rather than use a wildcard that doesn't work, use a substitution that
   most Make programs can handle

doc/examples/index.py:

* Do the same here

include/libxml/nanoftp.h:

* Some platforms (e.g. MSVC 6) already #define INVALID_SOCKET:

     user@host:/cygdrive/c/Program Files/Microsoft Visual Studio/VC98/\
     Include$ grep -R INVALID_SOCKET .
     ./WINSOCK.H:#define INVALID_SOCKET  (SOCKET)(~0)
     ./WINSOCK2.H:#define INVALID_SOCKET  (SOCKET)(~0)

include/libxml/xmlversion.h.in:

* Support ancient GCCs (I was actually able to build the library with 2.5
   but for this bit)

python/Makefile.am:

* Expanded CLEANFILES to allow "make distcheck" to pass

python/tests/Makefile.am:

* Define CLEANFILES instead of a "clean" rule, and added tmp.xml to allow
   "make distcheck" to pass

testRelax.c:

* Use HAVE_MMAP instead of the less explicit HAVE_SYS_MMAN_H (as some
   systems have the header but not the function)

testSchemas.c:

* Use HAVE_MMAP instead of the less explicit HAVE_SYS_MMAN_H

testapi.c:

* Don't use putenv() if it's not available

threads.c:

* This fixes the following build error on Solaris 8:

     libtool: compile:  cc -DHAVE_CONFIG_H -I. -I./include -I./include \
     -D_REENTRANT -D__EXTENSIONS__ -D_REENTRANT -Dsparc -Xa -mt -v \
     -xarch=v9 -xcrossfile -xO5 -c threads.c  -KPIC -DPIC -o threads.o
     "threads.c", line 442: controlling expressions must have scalar type
     "threads.c", line 512: controlling expressions must have scalar type
     cc: acomp failed for threads.c
     *** Error code 1

trio.c:

* Define isascii() if the system doesn't provide it

trio.h:

* The trio library's HAVE_CONFIG_H header is not the same as LibXML2's
   HAVE_CONFIG_H header; this change is needed to avoid a double-inclusion

win32/configure.js:

* Added support for the LZMA compression option

win32/Makefile.{bcb,mingw,msvc}:

* Added appropriate bits to support WITH_LZMA=1

* Install the header files under $(INCPREFIX)\libxml2\libxml instead of
   $(INCPREFIX)\libxml, to mirror the install location on Unix+Autotools

xml2-config.in:

* @MODULE_PLATFORM_LIBS@ (usually "-ldl") needs to be in there in order for
   `xml2-config --libs` to provide a complete set of dependencies

xmllint.c:

* Use HAVE_MMAP instead of the less-explicit HAVE_SYS_MMAN_H
2012-08-06 11:32:54 +08:00
Daniel Veillard
2e1eaca637 Fix xmllint --xpath node initialization
By default it's more sensible to initialize it to the document itself
than the root element
2012-05-25 16:44:20 +08:00
Brandon Slack
0c7109c81f Fix a compilation problem with --minimum
For https://bugzilla.gnome.org/show_bug.cgi?id=636750
Moved a #endif /* LIBXML_OUTPUT_ENABLED */ a few lines down
to avoid reference an undefined variable
2012-05-11 10:50:59 +08:00
Patrick R. Gansterer
023206fc08 xmllint: Build fix for endTimer if !defined(HAVE_GETTIMEOFDAY)
For https://bugzilla.gnome.org/show_bug.cgi?id=638649
code was broken !
2012-05-10 22:17:51 +08:00
Daniel Veillard
bdc64d6d5f Fix a crash with xmllint --path on empty results
If the returned node set is empty, it is possible for the nodetab
to be null
2012-03-27 14:41:37 +08:00