diff --git a/parser.c b/parser.c index 4cfcfe5d..9078c0ca 100644 --- a/parser.c +++ b/parser.c @@ -10342,6 +10342,7 @@ xmlCreateFileParserCtxt(const char *filename) { xmlParserCtxtPtr ctxt; xmlParserInputPtr inputStream; + char *canonicFilename; char *directory = NULL; ctxt = xmlNewParserCtxt(); @@ -10352,7 +10353,16 @@ xmlCreateFileParserCtxt(const char *filename) return(NULL); } - inputStream = xmlLoadExternalEntity(filename, NULL, ctxt); + canonicFilename = xmlCanonicPath(filename); + if (canonicFilename == NULL) { + if (xmlDefaultSAXHandler.error != NULL) { + xmlDefaultSAXHandler.error(NULL, "out of memory\n"); + } + return(NULL); + } + + inputStream = xmlLoadExternalEntity(canonicFilename, NULL, ctxt); + xmlFree(canonicFilename); if (inputStream == NULL) { xmlFreeParserCtxt(ctxt); return(NULL); diff --git a/uri.c b/uri.c index 65efe122..0e3d0e7c 100644 --- a/uri.c +++ b/uri.c @@ -1985,8 +1985,10 @@ done: xmlChar* xmlCanonicPath(const xmlChar *path) { - int len, i = 0; + int len = 0; + int i = 0; xmlChar *ret; + xmlChar *p = NULL; xmlURIPtr uri; if (path == NULL) @@ -1998,23 +2000,26 @@ xmlCanonicPath(const xmlChar *path) uri = xmlCreateURI(); -#if defined(_WIN32) && !defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) len = xmlStrlen(path); if ((len > 2) && IS_WINDOWS_PATH(path)) { uri->scheme = xmlStrdup(BAD_CAST "file"); - uri->path = xmlMalloc(len + 1); + uri->path = xmlMalloc(len + 2); uri->path[0] = '/'; - while (i < len) { - if (path[i] == '\\') - uri->path[i+1] = '/'; - else - uri->path[i+1] = path[i]; - i++; - } - uri->path[len] = '\0'; - } else -#endif + p = uri->path + 1; + strncpy(p, path, len + 1); + } else { uri->path = xmlStrdup(path); + p = uri->path; + } + while (*p != '\0') { + if (*p == '\\') + *p = '/'; + p++; + } +#else + uri->path = xmlStrdup(path); +#endif ret = xmlSaveUri(uri); xmlFreeURI(uri);