Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xczhm-0000Ds-IG for pgsql-bugs@arkaria.postgresql.org; Sat, 11 Oct 2014 16:39:42 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xczhl-000325-4q for pgsql-bugs@arkaria.postgresql.org; Sat, 11 Oct 2014 16:39:41 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xczhk-00031q-4E for pgsql-bugs@postgresql.org; Sat, 11 Oct 2014 16:39:40 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xczhg-0008SU-Ag for pgsql-bugs@postgresql.org; Sat, 11 Oct 2014 16:39:38 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s9BGdS3n026325; Sat, 11 Oct 2014 12:39:28 -0400 From: Tom Lane To: Mark Simonetti cc: pgsql-bugs@postgresql.org Subject: Re: pgxml bug (crash) in xslt_proc.c In-reply-to: <5439523F.8030500@opalsoftware.co.uk> References: <543920CE.9090505@opalsoftware.co.uk> <24870.1413041595@sss.pgh.pa.us> <5439523F.8030500@opalsoftware.co.uk> Comments: In-reply-to Mark Simonetti message dated "Sat, 11 Oct 2014 16:52:31 +0100" Date: Sat, 11 Oct 2014 12:39:28 -0400 Message-ID: <26324.1413045568@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) 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 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 ... > 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. 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? regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs