mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
second pass at fixing #63336, using Joel Young final patch. looks okay.
* uri.c: second pass at fixing #63336, using Joel Young final patch. looks okay. Daniel
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
Tue Oct 30 10:46:12 CET 2001 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* uri.c: second pass at fixing #63336, using Joel Young
|
||||||
|
final patch. looks okay.
|
||||||
|
|
||||||
Tue Oct 30 00:56:05 CET 2001 Daniel Veillard <daniel@veillard.com>
|
Tue Oct 30 00:56:05 CET 2001 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
* uri.c include/libxml/uri.h: trying to clear #63336
|
* uri.c include/libxml/uri.h: trying to clear #63336
|
||||||
|
299
uri.c
299
uri.c
@ -156,12 +156,12 @@
|
|||||||
(IS_RESERVED(*(p))))
|
(IS_RESERVED(*(p))))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* unwise = "{" | "}" | "|" | "\" | "^" | "[" | "]" | "`"
|
* unwise = "{" | "}" | "|" | "\" | "^" | "[" | "]" | "`"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define IS_UNWISE(p) \
|
#define IS_UNWISE(p) \
|
||||||
(((*(p) == '{')) || ((*(p) == '}')) || ((*(p) == '|')) || \
|
(((*(p) == '{')) || ((*(p) == '}')) || ((*(p) == '|')) || \
|
||||||
((*(p) == '\\')) || ((*(p) == '^')) || ((*(p) == '[')) || \
|
((*(p) == '\\')) || ((*(p) == '^')) || ((*(p) == '[')) || \
|
||||||
((*(p) == ']')) || ((*(p) == '`')))
|
((*(p) == ']')) || ((*(p) == '`')))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -936,7 +936,8 @@ xmlURIEscapeStr(const xmlChar *str, const xmlChar *list) {
|
|||||||
* - Carl Douglas
|
* - Carl Douglas
|
||||||
*/
|
*/
|
||||||
xmlChar *
|
xmlChar *
|
||||||
xmlURIEscape(const xmlChar *str) {
|
xmlURIEscape(const xmlChar * str)
|
||||||
|
{
|
||||||
xmlChar *ret, *segment = NULL;
|
xmlChar *ret, *segment = NULL;
|
||||||
xmlURIPtr uri;
|
xmlURIPtr uri;
|
||||||
int ret2;
|
int ret2;
|
||||||
@ -947,97 +948,103 @@ xmlURIEscape(const xmlChar *str) {
|
|||||||
return NULL; }
|
return NULL; }
|
||||||
|
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return(NULL);
|
return (NULL);
|
||||||
|
|
||||||
uri = xmlCreateURI();
|
uri = xmlCreateURI();
|
||||||
if (uri != NULL) {
|
if (uri != NULL) {
|
||||||
uri->cleanup = 1;
|
/*
|
||||||
ret2 = xmlParseURIReference(uri, str);
|
* Allow escaping errors in the unescaped form
|
||||||
|
*/
|
||||||
|
uri->cleanup = 1;
|
||||||
|
ret2 = xmlParseURIReference(uri, (const char *)str);
|
||||||
if (ret2) {
|
if (ret2) {
|
||||||
xmlFreeURI(uri);
|
xmlFreeURI(uri);
|
||||||
return(NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!uri)
|
if (!uri)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ret = NULL;
|
ret = NULL;
|
||||||
|
|
||||||
if(uri->scheme) {
|
if (uri->scheme) {
|
||||||
segment = xmlURIEscapeStr( BAD_CAST uri->scheme, BAD_CAST "+-.");
|
segment = xmlURIEscapeStr(BAD_CAST uri->scheme, BAD_CAST "+-.");
|
||||||
NULLCHK(segment)
|
NULLCHK(segment)
|
||||||
xmlStrcat(ret, segment);
|
ret = xmlStrcat(ret, segment);
|
||||||
xmlStrcat(ret, BAD_CAST ":");
|
ret = xmlStrcat(ret, BAD_CAST ":");
|
||||||
xmlFree(segment);
|
xmlFree(segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(uri->authority) {
|
if (uri->authority) {
|
||||||
segment = xmlURIEscapeStr( BAD_CAST uri->authority, BAD_CAST "/?;:@");
|
segment =
|
||||||
NULLCHK(segment)
|
xmlURIEscapeStr(BAD_CAST uri->authority, BAD_CAST "/?;:@");
|
||||||
xmlStrcat(ret, BAD_CAST "//");
|
NULLCHK(segment)
|
||||||
xmlStrcat(ret, segment);
|
ret = xmlStrcat(ret, BAD_CAST "//");
|
||||||
xmlFree(segment);
|
ret = xmlStrcat(ret, segment);
|
||||||
|
xmlFree(segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(uri->user) {
|
if (uri->user) {
|
||||||
segment = xmlURIEscapeStr( BAD_CAST uri->user, BAD_CAST ";:&=+$,");
|
segment = xmlURIEscapeStr(BAD_CAST uri->user, BAD_CAST ";:&=+$,");
|
||||||
NULLCHK(segment)
|
NULLCHK(segment)
|
||||||
xmlStrcat(ret, segment);
|
ret = xmlStrcat(ret, segment);
|
||||||
xmlStrcat(ret, BAD_CAST "@");
|
ret = xmlStrcat(ret, BAD_CAST "@");
|
||||||
xmlFree(segment);
|
xmlFree(segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(uri->server) {
|
if (uri->server) {
|
||||||
segment = xmlURIEscapeStr( BAD_CAST uri->server, BAD_CAST "/?;:@");
|
segment = xmlURIEscapeStr(BAD_CAST uri->server, BAD_CAST "/?;:@");
|
||||||
NULLCHK(segment)
|
NULLCHK(segment)
|
||||||
xmlStrcat(ret, BAD_CAST "//");
|
ret = xmlStrcat(ret, BAD_CAST "//");
|
||||||
xmlStrcat(ret, segment);
|
ret = xmlStrcat(ret, segment);
|
||||||
xmlFree(segment);
|
xmlFree(segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(uri->port) {
|
if (uri->port) {
|
||||||
xmlChar port[10];
|
xmlChar port[10];
|
||||||
snprintf((char *) segment, 10, "%d", uri->port);
|
|
||||||
xmlStrcat(ret, BAD_CAST ":");
|
snprintf((char *) segment, 10, "%d", uri->port);
|
||||||
xmlStrcat(ret, port);
|
ret = xmlStrcat(ret, BAD_CAST ":");
|
||||||
xmlFree(segment);
|
ret = xmlStrcat(ret, port);
|
||||||
|
xmlFree(segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(uri->path) {
|
if (uri->path) {
|
||||||
segment = xmlURIEscapeStr( BAD_CAST uri->path, BAD_CAST ":@&=+$,/?;");
|
segment =
|
||||||
NULLCHK(segment)
|
xmlURIEscapeStr(BAD_CAST uri->path, BAD_CAST ":@&=+$,/?;");
|
||||||
xmlStrcat(ret, segment);
|
NULLCHK(segment)
|
||||||
xmlFree(segment);
|
ret = xmlStrcat(ret, segment);
|
||||||
|
xmlFree(segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(uri->query) {
|
if (uri->query) {
|
||||||
segment = xmlURIEscapeStr( BAD_CAST uri->query, BAD_CAST ";/?:@&=+,$");
|
segment =
|
||||||
NULLCHK(segment)
|
xmlURIEscapeStr(BAD_CAST uri->query, BAD_CAST ";/?:@&=+,$");
|
||||||
xmlStrcat(ret, BAD_CAST "?");
|
NULLCHK(segment)
|
||||||
xmlStrcat(ret, segment);
|
ret = xmlStrcat(ret, BAD_CAST "?");
|
||||||
xmlFree(segment);
|
ret = xmlStrcat(ret, segment);
|
||||||
|
xmlFree(segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(uri->opaque) {
|
if (uri->opaque) {
|
||||||
segment = xmlURIEscapeStr( BAD_CAST uri->opaque, BAD_CAST "");
|
segment = xmlURIEscapeStr(BAD_CAST uri->opaque, BAD_CAST "");
|
||||||
NULLCHK(segment)
|
NULLCHK(segment)
|
||||||
xmlStrcat(ret, segment);
|
ret = xmlStrcat(ret, segment);
|
||||||
xmlStrcat(ret, BAD_CAST ":");
|
ret = xmlStrcat(ret, BAD_CAST ":");
|
||||||
xmlFree(segment);
|
xmlFree(segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(uri->fragment) {
|
if (uri->fragment) {
|
||||||
segment = xmlURIEscapeStr( BAD_CAST uri->fragment, BAD_CAST "#");
|
segment = xmlURIEscapeStr(BAD_CAST uri->fragment, BAD_CAST "#");
|
||||||
NULLCHK(segment)
|
NULLCHK(segment)
|
||||||
xmlStrcat(ret, BAD_CAST "#");
|
ret = xmlStrcat(ret, BAD_CAST "#");
|
||||||
xmlStrcat(ret, segment);
|
ret = xmlStrcat(ret, segment);
|
||||||
xmlFree(segment);
|
xmlFree(segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef NULLCHK
|
#undef NULLCHK
|
||||||
|
|
||||||
return(ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
@ -1059,18 +1066,22 @@ xmlURIEscape(const xmlChar *str) {
|
|||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
xmlParseURIFragment(xmlURIPtr uri, const char **str) {
|
xmlParseURIFragment(xmlURIPtr uri, const char **str)
|
||||||
|
{
|
||||||
const char *cur = *str;
|
const char *cur = *str;
|
||||||
|
|
||||||
if (str == NULL) return(-1);
|
if (str == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
while (IS_URIC(cur) || ((uri->cleanup) && (IS_UNWISE(cur)))) NEXT(cur);
|
while (IS_URIC(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))
|
||||||
|
NEXT(cur);
|
||||||
if (uri != NULL) {
|
if (uri != NULL) {
|
||||||
if (uri->fragment != NULL) xmlFree(uri->fragment);
|
if (uri->fragment != NULL)
|
||||||
uri->fragment = xmlURIUnescapeString(*str, cur - *str, NULL);
|
xmlFree(uri->fragment);
|
||||||
|
uri->fragment = xmlURIUnescapeString(*str, cur - *str, NULL);
|
||||||
}
|
}
|
||||||
*str = cur;
|
*str = cur;
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1085,18 +1096,22 @@ xmlParseURIFragment(xmlURIPtr uri, const char **str) {
|
|||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
xmlParseURIQuery(xmlURIPtr uri, const char **str) {
|
xmlParseURIQuery(xmlURIPtr uri, const char **str)
|
||||||
|
{
|
||||||
const char *cur = *str;
|
const char *cur = *str;
|
||||||
|
|
||||||
if (str == NULL) return(-1);
|
if (str == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
while (IS_URIC(cur)) NEXT(cur);
|
while (IS_URIC(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))
|
||||||
|
NEXT(cur);
|
||||||
if (uri != NULL) {
|
if (uri != NULL) {
|
||||||
if (uri->query != NULL) xmlFree(uri->query);
|
if (uri->query != NULL)
|
||||||
uri->query = xmlURIUnescapeString(*str, cur - *str, NULL);
|
xmlFree(uri->query);
|
||||||
|
uri->query = xmlURIUnescapeString(*str, cur - *str, NULL);
|
||||||
}
|
}
|
||||||
*str = cur;
|
*str = cur;
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1143,24 +1158,27 @@ xmlParseURIScheme(xmlURIPtr uri, const char **str) {
|
|||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
xmlParseURIOpaquePart(xmlURIPtr uri, const char **str) {
|
xmlParseURIOpaquePart(xmlURIPtr uri, const char **str)
|
||||||
|
{
|
||||||
const char *cur;
|
const char *cur;
|
||||||
|
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return(-1);
|
return (-1);
|
||||||
|
|
||||||
cur = *str;
|
cur = *str;
|
||||||
if (!(IS_URIC_NO_SLASH(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))) {
|
if (!(IS_URIC_NO_SLASH(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))) {
|
||||||
return(3);
|
return (3);
|
||||||
}
|
}
|
||||||
NEXT(cur);
|
NEXT(cur);
|
||||||
while (IS_URIC(cur) || ((uri->cleanup) && (IS_UNWISE(cur)))) NEXT(cur);
|
while (IS_URIC(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))
|
||||||
|
NEXT(cur);
|
||||||
if (uri != NULL) {
|
if (uri != NULL) {
|
||||||
if (uri->opaque != NULL) xmlFree(uri->opaque);
|
if (uri->opaque != NULL)
|
||||||
uri->opaque = xmlURIUnescapeString(*str, cur - *str, NULL);
|
xmlFree(uri->opaque);
|
||||||
|
uri->opaque = xmlURIUnescapeString(*str, cur - *str, NULL);
|
||||||
}
|
}
|
||||||
*str = cur;
|
*str = cur;
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1319,24 +1337,27 @@ host_done:
|
|||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
xmlParseURIRelSegment(xmlURIPtr uri, const char **str) {
|
xmlParseURIRelSegment(xmlURIPtr uri, const char **str)
|
||||||
|
{
|
||||||
const char *cur;
|
const char *cur;
|
||||||
|
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return(-1);
|
return (-1);
|
||||||
|
|
||||||
cur = *str;
|
cur = *str;
|
||||||
if (!IS_SEGMENT(cur) || ((uri->cleanup) && (IS_UNWISE(cur)))) {
|
if (!(IS_SEGMENT(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))) {
|
||||||
return(3);
|
return (3);
|
||||||
}
|
}
|
||||||
NEXT(cur);
|
NEXT(cur);
|
||||||
while (IS_SEGMENT(cur) || ((uri->cleanup) && (IS_UNWISE(cur)))) NEXT(cur);
|
while (IS_SEGMENT(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))
|
||||||
|
NEXT(cur);
|
||||||
if (uri != NULL) {
|
if (uri != NULL) {
|
||||||
if (uri->path != NULL) xmlFree(uri->path);
|
if (uri->path != NULL)
|
||||||
uri->path = xmlURIUnescapeString(*str, cur - *str, NULL);
|
xmlFree(uri->path);
|
||||||
|
uri->path = xmlURIUnescapeString(*str, cur - *str, NULL);
|
||||||
}
|
}
|
||||||
*str = cur;
|
*str = cur;
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1354,62 +1375,64 @@ xmlParseURIRelSegment(xmlURIPtr uri, const char **str) {
|
|||||||
* Returns 0 or the error code
|
* Returns 0 or the error code
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
xmlParseURIPathSegments(xmlURIPtr uri, const char **str, int slash) {
|
xmlParseURIPathSegments(xmlURIPtr uri, const char **str, int slash)
|
||||||
|
{
|
||||||
const char *cur;
|
const char *cur;
|
||||||
|
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return(-1);
|
return (-1);
|
||||||
|
|
||||||
cur = *str;
|
cur = *str;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
while (IS_PCHAR(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))
|
while (IS_PCHAR(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))
|
||||||
NEXT(cur);
|
NEXT(cur);
|
||||||
if (*cur == ';') {
|
if (*cur == ';') {
|
||||||
cur++;
|
cur++;
|
||||||
while (IS_PCHAR(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))
|
while (IS_PCHAR(cur) || ((uri->cleanup) && (IS_UNWISE(cur))))
|
||||||
NEXT(cur);
|
NEXT(cur);
|
||||||
}
|
}
|
||||||
if (*cur != '/') break;
|
if (*cur != '/')
|
||||||
cur++;
|
break;
|
||||||
|
cur++;
|
||||||
} while (1);
|
} while (1);
|
||||||
if (uri != NULL) {
|
if (uri != NULL) {
|
||||||
int len, len2 = 0;
|
int len, len2 = 0;
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Concat the set of path segments to the current path
|
* Concat the set of path segments to the current path
|
||||||
*/
|
*/
|
||||||
len = cur - *str;
|
len = cur - *str;
|
||||||
if (slash)
|
if (slash)
|
||||||
len++;
|
len++;
|
||||||
|
|
||||||
if (uri->path != NULL) {
|
if (uri->path != NULL) {
|
||||||
len2 = strlen(uri->path);
|
len2 = strlen(uri->path);
|
||||||
len += len2;
|
len += len2;
|
||||||
}
|
}
|
||||||
path = (char *) xmlMalloc(len + 1);
|
path = (char *) xmlMalloc(len + 1);
|
||||||
if (path == NULL) {
|
if (path == NULL) {
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
"xmlParseURIPathSegments: out of memory\n");
|
"xmlParseURIPathSegments: out of memory\n");
|
||||||
*str = cur;
|
*str = cur;
|
||||||
return(-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (uri->path != NULL)
|
if (uri->path != NULL)
|
||||||
memcpy(path, uri->path, len2);
|
memcpy(path, uri->path, len2);
|
||||||
if (slash) {
|
if (slash) {
|
||||||
path[len2] = '/';
|
path[len2] = '/';
|
||||||
len2++;
|
len2++;
|
||||||
}
|
}
|
||||||
path[len2] = 0;
|
path[len2] = 0;
|
||||||
if (cur - *str > 0)
|
if (cur - *str > 0)
|
||||||
xmlURIUnescapeString(*str, cur - *str, &path[len2]);
|
xmlURIUnescapeString(*str, cur - *str, &path[len2]);
|
||||||
if (uri->path != NULL)
|
if (uri->path != NULL)
|
||||||
xmlFree(uri->path);
|
xmlFree(uri->path);
|
||||||
uri->path = path;
|
uri->path = path;
|
||||||
}
|
}
|
||||||
*str = cur;
|
*str = cur;
|
||||||
return(0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user