Blame SOURCES/CVE-2017-1000061.patch

430364
diff -uPr xmlsec1-1.2.20/apps/xmlsec.c xmlsec1-1.2.20-CVE-2017-1000061/apps/xmlsec.c
430364
--- xmlsec1-1.2.20/apps/xmlsec.c	2017-08-09 12:45:45.246669522 -0400
430364
+++ xmlsec1-1.2.20-CVE-2017-1000061/apps/xmlsec.c	2017-07-18 12:21:59.554749331 -0400
430364
@@ -528,6 +528,19 @@
430364
     NULL
430364
 };    
430364
 
430364
+static xmlSecAppCmdLineParam xxeParam = { 
430364
+    xmlSecAppCmdLineTopicAll,
430364
+    "--xxe",
430364
+    NULL,   
430364
+    "--xxe"
430364
+    "\n\tenable External Entity resolution."
430364
+    "\n\tWARNING: this may allow the reading of arbitrary files and URLs,"
430364
+    "\n\tcontrolled by the input XML document.  Use with caution!",
430364
+    xmlSecAppCmdLineParamTypeFlag,
430364
+    xmlSecAppCmdLineParamFlagNone,
430364
+    NULL
430364
+};    
430364
+
430364
 
430364
 /****************************************************************
430364
  *
430364
@@ -904,6 +917,7 @@
430364
     &disableErrorMsgsParam,
430364
     &printCryptoErrorMsgsParam,
430364
     &helpParam,
430364
+    &xxeParam,
430364
         
430364
     /* MUST be the last one */
430364
     NULL
430364
@@ -1087,6 +1101,11 @@
430364
         goto fail;
430364
     }
430364
     
430364
+    /* enable XXE? */
430364
+    if(xmlSecAppCmdLineParamIsSet(&xxeParam)) {
430364
+        xmlSecSetExternalEntityLoader( NULL );     // reset to libxml2's default handler
430364
+    }
430364
+
430364
     /* get the "repeats" number */
430364
     if(xmlSecAppCmdLineParamIsSet(&repeatParam) && 
430364
        (xmlSecAppCmdLineParamGetInt(&repeatParam, 1) > 0)) {
430364
diff -uPr xmlsec1-1.2.20/include/xmlsec/xmlsec.h xmlsec1-1.2.20-CVE-2017-1000061/include/xmlsec/xmlsec.h
430364
--- xmlsec1-1.2.20/include/xmlsec/xmlsec.h	2014-05-27 14:29:01.000000000 -0400
430364
+++ xmlsec1-1.2.20-CVE-2017-1000061/include/xmlsec/xmlsec.h	2017-07-18 12:21:59.555749324 -0400
430364
@@ -89,6 +89,7 @@
430364
 
430364
 XMLSEC_EXPORT int       xmlSecInit              (void);
430364
 XMLSEC_EXPORT int       xmlSecShutdown          (void);
430364
+XMLSEC_EXPORT void      xmlSecSetExternalEntityLoader (xmlExternalEntityLoader);
430364
 
430364
 
430364
 
430364
diff -uPr xmlsec1-1.2.20/src/xmlsec.c xmlsec1-1.2.20-CVE-2017-1000061/src/xmlsec.c
430364
--- xmlsec1-1.2.20/src/xmlsec.c	2014-05-27 14:29:01.000000000 -0400
430364
+++ xmlsec1-1.2.20-CVE-2017-1000061/src/xmlsec.c	2017-08-09 12:44:03.386416274 -0400
430364
@@ -25,6 +25,56 @@
430364
 #include <xmlsec/errors.h>
430364
 
430364
 /**
430364
+ * Custom external entity handler, denies all files except the initial
430364
+ * document we're parsing (input_id == 1)
430364
+ */
430364
+/* default external entity loader, pointer saved during xmlInit */
430364
+static xmlExternalEntityLoader
430364
+xmlSecDefaultExternalEntityLoader = NULL;
430364
+
430364
+/*
430364
+ * xmlSecNoXxeExternalEntityLoader:
430364
+ * @URL:        the URL for the entity to load
430364
+ * @ID:         public ID for the entity to load
430364
+ * @ctxt:       XML parser context, or NULL
430364
+ *
430364
+ * See libxml2's xmlLoadExternalEntity and xmlNoNetExternalEntityLoader.
430364
+ * This function prevents any external (file or network) entities from being loaded.
430364
+ */
430364
+static xmlParserInputPtr
430364
+xmlSecNoXxeExternalEntityLoader(const char *URL, const char *ID,
430364
+                          xmlParserCtxtPtr ctxt) {
430364
+    if (ctxt == NULL) {
430364
+        return(NULL);
430364
+    }
430364
+    if (ctxt->input_id == 1) {
430364
+        return xmlSecDefaultExternalEntityLoader((const char *) URL, ID, ctxt);
430364
+    }
430364
+    xmlSecError(XMLSEC_ERRORS_HERE,
430364
+                NULL,
430364
+                "xmlSecNoXxeExternalEntityLoader",
430364
+                XMLSEC_ERRORS_R_XML_FAILED,
430364
+                "illegal external entity='%s'", xmlSecErrorsSafeString(URL));
430364
+    return(NULL);
430364
+}
430364
+
430364
+/*
430364
+ * xmlSecSetExternalEntityLoader:
430364
+ * @entityLoader:       the new entity resolver function, or NULL to restore 
430364
+ *                      libxml2's default handler
430364
+ *
430364
+ * Wrapper for xmlSetExternalEntityLoader.
430364
+ */
430364
+void
430364
+xmlSecSetExternalEntityLoader(xmlExternalEntityLoader entityLoader) {
430364
+    if (entityLoader == NULL) {
430364
+        entityLoader = xmlSecDefaultExternalEntityLoader;
430364
+    }
430364
+    xmlSetExternalEntityLoader(entityLoader);
430364
+}
430364
+
430364
+
430364
+/**
430364
  * xmlSecInit:
430364
  *
430364
  * Initializes XML Security Library. The depended libraries
430364
@@ -85,6 +135,12 @@
430364
     }
430364
 #endif /* XMLSEC_NO_XKMS */
430364
 
430364
+    /* initialise safe external entity loader */
430364
+    if (!xmlSecDefaultExternalEntityLoader) {
430364
+        xmlSecDefaultExternalEntityLoader = xmlGetExternalEntityLoader();
430364
+    }
430364
+    xmlSetExternalEntityLoader(xmlSecNoXxeExternalEntityLoader);
430364
+
430364
     /* we use rand() function to generate id attributes */
430364
     srand(time(NULL));
430364
     return(0);
430364
@@ -182,4 +238,3 @@
430364
     return(1);
430364
 }
430364
 
430364
-