Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20131007172547.GD20515@brightrain.aerifal.cx>
Date: Mon, 7 Oct 2013 13:25:47 -0400
From: Rich Felker <dalias@...ifal.cx>
To: musl@...ts.openwall.com
Subject: Re: [PATCH] getcwd: Set errno to EINVAL when size == 0

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))<size is true.

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.