File: 0019-variables-Fix-non-deterministic-generated-IDs.patch

package info (click to toggle)
libxslt 1.1.35-1%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 29,868 kB
  • sloc: xml: 75,625; ansic: 34,780; sh: 4,249; makefile: 3,128; python: 3,060; javascript: 429; perl: 34
file content (61 lines) | stat: -rw-r--r-- 1,953 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
From c45ed81aeb50a7fb6799a166270d6ccc9ffa63b2 Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer <wellnhofer@aevum.de>
Date: Thu, 19 Sep 2024 21:49:46 +0200
Subject: [PATCH] variables: Fix non-deterministic generated IDs

Evaluate global variables in deterministic order. Otherwise, generated
IDs could be non-deterministic if generate-id() is called.

Fixes #123.
---
 libxslt/variables.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

Index: libxslt-1.1.35/libxslt/variables.c
===================================================================
--- libxslt-1.1.35.orig/libxslt/variables.c
+++ libxslt-1.1.35/libxslt/variables.c
@@ -1258,13 +1258,6 @@ error:
     return(result);
 }
 
-static void
-xsltEvalGlobalVariableWrapper(void *payload, void *data,
-                              const xmlChar *name ATTRIBUTE_UNUSED) {
-    xsltEvalGlobalVariable((xsltStackElemPtr) payload,
-                           (xsltTransformContextPtr) data);
-}
-
 /**
  * xsltEvalGlobalVariables:
  * @ctxt:  the XSLT transformation context
@@ -1277,6 +1270,7 @@ xsltEvalGlobalVariableWrapper(void *payl
 int
 xsltEvalGlobalVariables(xsltTransformContextPtr ctxt) {
     xsltStackElemPtr elem;
+    xsltStackElemPtr head = NULL;
     xsltStylesheetPtr style;
 
     if ((ctxt == NULL) || (ctxt->document == NULL))
@@ -1337,9 +1331,19 @@ xsltEvalGlobalVariables(xsltTransformCon
     }
 
     /*
-     * This part does the actual evaluation
+     * This part does the actual evaluation. Note that scanning the hash
+     * table would result in a non-deterministic order, leading to
+     * non-deterministic generated IDs.
      */
-    xmlHashScan(ctxt->globalVars, xsltEvalGlobalVariableWrapper, ctxt);
+    elem = head;
+    while (elem != NULL) {
+        xsltStackElemPtr next;
+
+        xsltEvalGlobalVariable(elem, ctxt);
+        next = elem->next;
+        elem->next = NULL;
+        elem = next;
+    }
 
     return(0);
 }