From 44330f908de05881d1dcf5fe51171526377a70dc Mon Sep 17 00:00:00 2001 From: dogsheng <960055655@qq.com> Date: Wed, 25 Dec 2019 16:10:32 +0800 Subject: [PATCH] Package init --- ...arseMemory-memory-leak-issue-199-202.patch | 129 ++++++++++++++++++ xmlsec1.spec | 13 +- 2 files changed, 135 insertions(+), 7 deletions(-) create mode 100644 fix-xmlSecParseMemory-memory-leak-issue-199-202.patch diff --git a/fix-xmlSecParseMemory-memory-leak-issue-199-202.patch b/fix-xmlSecParseMemory-memory-leak-issue-199-202.patch new file mode 100644 index 0000000..f353af4 --- /dev/null +++ b/fix-xmlSecParseMemory-memory-leak-issue-199-202.patch @@ -0,0 +1,129 @@ +From 477d91c30f0ba433a35e3d6bcf69ea5ef3f75a5f Mon Sep 17 00:00:00 2001 +From: lsh123 +Date: Mon, 2 Jul 2018 16:48:09 -0700 +Subject: [PATCH] fix xmlSecParseMemory() memory leak (issue #199) (#202) + +--- + src/parser.c | 35 +++++++++++++++++++++++++++++++---- + src/xslt.c | 4 ++++ + 2 files changed, 35 insertions(+), 4 deletions(-) + +diff --git a/src/parser.c b/src/parser.c +index e18b2d3..ddeb590 100644 +--- a/src/parser.c ++++ b/src/parser.c +@@ -132,6 +132,10 @@ xmlSecParserFinalize(xmlSecTransformPtr transform) { + xmlSecAssert(ctx != NULL); + + if(ctx->parserCtx != NULL) { ++ if(ctx->parserCtx->myDoc != NULL) { ++ xmlFreeDoc(ctx->parserCtx->myDoc); ++ ctx->parserCtx->myDoc = NULL; ++ } + xmlFreeParserCtxt(ctx->parserCtx); + } + memset(ctx, 0, sizeof(xmlSecParserCtx)); +@@ -294,6 +298,10 @@ xmlSecParserPopXml(xmlSecTransformPtr transform, xmlSecNodeSetPtr* nodes, + xmlSecXmlParserError("inputPush", ctxt, + xmlSecTransformGetName(transform)); + xmlFreeInputStream(input); ++ if(ctxt->myDoc != NULL) { ++ xmlFreeDoc(ctxt->myDoc); ++ ctxt->myDoc = NULL; ++ } + xmlFreeParserCtxt(ctxt); + return(-1); + } +@@ -404,20 +412,27 @@ xmlSecParseFile(const char *filename) { + xmlSecXmlParserError2("xmlParseDocument", ctxt, NULL, + "filename=%s", + xmlSecErrorsSafeString(filename)); ++ if(ctxt->myDoc != NULL) { ++ xmlFreeDoc(ctxt->myDoc); ++ ctxt->myDoc = NULL; ++ } + xmlFreeParserCtxt(ctxt); + return(NULL); + } + + if(!ctxt->wellFormed) { + xmlSecInternalError("document is not well formed", NULL); +- xmlFreeDoc(ctxt->myDoc); +- ctxt->myDoc = NULL; ++ if(ctxt->myDoc != NULL) { ++ xmlFreeDoc(ctxt->myDoc); ++ ctxt->myDoc = NULL; ++ } + xmlFreeParserCtxt(ctxt); + return(NULL); + } + + /* done */ + res = ctxt->myDoc; ++ ctxt->myDoc = NULL; + xmlFreeParserCtxt(ctxt); + return(res); + +@@ -495,9 +510,14 @@ xmlSecParseMemoryExt(const xmlSecByte *prefix, xmlSecSize prefixSize, + goto done; + } + doc = ctxt->myDoc; ++ ctxt->myDoc = NULL; + + done: + if(ctxt != NULL) { ++ if(ctxt->myDoc != NULL) { ++ xmlFreeDoc(ctxt->myDoc); ++ ctxt->myDoc = NULL; ++ } + xmlFreeParserCtxt(ctxt); + } + return(doc); +@@ -536,20 +556,27 @@ xmlSecParseMemory(const xmlSecByte *buffer, xmlSecSize size, int recovery) { + ret = xmlParseDocument(ctxt); + if(ret < 0) { + xmlSecXmlParserError("xmlParseDocument", ctxt, NULL); ++ if(ctxt->myDoc != NULL) { ++ xmlFreeDoc(ctxt->myDoc); ++ ctxt->myDoc = NULL; ++ } + xmlFreeParserCtxt(ctxt); + return(NULL); + } + + if(!(ctxt->wellFormed) && !recovery) { + xmlSecInternalError("document is not well formed", NULL); +- xmlFreeDoc(ctxt->myDoc); +- ctxt->myDoc = NULL; ++ if(ctxt->myDoc != NULL) { ++ xmlFreeDoc(ctxt->myDoc); ++ ctxt->myDoc = NULL; ++ } + xmlFreeParserCtxt(ctxt); + return(NULL); + } + + /* done */ + res = ctxt->myDoc; ++ ctxt->myDoc = NULL; + xmlFreeParserCtxt(ctxt); + return(res); + } +diff --git a/src/xslt.c b/src/xslt.c +index 2f43e41..1822cdc 100644 +--- a/src/xslt.c ++++ b/src/xslt.c +@@ -219,6 +219,10 @@ xmlSecXsltFinalize(xmlSecTransformPtr transform) { + xsltFreeStylesheet(ctx->xslt); + } + if(ctx->parserCtx != NULL) { ++ if(ctx->parserCtx->myDoc != NULL) { ++ xmlFreeDoc(ctx->parserCtx->myDoc); ++ ctx->parserCtx->myDoc = NULL; ++ } + xmlFreeParserCtxt(ctx->parserCtx); + } + memset(ctx, 0, sizeof(xmlSecXsltCtx)); +-- +1.7.12.4 + diff --git a/xmlsec1.spec b/xmlsec1.spec index 2b71691..954f65f 100644 --- a/xmlsec1.spec +++ b/xmlsec1.spec @@ -1,6 +1,6 @@ Name: xmlsec1 Version: 1.2.25 -Release: 6 +Release: 7 Summary: A C library based on LibXML2 License: MIT URL: http://www.aleksey.com/xmlsec @@ -8,6 +8,7 @@ Source0: http://www.aleksey.com/xmlsec/download/xmlsec1-%{version}.tar # Path1 get from fedora Patch1: xmlSecOpenSSLX509DataNodeRead-error.patch +Patch6000: fix-xmlSecParseMemory-memory-leak-issue-199-202.patch BuildRequires: pkgconfig(libxml-2.0) >= 2.8.0 pkgconfig(libxslt) >= 1.0.20 pkgconfig(openssl) >= 1.0.0 BuildRequires: pkgconfig(nss) >= 3.11.1 pkgconfig(nspr) >= 4.4.1 libgcrypt-devel >= 1.4.0 libtool @@ -30,12 +31,7 @@ Obsoletes: xmlsec1-openssl-devel xmlsec1-gcrypt-devel xmlsec1-gnutls-dev %description devel This package contains the libraries and develop content for the xmlsec library. -%package help -Summary: Help documentation related to xmlsec library -Buildarch: noarch - -%description help -This package includes help documentation and manuals related to xmlsec library. +%package_help %prep %autosetup -p1 @@ -83,5 +79,8 @@ mv %{buildroot}%{_docdir}/xmlsec1/* __tmp_doc %{_mandir}/man1/*.1.* %changelog +* Mon Dec 16 2019 openEuler Buildteam - 1.2.25-7 +- Fix xmlSecParseMemory() memory leak + * Thu Sep 19 2019 dongjian - 1.2.25-6 - Package init