1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-02-11 01:58:56 +03:00

282 Commits

Author SHA1 Message Date
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
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
Nick Wellnhofer
a09c89545d Fix memory leak with invalid XSD
xmlSchemaClearElemInfo can add new items to the "matcher" cache, so the
cache must be cleared after calling this function, not before. This
only seems to affect invalid XSDs.

Fixes #390.
2022-08-15 12:19:25 +02:00
Nick Wellnhofer
3e7b4f37aa Avoid calling xmlSetTreeDoc
Create text nodes with xmlNewDocText or set the document directly to
avoid xmlSetTreeDoc being called when the node is inserted.
2022-06-20 01:49:39 +02:00
Damjan Jovanovic
2fe372a0aa Properly fold whitespace around the QName value when validating an XSD schema.
(May also need fixing in other places.)

Issue: 239
2022-03-02 14:22:36 +00: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
1c7d91abe4 Fix handling of XSD with empty namespace
An empty namespace means no default namespace.

Fixes #303.
2022-02-03 23:31:19 +01:00
huangduirong
e4c91f7473 Fix Null-deref-in-xmlSchemaGetComponentTargetNs 2022-01-16 16:24:47 +01:00
Nick Wellnhofer
c35628a24c Revert "Make schema validation fail with multiple top-level elements"
This reverts commit 4f2aee18f6e2d40e58eb224f4f7935dc2400fe25.

Fixes #305.
2022-01-15 18:18:22 +01:00
Nick Wellnhofer
8ca3a59b2e Fix integer overflow in xmlSchemaGetParticleTotalRangeMin
The function is only used once and its return value is only checked for
zero. Disable the function like its Max counterpart and add an
implementation for the special case.

Found by OSS-Fuzz.
2020-12-15 20:14:28 +01:00
Michael Matz
faea2fa9b8 Avoid quadratic checking of identity-constraints
key/unique/keyref schema attributes currently use qudratic loops
to check their various constraints (that keys are unique and that
keyrefs refer to existing keys).  That becomes extremely slow if
there are many elements with keys.  This happens in the wild with
e.g. the OVAL XML descriptions of security patches.  You need the
openscap schemata, and then an example xml file:

% zypper in openscap-utils
% wget ftp://ftp.suse.com/pub/projects/security/oval/opensuse.leap.15.1.xml
% time xmllint --schema /usr/share/openscap/schemas/oval/5.5/oval-definitions-schema.xsd opensuse.leap.15.1.xml > /dev/null
opensuse.leap.15.1.xml validates

real    16m59,857s
user    16m55,787s
sys     0m1,060s

This patch makes libxml use a hash table to avoid the quadratic
behaviour.  The existing hash table only accepts strings as keys, so
we're mostly reusing the canonical representation of key values to derive
such strings (with the caveat given in a comment).  The alternative
would be to rework the hash table code to accept either numbers or free
functions as hash workers, but the code is fast enough as is.

With the patch we have this then:

% time LD_LIBRARY_PATH=./libxml2/.libs/ ./libxml2/.libs/xmllint --schema /usr/share/openscap/schemas/oval/5.5/oval-definitions-schema.xsd opensuse.leap.15.1.xml > /dev/null
opensuse.leap.15.1.xml validates

real    0m3,531s
user    0m3,427s
sys     0m0,103s

So, a ~300x speedup.  This patch survives 'make check' and 'make tests'.
2020-11-30 11:22:54 +01:00
Nick Wellnhofer
070d635e77 Fix integer overflow when parsing {min,max}Occurs
Clamp value to INT_MAX.

Found with libFuzzer and UBSan.
2020-06-23 16:20:28 +02:00
Nick Wellnhofer
4f2aee18f6 Make schema validation fail with multiple top-level elements
Closes #126.
2020-05-04 14:03:52 +02:00
Nick Wellnhofer
20c60886e4 Fix typos
Resolves #133.
2020-03-08 17:41:53 +01:00
Zhipeng Xie
7ffcd44d7e Fix memory leak in xmlSchemaValidateStream
When ctxt->schema is NULL, xmlSchemaSAXPlug->xmlSchemaPreRun
alloc a new schema for ctxt->schema and set vctxt->xsiAssemble
to 1. Then xmlSchemaVStart->xmlSchemaPreRun initialize
vctxt->xsiAssemble to 0 again which cause the alloced schema
can not be freed anymore.

Found with libFuzzer.

Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
2020-02-11 11:38:56 +01:00
Nick Wellnhofer
9bd7abfba4 Remove useless comparisons
Found by lgtm.com
2020-01-02 14:14:48 +01:00
Jared Yanovich
2a350ee9b4 Large batch of typo fixes
Closes #109.
2019-09-30 18:04:38 +02:00
zhouzhongyuan
4e326a3aa9 Fix potential null deref in xmlSchemaIDCFillNodeTables
Merge request !45
2019-09-13 15:57:25 +02:00
bettermanzzy
01d8cf07d9 Misleading error message with xs:{min|max}Inclusive
Closes #53.
2019-08-25 14:12:34 +02:00
Greg Hildstrom
b697d7bb59 Fix xmlSchemaValidCtxtPtr reuse memory leak
When reusing an xmlSchemaValidCtxtPtr to validate multiple xml documents
against the same schema, there is a memory leak in xmlschemas.c in
xmlSchemaClearValidCtxt(). The vctxt->idcKeys and associated counters
are not cleaned up in xmlSchemaClearValidCtxt() as they are in
xmlSchemaFreeValidCtxt(). As a result, vctxt->idcKeys grows with each
xmlValidateDoc() call that uses the same context and that memory is
never freed. Similarly, vctxt->nbIdcKeys and vctxt->sizeIdcKeys
increment and are never reset.

Closes: #23
2018-09-04 16:48:15 +02:00
Nick Wellnhofer
359e750482 Fix -Wmisleading-indentation warnings 2017-11-27 13:42:30 +01:00
Nick Wellnhofer
e5f33e56ba Fix misc callback signatures
Fix parameter and return types for xmlC14NIsVisibleCallback and
xmlRegExecCallbacks.
2017-11-09 17:29:22 +01:00
Nick Wellnhofer
e03f0a199a Fix hash callback signatures
Make sure that all parameters and return values of hash callback
functions exactly match the callback function type. This is required
to pass clang's Control Flow Integrity checks and to allow compilation
to asm.js with Emscripten.

Fixes bug 784861.
2017-11-09 16:42:47 +01:00
J. Peter Mugaas
d2c329a9a4 Fix -Wimplicit-fallthrough warnings
Add "falls through" comments to quench implicit-fallthrough warnings
which are enabled by -Wextra under GCC 7.
2017-10-21 13:49:31 +02:00
Stéphane Michaut
454e397eb7 Porting libxml2 on zOS encoding of code
First set of patches for zOS
- entities.c parser.c tree.c xmlschemas.c xmlschemastypes.c xpath.c xpointer.c:
  ask conversion of code to ISO Latin 1 to avoid having the compiler assume
  EBCDIC codepoint for characters.
- xmlmodule.c: make sure we have support for modules
- xmlIO.c: zOS path names are special avoid dsome of the expectstions from
  Unix/Windows
2017-08-28 14:30:43 +02:00
Daniel Veillard
27f310d453 Fix signature of xmlSchemaAugmentImportedIDC
this is used in a callback which will pass a name, the name is ignored
but it's best to have the signature of the function match, pointed out
by Claude Petit
* xmlschemas.c: fix xmlSchemaAugmentImportedIDC() signature no functional
  change
2017-07-27 14:06:44 +08: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
Nick Wellnhofer
1a595cd173 Fix cast-align warnings
- Suppress warnings in xmlmemory.c by casting to 'void *'.
- Remove unneeded cast in xmlschemas.c that caused a macro precedence
  error.
- Add dummy fields to short structs in xmlschemas.c. This increases the
  size of the structs, but I can't see a better solution without using
  C11's _Alignof operator.

There are still a couple of cast-align warnings in encoding.c. These
are legitimate portability issues that can't be fixed without reworking
the conversion functions.
2017-06-17 14:17:27 +02:00
Alex Henrie
3169602058 Fix attribute decoding during XML schema validation
For https://bugzilla.gnome.org/show_bug.cgi?id=766834

vctxt->parserCtxt is always NULL in xmlSchemaSAXHandleStartElementNs,
so this function can't call xmlStringLenDecodeEntities to decode the
entities.
2016-08-29 11:21:08 +02:00
Chun-wei Fan
d77e5fc4bc relaxng.c, xmlschemas.c: Fix build on pre-C99 compilers
Make sure that the variables are declared at the top of the block.

https://bugzilla.gnome.org/show_bug.cgi?id=767063
2016-06-23 19:02:26 +08:00
David Kilzer
502f6a6d08 More format string warnings with possible format string vulnerability
For https://bugzilla.gnome.org/show_bug.cgi?id=761029

adds a new xmlEscapeFormatString() function to escape composed format
strings
2016-05-23 15:01:08 +08: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
Alex Henrie
f6599c5164 Fix XSD validation of URIs with ampersands
For https://bugzilla.gnome.org/show_bug.cgi?id=709171

This makes xmlSchemaSAXHandleStartElementNs pass attributes through
xmlStringDecodeEntities, similar to how xmlSchemaVDocWalk passes them
through xmlNodeListGetString.
2016-05-03 13:25:45 +08:00
Jan Pokorný
bb654feb9a Fix typos: dictio{ nn -> n }ar{y,ies}
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2016-04-15 22:22:48 +08:00
Alex Henrie
73c50805d9 Correct spelling of "calling" 2015-10-26 18:33:14 +08:00
Scott Graham
58b84e1f82 Fix a self assignment issue raised by clang
For https://bugzilla.gnome.org/show_bug.cgi?id=751679

Also added a few newline cleanups
2015-06-30 10:47:16 +08:00
Juergen Keil
d201e71ed0 no error column in structured error handler for xml schema validation errors
For https://bugzilla.gnome.org/show_bug.cgi?id=734363

When using xml schema validation, structured error callbacks do not get
passed a valid column number in xmlError field "int2".

$ ./xmlsaxparse colbug5.xml colbug5.xsd
colbug5.xml:3:0: Element '{urn:colbug5}bx': This element is not
expected.
Expected is ( {urn:colbug5}b ).

The schema error is reported for line 3, column 0 (= N/A).

I'd like to have the column number of the error passed in the xmlError
structure.  With this test case: line 3, column 9.
2014-08-07 11:42:07 +08:00
Jan Pokorný
761c9e9901 Get rid of 'REPLACEMENT CHARACTER' Unicode chars in xmlschemas.c
Middle dot pairs (as in [1]) turned to grave accents/backticks,
section signs to dollars (for compatibility with ASCII).

[1] http://www.w3.org/TR/xmlschema-1/

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2013-11-30 20:03:52 +08:00
Jan Pokorný
7a7cad6ed4 Fix typos in xmlschemas{,types}.c
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2013-11-30 20:03:52 +08:00
Gaurav
f3d79416d7 Type mismatch in xmlschemas.c
For https://bugzilla.gnome.org/show_bug.cgi?id=715152
2013-11-28 22:53:54 +08:00
Csaba László
1f6c42cffd Fix an old bug in xmlSchemaValidateOneElement
Recently I have run into the very same problem Tiberius Duluman did back in
Wed, 13 May 2009 15:56:55 +0300 ([xml] Bug in xmlSchemaValidateOneElement
function). Now I can proof now that his problem is a valid problem. I checked
the latest available version of xmlschemas.c (2.9.0.) and the problem is still
there!
I think I have found a solution to the problem which I'd like proof with you:
My quick solution to the problem is to replace line 27849 in
xmlschemas.c
(v2.9.0.) in function xmlSchemaVDocWalk
    valRoot = xmlDocGetRootElement(vctxt->doc);
with this one:
    valRoot = vctxt->validationRoot ? vctxt->validationRoot : xmlDocGetRootElement(vctxt->doc);
Currently I'm using version 2.7.8. in Windows and this change seems to solve
the problem.
2013-03-18 15:30:00 +08:00
Daniel Veillard
c100e69c4b fix schema validation in combination with xsi:nil
Based on Thomas Gamper <icicle@cg.tuwien.ac.at> findings and
initial patch

There is no point doing a regexp validation of further
content if there actually is no further content because the
element is nilled.
2013-02-28 19:02:32 +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
Daniel Veillard
c70d185a2a Fix an XSD error when generating internal automata
When generating a sequence add an extra epsilon transition
to avoid further constructs from entering via the last state
Bug reported by Johan Corveleyn <jcorvel@gmail.com>
2012-08-23 23:28:04 +08:00
Daniel Veillard
ef4526ad42 Fix a variable name in comment 2012-08-15 09:15:30 +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
Remi Gacogne
4609e6c980 XSD: optional element in complex type extension
For https://bugzilla.gnome.org/show_bug.cgi?id=609796
Libxml2 fails to validate an instance document against a schema if an element
whose type is a complex extension of some base type with an optional child
element and that child element is not specified in the instance document.  For
example, suppose I have some complex type BaseType that is defined to have one
child element in a sequence group that has minOccurs set to 0
2012-05-11 15:31:05 +08:00
Ryan Sleevi
5cf1deb080 Fix a logic error in Schemas Component Constraints 2012-02-29 10:56:32 +08:00
Toyoda Eizi
8bb12988c4 Fix XSD validation bug #630130
This bug in xmlschemas made validation with the GML Schemas fail
Test cases to be commited separately
2011-08-04 16:40:48 +08:00
Jim Panetta
c84e863c9c 627987 Fix XSD IDC errors in imported schemas
Fix XSD IDC references when xsi:schemalocation is used for
referencing the validation schemas
2010-11-03 21:05:18 +01:00