Skip to content

Commit eecbc64

Browse files
committed
Fix handling of URIs in custom XSL loader
There was an error how URIs were handled in our custom XSL loader that rewrites include URIs to point to admin dir if the include is not found in the current dir. The check for the file would not work if the path contains chars that are usually escaped in URIs, like a space (%20), as we get a already encoded version of that URI in the loader and did not decode it before checking the existence of the file. (Fix #2249)
1 parent 6e03196 commit eecbc64

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/xslt.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,27 @@ static xmlDocPtr custom_loader(const xmlChar *URI,
204204
{
205205
xmlDocPtr ret;
206206
xmlChar *rel_path, *fn, *final_URI = NULL;
207+
char *path_URI = NULL;
207208
xsltStylesheet *c;
208209
ice_config_t *config;
209210

210211
switch (type) {
211212
/* In case an include is loaded */
212213
case XSLT_LOAD_STYLESHEET:
214+
/* URI is an escaped URI, make an unescaped version */
215+
path_URI = util_url_unescape((const char*)URI);
216+
/* Error if we can't unescape */
217+
if (path_URI == NULL)
218+
return NULL;
219+
213220
/* Not look in admindir if the include file exists */
214-
if (access((const char *)URI, F_OK) == 0)
221+
if (access(path_URI, F_OK) == 0) {
222+
free(path_URI);
215223
break;
224+
}
225+
free(path_URI);
216226

217227
c = (xsltStylesheet *) ctxt;
218-
219228
/* Check if we actually have context/path */
220229
if (ctxt == NULL || c->doc->URL == NULL)
221230
break;
@@ -238,7 +247,11 @@ static xmlDocPtr custom_loader(const xmlChar *URI,
238247
/* In case a top stylesheet is loaded */
239248
case XSLT_LOAD_START:
240249
config = config_get_config();
241-
/* Check if admin path actually changed. If so clear it. */
250+
/* Admin path is cached, so that we don't need to get it from
251+
* the config every time we load a xsl include.
252+
* Whenever a new top stylesheet is loaded, we check here
253+
* if the path in the config has changed and adjust it, if needed.
254+
*/
242255
if (admin_path != NULL &&
243256
strcmp(config->adminroot_dir, (char *)admin_path) != 0) {
244257
xmlFree(admin_path);

0 commit comments

Comments
 (0)