Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 6000BB5D90E for ; Mon, 23 May 2011 11:33:26 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 40516-10 for ; Mon, 23 May 2011 14:33:19 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 055A1B5D801 for ; Mon, 23 May 2011 11:33:18 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p4NEXB4k012737; Mon, 23 May 2011 10:33:11 -0400 (EDT) To: Dean Rasheed cc: pgsql-bugs@postgresql.org Subject: Re: Seg-fault in format(text) In-reply-to: References: Comments: In-reply-to Dean Rasheed message dated "Mon, 23 May 2011 15:02:51 +0100" Date: Mon, 23 May 2011 10:33:11 -0400 Message-ID: <12736.1306161191@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.909 tagged_above=-5 required=5 tests=BAYES_00=-1.9, LOTS_OF_MONEY=0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201105/154 X-Sequence-Number: 30293 Dean Rasheed writes: > Testing 9.1beta: > select format('Hello %s, %2147483648$s', 'World'); > server closed the connection unexpectedly Yeah, same here. > do > { > /* Treat overflowing arg position as unterminated. */ > ! if (arg > INT_MAX / 10) > break; > arg = arg * 10 + (*cp - '0'); > ++cp; > --- 3837,3843 ---- > do > { > /* Treat overflowing arg position as unterminated. */ > ! if (arg >= INT_MAX / 10) > break; > arg = arg * 10 + (*cp - '0'); > ++cp; Not sure I trust this fix to catch all cases --- seems like the addition could still overflow. It'd probably be better if we made this code look like the overflow test in scanint8: int64 newtmp = tmp * 10 + (*ptr++ - '0'); if ((newtmp / 10) != tmp) /* overflow? */ regards, tom lane