path handling bug introduced by my recent machinations fixed

This commit is contained in:
Igor Zlatkovic 2003-02-23 13:39:39 +00:00
parent 10ee8b38fb
commit ce07616c08
2 changed files with 29 additions and 14 deletions

View File

@ -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);

31
uri.c
View File

@ -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);