1
0
mirror of https://gitlab.gnome.org/GNOME/libxslt synced 2025-08-07 10:42:55 +03:00

61 Commits

Author SHA1 Message Date
Nick Wellnhofer
73b955aea0 Explain why we have to mess with 'boolval' of value trees 2023-12-20 19:04:51 +01:00
Nick Wellnhofer
c5c66dfbf5 exslt: Fix EXSLT functions without parameters
Fix regression from commit 7364666b on platforms where malloc(0) returns
NULL.

Should fix #100.
2023-12-06 19:06:56 +01:00
Nick Wellnhofer
282bb94471 malloc-fail: Fix memory leak in exsltFuncRegisterImportFunc
Found with libFuzzer, see #84.
2023-02-26 16:55:37 +01:00
Nick Wellnhofer
293067bc3e malloc-fail: Fix null deref in exsltFuncShutdown
Found with libFuzzer, see #84.
2023-02-26 16:55:37 +01:00
Nick Wellnhofer
7364666ba3 malloc-fail: Fix null deref in exsltFuncFunctionFunction
Found with libFuzzer, see #84.
2023-02-26 16:55:37 +01:00
Nick Wellnhofer
ccec6fa31d Store RVT ownership in 'compression' member
'compression' is another unused member in struct _xmlDoc which is even
better suited to store ownership status. More importantly, this frees up
the 'psvi' member.

This changes the public API but this feature is only required to
implement EXSLT functions.
2022-08-31 18:03:50 +02:00
Nick Wellnhofer
adaa45aa25 Fix EXSLT functions tests when libxml2 is built --without-debug 2022-08-31 17:50:08 +02:00
David Kilzer
53174e798d Fix redundant includes already in libexslt.h
Remove includes of "config.h", <libxslt/xsltconfig.h> and
<libxml/xmlversion.h> in libexslt C sources since they are
already included with "libexslt/libexslt.h".
2020-02-11 11:01:09 +01:00
Nick Wellnhofer
29414ac962 Always reuse XPath context
Fix remaining calls to xmlXPathCompile without an existing XPath
context.
2019-05-13 11:13:21 +02:00
Nick Wellnhofer
45d1d8597e Backup context node in exsltFuncFunctionFunction
exsltFuncFunctionFunction handles XPath extension functions and is called
from the XPath engine. Since evaluation of function templates can change
the XPath context node, it must be backed up to avoid corruption.

Without proper backup, evaluating certain content in function templates
could also result in use-after-free errors.

It seems that libxml2 commit 029d0e96 helped to expose the error.

Fixes #11.
2019-02-12 12:31:20 +01:00
Nick Wellnhofer
00b327b6ca Fix memory leak in EXSLT functions error path 2019-02-12 12:31:20 +01:00
Nick Wellnhofer
5e16672db1 Move function result RVTs to context variable
If a variable with a "select" expression calls an EXSLT func:function,
the context variable must be restored before evaluating the function
result. This makes sure that the RVTs in the result will be moved to
the context variable's fragment list when they're released in
xsltReleaseLocalRVTs or xsltReleaseLocalRVTs.

Thanks to Nikolai Weibull for the report.
2018-09-26 23:20:48 +02:00
Nick Wellnhofer
7d81bd62d5 Fix EXSLT functions returning RVTs from outer scopes
The RVTs referenced from function results must not be blindly registered
as local, as they might be part of variables from an outer scope. Remove
LOCAL/VARIABLE distinction for RVTs. Don't register as local RVT
unconditionally when reflagging as LOCAL. Instead, register function
result RVTs from inner variables as local RVTs when they're released in
xsltFreeStackElem. Keep local function result RVTs xsltReleaseLocalRVTs
instead of reregistering.

Closes: https://gitlab.gnome.org/GNOME/libxslt/issues/2

Thanks to Daniel Mendler and Martin Gieseking for the reports.
2018-07-24 15:54:30 +02:00
Nick Wellnhofer
8bd32f7753 Fix handling of RVTs returned from nested EXSLT functions
Set the context variable to NULL when evaluating EXSLT functions.
Fixes potential use-after-free errors or memory leaks.

Fixes bug 792580. Thanks to Clemens Gutweiler for the report.

https://bugzilla.gnome.org/show_bug.cgi?id=792580
2018-01-16 19:01:55 +01:00
Nick Wellnhofer
840c8e2b6a Fix transform callback signatures 2017-11-29 17:33:21 +01:00
Nick Wellnhofer
3bea417b5e Fix extension callback signatures 2017-11-29 16:52:13 +01:00
Nick Wellnhofer
6a822a2c1a Fix deallocator signatures 2017-11-29 16:52:13 +01:00
Nick Wellnhofer
eb85472739 Fix hash callback signatures 2017-11-29 16:52:12 +01:00
Nick Wellnhofer
0beb813d64 Use _WIN32 macro instead of WIN32
_WIN32 is defined automatically by the compiler.
2017-10-25 18:22:52 +02:00
Nick Wellnhofer
2fc326e806 Also fix memory hazards in exsltFuncResultElem
Similar to the previous fix to exsltFuncFunctionFunction,
exsltFuncResultElem also has to get the current node from the transform
context instead of the XPath context.

Thanks to Nicolas Gregoire for the report.

Fixes bug 786989.
2017-08-29 23:52:37 +02:00
Nick Wellnhofer
3892a890d9 Fix memory hazards in exsltFuncFunctionFunction
Get the current node from the transform context. The current node in
the XPath context isn't guaranteed to be preserved when evaluating the
function template and could point to an invalid address.

Thanks to Nicolas Gregoire for the report.

Fixes bug 785589.
2017-07-31 15:00:53 +02:00
Nick Wellnhofer
ac29e4bdcd Fix memory leaks in EXSLT error paths
Found with libFuzzer and ASan.
2017-05-27 16:33:24 +02:00
Nick Wellnhofer
8ee72e4935 Detect infinite recursion when evaluating function arguments
This fixes a regression introduced when consolidating recursion checks
in commit 1c8e0e5. When a function is called recursively during
evaluation of its arguments, the recursion check in
xsltApplySequenceConstructor is never reached. Readd recursion check
in exsltFuncFunctionFunction but use the template depth counter.

Fixes bug #777293:

https://bugzilla.gnome.org/show_bug.cgi?id=777293
2017-01-16 15:09:06 +01:00
Nick Wellnhofer
1c8e0e5562 Consolidate recursion checks
Move the check for potentially infinite recursion to
xsltApplySequenceConstructor. In this function, both template and
func:function calls can be handled. This also checks for the following
case of infinite recursion in attribute sets found with afl-fuzz:

<x:attribute-set name="set">
    <x:attribute name="attr">
        <elem x:use-attribute-sets="set"/>
    </x:attribute>
</x:attribute-set>

Rename funcLevel to depth and check against maxTemplateDepth. I hope it
isn't a problem to rename an internal struct item.
2016-06-21 13:31:33 +02:00
Nick Wellnhofer
470b173461 Rewrite memory management of local RVTs
The psvi slot of RVTs documents is used to store ownership information.

XSLT_RVT_LOCAL for RVTs that are destroyed after the current instructions
ends.

XSLT_RVT_VARIABLE for RVTs that are part of a local variable and are
destroyed after the variable goes out of scope.

XSLT_RVT_FUNC_RESULT for RVTs that are part of results returned with
func:result. These RVTs won't be destroyed after exiting a template and
will be reset to XSLT_RVT_LOCAL or XSLT_RVT_VARIABLE in the template
that receives the return value.

XSLT_RVT_GLOBAL for RVTs that are part of a global variable.

The function xsltFlagRVTs is used for the following ownership
transitions:

- LOCAL or VARIABLE to FUNC_RESULT when returning a value with
  func:result.
- FUNC_RESULT to LOCAL or VARIABLE when receiving a func:result.
- LOCAL to GLOBAL after evaluating global variables or parameters.

This obsoletes the element localRVTBase in the context struct and the
xsltExtensionInstructionResultRegister function. Aside from the
func:result implementation, the only reason for the old mechanism was
to protect RVTs (which can only be returned from extension functions)
in global variables from being destroyed too early. This is done
automatically now, so there's no need for extension authors to call
this function anymore.

The function xsltExtensionInstructionResultFinalize is unsupported
now. To the best of my knowledge, it isn't used outside of libxslt.

Another benefit is that, in some cases, RVTs are freed earlier now.

Also fixes bug #602531.
2016-06-21 13:16:25 +02:00
Nick Wellnhofer
c68b3f3d64 Fix possible NULL pointer deref in libexslt/functions.c
Based on the patch by mahendra.n. Fixes bug #757663.

https://bugzilla.gnome.org/show_bug.cgi?id=757663
2015-12-13 19:22:48 +01:00
Nick Wellnhofer
fd675976f7 Check return value of exsltFuncNewFunctionData
Fixes bug #735957.

https://bugzilla.gnome.org/show_bug.cgi?id=735957

Thanks to Prabhat Kanth for the report.
2014-09-28 13:21:43 +02:00
Daniel Veillard
0ca0a15ffb Big space and tabs cleanup
Remove spaces followed by tabs, and space and tabs at the end of lines
2012-09-12 14:07:24 +08:00
Nick Wellnhofer
aebfee35d1 Exit after compilation of invalid func:result
Second part of bug #680920.
2012-09-04 14:54:48 +08:00
Nick Wellnhofer
14ee81b06c Fix for EXSLT func:function
For https://bugzilla.gnome.org/show_bug.cgi?id=680920

If the first child of a func:function template is xslt:text, it will be
removed by xsltParseTemplateContent. So xsltParseTemplateContent should
be called before setting func->content to the first child.
2012-09-04 14:53:14 +08:00
Daniel Veillard
2465307222 Hardening of code checking node types in EXSLT 2012-08-16 15:51:35 +08:00
Daniel Veillard
3058d809d2 Detect deep recusion on function calls
* libxslt/xsltInternals.h libexslt/functions.c: add a function call
  counting in the transformation context, and test/increment/decrement
  in exsltFuncFunctionFunction enter and exit
2009-09-17 11:56:08 +02:00
William M. Brack
e31e904dc2 *libexslt/functions.c: fixed minor error reported on the mailing
list by Mark Howe, which caused a segfault if func:result was
 postitioned as top-level element.

svn path=/trunk/; revision=1460
2008-03-15 03:17:05 +00:00
William M. Brack
3af40cccee further enhancement to the original fix for bug #381319 (which was not
* libexslt/functions.c: further enhancement to the original
  fix for bug #381319 (which was not correct).
* tests/exslt/functions: minor enhancement to function.9.xsl;
  function.10.[xsl,xml,out] added to regression tests to check
  recursive calls.
2006-12-11 22:51:47 +00:00
William M. Brack
7906844185 changed handling of function params to fix bug #381319 exposed
* libexslt/functions.c: changed handling of function params
  to fix bug #381319
* libxslt/transform.[ch]: exposed xsltLocalVariablePush and
  xsltLocalVariablePop as global entries so that they could
  be used from within libexslt/functions.c
* tests/exslt/functions/function.9.[xsl,xml,out] added to
  regression tests
2006-12-09 23:18:21 +00:00
William M. Brack
4b155f2bb2 Fixed problem with cleanup of RVT's, should clear bug350085; cleaned up
* libxslt/transform.c: Fixed problem with cleanup of RVT's, should
  clear bug350085; cleaned up most warnings (still a problem in
  xsltShallowCopyNsNode)
* trivial warning cleanup in libxslt/[extensions.c, namespaces.c,
  xslt.c and xsltInternals.h] and libexslt/functions.c
2006-08-09 18:22:39 +00:00
Kasimier T. Buchcik
7662584ea1 Committing again, since I forgot to switch from win to linux linebreaks in
* libxslt/attributes.c libxslt/documents.c
  libxslt/functions.c libxslt/keys.c libxslt/namespaces.c
  libxslt/pattern.c libxslt/preproc.c libxslt/templates.c
  libxslt/templates.h libxslt/transform.c
  libxslt/variables.c libxslt/xslt.c
  libxslt/xsltInternals.h libxslt/xsltutils.c
  libxslt/xsltutils.h libexslt/common.c libexslt/dynamic.c
  libexslt/functions.c libexslt/strings.c:
  Committing again, since I forgot to switch from win to linux
  linebreaks in the files.
2006-07-14 16:18:32 +00:00
Kasimier T. Buchcik
90d2d1c289 Refactored xsltValueOf(). Changed to use xmlXPathCastToString() directly,
* libxslt/attributes.c libxslt/documents.c
  libxslt/functions.c libxslt/keys.c libxslt/namespaces.c
  libxslt/pattern.c libxslt/preproc.c libxslt/templates.c
  libxslt/templates.h libxslt/transform.c libxslt/variables.c
  libxslt/xslt.c libxslt/xsltInternals.h libxslt/xsltutils.c
  libxslt/xsltutils.h libexslt/common.c libexslt/dynamic.c
  libexslt/functions.c libexslt/strings.c:
  Refactored xsltValueOf(). Changed to use xmlXPathCastToString()
  directly, rather than creating an intermediate object with
  xmlXPathConvertString(). This now does not add a text-node to
  the result if the string is empty (this has impact on
  serialization, since an empty text-node is serialized as
  <foo></foo>, and now it will be serialized as <foo/>).
  Refactored other functions in transform.c:
  Mostly code cleanup/restructuring. Minimized number of
  function variables for instruction which eat up function stack
  memory when recursing templates (xsltIf(), xsltChoose(),
  xsltApplyTemplates(),  xsltCallTemplate()).
  Changed XSLT tests to use xmlXPathCompiledEvalToBoolean().
  Implemented redefinition checks at compilation-time and
  eliminating them at transformation time in the refactored code
  paths.
  Introduced the field @currentTemplateRule on xsltTransformContext to
  reflect the "Current Template Rule" as defined by the spec.
  NOTE that ctxt->currentTemplateRule and ctxt->templ is not the
  same; the former is the "Current Template Rule" as defined by the
  XSLT spec, the latter is simply the template struct being
  currently processed by Libxslt.
  Added XML_COMMENT_NODE and XML_CDATA_SECTION_NODE to the macro
  IS_XSLT_REAL_NODE.
  Misc code cleanup/restructuring and everything else I already forgot.
  Refactored lifetime of temporary result tree fragments.
  Substituted all calls to the now deprecated xsltRegisterTmpRVT()
  for the new xsltRegisterLocalRVT().
  Fragments of xsl:variable and xsl:param are freed when the
  variable/pram is freed.
  Fragments created when evaluating a "select" of xsl:varible and
  xsl:param are also bound to the lifetime of the var/param.
  EXSLT's func:function now uses the following functions to let take
  care the transformation's garbage collector of returned tree
  fragments:
    xsltExtensionInstructionResultRegister(),
    xsltExtensionInstructionResultFinalize()
  Fixes:
  #339222 - xsl:param at invalid position inside an xsl:template is
            not catched
  #346015 - Non-declared caller-parameters are accepted
  #160400 - Compiles invalid XSLT; unbound variable accepted
  #308441 - namespaced parameters become unregistered
  #307103 - problem with proximity position in predicates of match
            patterns
  #328218 - problem with exsl:node-set() when converting strings
            to node sets
  #318088 - infinite recursion detection
  #321505 - Multiple contiguous CDATA in output
  #334493 - "--param" option does not have root context
  #114377 - weird func:result/xsl:variable/exsl:node-set interaction
  #150309 - Regression caused by fix for 142768
2006-07-14 16:10:25 +00:00
Kasimier T. Buchcik
eb037ebd81 Next step of refactoring (plus some bug-fixes). For more details see
* libxslt/xsltInternals.h libxslt/attributes.c
  libxslt/documents.c libxslt/extensions.c
  libxslt/extensions.h libxslt/functions.c
  libxslt/imports.c libxslt/keys.c libxslt/preproc.c
  libxslt/transform.c libxslt/variables.c libxslt/xslt.c
  libxslt/xsltutils.c libxslt/xsltutils.h libexslt/functions.c:
  Next step of refactoring (plus some bug-fixes).
  For more details see #340780.
2006-05-05 21:18:25 +00:00
Daniel Veillard
d2afa277f6 fix an problem raised by Ralf Junker in the use of xmlHashScanFull() fixes
* libexslt/functions.c: fix an problem raised by Ralf Junker in the
  use of xmlHashScanFull() fixes bug #321582
Daniel
2005-11-16 11:48:24 +00:00
William M. Brack
e21d0a503b changed some variable names for warning cleanup when -ansi flag is not
* libexslt/crypto.c, libexslt/functions.c, libxslt/keys.c,
  libxslt/numbers.c, libxslt/pattern.c, libxslt/transform.c,
  libxslt/variables.c: changed some variable names for warning
  cleanup when -ansi flag is not present.
* libxslt/namespaces.c: fixed potential NULL pointer reference
  pointed out by Dennis Dams (bug 156187)
2004-10-23 16:42:01 +00:00
William M. Brack
0d28f2ec4e changed date.c to use gmtime_r if available (bug 129983) fixed a namespace
* configure.in, config.h.in, libexslt/date.c: changed date.c to use
  gmtime_r if available (bug 129983)
* libexslt/functions.c: fixed a namespace problem concerning a
  function with a namespace-qualified name (bug 155197)
2004-10-15 05:46:56 +00:00
William M. Brack
0cd2f0c0e9 applied patch for param visibility from Shaun McCance. Changed variable
* libexslt/functions.c: applied patch for param visibility from
  Shaun McCance.  Changed variable scoping in accordance with
  Shaun's suggestions.  This fixed problem reported on the list
  by Bernd Lang
* tests/exslt/functions/function.8.[xml,xsl,out], Makefile.am:
  regression test for above
2003-11-12 10:20:03 +00:00
William M. Brack
a083b0b03e fixed bug #125502 and corrected expected test output fixed broken test
* libxslt/transform.c, tests/general/bug-119.out: fixed
  bug #125502 and corrected expected test output
* tests/general/bug-79.out: fixed broken test (bug #123328)
* libxslt/pattern.c, libexslt/functions.c: minor change to
  eliminate compilation warning
2003-11-02 01:10:43 +00:00
Daniel Veillard
1d9e27ecab applied patch from Mikhail Grushinskiy for compilation with MingW compiler
* xsltproc/Makefile.am libxslt/libxslt.h libxslt/numbersInternals.h
  libexslt/*.c configure.in: applied patch from Mikhail Grushinskiy
  for compilation with MingW compiler on Windows.
Daniel
2003-08-18 22:41:26 +00:00
William M. Brack
f6f82821e2 fixed bug 114812 2003-07-09 13:28:47 +00:00
Daniel Veillard
4f5120741e cleaning up Result Value Tree handling fixed a pair of implementations.
* libxslt/transform.c libxslt/variables.c libxslt/xsltInternals.h:
  cleaning up Result Value Tree handling
* libexslt/functions.c libexslt/strings.c: fixed a pair of
  implementations.
* tests/exslt/strings/Makefile.am tests/exslt/strings/tokenize.2.*:
  added Mark Vakoc test combining for-each and exslt:tokenize
Daniel
2003-04-30 20:47:47 +00:00
Daniel Veillard
79d36ecd29 preparing 1.0.14 updated rebuilt implemented the IN_LIBXSLT and
* configure.in: preparing 1.0.14
* doc/*: updated rebuilt
* libxslt/*.c libexslt/*.c libxslt/libxslt.h libexslt/libexslt.h:
  implemented the IN_LIBXSLT and IN_LIBEXSLT mechanism discussed
  with the Windows maintainers
Daniel
2002-03-18 19:53:55 +00:00
Daniel Veillard
cc0e7a04fd fixed bug #73791 related to extension function declared in included
* libxslt/extensions.c: fixed bug #73791 related to extension
  function declared in included stylesheets
* tests/exslt/functions/function.7.*: added specific test
Daniel
2002-03-07 16:03:34 +00:00
Daniel Veillard
fde4cdef0a applied Robert Collins patch for Cygwin support Daniel
* Makefile.am libexslt/common.c libexslt/date.c libexslt/exslt.c
  libexslt/exslt.h libexslt/exsltconfig.h.in libexslt/functions.c
  libexslt/libexslt.h libexslt/math.c libexslt/saxon.c
  libexslt/sets.c libexslt/strings.c libxslt/libxslt.h
  libxslt/xslt.h libxslt/xsltconfig.h.in libxslt/xsltutils.c
  xsltproc/xsltproc.c: applied Robert Collins patch for
  Cygwin support
Daniel
2002-01-17 09:43:36 +00:00