From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4114 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] getcwd: Set errno to EINVAL when size == 0 Date: Mon, 7 Oct 2013 13:25:47 -0400 Message-ID: <20131007172547.GD20515@brightrain.aerifal.cx> References: <1381126104-24579-1-git-send-email-mforney@mforney.org> <1381127894.6107.59.camel@eris.loria.fr> <20131007162157.GC20515@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1381166757 14258 80.91.229.3 (7 Oct 2013 17:25:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 7 Oct 2013 17:25:57 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4118-gllmg-musl=m.gmane.org@lists.openwall.com Mon Oct 07 19:26:00 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1VTEZE-0008Ix-0O for gllmg-musl@plane.gmane.org; Mon, 07 Oct 2013 19:26:00 +0200 Original-Received: (qmail 19709 invoked by uid 550); 7 Oct 2013 17:25:59 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 19701 invoked from network); 7 Oct 2013 17:25:59 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:4114 Archived-At: On Mon, Oct 07, 2013 at 06:15:24PM +0100, Justin Cormack wrote: > > If it is deemed important to support this weird GNU behavior, I think > > it would be beneficial to always allocate MAX(strlen(buf)+1,size) > > rather than just size, to avoid spurious failure. > > > > Opinions from anyone else? > > I can't see any way in which the user could detect (in the malloc > case) that you always allocated PATH_MAX not the provided size, so you > may as well just do that if they insist on using this stupid interface > in the first place. Well if the caller requested a size of 2*PATH_MAX and you only allocated PATH_MAX, this could result in the program invoking UB at a later time by trying to use the additional space (for whatever purpose). And conversely, the application _could_ detect allocation of too much space, if it expected the call to fail with an error but instead the call succeeded, or if it simply expected that, on successful return, strlen(getcwd(0, size))