OLD | NEW |
1 #define IN_LIBEXSLT | 1 #define IN_LIBEXSLT |
2 #include "libexslt/libexslt.h" | 2 #include "libexslt/libexslt.h" |
3 | 3 |
4 #if defined(WIN32) && !defined (__CYGWIN__) && (!__MINGW32__) | 4 #if defined(WIN32) && !defined (__CYGWIN__) && (!__MINGW32__) |
5 #include <win32config.h> | 5 #include <win32config.h> |
6 #else | 6 #else |
7 #include "config.h" | 7 #include "config.h" |
8 #endif | 8 #endif |
9 | 9 |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 typedef struct _exsltFuncImportRegData exsltFuncImportRegData; | 50 typedef struct _exsltFuncImportRegData exsltFuncImportRegData; |
51 struct _exsltFuncImportRegData { | 51 struct _exsltFuncImportRegData { |
52 xsltTransformContextPtr ctxt; | 52 xsltTransformContextPtr ctxt; |
53 xmlHashTablePtr hash; | 53 xmlHashTablePtr hash; |
54 }; | 54 }; |
55 | 55 |
56 static void exsltFuncFunctionFunction (xmlXPathParserContextPtr ctxt, | 56 static void exsltFuncFunctionFunction (xmlXPathParserContextPtr ctxt, |
57 int nargs); | 57 int nargs); |
58 static exsltFuncFunctionData *exsltFuncNewFunctionData(void); | 58 static exsltFuncFunctionData *exsltFuncNewFunctionData(void); |
59 | 59 |
| 60 #define MAX_FUNC_RECURSION 1000 |
| 61 |
60 /*static const xmlChar *exsltResultDataID = (const xmlChar *) "EXSLT Result";*/ | 62 /*static const xmlChar *exsltResultDataID = (const xmlChar *) "EXSLT Result";*/ |
61 | 63 |
62 /** | 64 /** |
63 * exsltFuncRegisterFunc: | 65 * exsltFuncRegisterFunc: |
64 * @func: the #exsltFuncFunctionData for the function | 66 * @func: the #exsltFuncFunctionData for the function |
65 * @ctxt: an XSLT transformation context | 67 * @ctxt: an XSLT transformation context |
66 * @URI: the function namespace URI | 68 * @URI: the function namespace URI |
67 * @name: the function name | 69 * @name: the function name |
68 * | 70 * |
69 * Registers a function declared by a func:function element | 71 * Registers a function declared by a func:function element |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 paramNode = func->content->prev; | 316 paramNode = func->content->prev; |
315 } | 317 } |
316 else | 318 else |
317 paramNode = NULL; | 319 paramNode = NULL; |
318 if ((paramNode == NULL) && (func->nargs != 0)) { | 320 if ((paramNode == NULL) && (func->nargs != 0)) { |
319 xsltGenericError(xsltGenericErrorContext, | 321 xsltGenericError(xsltGenericErrorContext, |
320 "exsltFuncFunctionFunction: nargs != 0 and " | 322 "exsltFuncFunctionFunction: nargs != 0 and " |
321 "param == NULL\n"); | 323 "param == NULL\n"); |
322 return; | 324 return; |
323 } | 325 } |
| 326 if (tctxt->funcLevel > MAX_FUNC_RECURSION) { |
| 327 xsltGenericError(xsltGenericErrorContext, |
| 328 "{%s}%s: detected a recursion\n", |
| 329 ctxt->context->functionURI, ctxt->context->function); |
| 330 ctxt->error = XPATH_MEMORY_ERROR; |
| 331 return; |
| 332 } |
| 333 tctxt->funcLevel++; |
| 334 |
324 /* | 335 /* |
325 * We have a problem with the evaluation of function parameters. | 336 * We have a problem with the evaluation of function parameters. |
326 * The original library code did not evaluate XPath expressions until | 337 * The original library code did not evaluate XPath expressions until |
327 * the last moment. After version 1.1.17 of the libxslt, the logic | 338 * the last moment. After version 1.1.17 of the libxslt, the logic |
328 * of other parts of the library was changed, and the evaluation of | 339 * of other parts of the library was changed, and the evaluation of |
329 * XPath expressions within parameters now takes place as soon as the | 340 * XPath expressions within parameters now takes place as soon as the |
330 * parameter is parsed/evaluated (xsltParseStylesheetCallerParam). | 341 * parameter is parsed/evaluated (xsltParseStylesheetCallerParam). |
331 * This means that the parameters need to be evaluated in lexical | 342 * This means that the parameters need to be evaluated in lexical |
332 * order (since a variable is "in scope" as soon as it is declared). | 343 * order (since a variable is "in scope" as soon as it is declared). |
333 * However, on entry to this routine, the values (from the caller) are | 344 * However, on entry to this routine, the values (from the caller) are |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 xmlFreeNode(fake); | 441 xmlFreeNode(fake); |
431 valuePush(ctxt, ret); | 442 valuePush(ctxt, ret); |
432 | 443 |
433 error: | 444 error: |
434 /* | 445 /* |
435 * IMPORTANT: This enables previously tree fragments marked as | 446 * IMPORTANT: This enables previously tree fragments marked as |
436 * being results of a function, to be garbage-collected after | 447 * being results of a function, to be garbage-collected after |
437 * the calling process exits. | 448 * the calling process exits. |
438 */ | 449 */ |
439 xsltExtensionInstructionResultFinalize(tctxt); | 450 xsltExtensionInstructionResultFinalize(tctxt); |
| 451 tctxt->funcLevel--; |
440 } | 452 } |
441 | 453 |
442 | 454 |
443 static void | 455 static void |
444 exsltFuncFunctionComp (xsltStylesheetPtr style, xmlNodePtr inst) { | 456 exsltFuncFunctionComp (xsltStylesheetPtr style, xmlNodePtr inst) { |
445 xmlChar *name, *prefix; | 457 xmlChar *name, *prefix; |
446 xmlNsPtr ns; | 458 xmlNsPtr ns; |
447 xmlHashTablePtr data; | 459 xmlHashTablePtr data; |
448 exsltFuncFunctionData *func; | 460 exsltFuncFunctionData *func; |
449 | 461 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 (xsltStyleExtShutdownFunction) exsltFuncStyleShutdown); | 765 (xsltStyleExtShutdownFunction) exsltFuncStyleShutdown); |
754 | 766 |
755 xsltRegisterExtModuleTopLevel ((const xmlChar *) "function", | 767 xsltRegisterExtModuleTopLevel ((const xmlChar *) "function", |
756 EXSLT_FUNCTIONS_NAMESPACE, | 768 EXSLT_FUNCTIONS_NAMESPACE, |
757 exsltFuncFunctionComp); | 769 exsltFuncFunctionComp); |
758 xsltRegisterExtModuleElement ((const xmlChar *) "result", | 770 xsltRegisterExtModuleElement ((const xmlChar *) "result", |
759 EXSLT_FUNCTIONS_NAMESPACE, | 771 EXSLT_FUNCTIONS_NAMESPACE, |
760 (xsltPreComputeFunction)exsltFuncResultComp, | 772 (xsltPreComputeFunction)exsltFuncResultComp, |
761 (xsltTransformFunction) exsltFuncResultElem); | 773 (xsltTransformFunction) exsltFuncResultElem); |
762 } | 774 } |
OLD | NEW |