1
0
mirror of https://gitlab.gnome.org/GNOME/libxslt synced 2025-09-11 16:10:45 +03:00

40 Commits

Author SHA1 Message Date
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
0beb813d64 Use _WIN32 macro instead of WIN32
_WIN32 is defined automatically by the compiler.
2017-10-25 18:22:52 +02:00
Nick Wellnhofer
b89ec93541 Fix memory leak in str:concat with empty node-set
Found with libFuzzer and ASan.
2017-05-27 16:33:15 +02:00
Nick Wellnhofer
8418a0b830 Fix UTF-8 check in str:padding
Make sure that all arguments are popped before checking for UTF-8
validity. Improves upon recent commit 1785d11.
2017-05-27 16:29:08 +02:00
Nick Wellnhofer
37b0934d8b Use xmlBuffers in EXSLT string functions
This improves performance with (pathologically) long strings. Make sure
to use a fast allocation scheme.
2017-05-18 17:59:00 +02:00
Nick Wellnhofer
8a1d5b6a5a Switch to xmlUTF8Strsize in EXSLT string functions
When encountering invalid UTF-8, xmlUTF8Size can return a size greater
than the actual string length or -1. Switch to xmlUTF8Strsize which
returns a sensible size even with invalid UTF-8.

Under normal conditions, libxslt should never receive invalid UTF-8.
But this change helps when fuzzing and hardens security.
2017-05-18 17:59:00 +02:00
Nick Wellnhofer
1785d1189e Check for return value of xmlUTF8Strlen
Check whether xmlUTF8Strlen returns -1 for invalid UTF-8.

Under normal conditions, libxslt should never receive invalid UTF-8.
But this change helps when fuzzing and hardens security.
2017-05-18 17:59:00 +02:00
Nick Wellnhofer
df87857190 Fix double to int conversion
Add range checks to avoid undefined behavior.

Limit str:padding length to 100,000 chars.
2017-05-18 17:14:28 +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
ec39a33e02 Fix str:align with UTF-8 strings
The offset computation for left-aligned strings containing UTF-8 was
wrong. Fixes bug #588544:

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

Also add some test cases.
2014-10-04 12:19:30 +02:00
Nick Wellnhofer
515283959a Fix str:padding to work with UTF-8 strings
Thanks to Tobias Hoffmann for the report.

Also add some tests.
2013-08-04 16:42:51 +02:00
Nick Wellnhofer
ae49d7a73b EXSLT function str:replace() is broken as-is
the str:replace() function is no longer usable without a transform
context. I take it from the bug report that it is not supposed to be used
from plain XPath but only from XSLT according to the EXSLT specification.

However, the previous implementation used to work in XPath and is still
registered on an xmlXPathContext by the exsltStrXpathCtxtRegister()
function. When called from plain XPath, it results in a memory error in
line 526 (exsltStrReturnString()) of strings.c because xsltCreateRVT()
returns NULL as an error indicator due to a NULL transform context being
passed in, which was the return value from xsltXPathGetTransformContext() a
bit further up (and the code doesn't validate that).

Since fixing the function looks impossible, best is to remove it.
2013-07-01 21:10:10 +08: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
0602c535e9 Rewrite EXSLT string:replace to be conformant
For https://bugzilla.gnome.org/show_bug.cgi?id=569703

The libexslt implementation of str:replace fails to conform to its
specification on several counts:

a) the current version returns a string; it's supposed to
   return a nodeset.

b) the current version treats the replacements as strings;
   it's supposed to treat them as nodes.

c) the current version can modify replacement text; it's
   supposed to only modify text from the original string.

d) the current version ignores the requirement to perform
   substitutions in descending order of search string length.

Steps to reproduce:
a) the returning of a string rather than a nodeset can be seen
   by simply inspecting the code.

b) the code explicity converts replacement nodes to strings;
   this can be seen by inspection.
d) the failure to perform substitutions in descending order
   of search string length can be seen in the lack of any
   sorting in the source code.

c) the problem of modifying text not belonging to the original
   string can be seen in the following stylesheet, which can
   be simply applied to itself to produce output.

<xsl:stylesheet version="1.0"
    extension-element-prefixes="str exsl"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:exsl="http://exslt.org/common"
    xmlns:str="http://exslt.org/strings"
    >
<xsl:variable name="Text">
    Price is $1.10
</xsl:variable>

<xsl:template match="/">
    <xsl:apply-templates select="exsl:node-set($Text)/text()"/>
</xsl:template>
<xsl:template match="text()">
   <xsl:variable name="Replace">
        <FromXml>
            <from>$</from>
            <from>\</from>
        </FromXml>
        <ToTex>
            <to>\$</to>
            <to>$\backslash$</to>
        </ToTex>
    </xsl:variable>
    <xsl:value-of

select="str:replace(.,exsl:node-set($Replace)/FromXml/from,exsl:node-set($Replace)/ToTex/to)"/>
</xsl:template>
</xsl:stylesheet>

Actual results:
The output is:

<?xml version="1.0"?>

    Price is $\backslash$$1.10

Expected results:
The output should be:
<?xml version="1.0"?>

    Price is \$1.10

Does this happen every time?
yes.

Other information:
str:replace specification is at:

http://www.exslt.org/str/functions/replace/str.replace.html
2012-09-04 14:38:06 +08:00
Martin
ce169a52f4 Allow use of EXSLT outside XSLT
* libexslt/exslt.h libexslt/date.c libexslt/math.c libexslt/sets.c
  libexslt/strings.c: provide registration function for an XPath
  context directly
2009-09-17 16:54:18 +02:00
William M. Brack
cc8f0964b2 Fixed indexing error reported by Ron Burk on the mailing list.
* libexslt/strings.c: Fixed indexing error reported by Ron Burk on the mailing list.

svn path=/trunk/; revision=1494
2009-01-24 03:06:51 +00:00
William M. Brack
ee016c46d1 Added code to mark the results of str:tokenize and str:split as "function
* libexslt/strings.c: Added code to mark the results of
  str:tokenize and str:split as "function result" to avoid
  garbage-collecting them during global variable initialisation.
  Should fix bug #495995.

svn path=/trunk/; revision=1448
2007-11-12 21:53:00 +00:00
William M. Brack
40e7c29b35 added new function replace from Joel Reed. added new test case for above.
* libexslt/strings.c: added new function replace from Joel
          Reed.
        * tests/exslt/Makefile.am, replace.1.xml, replace.1.xsl,
          replace.1.out: added new test case for above.
        * libxslt.spec.in: trivial change from Gnome to GNOME
        * configure.in: trivial change for flags on my compilations
        * libxslt/documents.c, libxslt/documents.h, libxslt/keys.c,
          libxslt/keys.h, libxslt/variables.c, libxslt/templates.c,
          libxslt/transform.c, libxslt/variables.c, libxslt/xslt.c,
          libxslt/xsltutils.c: fixed some documentation/comments and
          compilation warnings - no change to logic.
        * re-generated the documentation.

svn path=/trunk/; revision=1413
2007-01-11 03:13:13 +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
William M. Brack
391aed81b5 fixed str:tokenize for case when 2nd argument is an empty string (should
* libexslt/strings.c: fixed str:tokenize for case when 2nd
  argument is an empty string (should produce a token for
  each char in the string).  Reported on the mailing list by
  Peter Pawlowski.
2004-07-27 00:06:37 +00:00
William M. Brack
05225a3904 fixed bug in UTF8 string tokenize kindly reported by Vasily Tchekalkin
* libexslt/strings.c: fixed bug in UTF8 string tokenize
  kindly reported by Vasily Tchekalkin
2004-04-19 16:27:33 +00:00
William M. Brack
9f7db5f4b8 modified the 'tokenize' routine to work with UTF8 chars in both string and
* libexslt/strings.c: modified the 'tokenize' routine to work with
  UTF8 chars in both string and tokens (Bug 136183)
2004-03-10 09:17:08 +00:00
William M. Brack
06092dfad5 fixed entity problem in exslt:tokenize uncovered by newapi.xsl changed to
* libexslt/strings.c: fixed entity problem in exslt:tokenize
  uncovered by newapi.xsl
* libxslt/transform.c,libxslt/pattern.c,libxslt/keys.c: changed
  to use IS_BLANK_CH for char compares (fixes warnings)
2003-11-18 05:57:38 +00:00
Daniel Veillard
fa4f217009 fix bug #125265 about entities breaking exsl:tokenize and exsl:split
* libexslt/strings.c: fix bug #125265 about entities breaking
  exsl:tokenize and exsl:split
* tests/exslt/strings/split.1.* tests/exslt/strings/tokenize.1.*:
  augmented the reression tests with the example from the bug report.
Daniel
2003-11-01 06:45:21 +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
Daniel Veillard
91cefd843f applied patch from Shaun McCance to fix bug #117616 about EXST
* libexslt/strings.c: applied patch from Shaun McCance to fix bug
  #117616 about EXST str:tokenize.
* tests/exslt/strings/Makefile.am tests/exslt/strings/tokenize.3.*:
  added the test in the regression suite.
Daniel
2003-07-24 18:41:50 +00:00
Daniel Veillard
f826a45e68 applied patch from Shaun McCance to implement exslt:split c.f. #117752
* libexslt/strings.c: applied patch from Shaun McCance to implement
  exslt:split c.f. #117752
* tests/exslt/strings/Makefile.am tests/exslt/strings/split.1.*:
  added the test to the regression suite.
Daniel
2003-07-18 11:15:45 +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
b973e4a094 fixed a problem in the generator where the way functions are remapped as
* python/generator.py: fixed a problem in the generator where
  the way functions are remapped as methods on classes was
  not symetric and dependant on python internal hash order,
  as reported by Stphane Bidoul
* libexslt/strings.c: attempt at fixing an object type pbm
* libxslt/triodef.h: update for OpenVMS from libxml2
Daniel
2003-04-26 12:06:36 +00:00
Daniel Veillard
6c87e3dd3f applied last patch for #110023 from Mark Vakoc fixed a memory leak when
* libexslt/strings.c: applied last patch for #110023 from
  Mark Vakoc
* libexslt/sets.c: fixed a memory leak when mixing one of the
  EXSLT set functions and a Result Value Tree
* TODO: there are other bugs around in libexslt/sets.c in conjunction
  with Result Value Tree
Daniel
2003-04-23 20:44:16 +00:00
Daniel Veillard
7f12faefe8 applied patch from Mark Vakoc fixing a problem with RTF in libexslt Daniel
* libexslt/strings.c: applied patch from Mark Vakoc fixing a problem
  with RTF in libexslt
Daniel
2003-04-09 20:03:43 +00:00
Daniel Veillard
564262da5f applied patch from Jrg Walter to provide URI escaping and unescaping
* libexslt/strings.c: applied patch from Jrg Walter to provide
  URI escaping and unescaping functions.
Daniel
2003-01-02 22:30:08 +00:00
Daniel Veillard
69696d2182 Alexey Efimov found a typo bug in exsltStrPaddingFunction() Daniel
* libexslt/strings.c: Alexey Efimov found a typo bug in
  exsltStrPaddingFunction()
Daniel
2002-12-26 14:44:46 +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
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
Daniel Veillard
ae93ba0741 moved the config.h include out of exsltconfig.h since this header is
* libexslt/*.c libexslt/exsltconfig.h.in: moved the
  config.h include out of exsltconfig.h since this header is
  exported and config.h is not.
Daniel
2001-10-19 14:47:24 +00:00
Thomas Broyer
c0de2a55d5 fixed a typo and improved handling of non-XPath-expression arguments.
* libexslt/saxon.c: fixed a typo and improved handling of
	  non-XPath-expression arguments.
	* libexslt/strings.c: fixed a bug in tokenize: function was using
	  tctxt->output instead of tctxt->document->doc.
	* libxslt/transform.c: fixed a bug in xsltDefaultProcessOneNode
	  which was using variable "node" instead of "cur"
2001-10-09 20:57:29 +00:00
Daniel Veillard
cdad73d46d close #59570 by simply not providing Norm's extension on FreeBSD. added a
* libxslt/extra.c : close #59570 by simply not providing
  Norm's extension on FreeBSD.
* tests/general tests/docs: added a couple of new entries
  in the testsuite
* libexslt/strings.c: NULL initialized a local variable
  which was tested later on.
Daniel
2001-09-11 10:47:57 +00:00
Thomas Broyer
94c00a7753 added implementation of EXSLT - Strings. Currently implemented functins
* libexslt/Makefile.am libexslt/exslt.[ch] libexslt/strings.c:
	  added implementation of EXSLT - Strings.
	  Currently implemented functins are str:tokenize, str:align
	  str:concat and str:padding.
	* configure.in tests/exslt/Makefile.am
	  tests/exslt/strings/Makefile.am
	  tests/exslt/strings/tokenize.1.*: added a test for the
	  str:tokenize function.
2001-09-03 00:17:54 +00:00