1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-30 22:43:14 +03:00

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; xmlParserCtxtPtr ctxt;
xmlParserInputPtr inputStream; xmlParserInputPtr inputStream;
char *canonicFilename;
char *directory = NULL; char *directory = NULL;
ctxt = xmlNewParserCtxt(); ctxt = xmlNewParserCtxt();
@ -10352,7 +10353,16 @@ xmlCreateFileParserCtxt(const char *filename)
return(NULL); 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) { if (inputStream == NULL) {
xmlFreeParserCtxt(ctxt); xmlFreeParserCtxt(ctxt);
return(NULL); return(NULL);

31
uri.c
View File

@ -1985,8 +1985,10 @@ done:
xmlChar* xmlChar*
xmlCanonicPath(const xmlChar *path) xmlCanonicPath(const xmlChar *path)
{ {
int len, i = 0; int len = 0;
int i = 0;
xmlChar *ret; xmlChar *ret;
xmlChar *p = NULL;
xmlURIPtr uri; xmlURIPtr uri;
if (path == NULL) if (path == NULL)
@ -1998,23 +2000,26 @@ xmlCanonicPath(const xmlChar *path)
uri = xmlCreateURI(); uri = xmlCreateURI();
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
len = xmlStrlen(path); len = xmlStrlen(path);
if ((len > 2) && IS_WINDOWS_PATH(path)) { if ((len > 2) && IS_WINDOWS_PATH(path)) {
uri->scheme = xmlStrdup(BAD_CAST "file"); uri->scheme = xmlStrdup(BAD_CAST "file");
uri->path = xmlMalloc(len + 1); uri->path = xmlMalloc(len + 2);
uri->path[0] = '/'; uri->path[0] = '/';
while (i < len) { p = uri->path + 1;
if (path[i] == '\\') strncpy(p, path, len + 1);
uri->path[i+1] = '/'; } else {
else
uri->path[i+1] = path[i];
i++;
}
uri->path[len] = '\0';
} else
#endif
uri->path = xmlStrdup(path); uri->path = xmlStrdup(path);
p = uri->path;
}
while (*p != '\0') {
if (*p == '\\')
*p = '/';
p++;
}
#else
uri->path = xmlStrdup(path);
#endif
ret = xmlSaveUri(uri); ret = xmlSaveUri(uri);
xmlFreeURI(uri); xmlFreeURI(uri);