Hi,

  I am attaching a patch for some places where realloc is being done on the
original pointer, in case of re-alloc failure this would lead to problems.

 

Regards

Ashwin

*** uri.c       2008-04-24 08:33:58.099843208 -0700
--- urifix.c    2008-04-24 08:33:59.546623264 -0700
*************** xmlCreateURI(void) {
*** 225,230 ****
--- 225,231 ----
  xmlChar *
  xmlSaveUri(xmlURIPtr uri) {
      xmlChar *ret = NULL;
+     xmlChar *temp;
      const char *p;
      int len;
      int max;
*************** xmlSaveUri(xmlURIPtr uri) {
*** 246,268 ****
        while (*p != 0) {
            if (len >= max) {
                max *= 2;
!               ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
!               if (ret == NULL) {
                    xmlGenericError(xmlGenericErrorContext,
                            "xmlSaveUri: out of memory\n");
                    return(NULL);
                }
            }
            ret[len++] = *p++;
        }
        if (len >= max) {
            max *= 2;
!           ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
!           if (ret == NULL) {
                xmlGenericError(xmlGenericErrorContext,
                        "xmlSaveUri: out of memory\n");
                return(NULL);
            }
        }
        ret[len++] = ':';
      }
--- 247,273 ----
        while (*p != 0) {
            if (len >= max) {
                max *= 2;
!               temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
!               if (temp == NULL) {
                    xmlGenericError(xmlGenericErrorContext,
                            "xmlSaveUri: out of memory\n");
+                   xmlFree(ret);
                    return(NULL);
                }
+               ret = temp;
            }
            ret[len++] = *p++;
        }
        if (len >= max) {
            max *= 2;
!           temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
!           if (temp == NULL) {
                xmlGenericError(xmlGenericErrorContext,
                        "xmlSaveUri: out of memory\n");
+               xmlFree(ret);
                return(NULL);
            }
+           ret = temp;
        }
        ret[len++] = ':';
      }
*************** xmlSaveUri(xmlURIPtr uri) {
*** 271,282 ****
        while (*p != 0) {
            if (len + 3 >= max) {
                max *= 2;
!               ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
!               if (ret == NULL) {
                    xmlGenericError(xmlGenericErrorContext,
                            "xmlSaveUri: out of memory\n");
                    return(NULL);
                }
            }
            if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p)))
                ret[len++] = *p++;
--- 276,289 ----
        while (*p != 0) {
            if (len + 3 >= max) {
                max *= 2;
!               temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
!               if (temp == NULL) {
                    xmlGenericError(xmlGenericErrorContext,
                            "xmlSaveUri: out of memory\n");
+                   xmlFree(ret);
                    return(NULL);
                }
+               ret = temp;
            }
            if (IS_RESERVED(*(p)) || IS_UNRESERVED(*(p)))
                ret[len++] = *p++;
*************** xmlSaveUri(xmlURIPtr uri) {
*** 292,303 ****
        if (uri->server != NULL) {
            if (len + 3 >= max) {
                max *= 2;
!               ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
!               if (ret == NULL) {
                    xmlGenericError(xmlGenericErrorContext,
                            "xmlSaveUri: out of memory\n");
                    return(NULL);
                }
            }
            ret[len++] = '/';
            ret[len++] = '/';
--- 299,312 ----
        if (uri->server != NULL) {
            if (len + 3 >= max) {
                max *= 2;
!               temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
!               if (temp == NULL) {
                    xmlGenericError(xmlGenericErrorContext,
                            "xmlSaveUri: out of memory\n");
+                   xmlFree(ret);  
                    return(NULL);
                }
+               ret = temp;
            }
            ret[len++] = '/';
            ret[len++] = '/';
*************** xmlSaveUri(xmlURIPtr uri) {
*** 306,318 ****
                while (*p != 0) {
                    if (len + 3 >= max) {
                        max *= 2;
!                       ret = (xmlChar *) xmlRealloc(ret,
                                (max + 1) * sizeof(xmlChar));
!                       if (ret == NULL) {
                            xmlGenericError(xmlGenericErrorContext,
                                    "xmlSaveUri: out of memory\n");
                            return(NULL);
                        }
                    }
                    if ((IS_UNRESERVED(*(p))) ||
                        ((*(p) == ';')) || ((*(p) == ':')) ||
--- 315,329 ----
                while (*p != 0) {
                    if (len + 3 >= max) {
                        max *= 2;
!                       temp = (xmlChar *) xmlRealloc(ret,
                                (max + 1) * sizeof(xmlChar));
!                       if (temp == NULL) {
                            xmlGenericError(xmlGenericErrorContext,
                                    "xmlSaveUri: out of memory\n");
+                           xmlFree(ret);
                            return(NULL);
                        }
+                       ret = temp;
                    }
                    if ((IS_UNRESERVED(*(p))) ||
                        ((*(p) == ';')) || ((*(p) == ':')) ||
*************** xmlSaveUri(xmlURIPtr uri) {
*** 330,342 ****
                }
                if (len + 3 >= max) {
                    max *= 2;
!                   ret = (xmlChar *) xmlRealloc(ret,
                            (max + 1) * sizeof(xmlChar));
!                   if (ret == NULL) {
                        xmlGenericError(xmlGenericErrorContext,
                                "xmlSaveUri: out of memory\n");
                        return(NULL);
                    }
                }
                ret[len++] = '@';
            }
--- 341,355 ----
                }
                if (len + 3 >= max) {
                    max *= 2;
!                   temp = (xmlChar *) xmlRealloc(ret,
                            (max + 1) * sizeof(xmlChar));
!                   if (temp == NULL) {
                        xmlGenericError(xmlGenericErrorContext,
                                "xmlSaveUri: out of memory\n");
+                       xmlFree(ret);
                        return(NULL);
                    }
+                   ret = temp;
                }
                ret[len++] = '@';
            }
*************** xmlSaveUri(xmlURIPtr uri) {
*** 344,382 ****
            while (*p != 0) {
                if (len >= max) {
                    max *= 2;
!                   ret = (xmlChar *) xmlRealloc(ret,
                            (max + 1) * sizeof(xmlChar));
!                   if (ret == NULL) {
                        xmlGenericError(xmlGenericErrorContext,
                                "xmlSaveUri: out of memory\n");
                        return(NULL);
                    }
                }
                ret[len++] = *p++;
            }
            if (uri->port > 0) {
                if (len + 10 >= max) {
                    max *= 2;
!                   ret = (xmlChar *) xmlRealloc(ret,
                            (max + 1) * sizeof(xmlChar));
!                   if (ret == NULL) {
                        xmlGenericError(xmlGenericErrorContext,
                                "xmlSaveUri: out of memory\n");
                        return(NULL);
                    }
                }
                len += snprintf((char *) &ret[len], max - len, ":%d", 
uri->port);
            }
        } else if (uri->authority != NULL) {
            if (len + 3 >= max) {
                max *= 2;
!               ret = (xmlChar *) xmlRealloc(ret,
                        (max + 1) * sizeof(xmlChar));
!               if (ret == NULL) {
!                   xmlGenericError(xmlGenericErrorContext,
!                           "xmlSaveUri: out of memory\n");
!                   return(NULL);
!               }
            }
            ret[len++] = '/';
            ret[len++] = '/';
--- 357,401 ----
            while (*p != 0) {
                if (len >= max) {
                    max *= 2;
!                   temp = (xmlChar *) xmlRealloc(ret,
                            (max + 1) * sizeof(xmlChar));
!                   if (temp == NULL) {
                        xmlGenericError(xmlGenericErrorContext,
                                "xmlSaveUri: out of memory\n");
+                       xmlFree(ret);
                        return(NULL);
                    }
+                   ret = temp;
                }
                ret[len++] = *p++;
            }
            if (uri->port > 0) {
                if (len + 10 >= max) {
                    max *= 2;
!                   temp = (xmlChar *) xmlRealloc(ret,
                            (max + 1) * sizeof(xmlChar));
!                   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);
            }
        } else if (uri->authority != NULL) {
            if (len + 3 >= max) {
                max *= 2;
!               temp = (xmlChar *) xmlRealloc(ret,
                        (max + 1) * sizeof(xmlChar));
!               if (temp == NULL) {
!                       xmlGenericError(xmlGenericErrorContext,
!                               "xmlSaveUri: out of memory\n");
!                      xmlFree(ret);
!                       return(NULL);
!                   }
!                   ret = temp;
            }
            ret[len++] = '/';
            ret[len++] = '/';
*************** xmlSaveUri(xmlURIPtr uri) {
*** 384,396 ****
            while (*p != 0) {
                if (len + 3 >= max) {
                    max *= 2;
!                   ret = (xmlChar *) xmlRealloc(ret,
                            (max + 1) * sizeof(xmlChar));
!                   if (ret == NULL) {
                        xmlGenericError(xmlGenericErrorContext,
                                "xmlSaveUri: out of memory\n");
                        return(NULL);
                    }
                }
                if ((IS_UNRESERVED(*(p))) ||
                      ((*(p) == '$')) || ((*(p) == ',')) || ((*(p) == ';')) ||
--- 403,417 ----
            while (*p != 0) {
                if (len + 3 >= max) {
                    max *= 2;
!                   temp = (xmlChar *) xmlRealloc(ret,
                            (max + 1) * sizeof(xmlChar));
!                   if (temp == NULL) {
                        xmlGenericError(xmlGenericErrorContext,
                                "xmlSaveUri: out of memory\n");
+                      xmlFree(ret);
                        return(NULL);
                    }
+                   ret = temp;
                }
                if ((IS_UNRESERVED(*(p))) ||
                      ((*(p) == '$')) || ((*(p) == ',')) || ((*(p) == ';')) ||
*************** xmlSaveUri(xmlURIPtr uri) {
*** 408,420 ****
        } else if (uri->scheme != NULL) {
            if (len + 3 >= max) {
                max *= 2;
!               ret = (xmlChar *) xmlRealloc(ret,
                        (max + 1) * sizeof(xmlChar));
!               if (ret == NULL) {
!                   xmlGenericError(xmlGenericErrorContext,
!                           "xmlSaveUri: out of memory\n");
!                   return(NULL);
!               }
            }
            ret[len++] = '/';
            ret[len++] = '/';
--- 429,443 ----
        } else if (uri->scheme != NULL) {
            if (len + 3 >= max) {
                max *= 2;
!               temp = (xmlChar *) xmlRealloc(ret,
                        (max + 1) * sizeof(xmlChar));
!               if (temp == NULL) {
!                       xmlGenericError(xmlGenericErrorContext,
!                               "xmlSaveUri: out of memory\n");
!                      xmlFree(ret);
!                       return(NULL);
!                   }
!                   ret = temp;
            }
            ret[len++] = '/';
            ret[len++] = '/';
*************** xmlSaveUri(xmlURIPtr uri) {
*** 448,460 ****
            while (*p != 0) {
                if (len + 3 >= max) {
                    max *= 2;
!                   ret = (xmlChar *) xmlRealloc(ret,
                            (max + 1) * sizeof(xmlChar));
!                   if (ret == NULL) {
                        xmlGenericError(xmlGenericErrorContext,
                                "xmlSaveUri: out of memory\n");
                        return(NULL);
                    }
                }
                if ((IS_UNRESERVED(*(p))) || ((*(p) == '/')) ||
                      ((*(p) == ';')) || ((*(p) == '@')) || ((*(p) == '&')) ||
--- 471,485 ----
            while (*p != 0) {
                if (len + 3 >= max) {
                    max *= 2;
!                   temp = (xmlChar *) xmlRealloc(ret,
                            (max + 1) * sizeof(xmlChar));
!                   if (temp == NULL) {
                        xmlGenericError(xmlGenericErrorContext,
                                "xmlSaveUri: out of memory\n");
+                      xmlFree(ret);
                        return(NULL);
                    }
+                   ret = temp;
                }
                if ((IS_UNRESERVED(*(p))) || ((*(p) == '/')) ||
                      ((*(p) == ';')) || ((*(p) == '@')) || ((*(p) == '&')) ||
*************** xmlSaveUri(xmlURIPtr uri) {
*** 473,524 ****
        if (uri->query_raw != NULL) {
            if (len + 1 >= max) {
                max *= 2;
!               ret = (xmlChar *) xmlRealloc(ret,
                        (max + 1) * sizeof(xmlChar));
!               if (ret == NULL) {
!                   xmlGenericError(xmlGenericErrorContext,
!                           "xmlSaveUri: out of memory\n");
!                   return(NULL);
!               }
            }
            ret[len++] = '?';
            p = uri->query_raw;
            while (*p != 0) {
                if (len + 1 >= max) {
                    max *= 2;
!                   ret = (xmlChar *) xmlRealloc(ret,
                            (max + 1) * sizeof(xmlChar));
!                   if (ret == NULL) {
                        xmlGenericError(xmlGenericErrorContext,
                                "xmlSaveUri: out of memory\n");
                        return(NULL);
                    }
                }
                ret[len++] = *p++;
            }
        } else if (uri->query != NULL) {
            if (len + 3 >= max) {
                max *= 2;
!               ret = (xmlChar *) xmlRealloc(ret,
                        (max + 1) * sizeof(xmlChar));
!               if (ret == NULL) {
!                   xmlGenericError(xmlGenericErrorContext,
!                           "xmlSaveUri: out of memory\n");
!                   return(NULL);
!               }
            }
            ret[len++] = '?';
            p = uri->query;
            while (*p != 0) {
                if (len + 3 >= max) {
                    max *= 2;
!                   ret = (xmlChar *) xmlRealloc(ret,
                            (max + 1) * sizeof(xmlChar));
!                   if (ret == NULL) {
                        xmlGenericError(xmlGenericErrorContext,
                                "xmlSaveUri: out of memory\n");
                        return(NULL);
                    }
                }
                if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p)))) 
                    ret[len++] = *p++;
--- 498,557 ----
        if (uri->query_raw != NULL) {
            if (len + 1 >= max) {
                max *= 2;
!               temp = (xmlChar *) xmlRealloc(ret,
                        (max + 1) * sizeof(xmlChar));
!               if (temp == NULL) {
!                       xmlGenericError(xmlGenericErrorContext,
!                               "xmlSaveUri: out of memory\n");
!                      xmlFree(ret);
!                       return(NULL);
!                   }
!                   ret = temp;
            }
            ret[len++] = '?';
            p = uri->query_raw;
            while (*p != 0) {
                if (len + 1 >= max) {
                    max *= 2;
!                   temp = (xmlChar *) xmlRealloc(ret,
                            (max + 1) * sizeof(xmlChar));
!                   if (temp == NULL) {
                        xmlGenericError(xmlGenericErrorContext,
                                "xmlSaveUri: out of memory\n");
+                      xmlFree(ret);
                        return(NULL);
                    }
+                   ret = temp;
                }
                ret[len++] = *p++;
            }
        } else if (uri->query != NULL) {
            if (len + 3 >= max) {
                max *= 2;
!               temp = (xmlChar *) xmlRealloc(ret,
                        (max + 1) * sizeof(xmlChar));
!               if (temp == NULL) {
!                       xmlGenericError(xmlGenericErrorContext,
!                               "xmlSaveUri: out of memory\n");
!                      xmlFree(ret);
!                       return(NULL);
!                   }
!                   ret = temp;
            }
            ret[len++] = '?';
            p = uri->query;
            while (*p != 0) {
                if (len + 3 >= max) {
                    max *= 2;
!                   temp = (xmlChar *) xmlRealloc(ret,
                            (max + 1) * sizeof(xmlChar));
!                   if (temp == NULL) {
                        xmlGenericError(xmlGenericErrorContext,
                                "xmlSaveUri: out of memory\n");
+                      xmlFree(ret);
                        return(NULL);
                    }
+                   ret = temp;
                }
                if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p)))) 
                    ret[len++] = *p++;
*************** xmlSaveUri(xmlURIPtr uri) {
*** 535,560 ****
      if (uri->fragment != NULL) {
        if (len + 3 >= max) {
            max *= 2;
!           ret = (xmlChar *) xmlRealloc(ret,
                    (max + 1) * sizeof(xmlChar));
!           if (ret == NULL) {
!               xmlGenericError(xmlGenericErrorContext,
!                       "xmlSaveUri: out of memory\n");
!               return(NULL);
!           }
        }
        ret[len++] = '#';
        p = uri->fragment;
        while (*p != 0) {
            if (len + 3 >= max) {
                max *= 2;
!               ret = (xmlChar *) xmlRealloc(ret,
                        (max + 1) * sizeof(xmlChar));
!               if (ret == NULL) {
!                   xmlGenericError(xmlGenericErrorContext,
!                           "xmlSaveUri: out of memory\n");
!                   return(NULL);
!               }
            }
            if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p)))) 
                ret[len++] = *p++;
--- 568,597 ----
      if (uri->fragment != NULL) {
        if (len + 3 >= max) {
            max *= 2;
!           temp = (xmlChar *) xmlRealloc(ret,
                    (max + 1) * sizeof(xmlChar));
!           if (temp == NULL) {
!                       xmlGenericError(xmlGenericErrorContext,
!                               "xmlSaveUri: out of memory\n");
!                      xmlFree(ret);
!                       return(NULL);
!                   }
!                   ret = temp;
        }
        ret[len++] = '#';
        p = uri->fragment;
        while (*p != 0) {
            if (len + 3 >= max) {
                max *= 2;
!               temp = (xmlChar *) xmlRealloc(ret,
                        (max + 1) * sizeof(xmlChar));
!               if (temp == NULL) {
!                       xmlGenericError(xmlGenericErrorContext,
!                               "xmlSaveUri: out of memory\n");
!                      xmlFree(ret);
!                       return(NULL);
!                   }
!                   ret = temp;
            }
            if ((IS_UNRESERVED(*(p))) || (IS_RESERVED(*(p)))) 
                ret[len++] = *p++;
*************** xmlSaveUri(xmlURIPtr uri) {
*** 569,580 ****
      }
      if (len >= max) {
        max *= 2;
!       ret = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
!       if (ret == NULL) {
!           xmlGenericError(xmlGenericErrorContext,
!                   "xmlSaveUri: out of memory\n");
!           return(NULL);
!       }
      }
      ret[len++] = 0;
      return(ret);
--- 606,619 ----
      }
      if (len >= max) {
        max *= 2;
!       temp = (xmlChar *) xmlRealloc(ret, (max + 1) * sizeof(xmlChar));
!       if (temp == NULL) {
!                       xmlGenericError(xmlGenericErrorContext,
!                               "xmlSaveUri: out of memory\n");
!                      xmlFree(ret);
!                       return(NULL);
!                   }
!                   ret = temp;
      }
      ret[len++] = 0;
      return(ret);
*************** xmlURIUnescapeString(const char *str, in
*** 928,933 ****
--- 967,973 ----
  xmlChar *
  xmlURIEscapeStr(const xmlChar *str, const xmlChar *list) {
      xmlChar *ret, ch;
+     xmlChar *temp;
      const xmlChar *in;
  
      unsigned int len, out;
*************** xmlURIEscapeStr(const xmlChar *str, cons
*** 951,962 ****
      while(*in != 0) {
        if (len - out <= 3) {
            len += 20;
!           ret = (xmlChar *) xmlRealloc(ret, len);
!           if (ret == NULL) {
                xmlGenericError(xmlGenericErrorContext,
                        "xmlURIEscapeStr: out of memory\n");
                return(NULL);
            }
        }
  
        ch = *in;
--- 991,1004 ----
      while(*in != 0) {
        if (len - out <= 3) {
            len += 20;
!           temp = (xmlChar *) xmlRealloc(ret, len);
!           if (temp == NULL) {
                xmlGenericError(xmlGenericErrorContext,
                        "xmlURIEscapeStr: out of memory\n");
+               xmlFree(ret);
                return(NULL);
            }
+           ret = temp;
        }
  
        ch = *in;
*************** xmlURIEscape(const xmlChar * str)
*** 1009,1015 ****
  #define NULLCHK(p) if(!p) { \
                     xmlGenericError(xmlGenericErrorContext, \
                          "xmlURIEscape: out of memory\n"); \
!                    return NULL; }
  
      if (str == NULL)
          return (NULL);
--- 1051,1058 ----
  #define NULLCHK(p) if(!p) { \
                     xmlGenericError(xmlGenericErrorContext, \
                          "xmlURIEscape: out of memory\n"); \
!                         xmlFreeURI(uri); \
!                         return NULL; } \
  
      if (str == NULL)
          return (NULL);
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
[email protected]
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to