Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bemdy-0002FS-P4 for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Aug 2016 17:16:14 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bemdx-0000Vn-Cz for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Aug 2016 17:16:13 +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 1bemdw-0000Vg-Hh for pgsql-hackers@postgresql.org; Tue, 30 Aug 2016 17:16:12 +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.84_2) (envelope-from ) id 1bemdu-0008Rz-7z for pgsql-hackers@postgresql.org; Tue, 30 Aug 2016 17:16:11 +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 u7UHFqKC020339; Tue, 30 Aug 2016 13:15:53 -0400 From: Tom Lane To: Michael Paquier cc: Aleksander Alekseev , Heikki Linnakangas , PostgreSQL mailing lists Subject: Re: Missing checks when malloc returns NULL... In-reply-to: References: <7978.1466516782@sss.pgh.pa.us> <20160829130513.GA8340@e733> <20160829141315.GB8340@e733> Comments: In-reply-to Michael Paquier message dated "Tue, 30 Aug 2016 15:15:51 +0900" Date: Tue, 30 Aug 2016 13:15:52 -0400 Message-ID: <20338.1472577352@sss.pgh.pa.us> X-Pg-Spam-Score: -3.4 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Michael Paquier writes: > And with an actual patch things are better. Working through this patch, it suddenly strikes me that we are going about fixing the callers of simple_prompt the wrong way. The existing definition with returning a malloc'd string creates a hazard of malloc failure, and it *also* creates a hazard of not remembering to free the result. Moreover, there are almost no callers that want a max result longer than ~100 bytes. Seems like it would be a whole lot easier all around to make the caller supply the buffer, ie typical call would be roughly char buf[100]; simple_prompt("Password: ", buf, sizeof(buf), false); Callers that want to deal with a malloc'd buffer (all one of them, looks like) can do it themselves, for basically only one more line than is needed now. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers