Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jLa2t-00061a-RA for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Apr 2020 22:16:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jLa2s-0003hK-NJ for pgsql-hackers@arkaria.postgresql.org; Mon, 06 Apr 2020 22:16:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jLa2s-0003hD-Ge for pgsql-hackers@lists.postgresql.org; Mon, 06 Apr 2020 22:16:42 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jLa2q-00044B-CZ for pgsql-hackers@postgresql.org; Mon, 06 Apr 2020 22:16:41 +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 036MGc3h025258; Mon, 6 Apr 2020 18:16:38 -0400 From: Tom Lane To: David Zhang cc: pgsql-hackers@postgresql.org Subject: Re: ERROR: invalid input syntax for type circle In-reply-to: <332c47fa-d951-7574-b5cc-a8f7f7201202@highgo.ca> References: <332c47fa-d951-7574-b5cc-a8f7f7201202@highgo.ca> Comments: In-reply-to David Zhang message dated "Mon, 06 Apr 2020 14:12:38 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <25256.1586211397.1@sss.pgh.pa.us> Date: Mon, 06 Apr 2020 18:16:37 -0400 Message-ID: <25257.1586211397@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk David Zhang writes: > I got an error when I was trying to insert a circle using the syntax > (the 3rd one) specified in the latest document. Hm. Presumably, that has never worked, and we've had no complaints to date. I'm halfway inclined to treat it as a documentation bug and remove the claim that it works. > The patch based on tag "REL_12_2" is attached. This patch looks extremely dangerous to me, because it'll allow "s" to get incremented past the ending nul character ... and then the code will proceed to keep scanning, which at best is useless and at worst will end in a core dump. What actually looks wrong to me in this code is the initial bit if ((*s == LDELIM_C) || (*s == LDELIM)) { depth++; cp = (s + 1); while (isspace((unsigned char) *cp)) cp++; if (*cp == LDELIM) s = cp; } If the first test triggers but it doesn't then find a following paren, then it's incremented depth without moving s, which seems certain to end badly. Perhaps the correct fix is like if (*s == LDELIM_C) depth++, s++; else if (*s == LDELIM) { /* If there are two left parens, consume the first one */ cp = (s + 1); while (isspace((unsigned char) *cp)) cp++; if (*cp == LDELIM) depth++, s = cp; } regards, tom lane