8000 variables: Fix non-deterministic generated IDs · GNOME/libxslt@c45ed81 · GitHub
[go: up one dir, main page]

Skip to content

Commit c45ed81

Browse files
committed
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.
1 parent cb1e47d commit c45ed81

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

libxslt/variables.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,13 +1259,6 @@ xsltEvalGlobalVariable(xsltStackElemPtr elem, xsltTransformContextPtr ctxt)
12591259
return(result);
12601260
}
12611261

1262-
static void
1263-
xsltEvalGlobalVariableWrapper(void *payload, void *data,
1264-
const xmlChar *name ATTRIBUTE_UNUSED) {
1265-
xsltEvalGlobalVariable((xsltStackElemPtr) payload,
1266-
(xsltTransformContextPtr) data);
1267-
}
1268-
12691262
/**
12701263
* xsltEvalGlobalVariables:
12711264
* @ctxt: the XSLT transformation context
@@ -1278,6 +1271,7 @@ xsltEvalGlobalVariableWrapper(void *payload, void *data,
12781271
int
12791272
xsltEvalGlobalVariables(xsltTransformContextPtr ctxt) {
12801273
xsltStackElemPtr elem;
1274+
xsltStackElemPtr head = NULL;
12811275
xsltStylesheetPtr style;
12821276

12831277
if ((ctxt == NULL) || (ctxt->document == NULL))
@@ -1321,6 +1315,8 @@ xsltEvalGlobalVariables(xsltTransformContextPtr ctxt) {
13211315
xsltFreeStackElem(def);
13221316
return(-1);
13231317
}
1318+
def->next = head;
1319+
head = def;
13241320
} else if ((elem->comp != NULL) &&
13251321
(elem->comp->type == XSLT_FUNC_VARIABLE)) {
13261322
/*
@@ -1343,9 +1339,19 @@ xsltEvalGlobalVariables(xsltTransformContextPtr ctxt) {
13431339
}
13441340

13451341
/*
1346-
* This part does the actual evaluation
1342+
* This part does the actual evaluation. Note that scanning the hash
1343+
* table would result in a non-deterministic order, leading to
1344+
* non-deterministic generated IDs.
13471345
*/
1348-
xmlHashScan(ctxt->globalVars, xsltEvalGlobalVariableWrapper, ctxt);
1346+
elem = head;
1347+
while (elem != NULL) {
1348+
xsltStackElemPtr next;
1349+
1350+
xsltEvalGlobalVariable(elem, ctxt);
1351+
next = elem->next;
1352+
elem->next = NULL;
1353+
elem = next;
1354+
}
13491355

13501356
return(0);
13511357
}

0 commit comments

Comments
 (0)
0