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

fixing some problems in URI unescaping and output buffer opening, this

* uri.c xmlIO.c: fixing some problems in URI unescaping
  and output buffer opening, this should fix #141864
Daniel
This commit is contained in:
Daniel Veillard
2004-05-09 02:58:44 +00:00
parent aecc0dc1f5
commit 966a31e222
3 changed files with 31 additions and 13 deletions

View File

@ -1,3 +1,8 @@
Sat May 8 22:56:22 CEST 2004 Daniel Veillard <daniel@veillard.com>
* uri.c xmlIO.c: fixing some problems in URI unescaping
and output buffer opening, this should fix #141864
Fri May 7 22:31:54 CEST 2004 Daniel Veillard <daniel@veillard.com> Fri May 7 22:31:54 CEST 2004 Daniel Veillard <daniel@veillard.com>
* valid.c include/libxml/valid.h: fixes the use of 'list' as a parameter * valid.c include/libxml/valid.h: fixes the use of 'list' as a parameter

10
uri.c
View File

@ -785,6 +785,14 @@ xmlNormalizeURIPath(char *path) {
return(0); return(0);
} }
static int is_hex(char c) {
if (((c >= '0') && (c <= '9')) ||
((c >= 'a') && (c <= 'f')) ||
((c >= 'A') && (c <= 'F')))
return(1);
return(0);
}
/** /**
* xmlURIUnescapeString: * xmlURIUnescapeString:
* @str: the string to unescape * @str: the string to unescape
@ -818,7 +826,7 @@ xmlURIUnescapeString(const char *str, int len, char *target) {
in = str; in = str;
out = ret; out = ret;
while(len > 0) { while(len > 0) {
if (*in == '%') { if ((*in == '%') && (is_hex(in[1])) && (is_hex(in[2]))) {
in++; in++;
if ((*in >= '0') && (*in <= '9')) if ((*in >= '0') && (*in <= '9'))
*out = (*in - '0'); *out = (*in - '0');

29
xmlIO.c
View File

@ -2217,33 +2217,38 @@ xmlOutputBufferCreateFilename(const char *URI,
xmlCharEncodingHandlerPtr encoder, xmlCharEncodingHandlerPtr encoder,
int compression ATTRIBUTE_UNUSED) { int compression ATTRIBUTE_UNUSED) {
xmlOutputBufferPtr ret; xmlOutputBufferPtr ret;
xmlURIPtr puri;
int i = 0; int i = 0;
void *context = NULL; void *context = NULL;
char *unescaped; char *unescaped = NULL;
int is_file_uri = 1;
int is_http_uri = 0; /* Can't change if HTTP disabled */
if (xmlOutputCallbackInitialized == 0) if (xmlOutputCallbackInitialized == 0)
xmlRegisterDefaultOutputCallbacks(); xmlRegisterDefaultOutputCallbacks();
if (URI == NULL) return(NULL); if (URI == NULL) return(NULL);
#ifdef LIBXML_HTTP_ENABLED puri = xmlParseURI(URI);
/* Need to prevent HTTP URI's from falling into zlib short circuit */ if (puri != NULL) {
if ((puri->scheme == NULL) ||
is_http_uri = xmlIOHTTPMatch( URI ); (xmlStrEqual(BAD_CAST puri->scheme, BAD_CAST "file")))
#endif is_file_uri = 0;
/*
* try to limit the damages of the URI unescaping code.
*/
if (puri->scheme != NULL)
unescaped = xmlURIUnescapeString(URI, 0, NULL);
xmlFreeURI(puri);
}
/* /*
* Try to find one of the output accept method accepting that scheme * Try to find one of the output accept method accepting that scheme
* Go in reverse to give precedence to user defined handlers. * Go in reverse to give precedence to user defined handlers.
* try with an unescaped version of the URI * try with an unescaped version of the URI
*/ */
unescaped = xmlURIUnescapeString(URI, 0, NULL);
if (unescaped != NULL) { if (unescaped != NULL) {
#ifdef HAVE_ZLIB_H #ifdef HAVE_ZLIB_H
if ((compression > 0) && (compression <= 9) && (is_http_uri == 0)) { if ((compression > 0) && (compression <= 9) && (is_file_uri == 1)) {
context = xmlGzfileOpenW(unescaped, compression); context = xmlGzfileOpenW(unescaped, compression);
if (context != NULL) { if (context != NULL) {
ret = xmlAllocOutputBuffer(encoder); ret = xmlAllocOutputBuffer(encoder);
@ -2280,7 +2285,7 @@ xmlOutputBufferCreateFilename(const char *URI,
*/ */
if (context == NULL) { if (context == NULL) {
#ifdef HAVE_ZLIB_H #ifdef HAVE_ZLIB_H
if ((compression > 0) && (compression <= 9) && (is_http_uri == 0)) { if ((compression > 0) && (compression <= 9) && (is_file_uri == 1)) {
context = xmlGzfileOpenW(URI, compression); context = xmlGzfileOpenW(URI, compression);
if (context != NULL) { if (context != NULL) {
ret = xmlAllocOutputBuffer(encoder); ret = xmlAllocOutputBuffer(encoder);