Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJUqL-0004dW-EC for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Nov 2017 01:37:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eJUqK-0001GQ-V2 for pgsql-bugs@arkaria.postgresql.org; Tue, 28 Nov 2017 01:37:48 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eJUqK-0001GG-MO for pgsql-bugs@lists.postgresql.org; Tue, 28 Nov 2017 01:37:48 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eJUqI-0006Wz-9Y for pgsql-bugs@postgresql.org; Tue, 28 Nov 2017 01:37:47 +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 vAS1bGIt022671; Mon, 27 Nov 2017 20:37:16 -0500 From: Tom Lane To: bianpan2016@163.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14931: Unchecked attnum value in ATExecAlterColumnType() In-reply-to: <20171127095339.1464.29304@wrigleys.postgresql.org> References: <20171127095339.1464.29304@wrigleys.postgresql.org> Comments: In-reply-to bianpan2016@163.com message dated "Mon, 27 Nov 2017 09:53:39 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22669.1511833036.1@sss.pgh.pa.us> Date: Mon, 27 Nov 2017 20:37:16 -0500 Message-ID: <22670.1511833036@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk bianpan2016@163.com writes: > File: src/backend/commands/tablecmds.c > Function: ATExecAlterColumnType > Line: 8986 > The value of field attTup->attnum may be zero or even negative. However, in > function ATExecAlterColumnType(), its value is incorrectly assumed to be > larger than or equal to 1. In an exceptional case, it may lead to a buffer > overflow bug (see lines 8989 and 8990). I do not think this is a real problem, because ATPrepAlterColumnType has already checked for attnum <= 0 (at line 8826, in HEAD). If ATExecAlterColumnType can't assume that ATPrepAlterColumnType has already been run, we have more problems than this. > I also collect a function (i.e. ATExecDropNotNull) in the same file as an > example, shown as follows: The division of labor between Prep and Exec functions isn't very uniform in this file. That may not be a great thing stylistically, but if we decide it's something to improve, it'd have to be done holistically not one point at a time. regards, tom lane