Diff for /embedaddon/libxml2/uri.c between versions 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2013/07/22 01:22:20 version 1.1.1.3, 2014/06/15 19:53:31
Line 1 Line 1
 /**  /**
 * uri.c: set of generic URI related routines  * uri.c: set of generic URI related routines
  *   *
  * Reference: RFCs 3986, 2732 and 2373   * Reference: RFCs 3986, 2732 and 2373
  *   *
  * See Copyright for the status of this software.   * See Copyright for the status of this software.
  *   *
  * TODO: that module behaves really badly on OOM situation  
  *  
  * daniel@veillard.com   * daniel@veillard.com
  */   */
   
Line 20 Line 18
 #include <libxml/globals.h>  #include <libxml/globals.h>
 #include <libxml/xmlerror.h>  #include <libxml/xmlerror.h>
   
   /**
    * MAX_URI_LENGTH:
    *
    * The definition of the URI regexp in the above RFC has no size limit
    * In practice they are usually relativey short except for the
    * data URI scheme as defined in RFC 2397. Even for data URI the usual
    * maximum size before hitting random practical limits is around 64 KB
    * and 4KB is usually a maximum admitted limit for proper operations.
    * The value below is more a security limit than anything else and
    * really should never be hit by 'normal' operations
    * Set to 1 MByte in 2012, this is only enforced on output
    */
   #define MAX_URI_LENGTH 1024 * 1024
   
   static void
   xmlURIErrMemory(const char *extra)
   {
       if (extra)
           __xmlRaiseError(NULL, NULL, NULL,
                           NULL, NULL, XML_FROM_URI,
                           XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0,
                           extra, NULL, NULL, 0, 0,
                           "Memory allocation failed : %s\n", extra);
       else
           __xmlRaiseError(NULL, NULL, NULL,
                           NULL, NULL, XML_FROM_URI,
                           XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0,
                           NULL, NULL, NULL, 0, 0,
                           "Memory allocation failed\n");
   }
   
 static void xmlCleanURI(xmlURIPtr uri);  static void xmlCleanURI(xmlURIPtr uri);
   
 /*  /*
Line 982  xmlCreateURI(void) { Line 1011  xmlCreateURI(void) {
   
     ret = (xmlURIPtr) xmlMalloc(sizeof(xmlURI));      ret = (xmlURIPtr) xmlMalloc(sizeof(xmlURI));
     if (ret == NULL) {      if (ret == NULL) {
        xmlGenericError(xmlGenericErrorContext,        xmlURIErrMemory("creating URI structure\n");
                "xmlCreateURI: out of memory\n"); 
         return(NULL);          return(NULL);
     }      }
     memset(ret, 0, sizeof(xmlURI));      memset(ret, 0, sizeof(xmlURI));
Line 991  xmlCreateURI(void) { Line 1019  xmlCreateURI(void) {
 }  }
   
 /**  /**
    * xmlSaveUriRealloc:
    *
    * Function to handle properly a reallocation when saving an URI
    * Also imposes some limit on the length of an URI string output
    */
   static xmlChar *
   xmlSaveUriRealloc(xmlChar *ret, int *max) {
       xmlChar *temp;
       int tmp;
   
       if (*max > MAX_URI_LENGTH) {
           xmlURIErrMemory("reaching arbitrary MAX_URI_LENGTH limit\n");
           return(NULL);
       }
       tmp = *max * 2;
       temp = (xmlChar *) xmlRealloc(ret, (tmp + 1));
       if (temp == NULL) {
           xmlURIErrMemory("saving URI\n");
           return(NULL);
       }
       *max = tmp;
       return(temp);
   }
   
   /**
  * xmlSaveUri:   * xmlSaveUri:
  * @uri:  pointer to an xmlURI   * @uri:  pointer to an xmlURI
  *   *
Line 1012  xmlSaveUri(xmlURIPtr uri) { Line 1065  xmlSaveUri(xmlURIPtr uri) {
     max = 80;      max = 80;
     ret = (xmlChar *) xmlMallocAtomic((max + 1) * sizeof(xmlChar));      ret = (xmlChar *) xmlMallocAtomic((max + 1) * sizeof(xmlChar));
     if (ret == NULL) {      if (ret == NULL) {
        xmlGenericError(xmlGenericErrorContext,        xmlURIErrMemory("saving URI\n");
                "xmlSaveUri: out of memory\n"); 
         return(NULL);          return(NULL);
     }      }
     len = 0;      len = 0;
Line 1022  xmlSaveUri(xmlURIPtr uri) { Line 1074  xmlSaveUri(xmlURIPtr uri) {
         p = uri->scheme;          p = uri->scheme;
         while (*p != 0) {          while (*p != 0) {
             if (len >= max) {              if (len >= max) {
                max *= 2;                temp = xmlSaveUriRealloc(ret, &max);
                temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));                if (temp == NULL) goto mem_error;
                if (temp == NULL) { 
                    xmlGenericError(xmlGenericErrorContext, 
                            "xmlSaveUri: out of memory\n"); 
                    xmlFree(ret); 
                    return(NULL); 
                } 
                 ret = temp;                  ret = temp;
             }              }
             ret[len++] = *p++;              ret[len++] = *p++;
         }          }
         if (len >= max) {          if (len >= max) {
            max *= 2;            temp = xmlSaveUriRealloc(ret, &max);
            temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));            if (temp == NULL) goto mem_error;
            if (temp == NULL) {            ret = temp;
                xmlGenericError(xmlGenericErrorContext, 
                        "xmlSaveUri: out of memory\n"); 
                xmlFree(ret); 
                return(NULL); 
            } 
            ret = temp; 
         }          }
         ret[len++] = ':';          ret[len++] = ':';
     }      }
Line 1051  xmlSaveUri(xmlURIPtr uri) { Line 1091  xmlSaveUri(xmlURIPtr uri) {
         p = uri->opaque;          p = uri->opaque;
         while (*p != 0) {          while (*p != 0) {
             if (len + 3 >= max) {              if (len + 3 >= max) {
                max *= 2;                temp = xmlSaveUriRealloc(ret, &max);
                temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));                if (temp == NULL) goto mem_error;
                if (temp == NULL) {                ret = temp;
                    xmlGenericError(xmlGenericErrorContext, 
                            "xmlSaveUri: out of memory\n"); 
                    xmlFree(ret); 
                    return(NULL); 
                } 
                ret = temp; 
             }              }
             if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p)))              if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p)))
                 ret[len++] = *p++;                  ret[len++] = *p++;
Line 1074  xmlSaveUri(xmlURIPtr uri) { Line 1108  xmlSaveUri(xmlURIPtr uri) {
     } else {      } else {
         if (uri->server != NULL) {          if (uri->server != NULL) {
             if (len + 3 >= max) {              if (len + 3 >= max) {
                max *= 2;                temp = xmlSaveUriRealloc(ret, &max);
                temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));                if (temp == NULL) goto mem_error;
                if (temp == NULL) {                ret = temp;
                    xmlGenericError(xmlGenericErrorContext, 
                            "xmlSaveUri: out of memory\n"); 
                  xmlFree(ret);   
                    return(NULL); 
                } 
                ret = temp; 
             }              }
             ret[len++] = '/';              ret[len++] = '/';
             ret[len++] = '/';              ret[len++] = '/';
Line 1090  xmlSaveUri(xmlURIPtr uri) { Line 1118  xmlSaveUri(xmlURIPtr uri) {
                 p = uri->user;                  p = uri->user;
                 while (*p != 0) {                  while (*p != 0) {
                     if (len + 3 >= max) {                      if (len + 3 >= max) {
                        max *= 2;                        temp = xmlSaveUriRealloc(ret, &max);
                        temp = (xmlChar *) xmlRealloc(ret,                        if (temp == NULL) goto mem_error;
                                (max + 1) * sizeof(xmlChar));                        ret = temp;
                        if (temp == NULL) { 
                            xmlGenericError(xmlGenericErrorContext, 
                                    "xmlSaveUri: out of memory\n"); 
                            xmlFree(ret); 
                            return(NULL); 
                        } 
                        ret = temp; 
                     }                      }
                     if ((IS_UNRESERVED(*(p))) ||                      if ((IS_UNRESERVED(*(p))) ||
                         ((*(p) == ';')) || ((*(p) == ':')) ||                          ((*(p) == ';')) || ((*(p) == ':')) ||
Line 1116  xmlSaveUri(xmlURIPtr uri) { Line 1137  xmlSaveUri(xmlURIPtr uri) {
                     }                      }
                 }                  }
                 if (len + 3 >= max) {                  if (len + 3 >= max) {
                    max *= 2;                    temp = xmlSaveUriRealloc(ret, &max);
                    temp = (xmlChar *) xmlRealloc(ret,                    if (temp == NULL) goto mem_error;
                            (max + 1) * sizeof(xmlChar));                    ret = temp;
                    if (temp == NULL) { 
                        xmlGenericError(xmlGenericErrorContext, 
                                "xmlSaveUri: out of memory\n"); 
                        xmlFree(ret); 
                        return(NULL); 
                    } 
                    ret = temp; 
                 }                  }
                 ret[len++] = '@';                  ret[len++] = '@';
             }              }
             p = uri->server;              p = uri->server;
             while (*p != 0) {              while (*p != 0) {
                 if (len >= max) {                  if (len >= max) {
                    max *= 2;                    temp = xmlSaveUriRealloc(ret, &max);
                    temp = (xmlChar *) xmlRealloc(ret,                    if (temp == NULL) goto mem_error;
                            (max + 1) * sizeof(xmlChar));                    ret = temp;
                    if (temp == NULL) { 
                        xmlGenericError(xmlGenericErrorContext, 
                                "xmlSaveUri: out of memory\n"); 
                        xmlFree(ret); 
                        return(NULL); 
                    } 
                    ret = temp; 
                 }                  }
                 ret[len++] = *p++;                  ret[len++] = *p++;
             }              }
             if (uri->port > 0) {              if (uri->port > 0) {
                 if (len + 10 >= max) {                  if (len + 10 >= max) {
                    max *= 2;                    temp = xmlSaveUriRealloc(ret, &max);
                    temp = (xmlChar *) xmlRealloc(ret,                    if (temp == NULL) goto mem_error;
                            (max + 1) * sizeof(xmlChar));                    ret = temp;
                    if (temp == NULL) { 
                        xmlGenericError(xmlGenericErrorContext, 
                                "xmlSaveUri: out of memory\n"); 
                     xmlFree(ret); 
                        return(NULL); 
                    } 
                    ret = temp; 
                 }                  }
                 len += snprintf((char *) &ret[len], max - len, ":%d", uri->port);                  len += snprintf((char *) &ret[len], max - len, ":%d", uri->port);
             }              }
         } else if (uri->authority != NULL) {          } else if (uri->authority != NULL) {
             if (len + 3 >= max) {              if (len + 3 >= max) {
                max *= 2;                temp = xmlSaveUriRealloc(ret, &max);
                temp = (xmlChar *) xmlRealloc(ret,                if (temp == NULL) goto mem_error;
                        (max + 1) * sizeof(xmlChar));                ret = temp;
                if (temp == NULL) { 
                        xmlGenericError(xmlGenericErrorContext, 
                                "xmlSaveUri: out of memory\n"); 
                     xmlFree(ret); 
                        return(NULL); 
                    } 
                    ret = temp; 
             }              }
             ret[len++] = '/';              ret[len++] = '/';
             ret[len++] = '/';              ret[len++] = '/';
             p = uri->authority;              p = uri->authority;
             while (*p != 0) {              while (*p != 0) {
                 if (len + 3 >= max) {                  if (len + 3 >= max) {
                    max *= 2;                    temp = xmlSaveUriRealloc(ret, &max);
                    temp = (xmlChar *) xmlRealloc(ret,                    if (temp == NULL) goto mem_error;
                            (max + 1) * sizeof(xmlChar));                    ret = temp;
                    if (temp == NULL) { 
                        xmlGenericError(xmlGenericErrorContext, 
                                "xmlSaveUri: out of memory\n"); 
                     xmlFree(ret); 
                        return(NULL); 
                    } 
                    ret = temp; 
                 }                  }
                 if ((IS_UNRESERVED(*(p))) ||                  if ((IS_UNRESERVED(*(p))) ||
                     ((*(p) == '$')) || ((*(p) == ',')) || ((*(p) == ';')) ||                      ((*(p) == '$')) || ((*(p) == ',')) || ((*(p) == ';')) ||
Line 1204  xmlSaveUri(xmlURIPtr uri) { Line 1190  xmlSaveUri(xmlURIPtr uri) {
             }              }
         } else if (uri->scheme != NULL) {          } else if (uri->scheme != NULL) {
             if (len + 3 >= max) {              if (len + 3 >= max) {
                max *= 2;                temp = xmlSaveUriRealloc(ret, &max);
                temp = (xmlChar *) xmlRealloc(ret,                if (temp == NULL) goto mem_error;
                        (max + 1) * sizeof(xmlChar));                ret = temp;
                if (temp == NULL) { 
                        xmlGenericError(xmlGenericErrorContext, 
                                "xmlSaveUri: out of memory\n"); 
                     xmlFree(ret); 
                        return(NULL); 
                    } 
                    ret = temp; 
             }              }
             ret[len++] = '/';              ret[len++] = '/';
             ret[len++] = '/';              ret[len++] = '/';
Line 1231  xmlSaveUri(xmlURIPtr uri) { Line 1210  xmlSaveUri(xmlURIPtr uri) {
                 (p[2] == ':') &&                  (p[2] == ':') &&
                 (xmlStrEqual(BAD_CAST uri->scheme, BAD_CAST "file"))) {                  (xmlStrEqual(BAD_CAST uri->scheme, BAD_CAST "file"))) {
                 if (len + 3 >= max) {                  if (len + 3 >= max) {
                    max *= 2;                    temp = xmlSaveUriRealloc(ret, &max);
                    ret = (xmlChar *) xmlRealloc(ret,                    if (temp == NULL) goto mem_error;
                            (max + 1) * sizeof(xmlChar));                    ret = temp;
                    if (ret == NULL) { 
                        xmlGenericError(xmlGenericErrorContext, 
                                "xmlSaveUri: out of memory\n"); 
                        return(NULL); 
                    } 
                 }                  }
                 ret[len++] = *p++;                  ret[len++] = *p++;
                 ret[len++] = *p++;                  ret[len++] = *p++;
Line 1246  xmlSaveUri(xmlURIPtr uri) { Line 1220  xmlSaveUri(xmlURIPtr uri) {
             }              }
             while (*p != 0) {              while (*p != 0) {
                 if (len + 3 >= max) {                  if (len + 3 >= max) {
                    max *= 2;                    temp = xmlSaveUriRealloc(ret, &max);
                    temp = (xmlChar *) xmlRealloc(ret,                    if (temp == NULL) goto mem_error;
                            (max + 1) * sizeof(xmlChar));                    ret = temp;
                    if (temp == NULL) { 
                        xmlGenericError(xmlGenericErrorContext, 
                                "xmlSaveUri: out of memory\n"); 
                     xmlFree(ret); 
                        return(NULL); 
                    } 
                    ret = temp; 
                 }                  }
                 if ((IS_UNRESERVED(*(p))) || ((*(p) == '/')) ||                  if ((IS_UNRESERVED(*(p))) || ((*(p) == '/')) ||
                     ((*(p) == ';')) || ((*(p) == '@')) || ((*(p) == '&')) ||                      ((*(p) == ';')) || ((*(p) == '@')) || ((*(p) == '&')) ||
Line 1273  xmlSaveUri(xmlURIPtr uri) { Line 1240  xmlSaveUri(xmlURIPtr uri) {
         }          }
         if (uri->query_raw != NULL) {          if (uri->query_raw != NULL) {
             if (len + 1 >= max) {              if (len + 1 >= max) {
                max *= 2;                temp = xmlSaveUriRealloc(ret, &max);
                temp = (xmlChar *) xmlRealloc(ret,                if (temp == NULL) goto mem_error;
                        (max + 1) * sizeof(xmlChar));                ret = temp;
                if (temp == NULL) { 
                        xmlGenericError(xmlGenericErrorContext, 
                                "xmlSaveUri: out of memory\n"); 
                     xmlFree(ret); 
                        return(NULL); 
                    } 
                    ret = temp; 
             }              }
             ret[len++] = '?';              ret[len++] = '?';
             p = uri->query_raw;              p = uri->query_raw;
             while (*p != 0) {              while (*p != 0) {
                 if (len + 1 >= max) {                  if (len + 1 >= max) {
                    max *= 2;                    temp = xmlSaveUriRealloc(ret, &max);
                    temp = (xmlChar *) xmlRealloc(ret,                    if (temp == NULL) goto mem_error;
                            (max + 1) * sizeof(xmlChar));                    ret = temp;
                    if (temp == NULL) { 
                        xmlGenericError(xmlGenericErrorContext, 
                                "xmlSaveUri: out of memory\n"); 
                     xmlFree(ret); 
                        return(NULL); 
                    } 
                    ret = temp; 
                 }                  }
                 ret[len++] = *p++;                  ret[len++] = *p++;
             }              }
         } else if (uri->query != NULL) {          } else if (uri->query != NULL) {
             if (len + 3 >= max) {              if (len + 3 >= max) {
                max *= 2;                temp = xmlSaveUriRealloc(ret, &max);
                temp = (xmlChar *) xmlRealloc(ret,                if (temp == NULL) goto mem_error;
                        (max + 1) * sizeof(xmlChar));                ret = temp;
                if (temp == NULL) { 
                        xmlGenericError(xmlGenericErrorContext, 
                                "xmlSaveUri: out of memory\n"); 
                     xmlFree(ret); 
                        return(NULL); 
                    } 
                    ret = temp; 
             }              }
             ret[len++] = '?';              ret[len++] = '?';
             p = uri->query;              p = uri->query;
             while (*p != 0) {              while (*p != 0) {
                 if (len + 3 >= max) {                  if (len + 3 >= max) {
                    max *= 2;                    temp = xmlSaveUriRealloc(ret, &max);
                    temp = (xmlChar *) xmlRealloc(ret,                    if (temp == NULL) goto mem_error;
                            (max + 1) * sizeof(xmlChar));                    ret = temp;
                    if (temp == NULL) { 
                        xmlGenericError(xmlGenericErrorContext, 
                                "xmlSaveUri: out of memory\n"); 
                     xmlFree(ret); 
                        return(NULL); 
                    } 
                    ret = temp; 
                 }                  }
                if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))                 if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))
                     ret[len++] = *p++;                      ret[len++] = *p++;
                 else {                  else {
                     int val = *(unsigned char *)p++;                      int val = *(unsigned char *)p++;
Line 1343  xmlSaveUri(xmlURIPtr uri) { Line 1282  xmlSaveUri(xmlURIPtr uri) {
     }      }
     if (uri->fragment != NULL) {      if (uri->fragment != NULL) {
         if (len + 3 >= max) {          if (len + 3 >= max) {
            max *= 2;            temp = xmlSaveUriRealloc(ret, &max);
            temp = (xmlChar *) xmlRealloc(ret,            if (temp == NULL) goto mem_error;
                    (max + 1) * sizeof(xmlChar));            ret = temp;
            if (temp == NULL) { 
                        xmlGenericError(xmlGenericErrorContext, 
                                "xmlSaveUri: out of memory\n"); 
                     xmlFree(ret); 
                        return(NULL); 
                    } 
                    ret = temp; 
         }          }
         ret[len++] = '#';          ret[len++] = '#';
         p = uri->fragment;          p = uri->fragment;
         while (*p != 0) {          while (*p != 0) {
             if (len + 3 >= max) {              if (len + 3 >= max) {
                max *= 2;                temp = xmlSaveUriRealloc(ret, &max);
                temp = (xmlChar *) xmlRealloc(ret,                if (temp == NULL) goto mem_error;
                        (max + 1) * sizeof(xmlChar));                ret = temp;
                if (temp == NULL) { 
                        xmlGenericError(xmlGenericErrorContext, 
                                "xmlSaveUri: out of memory\n"); 
                     xmlFree(ret); 
                        return(NULL); 
                    } 
                    ret = temp; 
             }              }
            if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))             if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p))))
                 ret[len++] = *p++;                  ret[len++] = *p++;
             else {              else {
                 int val = *(unsigned char *)p++;                  int val = *(unsigned char *)p++;
Line 1381  xmlSaveUri(xmlURIPtr uri) { Line 1306  xmlSaveUri(xmlURIPtr uri) {
         }          }
     }      }
     if (len >= max) {      if (len >= max) {
        max *= 2;        temp = xmlSaveUriRealloc(ret, &max);
        temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));        if (temp == NULL) goto mem_error;
        if (temp == NULL) {        ret = temp;
                        xmlGenericError(xmlGenericErrorContext, 
                                "xmlSaveUri: out of memory\n"); 
                     xmlFree(ret); 
                        return(NULL); 
                    } 
                    ret = temp; 
     }      }
     ret[len] = 0;      ret[len] = 0;
     return(ret);      return(ret);
   
   mem_error:
       xmlFree(ret);
       return(NULL);
 }  }
   
 /**  /**
Line 1695  xmlURIUnescapeString(const char *str, int len, char *t Line 1618  xmlURIUnescapeString(const char *str, int len, char *t
     if (target == NULL) {      if (target == NULL) {
         ret = (char *) xmlMallocAtomic(len + 1);          ret = (char *) xmlMallocAtomic(len + 1);
         if (ret == NULL) {          if (ret == NULL) {
            xmlGenericError(xmlGenericErrorContext,            xmlURIErrMemory("unescaping URI value\n");
                    "xmlURIUnescapeString: out of memory\n"); 
             return(NULL);              return(NULL);
         }          }
     } else      } else
Line 1706  xmlURIUnescapeString(const char *str, int len, char *t Line 1628  xmlURIUnescapeString(const char *str, int len, char *t
     while(len > 0) {      while(len > 0) {
         if ((len > 2) && (*in == '%') && (is_hex(in[1])) && (is_hex(in[2]))) {          if ((len > 2) && (*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');
             else if ((*in >= 'a') && (*in <= 'f'))              else if ((*in >= 'a') && (*in <= 'f'))
                 *out = (*in - 'a') + 10;                  *out = (*in - 'a') + 10;
             else if ((*in >= 'A') && (*in <= 'F'))              else if ((*in >= 'A') && (*in <= 'F'))
                 *out = (*in - 'A') + 10;                  *out = (*in - 'A') + 10;
             in++;              in++;
            if ((*in >= '0') && (*in <= '9'))             if ((*in >= '0') && (*in <= '9'))
                 *out = *out * 16 + (*in - '0');                  *out = *out * 16 + (*in - '0');
             else if ((*in >= 'a') && (*in <= 'f'))              else if ((*in >= 'a') && (*in <= 'f'))
                 *out = *out * 16 + (*in - 'a') + 10;                  *out = *out * 16 + (*in - 'a') + 10;
Line 1746  xmlURIEscapeStr(const xmlChar *str, const xmlChar *lis Line 1668  xmlURIEscapeStr(const xmlChar *str, const xmlChar *lis
     xmlChar *ret, ch;      xmlChar *ret, ch;
     xmlChar *temp;      xmlChar *temp;
     const xmlChar *in;      const xmlChar *in;
       int len, out;
   
     unsigned int len, out;  
   
     if (str == NULL)      if (str == NULL)
         return(NULL);          return(NULL);
     if (str[0] == 0)      if (str[0] == 0)
Line 1759  xmlURIEscapeStr(const xmlChar *str, const xmlChar *lis Line 1680  xmlURIEscapeStr(const xmlChar *str, const xmlChar *lis
     len += 20;      len += 20;
     ret = (xmlChar *) xmlMallocAtomic(len);      ret = (xmlChar *) xmlMallocAtomic(len);
     if (ret == NULL) {      if (ret == NULL) {
        xmlGenericError(xmlGenericErrorContext,        xmlURIErrMemory("escaping URI value\n");
                "xmlURIEscapeStr: out of memory\n"); 
         return(NULL);          return(NULL);
     }      }
     in = (const xmlChar *) str;      in = (const xmlChar *) str;
     out = 0;      out = 0;
     while(*in != 0) {      while(*in != 0) {
         if (len - out <= 3) {          if (len - out <= 3) {
            len += 20;            temp = xmlSaveUriRealloc(ret, &len);
            temp = (xmlChar *) xmlRealloc(ret, len); 
             if (temp == NULL) {              if (temp == NULL) {
                xmlGenericError(xmlGenericErrorContext,                xmlURIErrMemory("escaping URI value\n");
                        "xmlURIEscapeStr: out of memory\n"); 
                 xmlFree(ret);                  xmlFree(ret);
                 return(NULL);                  return(NULL);
             }              }
Line 1826  xmlURIEscape(const xmlChar * str) Line 1744  xmlURIEscape(const xmlChar * str)
     int ret2;      int ret2;
   
 #define NULLCHK(p) if(!p) { \  #define NULLCHK(p) if(!p) { \
                   xmlGenericError(xmlGenericErrorContext, \         xmlURIErrMemory("escaping URI value\n"); \
                        "xmlURIEscape: out of memory\n"); \         xmlFreeURI(uri); \
                        xmlFreeURI(uri); \         return NULL; } \
                        return NULL; } \ 
   
     if (str == NULL)      if (str == NULL)
         return (NULL);          return (NULL);
Line 1872  xmlURIEscape(const xmlChar * str) Line 1789  xmlURIEscape(const xmlChar * str)
     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)
                ret = xmlStrcat(ret,BAD_CAST "//");                     ret = xmlStrcat(ret,BAD_CAST "//");
         ret = xmlStrcat(ret, segment);          ret = xmlStrcat(ret, segment);
         ret = xmlStrcat(ret, BAD_CAST "@");          ret = xmlStrcat(ret, BAD_CAST "@");
         xmlFree(segment);          xmlFree(segment);
Line 1950  xmlURIEscape(const xmlChar * str) Line 1867  xmlURIEscape(const xmlChar * str)
  *   *
  * Computes he final URI of the reference done by checking that   * Computes he final URI of the reference done by checking that
  * the given URI is valid, and building the final URI using the   * the given URI is valid, and building the final URI using the
 * base URI. This is processed according to section 5.2 of the  * base URI. This is processed according to section 5.2 of the
  * RFC 2396   * RFC 2396
  *   *
  * 5.2. Resolving Relative References to Absolute Form   * 5.2. Resolving Relative References to Absolute Form
Line 1974  xmlBuildURI(const xmlChar *URI, const xmlChar *base) { Line 1891  xmlBuildURI(const xmlChar *URI, const xmlChar *base) {
      *    as a reference to "." rather than as a synonym for the current       *    as a reference to "." rather than as a synonym for the current
      *    URI.  Should we do that here?       *    URI.  Should we do that here?
      */       */
    if (URI == NULL)     if (URI == NULL)
         ret = -1;          ret = -1;
     else {      else {
         if (*URI) {          if (*URI) {
Line 2045  xmlBuildURI(const xmlChar *URI, const xmlChar *base) { Line 1962  xmlBuildURI(const xmlChar *URI, const xmlChar *base) {
             res->server = xmlMemStrdup(bas->server);              res->server = xmlMemStrdup(bas->server);
             if (bas->user != NULL)              if (bas->user != NULL)
                 res->user = xmlMemStrdup(bas->user);                  res->user = xmlMemStrdup(bas->user);
            res->port = bas->port;                          res->port = bas->port;
         }          }
         if (bas->path != NULL)          if (bas->path != NULL)
             res->path = xmlMemStrdup(bas->path);              res->path = xmlMemStrdup(bas->path);
Line 2074  xmlBuildURI(const xmlChar *URI, const xmlChar *base) { Line 1991  xmlBuildURI(const xmlChar *URI, const xmlChar *base) {
     }      }
     if (bas->scheme != NULL)      if (bas->scheme != NULL)
         res->scheme = xmlMemStrdup(bas->scheme);          res->scheme = xmlMemStrdup(bas->scheme);
 
     if (ref->query_raw != NULL)      if (ref->query_raw != NULL)
         res->query_raw = xmlMemStrdup(ref->query_raw);          res->query_raw = xmlMemStrdup(ref->query_raw);
     else if (ref->query != NULL)      else if (ref->query != NULL)
Line 2096  xmlBuildURI(const xmlChar *URI, const xmlChar *base) { Line 2013  xmlBuildURI(const xmlChar *URI, const xmlChar *base) {
             res->server = xmlMemStrdup(ref->server);              res->server = xmlMemStrdup(ref->server);
             if (ref->user != NULL)              if (ref->user != NULL)
                 res->user = xmlMemStrdup(ref->user);                  res->user = xmlMemStrdup(ref->user);
            res->port = ref->port;                          res->port = ref->port;
         }          }
         if (ref->path != NULL)          if (ref->path != NULL)
             res->path = xmlMemStrdup(ref->path);              res->path = xmlMemStrdup(ref->path);
Line 2108  xmlBuildURI(const xmlChar *URI, const xmlChar *base) { Line 2025  xmlBuildURI(const xmlChar *URI, const xmlChar *base) {
         res->server = xmlMemStrdup(bas->server);          res->server = xmlMemStrdup(bas->server);
         if (bas->user != NULL)          if (bas->user != NULL)
             res->user = xmlMemStrdup(bas->user);              res->user = xmlMemStrdup(bas->user);
        res->port = bas->port;                  res->port = bas->port;
     }      }
   
     /*      /*
Line 2136  xmlBuildURI(const xmlChar *URI, const xmlChar *base) { Line 2053  xmlBuildURI(const xmlChar *URI, const xmlChar *base) {
         len += strlen(bas->path);          len += strlen(bas->path);
     res->path = (char *) xmlMallocAtomic(len);      res->path = (char *) xmlMallocAtomic(len);
     if (res->path == NULL) {      if (res->path == NULL) {
        xmlGenericError(xmlGenericErrorContext,        xmlURIErrMemory("resolving URI against base\n");
                "xmlBuildURI: out of memory\n"); 
         goto done;          goto done;
     }      }
     res->path[0] = 0;      res->path[0] = 0;
Line 2383  xmlBuildRelativeURI (const xmlChar * URI, const xmlCha Line 2299  xmlBuildRelativeURI (const xmlChar * URI, const xmlCha
         }          }
         len = xmlStrlen (uptr) + 1;          len = xmlStrlen (uptr) + 1;
     }      }
    
     if (nbslash == 0) {      if (nbslash == 0) {
         if (uptr != NULL)          if (uptr != NULL)
             /* exception characters from xmlSaveUri */              /* exception characters from xmlSaveUri */
Line 2398  xmlBuildRelativeURI (const xmlChar * URI, const xmlCha Line 2314  xmlBuildRelativeURI (const xmlChar * URI, const xmlCha
      */       */
     val = (xmlChar *) xmlMalloc (len + 3 * nbslash);      val = (xmlChar *) xmlMalloc (len + 3 * nbslash);
     if (val == NULL) {      if (val == NULL) {
        xmlGenericError(xmlGenericErrorContext,        xmlURIErrMemory("building relative URI\n");
                "xmlBuildRelativeURI: out of memory\n"); 
         goto done;          goto done;
     }      }
     vptr = val;      vptr = val;
Line 2451  done: Line 2366  done:
  * xmlCanonicPath:   * xmlCanonicPath:
  * @path:  the resource locator in a filesystem notation   * @path:  the resource locator in a filesystem notation
  *   *
 * Constructs a canonic path from the specified path.  * Constructs a canonic path from the specified path.
  *   *
 * Returns a new canonic path, or a duplicate of the path parameter if the  * Returns a new canonic path, or a duplicate of the path parameter if the
  * construction fails. The caller is responsible for freeing the memory occupied   * construction fails. The caller is responsible for freeing the memory occupied
 * by the returned string. If there is insufficient memory available, or the  * by the returned string. If there is insufficient memory available, or the
  * argument is NULL, the function returns NULL.   * argument is NULL, the function returns NULL.
  */   */
#define IS_WINDOWS_PATH(p)                                      \#define IS_WINDOWS_PATH(p)                                      \
         ((p != NULL) &&                                         \          ((p != NULL) &&                                         \
          (((p[0] >= 'a') && (p[0] <= 'z')) ||                   \           (((p[0] >= 'a') && (p[0] <= 'z')) ||                   \
           ((p[0] >= 'A') && (p[0] <= 'Z'))) &&                  \            ((p[0] >= 'A') && (p[0] <= 'Z'))) &&                  \
Line 2470  xmlCanonicPath(const xmlChar *path) Line 2385  xmlCanonicPath(const xmlChar *path)
  * For Windows implementations, additional work needs to be done to   * For Windows implementations, additional work needs to be done to
  * replace backslashes in pathnames with "forward slashes"   * replace backslashes in pathnames with "forward slashes"
  */   */
#if defined(_WIN32) && !defined(__CYGWIN__)    #if defined(_WIN32) && !defined(__CYGWIN__)
     int len = 0;      int len = 0;
     int i = 0;      int i = 0;
     xmlChar *p = NULL;      xmlChar *p = NULL;
Line 2482  xmlCanonicPath(const xmlChar *path) Line 2397  xmlCanonicPath(const xmlChar *path)
     if (path == NULL)      if (path == NULL)
         return(NULL);          return(NULL);
   
    /* sanitize filename starting with // so it can be used as URI */#if defined(_WIN32)
     /*
      * We must not change the backslashes to slashes if the the path
      * starts with \\?\
      * Those paths can be up to 32k characters long.
      * Was added specifically for OpenOffice, those paths can't be converted
      * to URIs anyway.
      */
     if ((path[0] == '\\') && (path[1] == '\\') && (path[2] == '?') &&
         (path[3] == '\\') )
         return xmlStrdup((const xmlChar *) path);
 #endif
 
         /* sanitize filename starting with // so it can be used as URI */
     if ((path[0] == '/') && (path[1] == '/') && (path[2] != '/'))      if ((path[0] == '/') && (path[1] == '/') && (path[2] != '/'))
         path++;          path++;
   
Line 2529  xmlCanonicPath(const xmlChar *path) Line 2457  xmlCanonicPath(const xmlChar *path)
   
 path_processing:  path_processing:
 /* For Windows implementations, replace backslashes with 'forward slashes' */  /* For Windows implementations, replace backslashes with 'forward slashes' */
#if defined(_WIN32) && !defined(__CYGWIN__)    #if defined(_WIN32) && !defined(__CYGWIN__)
     /*      /*
      * Create a URI structure       * Create a URI structure
      */       */
Line 2586  path_processing: Line 2514  path_processing:
  *   *
  * Constructs an URI expressing the existing path   * Constructs an URI expressing the existing path
  *   *
 * Returns a new URI, or a duplicate of the path parameter if the  * Returns a new URI, or a duplicate of the path parameter if the
  * construction fails. The caller is responsible for freeing the memory   * construction fails. The caller is responsible for freeing the memory
  * occupied by the returned string. If there is insufficient memory available,   * occupied by the returned string. If there is insufficient memory available,
  * or the argument is NULL, the function returns NULL.   * or the argument is NULL, the function returns NULL.
Line 2609  xmlPathToURI(const xmlChar *path) Line 2537  xmlPathToURI(const xmlChar *path)
     if (cal == NULL)      if (cal == NULL)
         return(NULL);          return(NULL);
 #if defined(_WIN32) && !defined(__CYGWIN__)  #if defined(_WIN32) && !defined(__CYGWIN__)
    /* xmlCanonicPath can return an URI on Windows (is that the intended behaviour?)     /* xmlCanonicPath can return an URI on Windows (is that the intended behaviour?)
        If 'cal' is a valid URI allready then we are done here, as continuing would make         If 'cal' is a valid URI allready then we are done here, as continuing would make
        it invalid. */         it invalid. */
     if ((uri = xmlParseURI((const char *) cal)) != NULL) {      if ((uri = xmlParseURI((const char *) cal)) != NULL) {

Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>