From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10643 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] use dynamic buffer for getmntent Date: Thu, 20 Oct 2016 01:25:27 -0400 Message-ID: <20161020052527.GL19318@brightrain.aerifal.cx> References: <20160908170731.30407-1-ncopa@alpinelinux.org> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1476941159 6425 195.159.176.226 (20 Oct 2016 05:25:59 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 20 Oct 2016 05:25:59 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-10656-gllmg-musl=m.gmane.org@lists.openwall.com Thu Oct 20 07:25:55 2016 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 1bx5rI-0007bV-VC for gllmg-musl@m.gmane.org; Thu, 20 Oct 2016 07:25:41 +0200 Original-Received: (qmail 30287 invoked by uid 550); 20 Oct 2016 05:25:40 -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 30266 invoked from network); 20 Oct 2016 05:25:39 -0000 Content-Disposition: inline In-Reply-To: <20160908170731.30407-1-ncopa@alpinelinux.org> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:10643 Archived-At: On Thu, Sep 08, 2016 at 07:07:31PM +0200, Natanael Copa wrote: > overlayfs may have fairly long lines so we use getline to allocate a > buffer dynamically. The buffer will be allocated on first use, expand as > needed, but will never be free'ed. > > Downstream bug: http://bugs.alpinelinux.org/issues/5703 > > Signed-off-by: Natanael Copa Thanks! Sorry for the delay. Committed with minor style fixes: > --- > src/misc/mntent.c | 16 ++++++++++++---- > 1 file changed, 12 insertions(+), 4 deletions(-) > > diff --git a/src/misc/mntent.c b/src/misc/mntent.c > index a16d652..722a030 100644 > --- a/src/misc/mntent.c > +++ b/src/misc/mntent.c > @@ -3,6 +3,11 @@ > #include > #include > > +static char *internal_buf = NULL; > +static size_t internal_bufsize = 0; Explicit zero initialization is not needed, and current/going-forward style in musl is not to use the NULL macro but rather 0 or (T*)0 if needed (e.g. for variadic args). > + > +#define SENTINEL (char *)&internal_buf > + > FILE *setmntent(const char *name, const char *mode) > { > return fopen(name, mode); > @@ -16,13 +21,17 @@ int endmntent(FILE *f) > > struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen) > { > - int cnt, n[8]; > + int cnt, n[8], use_internal = (linebuf == SENTINEL); > > mnt->mnt_freq = 0; > mnt->mnt_passno = 0; > > do { > - fgets(linebuf, buflen, f); > + if (use_internal) { > + getline(&internal_buf, &internal_bufsize, f); > + linebuf = internal_buf; > + } else > + fgets(linebuf, buflen, f); If if clause uses braces, else should too. There might be some existing violations but I'm trying to make this consistent. Rich