Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id BC044B5DBD3 for ; Mon, 23 May 2011 12:11:04 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 73407-04 for ; Mon, 23 May 2011 15:10:57 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og104.obsmtp.com (exprod7og104.obsmtp.com [64.18.2.161]) by mail.postgresql.org (Postfix) with ESMTP id E12C3B5DBE0 for ; Mon, 23 May 2011 12:10:56 -0300 (ADT) Received: from mail-ey0-f177.google.com ([209.85.215.177]) (using TLSv1) by exprod7ob104.postini.com ([64.18.6.12]) with SMTP ID DSNKTdp4/0nghV6lWa/TNEgkePr2ZkGGJPK+@postini.com; Mon, 23 May 2011 08:10:57 PDT Received: by eyh6 with SMTP id 6so2158659eyh.8 for ; Mon, 23 May 2011 08:10:54 -0700 (PDT) Received: by 10.213.98.195 with SMTP id r3mr1130794ebn.149.1306163454286; Mon, 23 May 2011 08:10:54 -0700 (PDT) Received: from [192.168.1.183] (dsl-hkibrasgw2-ff7ac300-240.dhcp.inet.fi [88.195.122.240]) by mx.google.com with ESMTPS id y2sm4698638eeh.25.2011.05.23.08.10.52 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 23 May 2011 08:10:53 -0700 (PDT) Message-ID: <4DDA78FB.2020103@enterprisedb.com> Date: Mon, 23 May 2011 18:10:51 +0300 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fi-FI; rv:1.9.1.16) Gecko/20110505 Icedove/3.0.11 MIME-Version: 1.0 To: Tom Lane CC: Dean Rasheed , pgsql-bugs@postgresql.org Subject: Re: Seg-fault in format(text) References: <12736.1306161191@sss.pgh.pa.us> In-Reply-To: <12736.1306161191@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201105/155 X-Sequence-Number: 30294 On 23.05.2011 17:33, Tom Lane wrote: > 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? */ It might be good to replace the loop altogether with strtoul() here, for readability purposes if nothing else. I also note that there's no overflow check in plain "%s" case which does "++arg". It seems impossible to cause that overflow, because a function can't have more than 100 arguments, but it doesn't make me feel very comfortable. It's actually possible to pass more than 100 arguments using the VARIADIC keyword, along the lines of: CREATE FUNCTION my_concat(variadic text[]) RETURNS text LANGUAGE SQL AS $$ SELECT array_to_string($1,''); $$; SELECT my_concat(VARIADIC (SELECT array_agg(a::text) FROM generate_series(1,1000) a)); However, built-in concat and text_format functions don't seem to behave that way: postgres=# SELECT my_concat(VARIADIC (SELECT array_agg(a::text) FROM generate_series(1,10) a)); my_concat ------------- 12345678910 (1 row) postgres=# SELECT concat(VARIADIC (SELECT array_agg(a::text) FROM generate_series(1,10) a)); concat ------------------------ {1,2,3,4,5,6,7,8,9,10} (1 row) I'm not sure what's going on here, something funny with the fact that those take an 'any' argument, I guess. It's a stretch that we'd ever support two billion arguments in any form, but an explicit check for "arg < 0" would make me feel better. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com