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

139 Commits

Author SHA1 Message Date
Nick Wellnhofer
79e119954c error: Make xmlLastError const 2024-07-16 17:42:10 +02:00
Nick Wellnhofer
728869809e error: Add helper functions to print errors and abort 2024-07-15 16:33:38 +02:00
Nick Wellnhofer
598ee0d2c6 error: Remove underscores from xmlRaiseError 2024-06-27 14:43:10 +02:00
Nick Wellnhofer
fa50be923b parser: Move implementation of xmlCtxtGetLastError 2024-06-27 14:37:53 +02:00
Nick Wellnhofer
e75e878e02 doc: Update and fix documentation 2024-05-20 14:23:39 +02:00
Nick Wellnhofer
fd8a35114f error: Fix direct invocation of SAX error handlers
Revert part of commit c5a8aef2 to make it safe to call the default SAX
error handlers directly. This has been deprecated for a long time but
even xmllint still uses these handlers.

Should fix #713.
2024-04-09 16:54:02 +02:00
Nick Wellnhofer
ee0c1f87c0 fuzz: New tree API fuzzer 2024-03-15 19:54:27 +01:00
Nick Wellnhofer
67e475b78e http: Improve error message for HTTPS redirects 2024-02-19 11:09:39 +01:00
Nick Wellnhofer
07c05546fa error: Make xmlFormatError public
This is a useful function to get a verbose error report.

Allows to remove duplicated code from runtest.c. Also reactivate check
for schema parser failures.
2024-01-04 15:41:43 +01:00
Nick Wellnhofer
d0eb5a7e54 parser: Remove xmlErrEncodingInt
Convert the last user to xmlFatalErr.
2024-01-04 15:28:57 +01:00
Nick Wellnhofer
2c9cd0b68b fuzz: Abort on internal errors 2024-01-02 19:48:23 +01:00
Nick Wellnhofer
e8fb3d639f parser: Convert some "internal errors" to meaningful codes 2024-01-02 19:48:23 +01:00
Nick Wellnhofer
16b0dbc1b3 parser: Fix XML_ERR_UNSUPPORTED_ENCODING errors
Commit 45157261 added the check in the wrong place.

Also allow unsupported encoding in xmlNewInputInternal.

Fixes #654.
2024-01-02 14:17:27 +01:00
Nick Wellnhofer
331dcd6200 error: Reenable full error reports to default handler
This should make console output include some information about nodes
again. Note that this extra information must be disabled if a custom
generic error handler was set. Many downstream test suites rely on this
behavior.
2023-12-25 23:38:40 +01:00
Nick Wellnhofer
c8f1f4a280 doc: Improve documentation of error handlers 2023-12-21 17:36:17 +01:00
Nick Wellnhofer
8d0aaf4b95 parser: Remove xmlErrEncoding
Use xmlFatalErr or xmlCtxtErrIO.
2023-12-21 15:02:24 +01:00
Nick Wellnhofer
9fbe46ba17 io: Consolidate error messages 2023-12-21 15:02:24 +01:00
Nick Wellnhofer
531d06add6 error: Stop printing some errors by default
Unfortunately, it's long-standing behavior for libxml2 to print all
reported errors to stderr by default. This default behavior is now
partially disabled. If no error handler is set, only parser and
validation errors are passed to a generic error handler or printed to
stderr. Other errors are still available via xmlGetLastError and can be
captured with a structured error handler.
2023-12-21 15:02:24 +01:00
Nick Wellnhofer
0c7a364f57 error: Remove xmlSimpleError 2023-12-21 15:02:24 +01:00
Nick Wellnhofer
c5a8aef2f6 error: Refactor error reporting
Introduce xmlStrVASPrintf, trying to handle buggy snprintf
implementations.

Introduce xmlSetError to set errors atomically.

Introduce xmlUpdateError to set an error, fixing up node, file and line.

Introduce helper function xmlRaiseMemoryError.

Make legacy error handlers call xmlReportError, avoiding checks in
xmlVRaiseError.

Remove fragile support for getting file and line info from XInclude
nodes.
2023-12-21 02:46:27 +01:00
Nick Wellnhofer
abd74186f9 html: Report malloc failures
Fix many places where malloc failures aren't reported.

Stop checking for ctxt->instate.
2023-12-11 22:13:06 +01:00
Nick Wellnhofer
f3455ecd52 error: Report malloc failures
Don't ignore malloc failures in xmlRaiseError and xmlCopyError.

Don't print filename if context has no input.

Introduce xmlVRaiseError taking a va_list.
2023-12-11 22:13:05 +01:00
Nick Wellnhofer
61034116d0 error: Make more xmlError structs constant
Prepare for future changes, see 45470611.
2023-10-24 15:02:36 +02:00
Nick Wellnhofer
45470611b0 error: Make xmlGetLastError return a const error
This is a slight break of the API, but users really shouldn't modify the
global error struct. The goal is to make xmlLastError use static buffers
for its strings eventually. This should warn people if they're abusing
the struct.
2023-09-22 13:29:07 +02:00
Nick Wellnhofer
eb985d6f8e globals: Move error globals back to xmlerror.c 2023-09-20 22:06:49 +02:00
Nick Wellnhofer
d9a8dab3a3 error: Don't move past current position
Make sure that we never move past the current position in
xmlParserPrintFileContextInternal.

Found with libFuzzer and -fsanitize=implicit-conversion.
2023-01-24 11:12:31 +01:00
Nick Wellnhofer
59b3366178 error: Limit number of parser errors
Reporting errors is expensive and some abusive test cases can generate
an error for each invalid input byte. This causes the parser to spend
most of the time with error handling. Limit the number of errors and
warnings to 100.
2022-12-27 14:41:19 +01:00
Nick Wellnhofer
dd3569eaa5 Remove XMLDECL macro from .c files 2022-12-08 02:43:17 +01:00
Nick Wellnhofer
76c6da4209 error: Make sure that error messages are valid UTF-8
This has caused issues with the Python bindings for a long time.

Should fix #64.
2022-12-04 23:34:19 +01:00
Nick Wellnhofer
a9669679f5 error: Don't use initGenericErrorDefaultFunc
The code in xmlInitParser did only set the error handler if it was NULL
which should never happen.
2022-09-09 13:52:48 +02:00
Nick Wellnhofer
0f568c0b73 Consolidate private header files
Private functions were previously declared

- in header files in the root directory
- in public headers guarded with IN_LIBXML
- in libxml.h
- redundantly in source files that used them.

Consolidate all private header files in include/private.
2022-08-26 02:11:56 +02:00
Nick Wellnhofer
346c3a930c Remove elfgcchack.h
The same optimization can be enabled with -fno-semantic-interposition
since GCC 5. clang has always used this option by default.
2022-02-20 21:49:04 +01:00
Nick Wellnhofer
2c74712977 Fix error reporting with xi:fallback
When reporting errors, don't use href of xi:include if xi:fallback
was used. I think this can only be reproduced with
"xmllint --postvalid", see the original bug report:

https://bugzilla.gnome.org/show_bug.cgi?id=152623
2020-08-17 01:17:39 +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
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
8bbe4508ef Spelling and grammar fixes
Fixes bug 743172, bug 743489, bug 769632, bug 782400 and a few other
misspellings.
2017-06-17 16:34:23 +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
Pavel Raiskup
c4184ba217 error.c: *input->cur == 0 does not mean no error
Complements: ce0b0d0d81
2016-04-08 10:32:29 +08:00
Daniel Veillard
ce0b0d0d81 Do not print error context when there is none
Which now happens more frequently du to xmlHaltParser use
2015-11-20 15:01:22 +08:00
Daniel Veillard
f8e3db0445 Big space and tab cleanup
Remove all space before tabs and space and tabs at end of lines.
2012-09-11 13:26:36 +08:00
Pietro Cerutti
890faa546b Fix problem with specific and generic error handlers
It seems that setting up both xmlTextReaderSetStructuredErrorHandler and
xmlSetStructuredErrorFunc confuses the code around error.c:592 and following
This patch works with any combinations of using xmlSetStructuredErrorFunc,
xmlTextReaderSetStructuredErrorHandler, both, or none.
2012-08-27 13:24:08 +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 Veillard
5756038650 Cleanup URI module memory allocation code
* uri.c: cleanup the code doing the allocations, set up a structured
  error handler to report memory errors, and set up an abitrary
  limit on URI saving size
* error.c include/libxml/xmlerror.h: add a new FROM_URI indication
  for structured error reporting, also adding strings for schematron
  and buffer which were missing
2012-07-24 11:44:23 +08:00
c2a0fdc4e6 __xmlRaiseError: fix use of the structured callback channel
If the structured callback channel is initialized, do not perform
unneeded initialization of the old callback channel to avoid
clobbering of the structured callback channel's data.
2011-02-23 22:44:05 +08:00
241d4a1069 __xmlRaiseError: fix the structured callback channel's data initialization
if we initialize the structured channel from the sax handler we should also
pass the userData
2011-02-23 22:30:59 +08:00
1b9128bae7 __xmlRaiseError: remove redundant schannel initialization
In case the domain is XML_FROM_VALID, ctxt and schannel are already initialized
earlier with the same data
2011-02-23 22:23:25 +08:00
111d705c28 __xmlRaiseError: do cheap code check early
if error code is XML_ERR_OK return immediately
2011-02-23 22:14:19 +08:00
Daniel Veillard
26b0687435 xmlCtxtResetLastError should reset ctxt->errNo
just fix it !
2010-03-15 15:59:07 +01:00