[libxml2] Null pointer handling in catalog.c



commit d724861536f3cfb82750176aa45e655634bbbbcc
Author: raniervf <ranier_gyn hotmail com>
Date:   Mon Nov 4 23:19:28 2019 -0300

    Null pointer handling in catalog.c
    
    Fix potential deferencing potential null pointers;
    Small optimizations.
    
    Closes #123.

 catalog.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
---
diff --git a/catalog.c b/catalog.c
index 7328fd31..b471e8a8 100644
--- a/catalog.c
+++ b/catalog.c
@@ -924,7 +924,7 @@ xmlParseCatalogFile(const char *filename) {
     xmlBufResetInput(buf->buffer, inputStream);
 
     inputPush(ctxt, inputStream);
-    if ((ctxt->directory == NULL) && (directory == NULL))
+    if (ctxt->directory == NULL)
         directory = xmlParserGetDirectory(filename);
     if ((ctxt->directory == NULL) && (directory != NULL))
         ctxt->directory = directory;
@@ -2069,8 +2069,7 @@ xmlCatalogListXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID,
                ret = xmlCatalogXMLResolve(catal->children, pubID, sysID);
                if (ret != NULL) {
                    break;
-                } else if ((catal->children != NULL) &&
-                          (catal->children->depth > MAX_CATAL_DEPTH)) {
+                } else if (catal->children->depth > MAX_CATAL_DEPTH) {
                    ret = NULL;
                    break;
                }
@@ -2353,7 +2352,7 @@ xmlParseSGMLCatalog(xmlCatalogPtr catal, const xmlChar *value,
            xmlCatalogEntryType type = XML_CATA_NONE;
 
            cur = xmlParseSGMLCatalogName(cur, &name);
-           if (name == NULL) {
+           if (cur == NULL || name == NULL) {
                /* error */
                break;
            }
@@ -3254,6 +3253,7 @@ xmlLoadCatalogs(const char *pathss) {
            while ((*cur != 0) && (*cur != PATH_SEPARATOR) && (!xmlIsBlank_ch(*cur)))
                cur++;
            path = xmlStrndup((const xmlChar *)paths, cur - paths);
+           if (path != NULL) {
 #ifdef _WIN32
         iLen = strlen((const char*)path);
         for(i = 0; i < iLen; i++) {
@@ -3262,7 +3262,6 @@ xmlLoadCatalogs(const char *pathss) {
             }
         }
 #endif
-           if (path != NULL) {
                xmlLoadCatalog((const char *) path);
                xmlFree(path);
            }
@@ -3427,9 +3426,10 @@ xmlCatalogAdd(const xmlChar *type, const xmlChar *orig, const xmlChar *replace)
        (xmlStrEqual(type, BAD_CAST "catalog"))) {
        xmlDefaultCatalog = xmlCreateNewCatalog(XML_XML_CATALOG_TYPE,
                                          xmlCatalogDefaultPrefer);
-       xmlDefaultCatalog->xml = xmlNewCatalogEntry(XML_CATA_CATALOG, NULL,
+       if (xmlDefaultCatalog != NULL) {
+          xmlDefaultCatalog->xml = xmlNewCatalogEntry(XML_CATA_CATALOG, NULL,
                                    orig, NULL,  xmlCatalogDefaultPrefer, NULL);
-
+       }
        xmlRMutexUnlock(xmlCatalogMutex);
        return(0);
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]