Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g1VSO-0004h5-MC for pgsql-hackers@arkaria.postgresql.org; Sun, 16 Sep 2018 11:43:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g1VSL-0000kw-5P for pgsql-hackers@arkaria.postgresql.org; Sun, 16 Sep 2018 11:43:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g1VSK-0000kp-QW for pgsql-hackers@lists.postgresql.org; Sun, 16 Sep 2018 11:43:12 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g1VSH-0007QS-8D for pgsql-hackers@postgresql.org; Sun, 16 Sep 2018 11:43:12 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 7BEF421C1F7E for ; Sun, 16 Sep 2018 14:43:07 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.0.103] (unknown [5.79.139.210]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 3F7CD21C1F53 for ; Sun, 16 Sep 2018 14:43:07 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1537098187; bh=VOMMMZbl3yeh19R6PrA6nA2oyOEZiKmpm2+KECsSUY4=; h=From:Subject:To:Date; b=gGkafkbph8wMjMq20fZLDDPcsj+8L2QhhU7pQdPOg1su8llLBpofBSHJCoBTCd5AW 7/auj0trVvjx8HbFzLcQLXri4tbjaQnPbcAVyncVJLRMI6IDFELiGmYodzaV2u2ODe sRMz6KjpvLEd0ydo1Eldo2afHQqhbX2itDdInipM= From: Andrey Lepikhov Subject: Clarification of nodeToString() use cases Organization: Postgres Professional To: PostgreSQL-Dev Message-ID: <3690074f-abd2-56a9-144a-aa5545d7a291@postgrespro.ru> Date: Sun, 16 Sep 2018 16:43:05 +0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------CE20C91B36CFCCE49D4C9C96" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------CE20C91B36CFCCE49D4C9C96 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi, Hackers! In the AQO project (Adaptive Query Optimization) [1] the nodeToString() function is used by the planner to convert an query parse tree into a string to generate a hash value [2]. In PostgreSQL v.11 call nodeToString(parse) segfaulted. The reason is: parse tree node for XMLNAMESPACES clause has null pointer in the case of DEFAULT namespace (the pointer will be initialized at executor on the first call). Function _outValue() uses value->val.str[0] [3] without checking of value->val.str. I want to know, which of next options is correct: 1. Converting a parse tree into string with nodeToString() is illegal operation. We need to add a comment to the description of nodeToString(). 2. We can use nodeToString() for parse tree convertation. In this case we need to check node variable 'value->val.str' to NULL pointer (Now I use this approach, see attachment). [1] https://github.com/postgrespro/aqo [2] hash.c, line 55. [3] outfuncs.c, line 3312. -- Andrey Lepikhov Postgres Professional https://postgrespro.com The Russian Postgres Company --------------CE20C91B36CFCCE49D4C9C96 Content-Type: text/x-patch; name="0001-XML-Bug-fix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-XML-Bug-fix.patch" From 26bfe91a4901b3b342e1b3ed58252ac750773207 Mon Sep 17 00:00:00 2001 From: "Andrey V. Lepikhov" Date: Sun, 16 Sep 2018 08:30:19 +0500 Subject: [PATCH] XML Bug fix --- src/backend/nodes/outfuncs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index 744a8b91b8..20eb033eac 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -3310,7 +3310,7 @@ _outValue(StringInfo str, const Value *value) * but we don't want it to do anything with an empty string. */ appendStringInfoChar(str, '"'); - if (value->val.str[0] != '\0') + if ((value->val.str) && (value->val.str[0] != '\0')) outToken(str, value->val.str); appendStringInfoChar(str, '"'); break; -- 2.17.1 --------------CE20C91B36CFCCE49D4C9C96--