Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XdLGi-0007Yu-Q5 for pgsql-bugs@arkaria.postgresql.org; Sun, 12 Oct 2014 15:41:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XdLGh-0006vn-6v for pgsql-bugs@arkaria.postgresql.org; Sun, 12 Oct 2014 15:41:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xd09n-0000Dj-JB for pgsql-bugs@postgresql.org; Sat, 11 Oct 2014 17:08:39 +0000 Received: from smarthost01c.mail.zen.net.uk ([212.23.1.5]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xd09k-0001ZP-H5 for pgsql-bugs@postgresql.org; Sat, 11 Oct 2014 17:08:38 +0000 Received: from [88.96.211.230] (helo=ash.forest) by smarthost01c.mail.zen.net.uk with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1Xd09j-000C1n-AA; Sat, 11 Oct 2014 17:08:35 +0000 Received: from 88-96-211-230.dsl.zen.co.uk ([88.96.211.230] helo=[10.0.0.12]) by ash.forest with esmtpa (Exim 4.80) (envelope-from ) id 1Xd09h-0005XL-MV; Sat, 11 Oct 2014 18:08:34 +0100 Message-ID: <54396413.8070808@opalsoftware.co.uk> Date: Sat, 11 Oct 2014 18:08:35 +0100 From: Mark Simonetti User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Tom Lane CC: pgsql-bugs@postgresql.org Subject: Re: pgxml bug (crash) in xslt_proc.c References: <543920CE.9090505@opalsoftware.co.uk> <24870.1413041595@sss.pgh.pa.us> <5439523F.8030500@opalsoftware.co.uk> <26324.1413045568@sss.pgh.pa.us> In-Reply-To: <26324.1413045568@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -2.9 (--) X-Spam-Report: Spam detection software, running on the system "ash.forest", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: On 11/10/2014 17:39, Tom Lane wrote: > Mark Simonetti writes: >> I hadn't really thought of it as a security issue, it came about from >> just trying to use it normally while developing software for one of my >> clients. At first I found it hard to repeat, but I eventually found a >> query to repeat the problem 100% of the time. Unfortunately the XML I >> used to repeat it is vast and generated from lots of database data so it >> would be hard to submit that as a test case (though I can if it would >> help by capturing the XML data into a file and sending it along with the >> XSLT file). > Well, it would be nice to have a test case ... [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP 0.0 TVD_RCVD_IP TVD_RCVD_IP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Originating-smarthost01c-IP: [88.96.211.230] X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 11/10/2014 17:39, Tom Lane wrote: > Mark Simonetti writes: >> I hadn't really thought of it as a security issue, it came about from >> just trying to use it normally while developing software for one of my >> clients. At first I found it hard to repeat, but I eventually found a >> query to repeat the problem 100% of the time. Unfortunately the XML I >> used to repeat it is vast and generated from lots of database data so it >> would be hard to submit that as a test case (though I can if it would >> help by capturing the XML data into a file and sending it along with the >> XSLT file). > Well, it would be nice to have a test case ... No problem, I will sort something out though it might be tomorrow now. > >> It seems to be to do with the order in which resources are >> freed: >> I changed this (xslt_proc.c, pgxml, postgres 9.3.5, line 167 onwards) : - >> xsltFreeStylesheet(stylesheet); >> xmlFreeDoc(restree); >> xmlFreeDoc(doctree); >> xsltFreeSecurityPrefs(xslt_sec_prefs); >> xsltFreeTransformContext(xslt_ctxt); <== crash here >> To this: >> xsltFreeTransformContext(xslt_ctxt); >> xsltFreeSecurityPrefs(xslt_sec_prefs); >> xsltFreeStylesheet(stylesheet); >> xmlFreeDoc(restree); >> xmlFreeDoc(doctree); >> No more crash. > ... but this seems like a pretty straightforward change: probably the > problem is that the xslt_ctxt has a dangling pointer to the > xslt_sec_prefs, stylesheet, or doctree. Yes I thought the same once I found where the problem was it seemed fairly trivial; finding it wasn't quite so straightforward admittedly! I'm almost certain it is doctree; xslt_sec_prefs is not touched in the transformation context free function and stylesheet is never associated with it (though I suppose it could be indirectly). I'm just glad I found it and can use this build of PostgreSQL for now as the people I'm working for are a rather large client and they want to see it working. This is the great thing about open source though. > > Actually it seems to me the most sensible thing would be to free these > various objects in reverse order of creation, which would mean that it > ought to be > > xmlFreeDoc(restree); > xsltFreeTransformContext(xslt_ctxt); > xsltFreeSecurityPrefs(xslt_sec_prefs); > xsltFreeStylesheet(stylesheet); > xmlFreeDoc(doctree); > > Would you try that on your test case and see if it's OK? Yep no problem, I will try that tomorrow. Regards, Mark. -- -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs