From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12784 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Some questions Date: Mon, 30 Apr 2018 11:31:12 -0400 Message-ID: <20180430153112.GL1392@brightrain.aerifal.cx> References: <20180430031653.GI1392@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="ZoaI/ZTpAVc4A5k6" X-Trace: blaine.gmane.org 1525102163 27884 195.159.176.226 (30 Apr 2018 15:29:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 30 Apr 2018 15:29:23 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) Cc: musl@lists.openwall.com To: Patrick Oppenlander Original-X-From: musl-return-12800-gllmg-musl=m.gmane.org@lists.openwall.com Mon Apr 30 17:29:19 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1fDAjt-00077y-8e for gllmg-musl@m.gmane.org; Mon, 30 Apr 2018 17:29:17 +0200 Original-Received: (qmail 16234 invoked by uid 550); 30 Apr 2018 15:31:25 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 16213 invoked from network); 30 Apr 2018 15:31:25 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:12784 Archived-At: --ZoaI/ZTpAVc4A5k6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Apr 30, 2018 at 03:29:39PM +1000, Patrick Oppenlander wrote: > On Mon, Apr 30, 2018 at 1:16 PM, Rich Felker wrote: > > On Mon, Apr 30, 2018 at 12:52:06PM +1000, Patrick Oppenlander wrote: > >> - getcwd returned buffer size can be incorrect. If you call > >> getcwd(NULL, 1234) the returned buffer is sized to match the path > >> length but should be 1234 to be compatible with the glibc extension. > > > > I'll look at this. It seems like a worse behavior for most callers, > > but maybe it should match. > > Actually, my biggest issue with getcwd is that it allocates a PATH_MAX > sized buffer on the stack. That's painful on deeply embedded stuff. That's unrelated, and could/should be fixed by the attached patch I think. Rich --ZoaI/ZTpAVc4A5k6 Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="getcwd-stack.diff" diff --git a/src/unistd/getcwd.c b/src/unistd/getcwd.c index 103fbbb..f407ffe 100644 --- a/src/unistd/getcwd.c +++ b/src/unistd/getcwd.c @@ -6,10 +6,10 @@ char *getcwd(char *buf, size_t size) { - char tmp[PATH_MAX]; + char tmp[buf ? 1 : PATH_MAX]; if (!buf) { buf = tmp; - size = PATH_MAX; + size = sizeof tmp; } else if (!size) { errno = EINVAL; return 0; --ZoaI/ZTpAVc4A5k6--