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 1p7g4d-0003bh-Bq for pgsql-bugs@arkaria.postgresql.org; Tue, 20 Dec 2022 17:06:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p7g4b-0003l3-Os for pgsql-bugs@arkaria.postgresql.org; Tue, 20 Dec 2022 17:06:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p7g4b-0003ku-HC for pgsql-bugs@lists.postgresql.org; Tue, 20 Dec 2022 17:06:37 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p7g4Z-0003kP-Ai for pgsql-bugs@lists.postgresql.org; Tue, 20 Dec 2022 17:06:37 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 2BKH6VuD1181727; Tue, 20 Dec 2022 12:06:31 -0500 From: Tom Lane To: Robins Tharakan cc: John Naylor , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17725: Sefault when seg_in() called with a large argument In-reply-to: <1180064.1671555286@sss.pgh.pa.us> References: <17725-0a09313b67fbe86e@postgresql.org> <1180064.1671555286@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Tue, 20 Dec 2022 11:54:46 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1181725.1671555991.1@sss.pgh.pa.us> Date: Tue, 20 Dec 2022 12:06:31 -0500 Message-ID: <1181726.1671555991@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > I don't see a crash either, but I can't help observing that this > input leads to a "seg" struct with "-46" significant digits: > ... > So we're invoking sprintf with a fairly insane precision spec: Actually, it looks like sprintf is not the problem. This is: (gdb) 984 buf[10 + n] = '\0'; (gdb) p n $9 = -46 So first off, we're stomping on something we shouldn't, and secondly we're failing to nul-terminate buf[], which easily explains your observed crash at the strcpy a little further down. On most platforms strcpy would find a nul byte not too much further on, which might prevent the worst sorts of damage, but this is still very ugly. regards, tom lane